From 14530289751e94f895ce7113a9434b5f09b90d63 Mon Sep 17 00:00:00 2001 From: ronak69 Date: Fri, 4 Aug 2023 14:57:39 +0000 Subject: [PATCH] Shell: Color bareword yellow if it's a prefix of at least one command Before, if a bareword wasn't a runnable program's filename it got colored red and white otherwise. Now, additionally it will be checked if it is a "prefix" of a possible command and colored yellow if it is and red if not. Coloring this way provides another "feedback" to the user: If while typing out a command name the color changes from yellow to red then a typo occurred :^) To check if a bareword is a prefix the `Shell::complete_program_name()` function is utilized (if pressing tab gives you some suggestions then it is a prefix). --- Userland/Shell/AST.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Userland/Shell/AST.cpp b/Userland/Shell/AST.cpp index e39062c3af..3492299c6b 100644 --- a/Userland/Shell/AST.cpp +++ b/Userland/Shell/AST.cpp @@ -654,6 +654,8 @@ ErrorOr BarewordLiteral::highlight_in_editor(Line::Editor& editor, Shell& #endif editor.stylize({ m_position.start_offset, m_position.end_offset }, style); + } else if (auto suggestions = shell.complete_program_name(m_text, m_text.bytes().size()); !suggestions.is_empty()) { + editor.stylize({ m_position.start_offset, m_position.end_offset }, { Line::Style::Foreground(Line::Style::XtermColor::Yellow) }); } else { editor.stylize({ m_position.start_offset, m_position.end_offset }, { Line::Style::Foreground(Line::Style::XtermColor::Red) }); }