pub trait Menu: Send {
Show 13 methods
fn name(&self) -> &str;
fn indicator(&self) -> &str;
fn is_active(&self) -> bool;
fn menu_event(&mut self, event: MenuEvent);
fn can_quick_complete(&self) -> bool;
fn can_partially_complete(
&mut self,
values_updated: bool,
line_buffer: &mut LineBuffer,
completer: &mut dyn Completer
) -> bool;
fn update_values(
&mut self,
line_buffer: &mut LineBuffer,
completer: &mut dyn Completer
);
fn update_working_details(
&mut self,
line_buffer: &mut LineBuffer,
completer: &mut dyn Completer,
painter: &Painter
);
fn replace_in_buffer(&self, line_buffer: &mut LineBuffer);
fn menu_required_lines(&self, terminal_columns: u16) -> u16;
fn menu_string(
&self,
available_lines: u16,
use_ansi_coloring: bool
) -> String;
fn min_rows(&self) -> u16;
fn get_values(&self) -> &[Suggestion];
}
Expand description
Trait that defines how a menu will be printed by the painter
Required Methods
Selects what type of event happened with the menu
fn can_quick_complete(&self) -> bool
fn can_quick_complete(&self) -> bool
A menu may not be allowed to quick complete because it needs to stay active even with one element
fn can_partially_complete(
&mut self,
values_updated: bool,
line_buffer: &mut LineBuffer,
completer: &mut dyn Completer
) -> bool
fn can_partially_complete(
&mut self,
values_updated: bool,
line_buffer: &mut LineBuffer,
completer: &mut dyn Completer
) -> bool
The completion menu can try to find the common string and replace it in the given line buffer
fn update_values(
&mut self,
line_buffer: &mut LineBuffer,
completer: &mut dyn Completer
)
fn update_values(
&mut self,
line_buffer: &mut LineBuffer,
completer: &mut dyn Completer
)
Updates the values presented in the menu
This function needs to be defined in the trait because when the menu is
activated or the quick_completion
option is true, the len of the values
is calculated to know if there is only one value so it can be selected
immediately
fn update_working_details(
&mut self,
line_buffer: &mut LineBuffer,
completer: &mut dyn Completer,
painter: &Painter
)
fn update_working_details(
&mut self,
line_buffer: &mut LineBuffer,
completer: &mut dyn Completer,
painter: &Painter
)
The working details of a menu are values that could change based on the menu conditions before it being printed, such as the number or size of columns, etc. In this function should be defined how the menu event is treated since it is called just before painting the menu
fn replace_in_buffer(&self, line_buffer: &mut LineBuffer)
fn replace_in_buffer(&self, line_buffer: &mut LineBuffer)
Indicates how to replace in the line buffer the selected value from the menu
Calculates the real required lines for the menu considering how many lines wrap the terminal or if entries have multiple lines
Creates the menu representation as a string which will be painted by the painter
fn get_values(&self) -> &[Suggestion]
fn get_values(&self) -> &[Suggestion]
Gets cached values from menu that will be displayed