nushell/crates/nu-command/src/platform
Ryan Devenney 2659c359e9
interrupt input command with Ctrl + C (#8159)
# Description

GH Issue: [#8074](https://github.com/nushell/nushell/issues/8074)

Adding SIGINT Ctrl + C functionality to *most* of the `input` command.
`input` with the flags `--suppress-output` and `--bytes-until` are
executed in raw mode which allows a ^C signal to be caught as it's
input, but an "optionless" call of `input` is using a standard
`read_line()` method that takes a ^C input and clears the buffer of any
data collected before the ^C. I'm more than happy to alter the
"optionless" call but putting it in raw mode hides the user input, so at
the moment that's unchanged.

# User-Facing Changes

Now ^C anywhere in the stdin stream will cause the command to SIGINT (as
long as the command isn't optionless), rather than being read in as part
of the input.
```
/home/rdevenney/projects/open_source/nushell〉input --suppress-output
Error: nu:🐚:io_error (link)

  × I/O error
  help: SIGINT
```

```
/home/rdevenney/projects/open_source/nushell〉input --bytes-until "a"
Error: nu:🐚:io_error (link)

  × I/O error
  help: SIGINT

```

As mentioned above, the default input behavior is the same.

# Tests + Formatting

Don't forget to add tests that cover your changes.

Make sure you've run and fixed any issues with these commands:

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect` to check that you're using the standard code
style
- `cargo test --workspace` to check that all tests pass

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-22 17:19:19 +00:00
..
ansi Use imported names in Command::run signatures (#7967) 2023-02-05 22:17:46 +01:00
reedline_commands Use imported names in Command::run signatures (#7967) 2023-02-05 22:17:46 +01:00
clear.rs Add more input/output type annotations (#7532) 2022-12-21 20:20:46 +01:00
dir_info.rs Further cleanup of Span::test_data usage + span fixes (#7595) 2022-12-24 07:41:57 -06:00
du.rs Validate input range of du flags (#7962) 2023-02-06 21:34:32 +01:00
input.rs interrupt input command with Ctrl + C (#8159) 2023-02-22 17:19:19 +00:00
kill.rs Add more input/output type annotations (#7532) 2022-12-21 20:20:46 +01:00
mod.rs Ansi link (#7751) 2023-01-15 17:23:37 +02:00
sleep.rs Add helper method to check whether ctrl+c was pressed, adopt it (#7482) 2022-12-15 09:39:24 -08:00
term_size.rs Use imported names in Command::run signatures (#7967) 2023-02-05 22:17:46 +01:00