mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2026-08-15 13:04:36 +00:00
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:
parent
9c994de2ee
commit
7bf342baab
14 changed files with 226 additions and 2 deletions
|
|
@ -63,6 +63,12 @@ namespace MinecraftClient
|
||||||
ConsoleInteractive.ConsoleReader.ClearBuffer();
|
ConsoleInteractive.ConsoleReader.ClearBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ClearScreen()
|
||||||
|
{
|
||||||
|
Console.Clear();
|
||||||
|
ConsoleInteractive.ConsoleSuggestion.ClearSuggestions();
|
||||||
|
}
|
||||||
|
|
||||||
public void SetInputVisible(bool visible)
|
public void SetInputVisible(bool visible)
|
||||||
{
|
{
|
||||||
ConsoleInteractive.ConsoleReader.SetInputVisible(visible);
|
ConsoleInteractive.ConsoleReader.SetInputVisible(visible);
|
||||||
|
|
|
||||||
45
MinecraftClient/Commands/ClearConsole.cs
Normal file
45
MinecraftClient/Commands/ClearConsole.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
49
MinecraftClient/Commands/ConsoleChat.cs
Normal file
49
MinecraftClient/Commands/ConsoleChat.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
|
@ -61,6 +62,11 @@ namespace MinecraftClient
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static bool EnableTimestamps = false;
|
public static bool EnableTimestamps = false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determine whether chat lines should be displayed in the console.
|
||||||
|
/// </summary>
|
||||||
|
public static bool ChatVisible = true;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Specify a generic log line prefix for WriteLogLine()
|
/// Specify a generic log line prefix for WriteLogLine()
|
||||||
/// </summary>
|
/// </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>
|
/// <summary>
|
||||||
/// Write a prefixed log line. Prefix is set in LogPrefix.
|
/// Write a prefixed log line. Prefix is set in LogPrefix.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -178,6 +195,30 @@ namespace MinecraftClient
|
||||||
Backend.ClearInputBuffer();
|
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
|
#endregion
|
||||||
|
|
||||||
internal static bool AutoCompleteDone = false;
|
internal static bool AutoCompleteDone = false;
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,8 @@ namespace MinecraftClient
|
||||||
|
|
||||||
void ClearInputBuffer();
|
void ClearInputBuffer();
|
||||||
|
|
||||||
|
void ClearScreen();
|
||||||
|
|
||||||
bool DisplayUserInput { get; set; }
|
bool DisplayUserInput { get; set; }
|
||||||
|
|
||||||
void SetInputVisible(bool visible);
|
void SetInputVisible(bool visible);
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,8 @@ namespace MinecraftClient.Logger
|
||||||
{
|
{
|
||||||
if (ShouldDisplay(FilterChannel.Chat, msg))
|
if (ShouldDisplay(FilterChannel.Chat, msg))
|
||||||
{
|
{
|
||||||
LogAndSave(msg);
|
ConsoleIO.WriteChatLineFormatted(msg);
|
||||||
|
Save(msg);
|
||||||
}
|
}
|
||||||
else Debug("[Logger] One Chat message filtered: " + msg);
|
else Debug("[Logger] One Chat message filtered: " + msg);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ namespace MinecraftClient.Logger
|
||||||
{
|
{
|
||||||
if (ShouldDisplay(FilterChannel.Chat, msg))
|
if (ShouldDisplay(FilterChannel.Chat, msg))
|
||||||
{
|
{
|
||||||
Log(msg);
|
ConsoleIO.WriteChatLineFormatted(msg);
|
||||||
}
|
}
|
||||||
else Debug("[Logger] One Chat message filtered: " + msg);
|
else Debug("[Logger] One Chat message filtered: " + msg);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Maximum number of input history records to keep..
|
/// Looks up a localized string similar to Maximum number of input history records to keep..
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -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">
|
<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>
|
<value>You can use "Ctrl+P" to print out the current input and cursor position.</value>
|
||||||
</data>
|
</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">
|
<data name="Console.General.History_Input_Records" xml:space="preserve">
|
||||||
<value>Maximum number of input history records to keep.</value>
|
<value>Maximum number of input history records to keep.</value>
|
||||||
</data>
|
</data>
|
||||||
|
|
|
||||||
|
|
@ -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>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to toggle debug messages..
|
/// Looks up a localized string similar to toggle debug messages..
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -1090,6 +1090,18 @@ Change EnableEmoji=false in the settings if the display is confusing.</value>
|
||||||
<data name="cmd.connect.unknown" xml:space="preserve">
|
<data name="cmd.connect.unknown" xml:space="preserve">
|
||||||
<value>Unknown account '{0}'.</value>
|
<value>Unknown account '{0}'.</value>
|
||||||
</data>
|
</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">
|
<data name="cmd.debug.desc" xml:space="preserve">
|
||||||
<value>toggle debug messages.</value>
|
<value>toggle debug messages.</value>
|
||||||
</data>
|
</data>
|
||||||
|
|
|
||||||
|
|
@ -1122,6 +1122,8 @@ namespace MinecraftClient
|
||||||
|
|
||||||
public void OnSettingUpdate()
|
public void OnSettingUpdate()
|
||||||
{
|
{
|
||||||
|
ConsoleIO.ChatVisible = General.Display_Chat;
|
||||||
|
|
||||||
var backend = ConsoleIO.Backend;
|
var backend = ConsoleIO.Backend;
|
||||||
if (backend == null) return;
|
if (backend == null) return;
|
||||||
|
|
||||||
|
|
@ -1225,6 +1227,9 @@ namespace MinecraftClient
|
||||||
[TomlInlineComment("$Console.General.Display_Input$")]
|
[TomlInlineComment("$Console.General.Display_Input$")]
|
||||||
public bool Display_Input = true;
|
public bool Display_Input = true;
|
||||||
|
|
||||||
|
[TomlInlineComment("$Console.General.Display_Chat$")]
|
||||||
|
public bool Display_Chat = true;
|
||||||
|
|
||||||
[TomlInlineComment("$Console.General.History_Input_Records$")]
|
[TomlInlineComment("$Console.General.History_Input_Records$")]
|
||||||
public int History_Input_Records = 32;
|
public int History_Input_Records = 32;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -268,6 +268,12 @@ namespace MinecraftClient.Tui
|
||||||
ScheduleScrollToEnd();
|
ScheduleScrollToEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ClearLog()
|
||||||
|
{
|
||||||
|
_logLines.Clear();
|
||||||
|
_logControls.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
private void TrimLog()
|
private void TrimLog()
|
||||||
{
|
{
|
||||||
while (_logLines.Count > MaxLogLines)
|
while (_logLines.Count > MaxLogLines)
|
||||||
|
|
|
||||||
|
|
@ -240,6 +240,15 @@ namespace MinecraftClient.Tui
|
||||||
Dispatcher.UIThread.Post(() => _view?.ClearInput());
|
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)
|
public void SetInputVisible(bool visible)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue