Skip to content

Commit

Permalink
UI vaguely half-ass works
Browse files Browse the repository at this point in the history
  • Loading branch information
doubleyewdee committed Sep 30, 2018
1 parent 59b5306 commit 2d0a195
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 35 deletions.
34 changes: 22 additions & 12 deletions src/ConsoleBuffer/ConsoleWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,30 @@ public string Contents

public ConsoleWrapper(string command)
{
this.Contents = string.Empty;

if (string.IsNullOrWhiteSpace(command))
using (var sr = new StreamWriter(new FileStream(@"c:\users\wd\source\repos\wincon\fuckme.log", FileMode.Create)))
{
throw new ArgumentException("No command specified.", nameof(command));
}
sr.WriteLine($"let's start this shit");

this.Command = command;
this.Contents = string.Empty;

this.CreatePTY();
this.InitializeStartupInfo();
this.StartProcess();
if (string.IsNullOrWhiteSpace(command))
{
throw new ArgumentException("No command specified.", nameof(command));
}

Task.Run(() => this.ReadConsoleTask());
this.Command = command;
sr.WriteLine($"running {command}");

this.CreatePTY();
sr.WriteLine($"created PTY");
this.InitializeStartupInfo();
sr.WriteLine($"initialized startup shit");
this.StartProcess();
sr.WriteLine($"started the fucking process");

Task.Run(() => this.ReadConsoleTask());
sr.WriteLine($"fuck ME");
}
}

private void CreatePTY()
Expand Down Expand Up @@ -126,7 +136,7 @@ private void ReadConsoleTask()
{
using (var ptyOutput = new FileStream(this.readHandle, FileAccess.Read))
{
var input = new byte[2048];
var input = new byte[32];

while (true)
{
Expand All @@ -149,7 +159,7 @@ private static void ThrowForHResult(int hr, string exceptionMessage)

#region INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(string name)
private void OnPropertyChanged(string name)
{
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
Expand Down
3 changes: 2 additions & 1 deletion src/condo/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:condo"
StartupUri="MainWindow.xaml">
StartupUri="MainWindow.xaml"
DispatcherUnhandledException="Application_DispatcherUnhandledException">
<Application.Resources>

</Application.Resources>
Expand Down
4 changes: 4 additions & 0 deletions src/condo/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@ namespace condo
/// </summary>
public partial class App : Application
{
private void Application_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
System.Windows.MessageBox.Show(e.Exception.ToString());
}
}
}
2 changes: 1 addition & 1 deletion src/condo/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<TextBox Background="Black" Foreground="Gray" Name="stuff" Text="{Binding Content}"/>
<TextBox Background="Black" Foreground="Gray" Name="stuff" FontFamily="Consolas" FontSize="14" IsReadOnly="True" />
</Grid>
</Window>
45 changes: 24 additions & 21 deletions src/condo/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace condo
namespace condo
{
using System;
using System.ComponentModel;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;

/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private ConsoleBuffer.ConsoleWrapper consoleWrapper;

public MainWindow()
{
InitializeComponent();
this.stuff.Text = "sdkjashfgdjkas";
var terminal = TerminalManager.Instance.GetOrCreate(0, "ping -t localhost");
terminal.PropertyChanged += this.UpdateContents;
}

private void UpdateContents(object sender, PropertyChangedEventArgs args)
{
var con = sender as ConsoleBuffer.ConsoleWrapper;
if (sender == null && args.PropertyName != "Content")
{
return; // XXX: log?
}

this.consoleWrapper = new ConsoleBuffer.ConsoleWrapper("debian run yes");
this.stuff.DataContext = this.consoleWrapper;
this.stuff.Text = this.consoleWrapper.Contents;
Dispatcher.InvokeAsync(() =>
{
this.stuff.Text = con.Contents;
});
}
}
}
38 changes: 38 additions & 0 deletions src/condo/TerminalManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
namespace condo
{
using ConsoleBuffer;
using System.Collections.Generic;
using System.Threading.Tasks;

/// <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)
{
ConsoleWrapper con;
lock (this.terminalLock)
{
if (this.terminals.TryGetValue(id, out con))
{
return con;
}

con = new ConsoleWrapper(command);
this.terminals[id] = con;
return con;
}
}
}
}
1 change: 1 addition & 0 deletions src/condo/condo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="TerminalManager.cs" />
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down

0 comments on commit 2d0a195

Please sign in to comment.