wrapCommand method

  1. @override
String wrapCommand(
  1. String line, {
  2. required bool interactive,
  3. required String tail,
})
override

Wraps a user-typed line so it runs and is followed by tail (a marker) as one logical unit. interactive enables terminal-echo handling where the dialect needs it (POSIX only; pipe-based Windows shells don't echo stdin).

Implementation

@override
String wrapCommand(
  String line, {
  required bool interactive,
  required String tail,
}) {
  // Run the command and the marker as one logical line (`eval` keeps this
  // valid for pipes, trailing `&`, `cd`…) so a foreground app consumes both
  // and the marker fires right after it exits.
  final escaped = line.replaceAll("'", r"'\''");
  final body = "eval '$escaped' ; $tail";
  // The remote shell runs with `stty -echo`; re-enable echo just for the
  // command so cooked-mode readers (read/cat/y-N) echo runtime input, then
  // disable it again before the marker.
  return interactive
      ? 'stty echo 2>/dev/null ; $body ; stty -echo 2>/dev/null'
      : body;
}