From 73530c6ba369b24c9e19e43a0620128d471c4ac5 Mon Sep 17 00:00:00 2001 From: Leonmmcoset Date: Wed, 4 Feb 2026 20:42:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8B=86=E5=88=86=E4=BB=A3=E7=A0=815?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shell/Commands/Editor/EditCommand.cs | 26 ++++++++++++++++++++++ shell/Commands/Editor/NanoCommand.cs | 26 ++++++++++++++++++++++ shell/Shell.cs | 32 ++-------------------------- 3 files changed, 54 insertions(+), 30 deletions(-) create mode 100644 shell/Commands/Editor/EditCommand.cs create mode 100644 shell/Commands/Editor/NanoCommand.cs diff --git a/shell/Commands/Editor/EditCommand.cs b/shell/Commands/Editor/EditCommand.cs new file mode 100644 index 0000000..065caf7 --- /dev/null +++ b/shell/Commands/Editor/EditCommand.cs @@ -0,0 +1,26 @@ +using System; + +namespace CMLeonOS.Commands.Editor +{ + public static class EditCommand + { + public static void EditFile(string fileName, CMLeonOS.FileSystem fileSystem, Action showError) + { + if (string.IsNullOrEmpty(fileName)) + { + showError("Please specify a file name"); + return; + } + + try + { + var editor = new CMLeonOS.Editor(fileName, fileSystem); + editor.Run(); + } + catch (Exception ex) + { + showError($"Error starting editor: {ex.Message}"); + } + } + } +} diff --git a/shell/Commands/Editor/NanoCommand.cs b/shell/Commands/Editor/NanoCommand.cs new file mode 100644 index 0000000..6d69a33 --- /dev/null +++ b/shell/Commands/Editor/NanoCommand.cs @@ -0,0 +1,26 @@ +using System; + +namespace CMLeonOS.Commands.Editor +{ + public static class NanoCommand + { + public static void NanoFile(string fileName, CMLeonOS.FileSystem fileSystem, CMLeonOS.UserSystem userSystem, Shell shell, Action showError) + { + if (string.IsNullOrEmpty(fileName)) + { + showError("Please specify a file name"); + return; + } + + try + { + var nano = new Nano(fileName, true, fileSystem, userSystem, shell); + nano.Start(); + } + catch (Exception ex) + { + showError($"Error starting nano: {ex.Message}"); + } + } + } +} diff --git a/shell/Shell.cs b/shell/Shell.cs index b14096c..a01f6be 100644 --- a/shell/Shell.cs +++ b/shell/Shell.cs @@ -437,40 +437,12 @@ namespace CMLeonOS public void EditFile(string fileName) { - if (string.IsNullOrEmpty(fileName)) - { - ShowError("Please specify a file name"); - return; - } - - try - { - var editor = new Editor(fileName, fileSystem); - editor.Run(); - } - catch (Exception ex) - { - ShowError($"Error starting editor: {ex.Message}"); - } + Commands.Editor.EditCommand.EditFile(fileName, fileSystem, ShowError); } public void NanoFile(string fileName) { - if (string.IsNullOrEmpty(fileName)) - { - ShowError("Please specify a file name"); - return; - } - - try - { - var nano = new Nano(fileName, true, fileSystem, userSystem, this); - nano.Start(); - } - catch (Exception ex) - { - ShowError($"Error starting nano: {ex.Message}"); - } + Commands.Editor.NanoCommand.NanoFile(fileName, fileSystem, userSystem, this, ShowError); } public void DiffFiles(string args)