Page navigation, CogwheelConsole
This commit is contained in:
11
SessionZero/Cogwheel/ConsoleControl.axaml
Normal file
11
SessionZero/Cogwheel/ConsoleControl.axaml
Normal file
@@ -0,0 +1,11 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
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>
|
||||
<TextBox Grid.Row="1" Name="Input" Background="#7F272727" Foreground="White" Height="30" AcceptsReturn="False" AcceptsTab="False"></TextBox>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
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();
|
||||
}
|
||||
}
|
||||
50
SessionZero/Cogwheel/SessionZeroConsole.cs
Normal file
50
SessionZero/Cogwheel/SessionZeroConsole.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using Avalonia.Media;
|
||||
using Cogwheel;
|
||||
|
||||
namespace SessionZero.Cogwheel;
|
||||
|
||||
public class SessionZeroConsole : ICogwheelConsole
|
||||
{
|
||||
public string OpeningMessage { get; set; } = "SessionZero Console";
|
||||
public bool IsRunning { get; set; }
|
||||
public CommandsManager CommandsManager { get; set; }
|
||||
|
||||
public void Initialize(CommandsManager commandsManager)
|
||||
{
|
||||
CommandsManager = commandsManager;
|
||||
}
|
||||
|
||||
public void Log(string message)
|
||||
{
|
||||
Console.WriteLine(message);
|
||||
AppManager.ConsoleControl.Log(message);
|
||||
}
|
||||
|
||||
public void LogError(string message)
|
||||
{
|
||||
Console.WriteLine("Error: " + message);
|
||||
AppManager.ConsoleControl.Log($"Error: {message}", Colors.Red);
|
||||
}
|
||||
|
||||
public void LogWarning(string message)
|
||||
{
|
||||
Console.WriteLine("Warning: " + message);
|
||||
AppManager.ConsoleControl.Log($"Warning: {message}", Colors.Yellow);
|
||||
}
|
||||
|
||||
public void Write(string message)
|
||||
{
|
||||
Console.Write(message);
|
||||
}
|
||||
|
||||
public void ClearConsole()
|
||||
{
|
||||
AppManager.ConsoleControl.ClearOutput();
|
||||
}
|
||||
|
||||
public void Exit()
|
||||
{
|
||||
AppManager.HideConsole();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user