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).
This commit is contained in:
ronak69 2023-08-04 14:57:39 +00:00 committed by Ali Mohammad Pur
parent ad440f9e9a
commit 1453028975
Notes: sideshowbarker 2024-07-17 03:45:48 +09:00

View file

@ -654,6 +654,8 @@ ErrorOr<void> 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) });
}