private void ListenToStdOut() { Task.Factory.StartNew(async() => { using (var reader = new StreamReader(_stdout)) { do { var buffer = new byte[Math.Max(1024, _terminalSize.Columns * _terminalSize.Rows * 4)]; var readBytes = await _stdout.ReadAsync(buffer, 0, buffer.Length).ConfigureAwait(false); var read = new byte[readBytes]; Buffer.BlockCopy(buffer, 0, read, 0, readBytes); if (readBytes > 0) { _terminalsManager.DisplayTerminalOutput(Id, read); } while (_paused && !_exited) { await Task.Delay(50); } }while (!_exited); } }, TaskCreationOptions.LongRunning); }
private void _terminal_OutputReady(object sender, EventArgs e) { if (_reader == null) { _reader = new BufferedReader(_terminal.ConsoleOutStream, bytes => _terminalsManager.DisplayTerminalOutput(Id, bytes), _enableBuffer); } }
private void ListenToStdOut() { Task.Factory.StartNew(async() => { using (var reader = new StreamReader(_terminal.ConsoleOutStream)) { do { var buffer = new byte[1024]; var readBytes = await _terminal.ConsoleOutStream.ReadAsync(buffer, 0, buffer.Length).ConfigureAwait(false); if (readBytes > 0) { _terminalsManager.DisplayTerminalOutput(Id, buffer); } }while (!_exited); } }, TaskCreationOptions.LongRunning); }
private void ListenToStdOut() { Task.Run(async() => { var reader = new StreamReader(_terminal.ConsoleOutStream); do { var offset = 0; var buffer = new char[1024]; var readChars = await reader.ReadAsync(buffer, offset, buffer.Length - offset).ConfigureAwait(false); if (readChars > 0) { var output = new String(buffer, 0, readChars); _terminalsManager.DisplayTerminalOutput(Id, output); } }while (!reader.EndOfStream); }); }
public void Start(CreateTerminalRequest request, TerminalsManager terminalsManager) { _enableBuffer = false; // request.Profile.UseBuffer; Id = request.Id; _terminalsManager = terminalsManager; var configHandle = IntPtr.Zero; var spawnConfigHandle = IntPtr.Zero; var errorHandle = IntPtr.Zero; try { configHandle = winpty_config_new(WINPTY_FLAG_COLOR_ESCAPES, out errorHandle); winpty_config_set_initial_size(configHandle, request.Size.Columns, request.Size.Rows); _handle = winpty_open(configHandle, out errorHandle); if (errorHandle != IntPtr.Zero) { throw new Exception(winpty_error_msg(errorHandle)); } var cwd = GetWorkingDirectory(request.Profile); var args = request.Profile.Arguments; if (!string.IsNullOrWhiteSpace(request.Profile.Location)) { args = $"\"{request.Profile.Location}\" {args}"; } spawnConfigHandle = winpty_spawn_config_new(WINPTY_SPAWN_FLAG_AUTO_SHUTDOWN, request.Profile.Location, args, cwd, terminalsManager.GetDefaultEnvironmentVariableString(request.Profile.EnvironmentVariables), out errorHandle); if (errorHandle != IntPtr.Zero) { throw new Exception(winpty_error_msg(errorHandle)); } _stdin = CreatePipe(winpty_conin_name(_handle), PipeDirection.Out); _stdout = CreatePipe(winpty_conout_name(_handle), PipeDirection.In); if (!winpty_spawn(_handle, spawnConfigHandle, out IntPtr process, out IntPtr thread, out int procError, out errorHandle)) { throw new Exception($@"Failed to start the shell process. Please check your shell settings.{Environment.NewLine}Tried to start: {request.Profile.Location} ""{request.Profile.Arguments}"""); } var shellProcessId = ProcessApi.GetProcessId(process); _shellProcess = Process.GetProcessById(shellProcessId); _shellProcess.EnableRaisingEvents = true; _shellProcess.Exited += _shellProcess_Exited; if (!string.IsNullOrWhiteSpace(request.Profile.Location)) { ShellExecutableName = Path.GetFileNameWithoutExtension(request.Profile.Location); } else { ShellExecutableName = request.Profile.Arguments.Split(' ')[0]; } } finally { winpty_config_free(configHandle); winpty_spawn_config_free(spawnConfigHandle); winpty_error_free(errorHandle); } _reader = new BufferedReader(_stdout, bytes => _terminalsManager.DisplayTerminalOutput(Id, bytes), _enableBuffer); }