Skip to content

Commit

Permalink
more uwp mucking
Browse files Browse the repository at this point in the history
  • Loading branch information
doubleyewdee committed Nov 13, 2018
1 parent 0e99eb8 commit ef05c6a
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 21 deletions.
3 changes: 2 additions & 1 deletion ConsoleBuffer.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/condo/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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">

<Grid>
<TextBox Background="Black" Foreground="Gray" Name="stuff" FontFamily="Consolas" FontSize="14" IsReadOnly="True" />
Expand Down
83 changes: 64 additions & 19 deletions src/condo/MainPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -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;

/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
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;
}
}
}
36 changes: 36 additions & 0 deletions src/condo/TerminalManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
namespace condo
{
using ConsoleBuffer;
using System.Collections.Generic;

/// <summary>
/// Manages creating/destroying terminals through queued requests.
/// </summary>
public sealed class TerminalManager
{
public static readonly TerminalManager Instance = new TerminalManager();

private readonly object terminalLock = new object();
private readonly Dictionary<int, ConsoleWrapper> terminals;

private TerminalManager()
{
this.terminals = new Dictionary<int, ConsoleWrapper>();
}

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;
}
}
}
}
7 changes: 7 additions & 0 deletions src/condo/condo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
<DependentUpon>MainPage.xaml</DependentUpon>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TerminalManager.cs" />
</ItemGroup>
<ItemGroup>
<AppxManifest Include="Package.appxmanifest">
Expand Down Expand Up @@ -131,6 +132,12 @@
<Version>6.1.9</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ConsoleBuffer\ConsoleBuffer.csproj">
<Project>{a16d11b0-4785-434f-8514-abcc16ddfbfd}</Project>
<Name>ConsoleBuffer</Name>
</ProjectReference>
</ItemGroup>
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
<VisualStudioVersion>14.0</VisualStudioVersion>
</PropertyGroup>
Expand Down

0 comments on commit ef05c6a

Please sign in to comment.