public XtermTerminalView() { InitializeComponent(); StartMediatorTask(); _webView = new WebView(WebViewExecutionMode.SeparateThread) { DefaultBackgroundColor = Colors.Transparent }; Root.Children.Add(_webView); _webView.NavigationCompleted += _webView_NavigationCompleted; _webView.NavigationStarting += _webView_NavigationStarting; _webView.NewWindowRequested += _webView_NewWindowRequested; _copyMenuItem = new MenuFlyoutItem { Text = I18N.Translate("Command.Copy") }; _copyMenuItem.Click += Copy_Click; _pasteMenuItem = new MenuFlyoutItem { Text = I18N.Translate("Command.Paste") }; _pasteMenuItem.Click += Paste_Click; _webView.ContextFlyout = new MenuFlyout { Items = { _copyMenuItem, _pasteMenuItem } }; _optionsChanged = new DebouncedAction <TerminalOptions>(Dispatcher, TimeSpan.FromMilliseconds(800), async options => { var serialized = JsonConvert.SerializeObject(options); await ExecuteScriptAsync($"changeOptions('{serialized}')"); }); // _sizedChanged is used to debounce terminal resize events to // avoid spamming the terminal with them (this can result in // buffer corruption). _sizeChanged = new DebouncedAction <TerminalSize>(Dispatcher, TimeSpan.FromMilliseconds(1000), async size => { await ViewModel.Terminal.SetSize(size).ConfigureAwait(true); // Allow output to the terminal soon (hopefully, once the resize event has been processed). _unblockOutput.Invoke(true); }); _outputBlockedBuffer = new MemoryStream(); _outputBlocked = new ManualResetEventSlim(); // _unblockOutput allows output to the terminal again, 500ms after it invoked. _unblockOutput = new DebouncedAction <bool>(Dispatcher, TimeSpan.FromMilliseconds(500), x => { _outputBlocked.Reset(); }); _navigationCompleted = new SemaphoreSlim(0, 1); _connectedEvent = new ManualResetEventSlim(false); _webView.Navigate(new Uri("ms-appx-web:///Client/index.html")); }
void IxtermEventListener.OnTerminalResized(int columns, int rows) { if (_connectedEvent.IsSet) // only propagate after xterm.js is finished with fitting { // Prevent output from being sent during the terminal while // resize events are being processed (to avoid buffer corruption). _outputBlocked.Set(); _dispatcherJobs.Add(() => _sizeChanged.Invoke(new TerminalSize { Columns = columns, Rows = rows })); } }
public Task ChangeOptions(TerminalOptions options) { _optionsChanged.Invoke(options); return(Task.CompletedTask); }