mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:27:45 +00:00
LibLine: Add a display trivia field to suggestions
These strings will be shown next to the completions as an optional hint or description.
This commit is contained in:
parent
9453e0e6d2
commit
d995be428a
3 changed files with 21 additions and 7 deletions
|
@ -22,11 +22,13 @@ void XtermSuggestionDisplay::display(SuggestionManager const& manager)
|
|||
|
||||
size_t longest_suggestion_length = 0;
|
||||
size_t longest_suggestion_byte_length = 0;
|
||||
size_t longest_suggestion_byte_length_without_trivia = 0;
|
||||
|
||||
manager.set_start_index(0);
|
||||
manager.for_each_suggestion([&](auto& suggestion, auto) {
|
||||
longest_suggestion_length = max(longest_suggestion_length, suggestion.text_view.length());
|
||||
longest_suggestion_byte_length = max(longest_suggestion_byte_length, suggestion.text_string.length());
|
||||
longest_suggestion_length = max(longest_suggestion_length, suggestion.text_view.length() + suggestion.display_trivia_view.length());
|
||||
longest_suggestion_byte_length = max(longest_suggestion_byte_length, suggestion.text_string.length() + suggestion.display_trivia_string.length());
|
||||
longest_suggestion_byte_length_without_trivia = max(longest_suggestion_byte_length_without_trivia, suggestion.text_string.length());
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
|
||||
|
@ -114,8 +116,10 @@ void XtermSuggestionDisplay::display(SuggestionManager const& manager)
|
|||
if (spans_entire_line) {
|
||||
num_printed += m_num_columns;
|
||||
stderr_stream.write(suggestion.text_string.bytes());
|
||||
stderr_stream.write(suggestion.display_trivia_string.bytes());
|
||||
} else {
|
||||
stderr_stream.write(String::formatted("{: <{}}", suggestion.text_string, longest_suggestion_byte_length + 2).bytes());
|
||||
auto field = String::formatted("{: <{}} {}", suggestion.text_string, longest_suggestion_byte_length_without_trivia, suggestion.display_trivia_string);
|
||||
stderr_stream.write(String::formatted("{: <{}}", field, longest_suggestion_byte_length + 2).bytes());
|
||||
num_printed += longest_suggestion_length + 2;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue