feat: Add console chat visibility controls and clear-console commands

This commit is contained in:
Anon 2026-05-04 13:42:17 +02:00 committed by GitHub
commit 92ab2f7378
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 292 additions and 2 deletions

View file

@ -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);

View file

@ -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<CmdResult> 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);
}
}
}

View file

@ -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<CmdResult> 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);
}
}
}

View file

@ -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
/// </summary>
public static bool EnableTimestamps = false;
/// <summary>
/// Determine whether chat lines should be displayed in the console.
/// </summary>
public static bool ChatVisible = true;
/// <summary>
/// Specify a generic log line prefix for WriteLogLine()
/// </summary>
@ -155,6 +161,17 @@ namespace MinecraftClient
}
}
/// <summary>
/// Write a formatted chat line to the console when chat output is enabled.
/// </summary>
public static void WriteChatLineIfVisible(string str, bool acceptnewlines = false, bool? displayTimestamp = null)
{
if (!ChatVisible)
return;
WriteLineFormatted(str, acceptnewlines, displayTimestamp);
}
/// <summary>
/// Write a prefixed log line. Prefix is set in LogPrefix.
/// </summary>
@ -178,6 +195,32 @@ namespace MinecraftClient
Backend.ClearInputBuffer();
}
/// <summary>
/// Clear the visible console output.
/// </summary>
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;

View file

@ -60,6 +60,8 @@ namespace MinecraftClient
void ClearInputBuffer();
void ClearScreen();
bool DisplayUserInput { get; set; }
void SetInputVisible(bool visible);

View file

@ -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);
}

View file

@ -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);
}

View file

@ -1429,6 +1429,15 @@ namespace MinecraftClient {
}
}
/// <summary>
/// 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..
/// </summary>
internal static string Console_General_Display_Chat {
get {
return ResourceManager.GetString("Console.General.Display_Chat", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Maximum number of input history records to keep..
/// </summary>

View file

@ -589,6 +589,9 @@ Custom colors are only available when using "vt100_24bit" color mode.</value>
<data name="Console.General.Display_Input" xml:space="preserve">
<value>You can use "Ctrl+P" to print out the current input and cursor position.</value>
</data>
<data name="Console.General.Display_Chat" xml:space="preserve">
<value>Whether to display received chat messages in the console. This does not affect chat bots or chat log files.</value>
</data>
<data name="Console.General.History_Input_Records" xml:space="preserve">
<value>Maximum number of input history records to keep.</value>
</data>

View file

@ -3024,6 +3024,42 @@ namespace MinecraftClient {
}
}
/// <summary>
/// Looks up a localized string similar to clear the console output..
/// </summary>
internal static string cmd_clear_console_desc {
get {
return ResourceManager.GetString("cmd.clear_console.desc", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to toggle chat visibility in the console..
/// </summary>
internal static string cmd_console_chat_desc {
get {
return ResourceManager.GetString("cmd.console_chat.desc", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Console chat output is now hidden..
/// </summary>
internal static string cmd_console_chat_state_off {
get {
return ResourceManager.GetString("cmd.console_chat.state_off", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Console chat output is now visible..
/// </summary>
internal static string cmd_console_chat_state_on {
get {
return ResourceManager.GetString("cmd.console_chat.state_on", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to toggle debug messages..
/// </summary>

View file

@ -1090,6 +1090,18 @@ Change EnableEmoji=false in the settings if the display is confusing.</value>
<data name="cmd.connect.unknown" xml:space="preserve">
<value>Unknown account '{0}'.</value>
</data>
<data name="cmd.console_chat.desc" xml:space="preserve">
<value>toggle chat visibility in the console.</value>
</data>
<data name="cmd.console_chat.state_off" xml:space="preserve">
<value>Console chat output is now hidden.</value>
</data>
<data name="cmd.console_chat.state_on" xml:space="preserve">
<value>Console chat output is now visible.</value>
</data>
<data name="cmd.clear_console.desc" xml:space="preserve">
<value>clear the console output.</value>
</data>
<data name="cmd.debug.desc" xml:space="preserve">
<value>toggle debug messages.</value>
</data>

View file

@ -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;

View file

@ -268,6 +268,13 @@ namespace MinecraftClient.Tui
ScheduleScrollToEnd();
}
public void ClearLog()
{
_logLines.Clear();
_logControls.Clear();
ScheduleScrollToEnd();
}
private void TrimLog()
{
while (_logLines.Count > MaxLogLines)

View file

@ -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)
{
}

View file

@ -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:**

View file

@ -882,6 +882,24 @@ In scripts and remote control, no slash is needed to perform the command, eg. `q
</details>
<details>
<summary><code>clear-console</code></summary>
- **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
```
</details>
<details>
<summary><code>connect</code></summary>
@ -1584,6 +1602,39 @@ In scripts and remote control, no slash is needed to perform the command, eg. `q
</details>
<details>
<summary><code>console-chat</code></summary>
- **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
```
</details>
<details>
<summary><code>debug</code></summary>