Skip to content

Commit

Permalink
hey I can send 'return' commands now that's cool I guess.
Browse files Browse the repository at this point in the history
  • Loading branch information
doubleyewdee committed Nov 15, 2018
1 parent e7822e3 commit 996e64f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
21 changes: 14 additions & 7 deletions src/ConsoleBuffer/ConsoleWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ public sealed class ConsoleWrapper : IDisposable, INotifyPropertyChanged
/// The handle into which we write data to the console.
/// </summary>
private SafeFileHandle writeHandle;
private FileStream writeStream;

/// <summary>
/// Handle to the console PTY.
/// </summary>
private IntPtr consoleHandle;

private Task readTask;

// used for booting / running the underlying process.
private NativeMethods.STARTUPINFOEX startupInfo;
private NativeMethods.PROCESS_INFORMATION processInfo;
Expand All @@ -53,7 +52,14 @@ public ConsoleWrapper(string command)
this.InitializeStartupInfo();
this.StartProcess();

this.readTask = Task.Run(() => this.ReadConsoleTask());
Task.Run(() => this.ReadConsoleTask());
this.writeStream = new FileStream(this.writeHandle, FileAccess.Write);
}

public void SendKey(char value)
{
this.writeStream.WriteByte((byte)value);
this.writeStream.Flush();
}

private void CreatePTY()
Expand Down Expand Up @@ -131,6 +137,11 @@ private void ReadConsoleTask()
this.Buffer.Append(input, read);
this.OnPropertyChanged(nameof(this.Buffer));
}
catch (ObjectDisposedException)
{
// this can happen when our parent disposes, safe to bail out silently.
return;
}
catch (Exception ex) // XXX: this is some lousy logging I don't normally recommend, need to kill later.
{
Logger.Verbose(ex.ToString());
Expand Down Expand Up @@ -178,10 +189,6 @@ void Dispose(bool disposing)

if (disposing)
{
this.readTask?.Wait(TimeSpan.FromSeconds(1));
this.readTask?.Dispose();
this.readTask = null;

this.readHandle?.Dispose();
this.readHandle = null;
this.writeHandle?.Dispose();
Expand Down
15 changes: 14 additions & 1 deletion src/condo/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Globalization;
using System.Text;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;

/// <summary>
Expand Down Expand Up @@ -46,7 +47,7 @@ private Size DetermineSize()
private void OnLoaded(object sender, RoutedEventArgs e)
{
this.dpiInfo = VisualTreeHelper.GetDpi(this);
this.console = TerminalManager.Instance.GetOrCreate(0, "ping -t localhost");
this.console = TerminalManager.Instance.GetOrCreate(0, "cmd.exe");

var stuffSize = this.DetermineSize();
this.stuff.Height = stuffSize.Height;
Expand All @@ -65,6 +66,18 @@ private void OnLoaded(object sender, RoutedEventArgs e)
};

this.Closing += HandleClosing;
this.KeyDown += HandleKeyDown;
}

private void HandleKeyDown(object sender, KeyEventArgs e)
{
switch (e.Key)
{
case Key.Return:
this.console.SendKey('\r');
this.console.SendKey('\n');
break;
}
}

private void HandleClosing(object sender, CancelEventArgs e)
Expand Down

0 comments on commit 996e64f

Please sign in to comment.