ptyProvider top-level property

StateProvider<Pty> ptyProvider
final

Implementation

final ptyProvider = StateProvider<Pty>((ref) {
  // Create a pseudo termminal provider.

  Terminal terminal = ref.watch(terminalProvider);
  debugText('  STARTUP', shell);
  Pty pty = Pty.start(shell, arguments: ['--no-save']);

  // Options
  //   columns: terminal.viewWidth,
  //   rows: terminal.viewHeight,

  // Add a listener of the pty to show the pty output within the enclosing
  // terminal. I also want to capture the output for parsing in the app.

  pty.output.cast<List<int>>().transform(const Utf8Decoder()).listen((data) {
    terminal.write(data);
    // debugPrint('update stdoutProvider');
    ref.read(stdoutProvider.notifier).state =
        ref.read(stdoutProvider) + cleanString(data);
  });

  pty.exitCode.then((code) {
    terminal.write('the process exited with exit code $code');
  });

  terminal.onOutput = (data) {
    // This gets called when a user types into the R console. So typing the
    // command `ls()` in the R console the command is echoed in the R
    // console. This is not capturing the output from the console.

    pty.write(const Utf8Encoder().convert(data));
  };

  terminal.onResize = (w, h, pw, ph) {
    pty.resize(h, w);
  };

  return pty;
});