diff --git a/MinecraftClient/ClassicConsoleBackend.cs b/MinecraftClient/ClassicConsoleBackend.cs index ac4912c9..02712459 100644 --- a/MinecraftClient/ClassicConsoleBackend.cs +++ b/MinecraftClient/ClassicConsoleBackend.cs @@ -63,6 +63,12 @@ namespace MinecraftClient ConsoleInteractive.ConsoleReader.ClearBuffer(); } + public void ClearScreen() + { + Console.Clear(); + ConsoleInteractive.ConsoleSuggestion.ClearSuggestions(); + } + public void SetInputVisible(bool visible) { ConsoleInteractive.ConsoleReader.SetInputVisible(visible); diff --git a/MinecraftClient/Commands/ClearConsole.cs b/MinecraftClient/Commands/ClearConsole.cs new file mode 100644 index 00000000..68ff58cc --- /dev/null +++ b/MinecraftClient/Commands/ClearConsole.cs @@ -0,0 +1,45 @@ +using Brigadier.NET; +using Brigadier.NET.Builder; +using MinecraftClient.CommandHandler; + +namespace MinecraftClient.Commands +{ + public class ClearConsole : Command + { + public override string CmdName => "clear-console"; + public override string CmdUsage => "clear-console"; + public override string CmdDesc => Translations.cmd_clear_console_desc; + + public override void RegisterCommand(CommandDispatcher dispatcher) + { + dispatcher.Register(l => l.Literal("help") + .Then(l => l.Literal(CmdName) + .Executes(r => GetUsage(r.Source)) + ) + ); + + var clearConsole = dispatcher.Register(l => l.Literal(CmdName) + .Executes(r => Execute(r.Source)) + .Then(l => l.Literal("_help") + .Executes(r => GetUsage(r.Source)) + .Redirect(dispatcher.GetRoot().GetChild("help").GetChild(CmdName))) + ); + + dispatcher.Register(l => l.Literal("cc") + .Executes(r => Execute(r.Source)) + .Redirect(clearConsole) + ); + } + + private int GetUsage(CmdResult result) + { + return result.SetAndReturn(GetCmdDescTranslated()); + } + + private int Execute(CmdResult result) + { + ConsoleIO.ClearConsole(); + return result.SetAndReturn(CmdResult.Status.Done); + } + } +} diff --git a/MinecraftClient/Commands/ConsoleChat.cs b/MinecraftClient/Commands/ConsoleChat.cs new file mode 100644 index 00000000..fd52a6e4 --- /dev/null +++ b/MinecraftClient/Commands/ConsoleChat.cs @@ -0,0 +1,49 @@ +using Brigadier.NET; +using Brigadier.NET.Builder; +using MinecraftClient.CommandHandler; + +namespace MinecraftClient.Commands +{ + public class ConsoleChat : Command + { + public override string CmdName => "console-chat"; + public override string CmdUsage => "console-chat [on|off]"; + public override string CmdDesc => Translations.cmd_console_chat_desc; + + public override void RegisterCommand(CommandDispatcher dispatcher) + { + dispatcher.Register(l => l.Literal("help") + .Then(l => l.Literal(CmdName) + .Executes(r => GetUsage(r.Source)) + ) + ); + + dispatcher.Register(l => l.Literal(CmdName) + .Executes(r => SetChatVisibility(r.Source, null)) + .Then(l => l.Literal("on") + .Executes(r => SetChatVisibility(r.Source, true))) + .Then(l => l.Literal("off") + .Executes(r => SetChatVisibility(r.Source, false))) + .Then(l => l.Literal("_help") + .Executes(r => GetUsage(r.Source)) + .Redirect(dispatcher.GetRoot().GetChild("help").GetChild(CmdName))) + ); + } + + private int GetUsage(CmdResult result) + { + return result.SetAndReturn(GetCmdDescTranslated()); + } + + private int SetChatVisibility(CmdResult result, bool? visible) + { + ConsoleIO.ChatVisible = visible ?? !ConsoleIO.ChatVisible; + + return result.SetAndReturn( + CmdResult.Status.Done, + ConsoleIO.ChatVisible + ? Translations.cmd_console_chat_state_on + : Translations.cmd_console_chat_state_off); + } + } +} diff --git a/MinecraftClient/ConsoleIO.cs b/MinecraftClient/ConsoleIO.cs index 8a77aaee..2c5a168c 100644 --- a/MinecraftClient/ConsoleIO.cs +++ b/MinecraftClient/ConsoleIO.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; using System.Threading; @@ -61,6 +62,11 @@ namespace MinecraftClient /// public static bool EnableTimestamps = false; + /// + /// Determine whether chat lines should be displayed in the console. + /// + public static bool ChatVisible = true; + /// /// Specify a generic log line prefix for WriteLogLine() /// @@ -155,6 +161,17 @@ namespace MinecraftClient } } + /// + /// Write a formatted chat line to the console when chat output is enabled. + /// + public static void WriteChatLineIfVisible(string str, bool acceptnewlines = false, bool? displayTimestamp = null) + { + if (!ChatVisible) + return; + + WriteLineFormatted(str, acceptnewlines, displayTimestamp); + } + /// /// Write a prefixed log line. Prefix is set in LogPrefix. /// @@ -178,6 +195,32 @@ namespace MinecraftClient Backend.ClearInputBuffer(); } + /// + /// Clear the visible console output. + /// + public static void ClearConsole() + { + if (BasicIO || Backend is null) + { + try + { + Console.Clear(); + } + catch (IOException ex) + { + System.Diagnostics.Debug.WriteLine(ex); + } + catch (PlatformNotSupportedException ex) + { + System.Diagnostics.Debug.WriteLine(ex); + } + + return; + } + + Backend.ClearScreen(); + } + #endregion internal static bool AutoCompleteDone = false; diff --git a/MinecraftClient/IConsoleBackend.cs b/MinecraftClient/IConsoleBackend.cs index b4d52ebf..0fd23389 100644 --- a/MinecraftClient/IConsoleBackend.cs +++ b/MinecraftClient/IConsoleBackend.cs @@ -60,6 +60,8 @@ namespace MinecraftClient void ClearInputBuffer(); + void ClearScreen(); + bool DisplayUserInput { get; set; } void SetInputVisible(bool visible); diff --git a/MinecraftClient/Logger/FileLogLogger.cs b/MinecraftClient/Logger/FileLogLogger.cs index a7931202..53fb9a57 100644 --- a/MinecraftClient/Logger/FileLogLogger.cs +++ b/MinecraftClient/Logger/FileLogLogger.cs @@ -72,7 +72,8 @@ namespace MinecraftClient.Logger { if (ShouldDisplay(FilterChannel.Chat, msg)) { - LogAndSave(msg); + ConsoleIO.WriteChatLineIfVisible(msg); + Save(msg); } else Debug("[Logger] One Chat message filtered: " + msg); } diff --git a/MinecraftClient/Logger/FilteredLogger.cs b/MinecraftClient/Logger/FilteredLogger.cs index 09a3596c..6260c373 100644 --- a/MinecraftClient/Logger/FilteredLogger.cs +++ b/MinecraftClient/Logger/FilteredLogger.cs @@ -81,7 +81,7 @@ namespace MinecraftClient.Logger { if (ShouldDisplay(FilterChannel.Chat, msg)) { - Log(msg); + ConsoleIO.WriteChatLineIfVisible(msg); } else Debug("[Logger] One Chat message filtered: " + msg); } diff --git a/MinecraftClient/Resources/ConfigComments/ConfigComments.Designer.cs b/MinecraftClient/Resources/ConfigComments/ConfigComments.Designer.cs index ee4b68ed..fe4b188b 100644 --- a/MinecraftClient/Resources/ConfigComments/ConfigComments.Designer.cs +++ b/MinecraftClient/Resources/ConfigComments/ConfigComments.Designer.cs @@ -1429,6 +1429,15 @@ namespace MinecraftClient { } } + /// + /// Looks up a localized string similar to Whether to display received chat messages in the console. This does not affect chat bots or chat log files.. + /// + internal static string Console_General_Display_Chat { + get { + return ResourceManager.GetString("Console.General.Display_Chat", resourceCulture); + } + } + /// /// Looks up a localized string similar to Maximum number of input history records to keep.. /// diff --git a/MinecraftClient/Resources/ConfigComments/ConfigComments.resx b/MinecraftClient/Resources/ConfigComments/ConfigComments.resx index 3c5804ba..1495d83b 100644 --- a/MinecraftClient/Resources/ConfigComments/ConfigComments.resx +++ b/MinecraftClient/Resources/ConfigComments/ConfigComments.resx @@ -589,6 +589,9 @@ Custom colors are only available when using "vt100_24bit" color mode. You can use "Ctrl+P" to print out the current input and cursor position. + + Whether to display received chat messages in the console. This does not affect chat bots or chat log files. + Maximum number of input history records to keep. diff --git a/MinecraftClient/Resources/Translations/Translations.Designer.cs b/MinecraftClient/Resources/Translations/Translations.Designer.cs index 78fa66ab..52ec91ae 100644 --- a/MinecraftClient/Resources/Translations/Translations.Designer.cs +++ b/MinecraftClient/Resources/Translations/Translations.Designer.cs @@ -3024,6 +3024,42 @@ namespace MinecraftClient { } } + /// + /// Looks up a localized string similar to clear the console output.. + /// + internal static string cmd_clear_console_desc { + get { + return ResourceManager.GetString("cmd.clear_console.desc", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to toggle chat visibility in the console.. + /// + internal static string cmd_console_chat_desc { + get { + return ResourceManager.GetString("cmd.console_chat.desc", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Console chat output is now hidden.. + /// + internal static string cmd_console_chat_state_off { + get { + return ResourceManager.GetString("cmd.console_chat.state_off", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Console chat output is now visible.. + /// + internal static string cmd_console_chat_state_on { + get { + return ResourceManager.GetString("cmd.console_chat.state_on", resourceCulture); + } + } + /// /// Looks up a localized string similar to toggle debug messages.. /// diff --git a/MinecraftClient/Resources/Translations/Translations.resx b/MinecraftClient/Resources/Translations/Translations.resx index d4442833..6052e661 100644 --- a/MinecraftClient/Resources/Translations/Translations.resx +++ b/MinecraftClient/Resources/Translations/Translations.resx @@ -1090,6 +1090,18 @@ Change EnableEmoji=false in the settings if the display is confusing. Unknown account '{0}'. + + toggle chat visibility in the console. + + + Console chat output is now hidden. + + + Console chat output is now visible. + + + clear the console output. + toggle debug messages. diff --git a/MinecraftClient/Settings.cs b/MinecraftClient/Settings.cs index caf92226..889abe5a 100644 --- a/MinecraftClient/Settings.cs +++ b/MinecraftClient/Settings.cs @@ -1122,6 +1122,8 @@ namespace MinecraftClient public void OnSettingUpdate() { + ConsoleIO.ChatVisible = General.Display_Chat; + var backend = ConsoleIO.Backend; if (backend == null) return; @@ -1225,6 +1227,9 @@ namespace MinecraftClient [TomlInlineComment("$Console.General.Display_Input$")] public bool Display_Input = true; + [TomlInlineComment("$Console.General.Display_Chat$")] + public bool Display_Chat = true; + [TomlInlineComment("$Console.General.History_Input_Records$")] public int History_Input_Records = 32; diff --git a/MinecraftClient/Tui/MainTuiView.cs b/MinecraftClient/Tui/MainTuiView.cs index 7c34d17c..9eda3c62 100644 --- a/MinecraftClient/Tui/MainTuiView.cs +++ b/MinecraftClient/Tui/MainTuiView.cs @@ -268,6 +268,13 @@ namespace MinecraftClient.Tui ScheduleScrollToEnd(); } + public void ClearLog() + { + _logLines.Clear(); + _logControls.Clear(); + ScheduleScrollToEnd(); + } + private void TrimLog() { while (_logLines.Count > MaxLogLines) diff --git a/MinecraftClient/Tui/TuiConsoleBackend.cs b/MinecraftClient/Tui/TuiConsoleBackend.cs index 58bd444d..523b27f1 100644 --- a/MinecraftClient/Tui/TuiConsoleBackend.cs +++ b/MinecraftClient/Tui/TuiConsoleBackend.cs @@ -240,6 +240,15 @@ namespace MinecraftClient.Tui Dispatcher.UIThread.Post(() => _view?.ClearInput()); } + public void ClearScreen() + { + if (_view == null) return; + if (Dispatcher.UIThread.CheckAccess()) + _view.ClearLog(); + else + Dispatcher.UIThread.Post(() => _view?.ClearLog()); + } + public void SetInputVisible(bool visible) { } diff --git a/docs/guide/configuration.md b/docs/guide/configuration.md index a21c40e3..aa04e050 100644 --- a/docs/guide/configuration.md +++ b/docs/guide/configuration.md @@ -1132,6 +1132,18 @@ Coordinate = { x = 145, y = 64, z = 2045 } - **Default:** `true` +#### `Display_Chat` + +- **Description:** + + Set this to `false` if you want MCC to keep receiving chat without printing it in the console. + + This only affects console output. It does not stop bots from receiving chat, and it does not turn off chat file logging. + +- **Type:** `boolean` + +- **Default:** `true` + #### `History_Input_Records` - **Description:** diff --git a/docs/guide/usage.md b/docs/guide/usage.md index f72062f9..b165ccd5 100644 --- a/docs/guide/usage.md +++ b/docs/guide/usage.md @@ -882,6 +882,24 @@ In scripts and remote control, no slash is needed to perform the command, eg. `q +
+clear-console + +- **Description:** + + Clear the visible console output. + + In TUI mode this clears the log panel. In the classic console it clears the terminal screen. + +- **Usage:** + + ``` + /clear-console + /cc + ``` + +
+
connect @@ -1584,6 +1602,39 @@ In scripts and remote control, no slash is needed to perform the command, eg. `q
+
+console-chat + +- **Description:** + + Temporarily show or hide chat in the console. + + This changes the current session only. If you want the same behavior every time MCC starts, use [`Console.General.Display_Chat`](configuration.md#display_chat). + +- **Usage:** + + ``` + /console-chat + /console-chat on + /console-chat off + ``` + +- **Examples:** + + Hide chat until you turn it back on: + + ``` + /console-chat off + ``` + + Show chat again: + + ``` + /console-chat on + ``` + +
+
debug