Implement console chat visibility controls

Agent-Logs-Url: https://github.com/MCCTeam/Minecraft-Console-Client/sessions/159bd460-7950-4afe-9e69-4892220665e1

Co-authored-by: milutinke <441903+milutinke@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2026-05-04 11:17:45 +00:00 committed by GitHub
parent 9c994de2ee
commit 7bf342baab
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 226 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 WriteChatLineFormatted(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,30 @@ 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)
{
}
catch (PlatformNotSupportedException)
{
}
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.WriteChatLineFormatted(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.WriteChatLineFormatted(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,12 @@ namespace MinecraftClient.Tui
ScheduleScrollToEnd();
}
public void ClearLog()
{
_logLines.Clear();
_logControls.Clear();
}
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)
{
}