Page navigation, CogwheelConsole
This commit is contained in:
61
SessionZero/Cogwheel/ConsoleControl.axaml.cs
Normal file
61
SessionZero/Cogwheel/ConsoleControl.axaml.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Documents;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.Media;
|
||||
using Cogwheel;
|
||||
|
||||
namespace SessionZero.Cogwheel;
|
||||
|
||||
public partial class ConsoleControl : UserControl
|
||||
{
|
||||
private TextBlock? _output;
|
||||
private TextBox? _input;
|
||||
|
||||
public ConsoleControl()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
_output = this.FindControl<TextBlock>("Output");
|
||||
_input = this.FindControl<TextBox>("Input");
|
||||
|
||||
_input?.KeyDown += Input_OnKeyDown;
|
||||
}
|
||||
|
||||
private void Input_OnKeyDown(object? sender, KeyEventArgs e)
|
||||
{
|
||||
if (e.Key == Key.Enter)
|
||||
{
|
||||
var inputText = _input!.Text ?? string.Empty;
|
||||
Log(inputText);
|
||||
if (inputText.Length > 0) COGWHEEL.RunCommand(inputText);
|
||||
_input.Text = string.Empty;
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void Log(string text, Color? color = null)
|
||||
{
|
||||
if (_output == null)
|
||||
return;
|
||||
|
||||
_output?.Inlines?.Add(new Run("> ")
|
||||
{
|
||||
Foreground = Brushes.LightGray
|
||||
});
|
||||
|
||||
_output?.Inlines?.Add(new Run(text)
|
||||
{
|
||||
Foreground = color != null ? new SolidColorBrush(color.Value)
|
||||
: Brushes.White
|
||||
});
|
||||
|
||||
_output?.Inlines?.Add(new LineBreak());
|
||||
}
|
||||
|
||||
public void ClearOutput()
|
||||
{
|
||||
_output?.Inlines?.Clear();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user