diff --git a/ConsoleBuffer.sln b/ConsoleBuffer.sln index 9f18b32..39c61ed 100644 --- a/ConsoleBuffer.sln +++ b/ConsoleBuffer.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 VisualStudioVersion = 15.0.28010.2036 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleBuffer", "src\ConsoleBuffer\ConsoleBuffer.csproj", "{A16D11B0-4785-434F-8514-ABCC16DDFBFD}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleBuffer", "src\ConsoleBuffer\ConsoleBuffer.csproj", "{A16D11B0-4785-434F-8514-ABCC16DDFBFD}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "condo.wpf", "src\condo.wpf\condo.wpf.csproj", "{D890EB09-11B9-41A8-B9A7-C1D159312A32}" EndProject @@ -54,6 +54,7 @@ Global {D890EB09-11B9-41A8-B9A7-C1D159312A32}.Release|x86.ActiveCfg = Release|Any CPU {D890EB09-11B9-41A8-B9A7-C1D159312A32}.Release|x86.Build.0 = Release|Any CPU {FB9FD3E5-EDF1-4924-8945-42DC0AFE478F}.Debug|Any CPU.ActiveCfg = Debug|x86 + {FB9FD3E5-EDF1-4924-8945-42DC0AFE478F}.Debug|Any CPU.Build.0 = Debug|x86 {FB9FD3E5-EDF1-4924-8945-42DC0AFE478F}.Debug|ARM.ActiveCfg = Debug|ARM {FB9FD3E5-EDF1-4924-8945-42DC0AFE478F}.Debug|ARM.Build.0 = Debug|ARM {FB9FD3E5-EDF1-4924-8945-42DC0AFE478F}.Debug|ARM.Deploy.0 = Debug|ARM diff --git a/src/condo/MainPage.xaml b/src/condo/MainPage.xaml index 523c99b..2bcbf2a 100644 --- a/src/condo/MainPage.xaml +++ b/src/condo/MainPage.xaml @@ -6,7 +6,8 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" - Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> + Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" + Height="Auto" Width="Auto"> diff --git a/src/condo/MainPage.xaml.cs b/src/condo/MainPage.xaml.cs index e765285..57b8415 100644 --- a/src/condo/MainPage.xaml.cs +++ b/src/condo/MainPage.xaml.cs @@ -1,30 +1,75 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Runtime.InteropServices.WindowsRuntime; -using Windows.Foundation; -using Windows.Foundation.Collections; -using Windows.UI.Xaml; -using Windows.UI.Xaml.Controls; -using Windows.UI.Xaml.Controls.Primitives; -using Windows.UI.Xaml.Data; -using Windows.UI.Xaml.Input; -using Windows.UI.Xaml.Media; -using Windows.UI.Xaml.Navigation; - -// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409 - -namespace condo +namespace condo { + using System; + using System.ComponentModel; + // The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409 + using System.Text; + using Windows.Foundation; + using Windows.UI.Xaml; + using Windows.UI.Xaml.Controls; + using Windows.UI.Xaml.Media; + /// /// An empty page that can be used on its own or navigated to within a Frame. /// - public sealed partial class MainPage : Page + public sealed partial class MainPage : Page, ConsoleBuffer.IRenderTarget { + private ConsoleBuffer.ConsoleWrapper console; + private ConsoleBuffer.Character[,] characters; + public MainPage() { this.InitializeComponent(); + + this.Loaded += this.OnLoaded; + + this.console = TerminalManager.Instance.GetOrCreate(0, "ping -t localhost"); + System.Diagnostics.Debugger.Launch(); + this.stuff.Text = "abjkkas"; + //this.console.PropertyChanged += this.UpdateContents; + } + + private async void UpdateContents(object sender, PropertyChangedEventArgs args) + { + this.console.Buffer.Render(this); + await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => this.Redraw()); + } + + private Size DetermineSize() + { + var measureText = new TextBlock { Text = "x", FontFamily = new FontFamily("Consolas"), FontSize = 12 }; + measureText.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); + return new Size(measureText.DesiredSize.Width * this.console.Width, measureText.DesiredSize.Height * this.console.Height); + } + + private void OnLoaded(object sender, RoutedEventArgs e) + { + var stuffSize = this.DetermineSize(); + this.stuff.Height = stuffSize.Height; + this.stuff.Width = stuffSize.Width; + + this.characters = new ConsoleBuffer.Character[this.console.Height, this.console.Width]; + this.Redraw(); + } + + private void Redraw() + { + var sb = new StringBuilder(); + for (var x = 0; x < this.console.Height; ++x) + { + for (var y = 0; y < this.console.Width; ++y) + { + sb.Append((char)this.characters[x, y].Glyph); + } + sb.Append('\n'); + } + + this.stuff.Text = sb.ToString(); + } + + public void RenderCharacter(ConsoleBuffer.Character c, int x, int y) + { + this.characters[x, y] = c; } } } diff --git a/src/condo/TerminalManager.cs b/src/condo/TerminalManager.cs new file mode 100644 index 0000000..c3c403a --- /dev/null +++ b/src/condo/TerminalManager.cs @@ -0,0 +1,36 @@ +namespace condo +{ + using ConsoleBuffer; + using System.Collections.Generic; + + /// + /// Manages creating/destroying terminals through queued requests. + /// + public sealed class TerminalManager + { + public static readonly TerminalManager Instance = new TerminalManager(); + + private readonly object terminalLock = new object(); + private readonly Dictionary terminals; + + private TerminalManager() + { + this.terminals = new Dictionary(); + } + + public ConsoleWrapper GetOrCreate(int id, string command) + { + lock (this.terminalLock) + { + if (this.terminals.TryGetValue(id, out ConsoleWrapper con)) + { + return con; + } + + con = new ConsoleWrapper(command); + this.terminals[id] = con; + return con; + } + } + } +} diff --git a/src/condo/condo.csproj b/src/condo/condo.csproj index 3eee16e..28c39c6 100644 --- a/src/condo/condo.csproj +++ b/src/condo/condo.csproj @@ -99,6 +99,7 @@ MainPage.xaml + @@ -131,6 +132,12 @@ 6.1.9 + + + {a16d11b0-4785-434f-8514-abcc16ddfbfd} + ConsoleBuffer + + 14.0