mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-20 09:49:15 +03:00
Shell: Add formatter for history events
This commit is contained in:
parent
239472ba69
commit
c1b4e86004
Notes:
sideshowbarker
2024-07-18 23:50:52 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/c1b4e860041 Pull-request: https://github.com/SerenityOS/serenity/pull/4899
@ -369,6 +369,62 @@ void Formatter::visit(const AST::Glob* node)
|
||||
visited(node);
|
||||
}
|
||||
|
||||
void Formatter::visit(const AST::HistoryEvent* node)
|
||||
{
|
||||
will_visit(node);
|
||||
test_and_update_output_cursor(node);
|
||||
|
||||
current_builder().append('!');
|
||||
switch (node->selector().event.kind) {
|
||||
case AST::HistorySelector::EventKind::ContainingStringLookup:
|
||||
current_builder().append('?');
|
||||
current_builder().append(node->selector().event.text);
|
||||
break;
|
||||
case AST::HistorySelector::EventKind::StartingStringLookup:
|
||||
current_builder().append(node->selector().event.text);
|
||||
break;
|
||||
case AST::HistorySelector::EventKind::IndexFromStart:
|
||||
current_builder().append(node->selector().event.text);
|
||||
break;
|
||||
case AST::HistorySelector::EventKind::IndexFromEnd:
|
||||
if (node->selector().event.index == 0)
|
||||
current_builder().append('!');
|
||||
else
|
||||
current_builder().append(node->selector().event.text);
|
||||
break;
|
||||
}
|
||||
|
||||
auto& range = node->selector().word_selector_range;
|
||||
if (!range.end.has_value()
|
||||
|| range.end.value().kind != AST::HistorySelector::WordSelectorKind::Last
|
||||
|| range.start.kind != AST::HistorySelector::WordSelectorKind::Index || range.start.selector != 0) {
|
||||
|
||||
auto append_word = [this](auto& selector) {
|
||||
switch (selector.kind) {
|
||||
case AST::HistorySelector::WordSelectorKind::Index:
|
||||
if (selector.selector == 0)
|
||||
current_builder().append('^');
|
||||
else
|
||||
current_builder().appendff("{}", selector.selector);
|
||||
break;
|
||||
case AST::HistorySelector::WordSelectorKind::Last:
|
||||
current_builder().append('$');
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
current_builder().append(':');
|
||||
append_word(range.start);
|
||||
|
||||
if (range.end.has_value()) {
|
||||
current_builder().append('-');
|
||||
append_word(range.end.value());
|
||||
}
|
||||
}
|
||||
|
||||
visited(node);
|
||||
}
|
||||
|
||||
void Formatter::visit(const AST::Execute* node)
|
||||
{
|
||||
will_visit(node);
|
||||
|
@ -71,6 +71,7 @@ private:
|
||||
virtual void visit(const AST::FunctionDeclaration*) override;
|
||||
virtual void visit(const AST::ForLoop*) override;
|
||||
virtual void visit(const AST::Glob*) override;
|
||||
virtual void visit(const AST::HistoryEvent*) override;
|
||||
virtual void visit(const AST::Execute*) override;
|
||||
virtual void visit(const AST::IfCond*) override;
|
||||
virtual void visit(const AST::Join*) override;
|
||||
|
Loading…
Reference in New Issue
Block a user