-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[LLDB][Editline] empty current line before el_wgets
#165830
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
el_wgets
|
@llvm/pr-subscribers-lldb Author: Kiva (imkiva) ChangesThis PR fixes #157637 by printing ANSI sequence "\r\x1b[K" to empty the line before calling to Full diff: https://github.com/llvm/llvm-project/pull/165830.diff 2 Files Affected:
diff --git a/lldb/source/Host/common/Editline.cpp b/lldb/source/Host/common/Editline.cpp
index 1b1922e710764..03b442cce973e 100644
--- a/lldb/source/Host/common/Editline.cpp
+++ b/lldb/source/Host/common/Editline.cpp
@@ -1626,6 +1626,12 @@ bool Editline::GetLine(std::string &line, bool &interrupted) {
m_editor_status = EditorStatus::Editing;
m_revert_cursor_index = -1;
+ if (m_locked_output && m_output_stream_sp) {
+ FILE *f = m_locked_output->GetFile().GetStream();
+ fprintf(f, "\r" ANSI_CLEAR_RIGHT);
+ fflush(f);
+ }
+
int count;
auto input = el_wgets(m_editline, &count);
diff --git a/lldb/test/API/terminal/TestEditline.py b/lldb/test/API/terminal/TestEditline.py
index 38f4f34ed740b..4696b1e1b112e 100644
--- a/lldb/test/API/terminal/TestEditline.py
+++ b/lldb/test/API/terminal/TestEditline.py
@@ -94,7 +94,7 @@ def test_prompt_no_color(self):
# after the prompt.
self.child.send("foo")
# Check that there are no escape codes.
- self.child.expect(re.escape("\n(lldb) foo"))
+ self.child.expect(re.escape("\n\r\x1b[K(lldb) foo"))
@skipIfAsan
@skipIfEditlineSupportMissing
|
|
Thanks for looking at this! I don't know enough here to review, but I think @JDevlieghere does. |
lldb/source/Host/common/Editline.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The flush shouldn't be necessary, the locked output streams will flush when they're unlocked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, thanks~
lldb/source/Host/common/Editline.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't have to check m_output_stream_sp, and the code on 1638 assumes that we have a locked output stream, so let's replace the check with an assert here (to cover both) and then use it unconditionally like we do below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, thanks~
JDevlieghere
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This PR fixes llvm#157637 by printing ANSI sequence "\r\x1b[K" to empty the line before calling to `el_wgets`. Later when `el_wgets` prints the real prompt, all wrongly printed characters are removed from the terminal.
This PR fixes #157637 by printing ANSI sequence "\r\x1b[K" to empty the line before calling to
el_wgets. Later whenel_wgetsprints the real prompt, all wrongly printed characters are removed from the terminal.