mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-26 14:28:49 +00:00
Shell: Ensure that the cursor starts on a new line
And print an indicator when it doesn't, a la zsh.
This commit is contained in:
parent
c96b9fdb0a
commit
14a54a72fa
Notes:
sideshowbarker
2024-07-19 03:29:30 +09:00
Author: https://github.com/alimpfard
Commit: 14a54a72fa
Pull-request: https://github.com/SerenityOS/serenity/pull/3191
2 changed files with 25 additions and 0 deletions
|
@ -1087,9 +1087,33 @@ Vector<Line::CompletionSuggestion> Shell::complete_option(const String& program_
|
|||
return suggestions;
|
||||
}
|
||||
|
||||
void Shell::bring_cursor_to_beginning_of_a_line() const
|
||||
{
|
||||
struct winsize ws;
|
||||
if (editor) {
|
||||
ws = editor->terminal_size();
|
||||
} else {
|
||||
if (ioctl(STDERR_FILENO, TIOCGWINSZ, &ws) < 0) {
|
||||
// Very annoying assumptions.
|
||||
ws.ws_col = 80;
|
||||
ws.ws_row = 25;
|
||||
}
|
||||
}
|
||||
|
||||
Line::VT::apply_style(Line::Style { Line::Style::Background(Line::Style::XtermColor::Cyan), Line::Style::Foreground(Line::Style::XtermColor::Black) });
|
||||
putc('%', stderr);
|
||||
Line::VT::apply_style(Line::Style::reset_style());
|
||||
|
||||
for (auto i = 2; i < ws.ws_col; ++i)
|
||||
putc(' ', stderr);
|
||||
|
||||
putc('\r', stderr);
|
||||
}
|
||||
|
||||
bool Shell::read_single_line()
|
||||
{
|
||||
restore_ios();
|
||||
bring_cursor_to_beginning_of_a_line();
|
||||
auto line_result = editor->get_line(prompt());
|
||||
|
||||
if (line_result.is_error()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue