mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 06:37:43 +00:00
Shell: Highlight commands with a hyperlink to open their help pages
This commit is contained in:
parent
85152d2f7f
commit
99c0b895fe
4 changed files with 142 additions and 27 deletions
|
@ -620,8 +620,22 @@ RefPtr<Value> BarewordLiteral::run(RefPtr<Shell>)
|
|||
void BarewordLiteral::highlight_in_editor(Line::Editor& editor, Shell& shell, HighlightMetadata metadata)
|
||||
{
|
||||
if (metadata.is_first_in_list) {
|
||||
if (shell.is_runnable(m_text)) {
|
||||
editor.stylize({ m_position.start_offset, m_position.end_offset }, { Line::Style::Bold });
|
||||
auto runnable = shell.runnable_path_for(m_text);
|
||||
if (runnable.has_value()) {
|
||||
Line::Style bold = { Line::Style::Bold };
|
||||
Line::Style style = bold;
|
||||
|
||||
#ifdef __serenity__
|
||||
if (runnable->kind == Shell::RunnablePath::Kind::Executable || runnable->kind == Shell::RunnablePath::Kind::Alias) {
|
||||
auto name = shell.help_path_for({}, *runnable);
|
||||
if (name.has_value()) {
|
||||
auto url = URL::create_with_help_scheme(name.release_value(), shell.hostname);
|
||||
style = bold.unified_with(Line::Style::Hyperlink(url.to_string()));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
editor.stylize({ m_position.start_offset, m_position.end_offset }, style);
|
||||
} else {
|
||||
editor.stylize({ m_position.start_offset, m_position.end_offset }, { Line::Style::Foreground(Line::Style::XtermColor::Red) });
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue