summaryrefslogtreecommitdiff
path: root/Libraries/LibLine
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-03-31 18:59:15 +0200
committerAndreas Kling <kling@serenityos.org>2020-03-31 18:59:15 +0200
commit28edafbfa64ed02b932fc2cba2b97ed70c669b0a (patch)
treef277c449414d66839292ba708f45b0f693c650a0 /Libraries/LibLine
parent6529b78d08249fd643fb33b96a27750ee5a67efd (diff)
downloadserenity-28edafbfa64ed02b932fc2cba2b97ed70c669b0a.zip
LibLine: Fix build in Linux environment
My host compiler was complaining about "%b" in format strings and about ignoring the return value from a bunch of write() calls.
Diffstat (limited to 'Libraries/LibLine')
-rw-r--r--Libraries/LibLine/Editor.cpp18
1 files changed, 12 insertions, 6 deletions
diff --git a/Libraries/LibLine/Editor.cpp b/Libraries/LibLine/Editor.cpp
index 1bc92ce58f..9a2ff2c70e 100644
--- a/Libraries/LibLine/Editor.cpp
+++ b/Libraries/LibLine/Editor.cpp
@@ -28,6 +28,7 @@
#include <ctype.h>
#include <stdio.h>
#include <sys/ioctl.h>
+#include <sys/uio.h>
#include <unistd.h>
namespace Line {
@@ -250,7 +251,7 @@ String Editor::get_line(const String& prompt)
m_state = InputState::ExpectTerminator;
continue;
default:
- dbgprintf("Shell: Unhandled final: %b (%c)\n", ch, ch);
+ dbgprintf("Shell: Unhandled final: %02x (%c)\n", ch, ch);
m_state = InputState::Free;
continue;
}
@@ -323,11 +324,16 @@ String Editor::get_line(const String& prompt)
}
putchar('\n');
- write(STDOUT_FILENO, prompt.characters(), prompt.length());
- write(STDOUT_FILENO, m_buffer.data(), m_cursor);
- // Prevent not printing characters in case the user has moved the cursor and then pressed tab
- write(STDOUT_FILENO, m_buffer.data() + m_cursor, m_buffer.size() - m_cursor);
- m_cursor = m_buffer.size(); // bash doesn't do this, but it makes a little bit more sense
+ struct iovec iov[] = {
+ { const_cast<char*>(prompt.characters()), prompt.length() },
+ { m_buffer.data(), m_cursor },
+ { m_buffer.data() + m_cursor, m_buffer.size() - m_cursor }
+ };
+ if (writev(STDOUT_FILENO, iov, 3)) {
+ perror("writev");
+ ASSERT_NOT_REACHED();
+ }
+ m_cursor = m_buffer.size();
}
suggestions.clear_with_capacity();