Settings management started
This commit is contained in:
@@ -5,7 +5,9 @@
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="SessionZero.Cogwheel.ConsoleControl">
|
||||
<Grid Background="Transparent" RowDefinitions="*, Auto, *" HorizontalAlignment="Stretch">
|
||||
<TextBlock Grid.Row="0" Name="Output" Foreground="White" Background="#7F272727" HorizontalAlignment="Stretch" TextWrapping="Wrap"></TextBlock>
|
||||
<ScrollViewer Name="OutputScrollView">
|
||||
<TextBlock Grid.Row="0" Name="Output" Foreground="White" Background="#7F272727" HorizontalAlignment="Stretch" TextWrapping="Wrap"></TextBlock>
|
||||
</ScrollViewer>
|
||||
<TextBox Grid.Row="1" Name="Input" Background="#7F272727" Foreground="White" Height="30" AcceptsReturn="False" AcceptsTab="False"></TextBox>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
|
||||
@@ -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