From 1bcceafd931ece172de77a84db6009e4d1ac12ea Mon Sep 17 00:00:00 2001 From: Tooster <5300963+T3sT3ro@users.noreply.github.com> Date: Wed, 11 Sep 2024 22:33:20 +0200 Subject: [PATCH] Improve #12008 UX, clear scrollback by default on `clear` (#13821) # Description Related to #11693. It looks like there is no reason for Nu shell's `clear` to behave differently than other shells' `clear`. To improve the UX and fulfill the user expectations, the default has been adjusted to work the same as in other shells by clearing the scrollback buffer. For edge cases where someone depends on the current behavior of keeping the scrollback, a `-k` option has been added. # User-Facing Changes - Improve the UX of `clear` by changing the default behavior to the same as other popular shells, i.e clear scrollback by default. - Remove `-a --all` flag, make it the default behavior to clear the scrollback - Add `-k --keep-scrollback` flag for backward compat to keep the scrollback buffer # Tests + Formatting This is a simple change flipping the flag and default behavior, no tests should be needed. # After Submitting - [ ] update the `clear` command docs --------- Co-authored-by: Douglas <32344964+NotTheDr01ds@users.noreply.github.com> Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com> --- crates/nu-command/src/platform/clear.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/crates/nu-command/src/platform/clear.rs b/crates/nu-command/src/platform/clear.rs index 30c6cc69a5..b47db161c6 100644 --- a/crates/nu-command/src/platform/clear.rs +++ b/crates/nu-command/src/platform/clear.rs @@ -19,14 +19,18 @@ impl Command for Clear { "Clear the terminal." } + fn extra_description(&self) -> &str { + "By default clears the current screen and the off-screen scrollback buffer." + } + fn signature(&self) -> Signature { Signature::build("clear") .category(Category::Platform) .input_output_types(vec![(Type::Nothing, Type::Nothing)]) .switch( - "all", - "Clear the terminal and its scroll-back history", - Some('a'), + "keep-scrollback", + "Do not clear the scrollback history", + Some('k'), ) } @@ -37,9 +41,9 @@ impl Command for Clear { call: &Call, _input: PipelineData, ) -> Result { - let clear_type: ClearType = match call.has_flag(engine_state, stack, "all")? { - true => ClearType::Purge, - _ => ClearType::All, + let clear_type: ClearType = match call.has_flag(engine_state, stack, "keep-scrollback")? { + true => ClearType::All, + _ => ClearType::Purge, }; std::io::stdout() .queue(ClearCommand(clear_type))? @@ -57,8 +61,8 @@ impl Command for Clear { result: None, }, Example { - description: "Clear the terminal and its scroll-back history", - example: "clear --all", + description: "Clear the terminal but not its scrollback history", + example: "clear --keep-scrollback", result: None, }, ]