diff --git a/src/builtins/read.rs b/src/builtins/read.rs index 45d4d507d..e7355b88e 100644 --- a/src/builtins/read.rs +++ b/src/builtins/read.rs @@ -248,6 +248,7 @@ fn read_interactive( shell: bool, silent: bool, prompt: &wstr, + prompt_str_is_empty: bool, right_prompt: &wstr, commandline: &Option, inputfd: RawFd, @@ -265,6 +266,7 @@ fn read_interactive( expand_abbrev_ok: false, exit_on_interrupt: true, + read_prompt_str_is_empty: prompt_str_is_empty, in_silent_mode: silent, left_prompt_cmd: prompt.to_owned(), @@ -644,6 +646,7 @@ pub fn read(parser: &Parser, streams: &mut IoStreams, argv: &mut [&wstr]) -> Bui opts.shell, opts.silent, opts.prompt.as_ref().unwrap(), + opts.prompt_str.as_ref().is_some_and(|ps| ps.is_empty()), &opts.right_prompt, &opts.commandline, streams.stdin_fd(), diff --git a/src/reader/reader.rs b/src/reader/reader.rs index 61aa5e0d7..59692991b 100644 --- a/src/reader/reader.rs +++ b/src/reader/reader.rs @@ -479,6 +479,8 @@ pub struct ReaderConfig { /// Whether to exit on interrupt (^C). pub exit_on_interrupt: bool, + pub read_prompt_str_is_empty: bool, + /// If set, do not show what is typed. pub in_silent_mode: bool, @@ -2372,16 +2374,17 @@ fn readline( self.history_search.reset(); - // HACK: Don't abandon line for the first prompt, because - // if we're started with the terminal it might not have settled, - // so the width is quite likely to be in flight. + // HACK: Use a simple \r for the first prompt, because if we're started with the terminal + // it might not have settled, so the width is quite likely to be in flight. // // This means that `printf %s foo; fish` will overwrite the `foo`, // but that's a smaller problem than having the omitted newline char // appear constantly. - let trusted_width = (!self.first_prompt).then_some(termsize_last().width()); + if !self.first_prompt || !self.conf.read_prompt_str_is_empty { + let trusted_width = (!self.first_prompt).then_some(termsize_last().width()); + self.screen.reset_abandoning_line(trusted_width); + } self.first_prompt = false; - self.screen.reset_abandoning_line(trusted_width); if !self.conf.event.is_empty() { event::fire_generic(self.parser, self.conf.event.to_owned(), vec![]);