From bc4d597e910b47626327f62402db776f86a0e7e3 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Sat, 10 Apr 2021 17:10:45 +0200 Subject: [PATCH] Don't abandon line before the first prompt When a terminal in a tiling WM starts, it might start the shell before it has reached its "final" size. So we get the terminal width, then the terminal would be resized (to appease the tiling logic), and then we would print the abandon line with the omitted newline char, only if the size got smaller (likely!), we would overflow the line and land on the next. So what we do is a bit of a hack: We don't abandon the first line. This means that `printf %s foo; fish` will overwrite the `foo`, but that's a super small problem and I don't see another way around this. Fixes #7893. --- src/reader.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/reader.cpp b/src/reader.cpp index 3f8f906b3..eb49aa6c1 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -586,6 +586,9 @@ class reader_data_t : public std::enable_shared_from_this { /// HACK: A flag to reset the loop state from the outside. bool reset_loop_state{false}; + /// Whether this is the first prompt. + bool first_prompt{true}; + /// The representation of the current screen contents. screen_t screen; @@ -3881,7 +3884,20 @@ maybe_t reader_data_t::readline(int nchars_or_0) { } } - s_reset_abandoning_line(&screen, termsize_last().width); + // 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. + // + // 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. + // + // I can't see a good way around this. + if (!first_prompt) { + s_reset_abandoning_line(&screen, termsize_last().width); + } + first_prompt = false; + event_fire_generic(parser(), L"fish_prompt"); exec_prompt();