-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e99eb8
commit ef05c6a
Showing
5 changed files
with
111 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters