Settings management started
This commit is contained in:
@@ -10,8 +10,11 @@ namespace SessionZero.Cogwheel;
|
||||
|
||||
public partial class ConsoleControl : UserControl
|
||||
{
|
||||
public int OutputTrimSize { get; set; } = 200;
|
||||
|
||||
private TextBlock? _output;
|
||||
private TextBox? _input;
|
||||
private ScrollViewer? _outputScrollViewer;
|
||||
|
||||
public ConsoleControl()
|
||||
{
|
||||
@@ -19,6 +22,7 @@ public partial class ConsoleControl : UserControl
|
||||
|
||||
_output = this.FindControl<TextBlock>("Output");
|
||||
_input = this.FindControl<TextBox>("Input");
|
||||
_outputScrollViewer = this.FindControl<ScrollViewer>("OutputScrollView");
|
||||
|
||||
_input?.KeyDown += Input_OnKeyDown;
|
||||
}
|
||||
@@ -27,14 +31,37 @@ public partial class ConsoleControl : UserControl
|
||||
{
|
||||
if (e.Key == Key.Enter)
|
||||
{
|
||||
var inputText = _input!.Text ?? string.Empty;
|
||||
Log(inputText);
|
||||
if (inputText.Length > 0) COGWHEEL.RunCommand(inputText);
|
||||
_input.Text = string.Empty;
|
||||
SubmitInput();
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void SubmitInput()
|
||||
{
|
||||
var inputText = _input!.Text ?? string.Empty;
|
||||
Log(inputText);
|
||||
if (inputText.Length > 0) COGWHEEL.RunCommand(inputText);
|
||||
_input.Text = string.Empty;
|
||||
TrimOutput();
|
||||
ScrollToEnd();
|
||||
}
|
||||
|
||||
private void TrimOutput()
|
||||
{
|
||||
var maxInLines = OutputTrimSize * 3;
|
||||
while (_output?.Inlines?.Count > maxInLines)
|
||||
{
|
||||
if (_output?.Inlines?.Count >= 3)
|
||||
{
|
||||
_output?.Inlines?.RemoveRange(0,3);
|
||||
}
|
||||
else
|
||||
{
|
||||
_output?.Inlines?.RemoveAt(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Log(string text, Color? color = null)
|
||||
{
|
||||
if (_output == null)
|
||||
@@ -58,4 +85,9 @@ public partial class ConsoleControl : UserControl
|
||||
{
|
||||
_output?.Inlines?.Clear();
|
||||
}
|
||||
|
||||
public void ScrollToEnd()
|
||||
{
|
||||
_outputScrollViewer?.ScrollToEnd();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user