mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 21:57:35 +00:00
Shell: factor out updating the path cache into a function.
This commit is contained in:
parent
f6d4c4f02c
commit
0622b60fbd
4 changed files with 22 additions and 16 deletions
|
@ -367,9 +367,9 @@ RefPtr<Value> BarewordLiteral::run(RefPtr<Shell>)
|
||||||
void BarewordLiteral::highlight_in_editor(Line::Editor& editor, Shell& shell, HighlightMetadata metadata)
|
void BarewordLiteral::highlight_in_editor(Line::Editor& editor, Shell& shell, HighlightMetadata metadata)
|
||||||
{
|
{
|
||||||
if (metadata.is_first_in_list) {
|
if (metadata.is_first_in_list) {
|
||||||
if (shell.is_runnable(m_text))
|
if (shell.is_runnable(m_text)) {
|
||||||
editor.stylize({ m_position.start_offset, m_position.end_offset }, { Line::Style::Bold });
|
editor.stylize({ m_position.start_offset, m_position.end_offset }, { Line::Style::Bold });
|
||||||
else {
|
} else {
|
||||||
editor.stylize({ m_position.start_offset, m_position.end_offset }, { Line::Style::Foreground(Line::Style::XtermColor::Red) });
|
editor.stylize({ m_position.start_offset, m_position.end_offset }, { Line::Style::Foreground(Line::Style::XtermColor::Red) });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,20 +64,7 @@ int Shell::builtin_alias(int argc, const char** argv)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
m_aliases.set(parts[0], parts[1]);
|
m_aliases.set(parts[0], parts[1]);
|
||||||
size_t index = 0;
|
add_entry_to_cache(parts[0]);
|
||||||
auto match = binary_search(
|
|
||||||
cached_path.span(), parts[0], [](const String& name, const String& program) -> int {
|
|
||||||
return strcmp(name.characters(), program.characters());
|
|
||||||
},
|
|
||||||
&index);
|
|
||||||
|
|
||||||
if (match)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
while (strcmp(cached_path[index].characters(), parts[0].characters()) < 0) {
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
cached_path.insert(index, parts[0]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -795,6 +795,24 @@ void Shell::cache_path()
|
||||||
quick_sort(cached_path);
|
quick_sort(cached_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Shell::add_entry_to_cache(const String& entry)
|
||||||
|
{
|
||||||
|
size_t index = 0;
|
||||||
|
auto match = binary_search(
|
||||||
|
cached_path.span(), entry, [](const String& name, const String& program) -> int {
|
||||||
|
return strcmp(name.characters(), program.characters());
|
||||||
|
},
|
||||||
|
&index);
|
||||||
|
|
||||||
|
if (match)
|
||||||
|
return;
|
||||||
|
|
||||||
|
while (strcmp(cached_path[index].characters(), entry.characters()) < 0) {
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
cached_path.insert(index, entry);
|
||||||
|
}
|
||||||
|
|
||||||
void Shell::highlight(Line::Editor& editor) const
|
void Shell::highlight(Line::Editor& editor) const
|
||||||
{
|
{
|
||||||
auto line = editor.line();
|
auto line = editor.line();
|
||||||
|
|
|
@ -188,6 +188,7 @@ private:
|
||||||
virtual void save_to(JsonObject&) override;
|
virtual void save_to(JsonObject&) override;
|
||||||
|
|
||||||
void cache_path();
|
void cache_path();
|
||||||
|
void add_entry_to_cache(const String&);
|
||||||
void stop_all_jobs();
|
void stop_all_jobs();
|
||||||
const Job* m_current_job { nullptr };
|
const Job* m_current_job { nullptr };
|
||||||
LocalFrame* find_frame_containing_local_variable(const String& name);
|
LocalFrame* find_frame_containing_local_variable(const String& name);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue