public TerminalWidget() { terminal = new Terminal(); terminalInputOutputSource = new TerminalIOSource(terminal); IO = new DetachableIO(terminalInputOutputSource); IO.BeforeWrite += b => { // we do not check if previous byte was '\r', because it should not cause any problem to // send it twice if (ModifyLineEndings && b == '\n') { IO.Write((byte)'\r'); } }; terminal.InnerMargin = new WidgetSpacing(5, 5, 5, 5); terminal.Cursor.Enabled = true; terminal.ContextMenu = CreatePopupMenu(); var fontFile = typeof(TerminalWidget).Assembly.FromResourceToTemporaryFile("RobotoMono-Regular.ttf"); Xwt.Drawing.Font.RegisterFontFromFile(fontFile); terminal.CurrentFont = Xwt.Drawing.Font.FromName("Roboto Mono").WithSize(10); var encoder = new TermSharp.Vt100.Encoder(x => { terminal.ClearSelection(); terminal.MoveScrollbarToEnd(); terminalInputOutputSource.HandleInput(x); }); terminal.KeyPressed += (s, a) => { a.Handled = true; var modifiers = a.Modifiers; if (!Misc.IsOnOsX) { modifiers &= ~(ModifierKeys.Command); } if (modifiers == ModifierKeys.Shift) { if (a.Key == Key.PageUp) { terminal.PageUp(); return; } if (a.Key == Key.PageDown) { terminal.PageDown(); return; } } encoder.Feed(a.Key, modifiers); }; Content = terminal; }
public TerminalWidget() { terminal = new Terminal(); terminalInputOutputSource = new TerminalIOSource(terminal); IO = new DetachableIO(terminalInputOutputSource); IO.BeforeWrite += b => { // we do not check if previous byte was '\r', because it should not cause any problem to // send it twice if(ModifyLineEndings && b == '\n') { IO.Write((byte)'\r'); } }; terminal.InnerMargin = new WidgetSpacing(5, 5, 5, 5); terminal.Cursor.Enabled = true; terminal.ContextMenu = CreatePopupMenu(); var fontFile = typeof(TerminalWidget).Assembly.FromResourceToTemporaryFile("RobotoMono-Regular.ttf"); Xwt.Drawing.Font.RegisterFontFromFile(fontFile); terminal.CurrentFont = Xwt.Drawing.Font.FromName("Roboto Mono").WithSize(10); var encoder = new TermSharp.Vt100.Encoder(x => { terminal.ClearSelection(); terminal.MoveScrollbarToEnd(); terminalInputOutputSource.HandleInput(x); }); terminal.KeyPressed += (s, a) => { a.Handled = true; var modifiers = a.Modifiers; if(!Misc.IsOnOsX) { modifiers &= ~(ModifierKeys.Command); } if(modifiers == ModifierKeys.Shift) { if(a.Key == Key.PageUp) { terminal.PageUp(); return; } if(a.Key == Key.PageDown) { terminal.PageDown(); return; } } encoder.Feed(a.Key, modifiers); }; Content = terminal; }
public MainWindow(string title, string pty) { Title = title; Width = 700; Height = 400; terminal = new TermSharp.Terminal(); Content = terminal; terminal.InnerMargin = new WidgetSpacing(5, 0, 5, 0); Padding = new WidgetSpacing(); terminal.Cursor.Enabled = true; Font.RegisterFontFromFile(Path.Combine(Directory.GetCurrentDirectory(), "External/TermsharpConsole/RobotoMono-Regular.ttf")); var robotoMonoFont = Font.FromName("Roboto Mono"); if(robotoMonoFont.Family.Contains("Roboto")) { terminal.CurrentFont = robotoMonoFont; } var contextMenu = new Menu(); var copyMenuItem = new MenuItem("Copy"); copyMenuItem.Clicked += (sender, e) => Clipboard.SetText(terminal.CollectClipboardData().Text); contextMenu.Items.Add(copyMenuItem); var pasteMenuItem = new MenuItem("Paste"); contextMenu.Items.Add(pasteMenuItem); terminal.ContextMenu = contextMenu; CloseRequested += delegate { Application.Exit(); }; terminal.SetFocus(); var readerThread = new Thread(() => { var stream = new PtyUnixStream(pty); var vt100decoder = new TermSharp.Vt100.Decoder(terminal, stream.WriteByte, new ConsoleDecoderLogger()); var utfDecoder = new ByteUtf8Decoder(vt100decoder.Feed); Application.Invoke(() => { pasteMenuItem.Clicked += delegate { var text = Clipboard.GetText(); var textAsBytes = Encoding.UTF8.GetBytes(text); foreach(var b in textAsBytes) { stream.WriteByte(b); } }; }); var encoder = new TermSharp.Vt100.Encoder(x => { terminal.ClearSelection(); terminal.MoveScrollbarToEnd(); stream.WriteByte(x); }); terminal.KeyPressed += (s, a) => { a.Handled = true; var modifiers = a.Modifiers; if(!Utilities.IsOnOsX) { modifiers &= ~(ModifierKeys.Command); } if(modifiers== ModifierKeys.Shift) { if(a.Key == Key.PageUp) { terminal.PageUp(); return; } if(a.Key == Key.PageDown) { terminal.PageDown(); return; } } encoder.Feed(a.Key, modifiers); }; var buffer = new List<byte>(); var noTimeoutNextTime = true; while(true) { if(noTimeoutNextTime) { noTimeoutNextTime = false; } else { stream.ReadTimeout = 10; } var readByte = buffer.Count > 1024 ? BufferFull : stream.ReadByte(); if(readByte == StreamClosed) { Application.Invoke(Application.Exit); return; } if(readByte >= 0) { buffer.Add((byte)readByte); } else { var bufferToWrite = buffer; Application.Invoke(() => { foreach (var b in bufferToWrite) { utfDecoder.Feed(b); } }); buffer = new List<byte>(); noTimeoutNextTime = true; } } }) { IsBackground = true }; readerThread.Start(); }
public MainWindow(string title, string pty) { Title = title; Width = 700; Height = 400; terminal = new TermSharp.Terminal(); Content = terminal; terminal.InnerMargin = new WidgetSpacing(5, 0, 5, 0); Padding = new WidgetSpacing(); terminal.Cursor.Enabled = true; Font.RegisterFontFromFile(Path.Combine(Directory.GetCurrentDirectory(), "External/TermsharpConsole/RobotoMono-Regular.ttf")); var robotoMonoFont = Font.FromName("Roboto Mono"); if (robotoMonoFont.Family.Contains("Roboto")) { terminal.CurrentFont = robotoMonoFont; } var contextMenu = new Menu(); var copyMenuItem = new MenuItem("Copy"); copyMenuItem.Clicked += (sender, e) => Clipboard.SetText(terminal.CollectClipboardData().Text); contextMenu.Items.Add(copyMenuItem); var pasteMenuItem = new MenuItem("Paste"); contextMenu.Items.Add(pasteMenuItem); terminal.ContextMenu = contextMenu; CloseRequested += delegate { Application.Exit(); }; terminal.SetFocus(); var readerThread = new Thread(() => { var stream = new PtyUnixStream(pty); var vt100decoder = new TermSharp.Vt100.Decoder(terminal, stream.WriteByte, new ConsoleDecoderLogger()); var utfDecoder = new ByteUtf8Decoder(vt100decoder.Feed); Application.Invoke(() => { pasteMenuItem.Clicked += delegate { var text = Clipboard.GetText(); var textAsBytes = Encoding.UTF8.GetBytes(text); foreach (var b in textAsBytes) { stream.WriteByte(b); } }; }); var encoder = new TermSharp.Vt100.Encoder(x => { terminal.ClearSelection(); terminal.MoveScrollbarToEnd(); stream.WriteByte(x); }); terminal.KeyPressed += (s, a) => { a.Handled = true; var modifiers = a.Modifiers; if (!Utilities.IsOnOsX) { modifiers &= ~(ModifierKeys.Command); } if (modifiers == ModifierKeys.Shift) { if (a.Key == Key.PageUp) { terminal.PageUp(); return; } if (a.Key == Key.PageDown) { terminal.PageDown(); return; } } encoder.Feed(a.Key, modifiers); }; var buffer = new List <byte>(); var noTimeoutNextTime = true; while (true) { if (noTimeoutNextTime) { noTimeoutNextTime = false; } else { stream.ReadTimeout = 10; } var readByte = buffer.Count > 1024 ? BufferFull : stream.ReadByte(); if (readByte == StreamClosed) { Application.Invoke(Application.Exit); return; } if (readByte >= 0) { buffer.Add((byte)readByte); } else { var bufferToWrite = buffer; Application.Invoke(() => { foreach (var b in bufferToWrite) { utfDecoder.Feed(b); } }); buffer = new List <byte>(); noTimeoutNextTime = true; } } }) { IsBackground = true }; readerThread.Start(); }