Debian Codegraph @

src/canvas/dialogs/help_dialog.rs

raw symbols SCIP
1 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::{maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/max()., minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/min().};
2
3 use ratatuirust-analyzer cargo ratatui 0.30.2 crate/::{
4 Framerust-analyzer cargo ratatui-core 0.1.2 terminal/frame/Frame#,
5 layoutrust-analyzer cargo ratatui-core 0.1.2 layout/::{Alignmentrust-analyzer cargo ratatui-core 0.1.2 layout/alignment/Alignment#, Constraintrust-analyzer cargo ratatui-core 0.1.2 layout/constraint/Constraint#, Directionrust-analyzer cargo ratatui-core 0.1.2 layout/direction/Direction#, Layoutrust-analyzer cargo ratatui-core 0.1.2 layout/layout/Layout#, Rectrust-analyzer cargo ratatui-core 0.1.2 layout/rect/Rect#},
6 stylerust-analyzer cargo ratatui-core 0.1.2 style/::Stylerust-analyzer cargo ratatui-core 0.1.2 style/Style#,
7 textrust-analyzer cargo ratatui-core 0.1.2 text/::{Linerust-analyzer cargo ratatui-core 0.1.2 text/line/Line#, Spanrust-analyzer cargo ratatui-core 0.1.2 text/span/Span#},
8 widgetsrust-analyzer cargo ratatui 0.30.2 widgets/::{Paddingrust-analyzer cargo ratatui-widgets 0.3.2 block/padding/Padding#, Paragraphrust-analyzer cargo ratatui-widgets 0.3.2 paragraph/Paragraph#, Wraprust-analyzer cargo ratatui-widgets 0.3.2 paragraph/Wrap#},
9 };
10 use unicode_widthrust-analyzer cargo unicode-width 0.2.2 crate/::UnicodeWidthStrrust-analyzer cargo unicode-width 0.2.2 UnicodeWidthStr#;
11
12 use craterust-analyzer cargo bottom 0.14.9 crate/::{
13 apprust-analyzer cargo bottom 0.14.9 app/::Apprust-analyzer cargo bottom 0.14.9 app/App#,
14 canvasrust-analyzer cargo bottom 0.14.9 canvas/::{
15 Painterrust-analyzer cargo bottom 0.14.9 canvas/Painter#,
16 componentsrust-analyzer cargo bottom 0.14.9 canvas/components/::{
17 scroll_barrust-analyzer cargo bottom 0.14.9 canvas/components/scroll_bar/::{ScrollBarArgsrust-analyzer cargo bottom 0.14.9 canvas/components/scroll_bar/ScrollBarArgs#, dialog_scroll_bar_arearust-analyzer cargo bottom 0.14.9 canvas/components/scroll_bar/dialog_scroll_bar_area()., draw_scroll_barrust-analyzer cargo bottom 0.14.9 canvas/components/scroll_bar/draw_scroll_bar().},
18 search_inputrust-analyzer cargo bottom 0.14.9 canvas/components/search_input/,
19 },
20 drawing_utilsrust-analyzer cargo bottom 0.14.9 canvas/drawing_utils/::dialog_blockrust-analyzer cargo bottom 0.14.9 canvas/drawing_utils/dialog_block().,
21 },
22 constantsrust-analyzer cargo bottom 0.14.9 constants/::{selfrust-analyzer cargo bottom 0.14.9 constants/, HELP_TEXTrust-analyzer cargo bottom 0.14.9 constants/HELP_TEXT.},
23 };
24
25 /// Append a highlighted match to `lines`, and return whether a match was found.
26 fn add_highlight_matchrust-analyzer cargo bottom 0.14.9 canvas/dialogs/help_dialog/add_highlight_match().<'a>(
27 query: &str, target: &'a str, lines: &mut Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Linerust-analyzer cargo ratatui-core 0.1.2 text/line/Line#<'a>>, normal_style: Stylerust-analyzer cargo ratatui-core 0.1.2 style/Style#,
28 match_style: Stylerust-analyzer cargo ratatui-core 0.1.2 style/Style#,
29 ) -> bool {
30 let lower = target.to_lowercaserust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]to_lowercase().();
31
32 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(pos) = lower.findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]find().(query) {
33 let match_end = pos rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().query.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().();
34 lines.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Linerust-analyzer cargo ratatui-core 0.1.2 text/line/Line#::fromrust-analyzer cargo ratatui-core 0.1.2 text/line/impl#[`Line<'a>`][`From<Vec<Span<'a>>>`]from().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![
35 Spanrust-analyzer cargo ratatui-core 0.1.2 text/span/Span#::styledrust-analyzer cargo ratatui-core 0.1.2 text/span/impl#[`Span<'a>`]styled().(&target[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...pos]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., normal_style),
36 Spanrust-analyzer cargo ratatui-core 0.1.2 text/span/Span#::styledrust-analyzer cargo ratatui-core 0.1.2 text/span/impl#[`Span<'a>`]styled().(&target[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().pos..match_end]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., match_style),
37 Spanrust-analyzer cargo ratatui-core 0.1.2 text/span/Span#::styledrust-analyzer cargo ratatui-core 0.1.2 text/span/impl#[`Span<'a>`]styled().(&target[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().match_end..]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., normal_style),
38 ]));
39 true
40 } else {
41 false
42 }
43 }
44
45 // TODO: [REFACTOR] Make generic dialog boxes to build off of instead?
46 impl Painterrust-analyzer cargo bottom 0.14.9 canvas/Painter# {
47 fn help_text_linesrust-analyzer cargo bottom 0.14.9 canvas/dialogs/help_dialog/impl#[Painter]help_text_lines().(&self, app_state: &Apprust-analyzer cargo bottom 0.14.9 app/App#) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Linerust-analyzer cargo ratatui-core 0.1.2 text/line/Line#<'_>> {
48 let mut lines: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Linerust-analyzer cargo ratatui-core 0.1.2 text/line/Line#<'_>> = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
49
50 let query = app_state
51 .help_dialog_staterust-analyzer cargo bottom 0.14.9 app/App#help_dialog_state.
52 .search_input_staterust-analyzer cargo bottom 0.14.9 app/states/AppHelpDialogState#search_input_state.
53 .current_queryrust-analyzer cargo bottom 0.14.9 utils/input/impl#[InputFieldState]current_query().()
54 .trimrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim().()
55 .to_lowercaserust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]to_lowercase().();
56
57 let is_filtering = !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().query.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]is_empty().();
58 if is_filtering {
59 let selected_header_style = self
60 .stylesrust-analyzer cargo bottom 0.14.9 canvas/Painter#styles.
61 .selected_text_stylerust-analyzer cargo bottom 0.14.9 options/config/style/Styles#selected_text_style.
62 .add_modifierrust-analyzer cargo ratatui-core 0.1.2 style/impl#[Style]add_modifier().(self.stylesrust-analyzer cargo bottom 0.14.9 canvas/Painter#styles..table_header_stylerust-analyzer cargo bottom 0.14.9 options/config/style/Styles#table_header_style..add_modifierrust-analyzer cargo ratatui-core 0.1.2 style/Style#add_modifier.);
63
64 HELP_TEXTrust-analyzer cargo bottom 0.14.9 constants/HELP_TEXT..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().().for_eachrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#for_each().(|(itx, section)| {
65 let mut iter = section.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().();
66
67 if itx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 {
68 return;
69 }
70
71 let header_str = iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]next().().copiedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<&T>`]copied().();
72
73 let mut header_line: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Linerust-analyzer cargo ratatui-core 0.1.2 text/line/Line#<'_>> = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
74 let header_matches = if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(h) = header_str {
75 add_highlight_matchrust-analyzer cargo bottom 0.14.9 canvas/dialogs/help_dialog/add_highlight_match().(
76 &query,
77 h,
78 &mut header_line,
79 self.stylesrust-analyzer cargo bottom 0.14.9 canvas/Painter#styles..table_header_stylerust-analyzer cargo bottom 0.14.9 options/config/style/Styles#table_header_style.,
80 selected_header_style,
81 )
82 } else {
83 false
84 };
85
86 let mut matched_body: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Linerust-analyzer cargo ratatui-core 0.1.2 text/line/Line#<'_>> = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
87 for &text in iter {
88 add_highlight_matchrust-analyzer cargo bottom 0.14.9 canvas/dialogs/help_dialog/add_highlight_match().(
89 &query,
90 text,
91 &mut matched_body,
92 self.stylesrust-analyzer cargo bottom 0.14.9 canvas/Painter#styles..text_stylerust-analyzer cargo bottom 0.14.9 options/config/style/Styles#text_style.,
93 self.stylesrust-analyzer cargo bottom 0.14.9 canvas/Painter#styles..selected_text_stylerust-analyzer cargo bottom 0.14.9 options/config/style/Styles#selected_text_style.,
94 );
95 }
96
97 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().matched_body.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() || header_matches {
98 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(header) = header_str {
99 // Don't insert the space if there's nothing above anyway.
100 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().lines.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() {
101 lines.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Linerust-analyzer cargo ratatui-core 0.1.2 text/line/Line#::fromrust-analyzer cargo ratatui-core 0.1.2 text/line/impl#[`Line<'a>`][`From<Span<'a>>`]from().(Spanrust-analyzer cargo ratatui-core 0.1.2 text/span/Span#::defaultrust-analyzer cargo ratatui-core 0.1.2 text/span/impl#[`Span<'a>`][Default]default().()));
102 }
103
104 if header_matches {
105 lines.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<T>`]extend().(header_line);
106 } else {
107 lines.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Linerust-analyzer cargo ratatui-core 0.1.2 text/line/Line#::fromrust-analyzer cargo ratatui-core 0.1.2 text/line/impl#[`Line<'a>`][`From<Span<'a>>`]from().(Spanrust-analyzer cargo ratatui-core 0.1.2 text/span/Span#::styledrust-analyzer cargo ratatui-core 0.1.2 text/span/impl#[`Span<'a>`]styled().(
108 header,
109 self.stylesrust-analyzer cargo bottom 0.14.9 canvas/Painter#styles..table_header_stylerust-analyzer cargo bottom 0.14.9 options/config/style/Styles#table_header_style.,
110 )));
111 }
112 }
113
114 lines.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<T>`]extend().(matched_body);
115 }
116 });
117 } else {
118 HELP_TEXTrust-analyzer cargo bottom 0.14.9 constants/HELP_TEXT..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().().for_eachrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#for_each().(|(itx, section)| {
119 let mut iter = section.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().();
120
121 if itx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 {
122 for &text in iter {
123 lines.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Linerust-analyzer cargo ratatui-core 0.1.2 text/line/Line#::fromrust-analyzer cargo ratatui-core 0.1.2 text/line/impl#[`Line<'a>`][`From<Span<'a>>`]from().(Spanrust-analyzer cargo ratatui-core 0.1.2 text/span/Span#::styledrust-analyzer cargo ratatui-core 0.1.2 text/span/impl#[`Span<'a>`]styled().(text, self.stylesrust-analyzer cargo bottom 0.14.9 canvas/Painter#styles..text_stylerust-analyzer cargo bottom 0.14.9 options/config/style/Styles#text_style.)));
124 }
125 return;
126 }
127
128 let header_opt = iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]next().();
129 let header_str = header_opt.copiedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<&T>`]copied().();
130
131 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(header) = header_str {
132 lines.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Linerust-analyzer cargo ratatui-core 0.1.2 text/line/Line#::fromrust-analyzer cargo ratatui-core 0.1.2 text/line/impl#[`Line<'a>`][`From<Span<'a>>`]from().(Spanrust-analyzer cargo ratatui-core 0.1.2 text/span/Span#::defaultrust-analyzer cargo ratatui-core 0.1.2 text/span/impl#[`Span<'a>`][Default]default().()));
133 lines.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Linerust-analyzer cargo ratatui-core 0.1.2 text/line/Line#::fromrust-analyzer cargo ratatui-core 0.1.2 text/line/impl#[`Line<'a>`][`From<Span<'a>>`]from().(Spanrust-analyzer cargo ratatui-core 0.1.2 text/span/Span#::styledrust-analyzer cargo ratatui-core 0.1.2 text/span/impl#[`Span<'a>`]styled().(
134 header,
135 self.stylesrust-analyzer cargo bottom 0.14.9 canvas/Painter#styles..table_header_stylerust-analyzer cargo bottom 0.14.9 options/config/style/Styles#table_header_style.,
136 )));
137 }
138 for &text in iter {
139 lines.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Linerust-analyzer cargo ratatui-core 0.1.2 text/line/Line#::fromrust-analyzer cargo ratatui-core 0.1.2 text/line/impl#[`Line<'a>`][`From<Span<'a>>`]from().(Spanrust-analyzer cargo ratatui-core 0.1.2 text/span/Span#::styledrust-analyzer cargo ratatui-core 0.1.2 text/span/impl#[`Span<'a>`]styled().(text, self.stylesrust-analyzer cargo bottom 0.14.9 canvas/Painter#styles..text_stylerust-analyzer cargo bottom 0.14.9 options/config/style/Styles#text_style.)));
140 }
141 });
142 }
143
144 lines
145 }
146
147 pub fn draw_help_dialogrust-analyzer cargo bottom 0.14.9 canvas/dialogs/help_dialog/impl#[Painter]draw_help_dialog().(&self, f: &mut Framerust-analyzer cargo ratatui-core 0.1.2 terminal/frame/Frame#<'_>, app_state: &mut Apprust-analyzer cargo bottom 0.14.9 app/App#, draw_loc: Rectrust-analyzer cargo ratatui-core 0.1.2 layout/rect/Rect#) {
148 // TODO: We can reduce lines processed based on the known height.
149 let styled_help_text = self.help_text_linesrust-analyzer cargo bottom 0.14.9 canvas/dialogs/help_dialog/impl#[Painter]help_text_lines().(app_state);
150
151 // Reserve one column on the right for the scroll bar.
152 let block = dialog_blockrust-analyzer cargo bottom 0.14.9 canvas/drawing_utils/dialog_block().(self.stylesrust-analyzer cargo bottom 0.14.9 canvas/Painter#styles..border_typerust-analyzer cargo bottom 0.14.9 options/config/style/Styles#border_type., self.stylesrust-analyzer cargo bottom 0.14.9 canvas/Painter#styles..border_stylerust-analyzer cargo bottom 0.14.9 options/config/style/Styles#border_style.)
153 .title_toprust-analyzer cargo ratatui-widgets 0.3.2 block/impl#[`Block<'a>`]title_top().(Linerust-analyzer cargo ratatui-core 0.1.2 text/line/Line#::styledrust-analyzer cargo ratatui-core 0.1.2 text/line/impl#[`Line<'a>`]styled().(" Help ", self.stylesrust-analyzer cargo bottom 0.14.9 canvas/Painter#styles..widget_title_stylerust-analyzer cargo bottom 0.14.9 options/config/style/Styles#widget_title_style.))
154 .title_toprust-analyzer cargo ratatui-widgets 0.3.2 block/impl#[`Block<'a>`]title_top().(
155 Linerust-analyzer cargo ratatui-core 0.1.2 text/line/Line#::styledrust-analyzer cargo ratatui-core 0.1.2 text/line/impl#[`Line<'a>`]styled().(" Esc to close ", self.stylesrust-analyzer cargo bottom 0.14.9 canvas/Painter#styles..widget_title_stylerust-analyzer cargo bottom 0.14.9 options/config/style/Styles#widget_title_style.).right_alignedrust-analyzer cargo ratatui-core 0.1.2 text/line/impl#[`Line<'a>`]right_aligned().(),
156 )
157 .paddingrust-analyzer cargo ratatui-widgets 0.3.2 block/impl#[`Block<'a>`]padding().(Paddingrust-analyzer cargo ratatui-widgets 0.3.2 block/padding/Padding#::rightrust-analyzer cargo ratatui-widgets 0.3.2 block/padding/impl#[Padding]right().(1));
158
159 let [content_area, input_area] = if app_state.help_dialog_staterust-analyzer cargo bottom 0.14.9 app/App#help_dialog_state..is_searchingrust-analyzer cargo bottom 0.14.9 app/states/impl#[AppHelpDialogState]is_searching().() {
160 Layoutrust-analyzer cargo ratatui-core 0.1.2 layout/layout/Layout#::defaultrust-analyzer cargo ratatui-core 0.1.2 layout/layout/impl#[Layout][Default]default().()
161 .directionrust-analyzer cargo ratatui-core 0.1.2 layout/layout/impl#[Layout]direction().(Directionrust-analyzer cargo ratatui-core 0.1.2 layout/direction/Direction#::Verticalrust-analyzer cargo ratatui-core 0.1.2 layout/direction/Direction#Vertical#)
162 .constraintsrust-analyzer cargo ratatui-core 0.1.2 layout/layout/impl#[Layout]constraints().([Constraintrust-analyzer cargo ratatui-core 0.1.2 layout/constraint/Constraint#::Minrust-analyzer cargo ratatui-core 0.1.2 layout/constraint/Constraint#Min#(1), Constraintrust-analyzer cargo ratatui-core 0.1.2 layout/constraint/Constraint#::Lengthrust-analyzer cargo ratatui-core 0.1.2 layout/constraint/Constraint#Length#(1)])
163 .areasrust-analyzer cargo ratatui-core 0.1.2 layout/layout/impl#[Layout]areas().::<2>(draw_loc)
164 } else {
165 [draw_loc, Rectrust-analyzer cargo ratatui-core 0.1.2 layout/rect/Rect#::defaultrust-analyzer cargo ratatui-core 0.1.2 layout/rect/impl#[Rect][Default]default().()]
166 };
167
168 if app_state.should_get_widget_boundsrust-analyzer cargo bottom 0.14.9 app/impl#[App]should_get_widget_bounds().() {
169 // We must also recalculate how many lines are wrapping to properly get
170 // scrolling to work on small terminal sizes... oh joy.
171
172 let inner = block.innerrust-analyzer cargo ratatui-widgets 0.3.2 block/impl#[`Block<'a>`]inner().(content_area);
173 app_state.help_dialog_staterust-analyzer cargo bottom 0.14.9 app/App#help_dialog_state..heightrust-analyzer cargo bottom 0.14.9 app/states/AppHelpDialogState#height. = inner.heightrust-analyzer cargo ratatui-core 0.1.2 layout/rect/Rect#height.;
174
175 // The overflow buffer is used to account for lines that wrap onto multiple lines,
176 // so we can properly calculate the max scroll index later.
177 let mut overflow_buffer = 0;
178 let paragraph_width: usize = maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/max().(inner.widthrust-analyzer cargo ratatui-core 0.1.2 layout/rect/Rect#width., 1).intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().();
179 let mut prev_section_len = 0;
180
181 if app_state
182 .help_dialog_staterust-analyzer cargo bottom 0.14.9 app/App#help_dialog_state.
183 .search_input_staterust-analyzer cargo bottom 0.14.9 app/states/AppHelpDialogState#search_input_state.
184 .current_queryrust-analyzer cargo bottom 0.14.9 utils/input/impl#[InputFieldState]current_query().()
185 .is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_empty().()
186 {
187 constantsrust-analyzer cargo bottom 0.14.9 constants/::HELP_TEXTrust-analyzer cargo bottom 0.14.9 constants/HELP_TEXT.
188 .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()
189 .enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().()
190 .for_eachrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#for_each().(|(itx, section)| {
191 let mut buffer = 0;
192
193 section.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().for_eachrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]for_each().(|text_line| {
194 buffer rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`AddAssign<Self>`]add_assign().UnicodeWidthStrrust-analyzer cargo unicode-width 0.2.2 UnicodeWidthStr#::widthrust-analyzer cargo unicode-width 0.2.2 impl#[str][UnicodeWidthStr]width().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().text_line).saturating_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]saturating_sub().(1) as u16
195 /rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Div<Self>`]div().paragraph_width as u16;
196 });
197
198 if itx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 {
199 app_state.help_dialog_staterust-analyzer cargo bottom 0.14.9 app/App#help_dialog_state..index_shortcutsrust-analyzer cargo bottom 0.14.9 app/states/AppHelpDialogState#index_shortcuts.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().itx]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut(). = 0;
200 } else {
201 app_state.help_dialog_staterust-analyzer cargo bottom 0.14.9 app/App#help_dialog_state..index_shortcutsrust-analyzer cargo bottom 0.14.9 app/states/AppHelpDialogState#index_shortcuts.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().itx]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut(). =
202 app_state.help_dialog_staterust-analyzer cargo bottom 0.14.9 app/App#help_dialog_state..index_shortcutsrust-analyzer cargo bottom 0.14.9 app/states/AppHelpDialogState#index_shortcuts.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().itx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().
203 +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add().1
204 +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add().prev_section_len;
205 }
206 prev_section_len = section.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() as u16 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add().buffer;
207 overflow_buffer rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`AddAssign<Self>`]add_assign().buffer;
208 });
209 } else {
210 for line in &styled_help_text {
211 let width: usize = line
212 .spansrust-analyzer cargo ratatui-core 0.1.2 text/line/Line#spans.
213 .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()
214 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|s| UnicodeWidthStrrust-analyzer cargo unicode-width 0.2.2 UnicodeWidthStr#::widthrust-analyzer cargo unicode-width 0.2.2 impl#[str][UnicodeWidthStr]width().(s.contentrust-analyzer cargo ratatui-core 0.1.2 text/span/Span#content..as_refrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'_, T>`][`AsRef<T>`]as_ref().()))
215 .sumrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#sum().();
216
217 if width rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().paragraph_width {
218 overflow_buffer rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`AddAssign<Self>`]add_assign().(width.saturating_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]saturating_sub().(1) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div().paragraph_width) as u16;
219 }
220 }
221 }
222
223 let max_scroll_index = &mut app_state.help_dialog_staterust-analyzer cargo bottom 0.14.9 app/App#help_dialog_state..scroll_staterust-analyzer cargo bottom 0.14.9 app/states/AppHelpDialogState#scroll_state..max_scroll_indexrust-analyzer cargo bottom 0.14.9 app/states/ParagraphScrollState#max_scroll_index.;
224 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().max_scroll_index = (styled_help_text.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() as u16 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add().3 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add().overflow_buffer)
225 .saturating_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u16]saturating_sub().(draw_loc.heightrust-analyzer cargo ratatui-core 0.1.2 layout/rect/Rect#height. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add().1);
226
227 // Fix the scroll index if it is over-scrolled
228 let index = &mut app_state
229 .help_dialog_staterust-analyzer cargo bottom 0.14.9 app/App#help_dialog_state.
230 .scroll_staterust-analyzer cargo bottom 0.14.9 app/states/AppHelpDialogState#scroll_state.
231 .current_scroll_indexrust-analyzer cargo bottom 0.14.9 app/states/ParagraphScrollState#current_scroll_index.;
232
233 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().index = minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/min().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().index, *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().max_scroll_index);
234 }
235
236 f.render_widgetrust-analyzer cargo ratatui-core 0.1.2 terminal/frame/impl#[`Frame<'_>`]render_widget().(
237 Paragraphrust-analyzer cargo ratatui-widgets 0.3.2 paragraph/Paragraph#::newrust-analyzer cargo ratatui-widgets 0.3.2 paragraph/impl#[`Paragraph<'a>`]new().(styled_help_text)
238 .blockrust-analyzer cargo ratatui-widgets 0.3.2 paragraph/impl#[`Paragraph<'a>`]block().(block)
239 .stylerust-analyzer cargo ratatui-widgets 0.3.2 paragraph/impl#[`Paragraph<'a>`]style().(self.stylesrust-analyzer cargo bottom 0.14.9 canvas/Painter#styles..text_stylerust-analyzer cargo bottom 0.14.9 options/config/style/Styles#text_style.)
240 .alignmentrust-analyzer cargo ratatui-widgets 0.3.2 paragraph/impl#[`Paragraph<'a>`]alignment().(Alignmentrust-analyzer cargo ratatui-core 0.1.2 layout/alignment/Alignment#::Leftrust-analyzer cargo ratatui-core 0.1.2 layout/alignment/HorizontalAlignment#Left#)
241 .wraprust-analyzer cargo ratatui-widgets 0.3.2 paragraph/impl#[`Paragraph<'a>`]wrap().(Wraprust-analyzer cargo ratatui-widgets 0.3.2 paragraph/Wrap# { trimrust-analyzer cargo ratatui-widgets 0.3.2 paragraph/Wrap#trim.: true })
242 .scrollrust-analyzer cargo ratatui-widgets 0.3.2 paragraph/impl#[`Paragraph<'a>`]scroll().((
243 app_state
244 .help_dialog_staterust-analyzer cargo bottom 0.14.9 app/App#help_dialog_state.
245 .scroll_staterust-analyzer cargo bottom 0.14.9 app/states/AppHelpDialogState#scroll_state.
246 .current_scroll_indexrust-analyzer cargo bottom 0.14.9 app/states/ParagraphScrollState#current_scroll_index.,
247 0,
248 )),
249 content_area,
250 );
251
252 if app_state.help_dialog_staterust-analyzer cargo bottom 0.14.9 app/App#help_dialog_state..is_searchingrust-analyzer cargo bottom 0.14.9 app/states/impl#[AppHelpDialogState]is_searching().() {
253 search_inputrust-analyzer cargo bottom 0.14.9 canvas/components/search_input/::render_search_inputrust-analyzer cargo bottom 0.14.9 canvas/components/search_input/render_search_input().(
254 f,
255 input_area,
256 search_inputrust-analyzer cargo bottom 0.14.9 canvas/components/search_input/::SearchInputStaterust-analyzer cargo bottom 0.14.9 canvas/components/search_input/SearchInputState# {
257 input_field_staterust-analyzer cargo bottom 0.14.9 canvas/components/search_input/SearchInputState#input_field_state.: &app_state.help_dialog_staterust-analyzer cargo bottom 0.14.9 app/App#help_dialog_state..search_input_staterust-analyzer cargo bottom 0.14.9 app/states/AppHelpDialogState#search_input_state.,
258 is_focusedrust-analyzer cargo bottom 0.14.9 canvas/components/search_input/SearchInputState#is_focused.: true,
259 prefixrust-analyzer cargo bottom 0.14.9 canvas/components/search_input/SearchInputState#prefix.: "Search: ",
260 hintrust-analyzer cargo bottom 0.14.9 canvas/components/search_input/SearchInputState#hint.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("Type to search, Esc to close"),
261 },
262 search_inputrust-analyzer cargo bottom 0.14.9 canvas/components/search_input/::SearchInputStylesrust-analyzer cargo bottom 0.14.9 canvas/components/search_input/SearchInputStyles# {
263 prefix_stylerust-analyzer cargo bottom 0.14.9 canvas/components/search_input/SearchInputStyles#prefix_style.: self.stylesrust-analyzer cargo bottom 0.14.9 canvas/Painter#styles..widget_title_stylerust-analyzer cargo bottom 0.14.9 options/config/style/Styles#widget_title_style.,
264 text_stylerust-analyzer cargo bottom 0.14.9 canvas/components/search_input/SearchInputStyles#text_style.: self.stylesrust-analyzer cargo bottom 0.14.9 canvas/Painter#styles..text_stylerust-analyzer cargo bottom 0.14.9 options/config/style/Styles#text_style.,
265 cursor_stylerust-analyzer cargo bottom 0.14.9 canvas/components/search_input/SearchInputStyles#cursor_style.: self.stylesrust-analyzer cargo bottom 0.14.9 canvas/Painter#styles..selected_text_stylerust-analyzer cargo bottom 0.14.9 options/config/style/Styles#selected_text_style.,
266 hint_stylerust-analyzer cargo bottom 0.14.9 canvas/components/search_input/SearchInputStyles#hint_style.: self.stylesrust-analyzer cargo bottom 0.14.9 canvas/Painter#styles..text_stylerust-analyzer cargo bottom 0.14.9 options/config/style/Styles#text_style..dimrust-analyzer cargo ratatui-core 0.1.2 style/impl#[Style]dim().(),
267 },
268 );
269 }
270
271 let scrollbar_area = dialog_scroll_bar_arearust-analyzer cargo bottom 0.14.9 canvas/components/scroll_bar/dialog_scroll_bar_area().(draw_loc);
272 let content_length = app_state
273 .help_dialog_staterust-analyzer cargo bottom 0.14.9 app/App#help_dialog_state.
274 .scroll_staterust-analyzer cargo bottom 0.14.9 app/states/AppHelpDialogState#scroll_state.
275 .max_scroll_indexrust-analyzer cargo bottom 0.14.9 app/states/ParagraphScrollState#max_scroll_index.
276 .intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().();
277 let viewport_length = app_state.help_dialog_staterust-analyzer cargo bottom 0.14.9 app/App#help_dialog_state..heightrust-analyzer cargo bottom 0.14.9 app/states/AppHelpDialogState#height..intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().();
278 let position = app_state
279 .help_dialog_staterust-analyzer cargo bottom 0.14.9 app/App#help_dialog_state.
280 .scroll_staterust-analyzer cargo bottom 0.14.9 app/states/AppHelpDialogState#scroll_state.
281 .current_scroll_indexrust-analyzer cargo bottom 0.14.9 app/states/ParagraphScrollState#current_scroll_index.
282 .intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().();
283
284 draw_scroll_barrust-analyzer cargo bottom 0.14.9 canvas/components/scroll_bar/draw_scroll_bar().(
285 f,
286 scrollbar_area,
287 ScrollBarArgsrust-analyzer cargo bottom 0.14.9 canvas/components/scroll_bar/ScrollBarArgs# {
288 content_lengthrust-analyzer cargo bottom 0.14.9 canvas/components/scroll_bar/ScrollBarArgs#content_length.,
289 viewport_lengthrust-analyzer cargo bottom 0.14.9 canvas/components/scroll_bar/ScrollBarArgs#viewport_length.,
290 positionrust-analyzer cargo bottom 0.14.9 canvas/components/scroll_bar/ScrollBarArgs#position.,
291 stylerust-analyzer cargo bottom 0.14.9 canvas/components/scroll_bar/ScrollBarArgs#style.: self.stylesrust-analyzer cargo bottom 0.14.9 canvas/Painter#styles..text_stylerust-analyzer cargo bottom 0.14.9 options/config/style/Styles#text_style.,
292 },
293 );
294 }
295 }
296
297 #[cfg(test)]
298 mod testsrust-analyzer cargo bottom 0.14.9 canvas/dialogs/help_dialog/tests/ {
299 use superrust-analyzer cargo bottom 0.14.9 canvas/dialogs/help_dialog/::*;
300
301 fn check_spansrust-analyzer cargo bottom 0.14.9 canvas/dialogs/help_dialog/tests/check_spans().(line: &Linerust-analyzer cargo ratatui-core 0.1.2 text/line/Line#<'_>, expected: [&str; 3]) {
302 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(line.spansrust-analyzer cargo ratatui-core 0.1.2 text/line/Line#spans.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..contentrust-analyzer cargo ratatui-core 0.1.2 text/span/Span#content., expected[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().);
303 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(line.spansrust-analyzer cargo ratatui-core 0.1.2 text/line/Line#spans.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..contentrust-analyzer cargo ratatui-core 0.1.2 text/span/Span#content., expected[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().);
304 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(line.spansrust-analyzer cargo ratatui-core 0.1.2 text/line/Line#spans.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().2]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..contentrust-analyzer cargo ratatui-core 0.1.2 text/span/Span#content., expected[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().2]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().);
305 }
306
307 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
308 fn test_no_matchrust-analyzer cargo bottom 0.14.9 canvas/dialogs/help_dialog/tests/test_no_match().() {
309 let mut lines = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
310 let matched = add_highlight_matchrust-analyzer cargo bottom 0.14.9 canvas/dialogs/help_dialog/add_highlight_match().(
311 "xyz",
312 "hello world",
313 &mut lines,
314 Stylerust-analyzer cargo ratatui-core 0.1.2 style/Style#::defaultrust-analyzer cargo ratatui-core 0.1.2 style/impl#[Style][Default]default().(),
315 Stylerust-analyzer cargo ratatui-core 0.1.2 style/Style#::defaultrust-analyzer cargo ratatui-core 0.1.2 style/impl#[Style][Default]default().(),
316 );
317 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().matched);
318 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(lines.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().());
319 }
320
321 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
322 fn test_match_in_middlerust-analyzer cargo bottom 0.14.9 canvas/dialogs/help_dialog/tests/test_match_in_middle().() {
323 let mut lines = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
324 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(add_highlight_matchrust-analyzer cargo bottom 0.14.9 canvas/dialogs/help_dialog/add_highlight_match().(
325 "world",
326 "hello world!",
327 &mut lines,
328 Stylerust-analyzer cargo ratatui-core 0.1.2 style/Style#::defaultrust-analyzer cargo ratatui-core 0.1.2 style/impl#[Style][Default]default().(),
329 Stylerust-analyzer cargo ratatui-core 0.1.2 style/Style#::defaultrust-analyzer cargo ratatui-core 0.1.2 style/impl#[Style][Default]default().()
330 ));
331 check_spansrust-analyzer cargo bottom 0.14.9 canvas/dialogs/help_dialog/tests/check_spans().(&lines[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., ["hello ", "world", "!"]);
332 }
333
334 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
335 fn test_match_at_startrust-analyzer cargo bottom 0.14.9 canvas/dialogs/help_dialog/tests/test_match_at_start().() {
336 let mut lines = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
337 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(add_highlight_matchrust-analyzer cargo bottom 0.14.9 canvas/dialogs/help_dialog/add_highlight_match().(
338 "hello",
339 "hello world",
340 &mut lines,
341 Stylerust-analyzer cargo ratatui-core 0.1.2 style/Style#::defaultrust-analyzer cargo ratatui-core 0.1.2 style/impl#[Style][Default]default().(),
342 Stylerust-analyzer cargo ratatui-core 0.1.2 style/Style#::defaultrust-analyzer cargo ratatui-core 0.1.2 style/impl#[Style][Default]default().()
343 ));
344 check_spansrust-analyzer cargo bottom 0.14.9 canvas/dialogs/help_dialog/tests/check_spans().(&lines[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., ["", "hello", " world"]);
345 }
346
347 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
348 fn test_match_at_endrust-analyzer cargo bottom 0.14.9 canvas/dialogs/help_dialog/tests/test_match_at_end().() {
349 let mut lines = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
350 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(add_highlight_matchrust-analyzer cargo bottom 0.14.9 canvas/dialogs/help_dialog/add_highlight_match().(
351 "world",
352 "hello world",
353 &mut lines,
354 Stylerust-analyzer cargo ratatui-core 0.1.2 style/Style#::defaultrust-analyzer cargo ratatui-core 0.1.2 style/impl#[Style][Default]default().(),
355 Stylerust-analyzer cargo ratatui-core 0.1.2 style/Style#::defaultrust-analyzer cargo ratatui-core 0.1.2 style/impl#[Style][Default]default().()
356 ));
357 check_spansrust-analyzer cargo bottom 0.14.9 canvas/dialogs/help_dialog/tests/check_spans().(&lines[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., ["hello ", "world", ""]);
358 }
359
360 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
361 fn test_full_matchrust-analyzer cargo bottom 0.14.9 canvas/dialogs/help_dialog/tests/test_full_match().() {
362 let mut lines = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
363 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(add_highlight_matchrust-analyzer cargo bottom 0.14.9 canvas/dialogs/help_dialog/add_highlight_match().(
364 "hello",
365 "hello",
366 &mut lines,
367 Stylerust-analyzer cargo ratatui-core 0.1.2 style/Style#::defaultrust-analyzer cargo ratatui-core 0.1.2 style/impl#[Style][Default]default().(),
368 Stylerust-analyzer cargo ratatui-core 0.1.2 style/Style#::defaultrust-analyzer cargo ratatui-core 0.1.2 style/impl#[Style][Default]default().()
369 ));
370 check_spansrust-analyzer cargo bottom 0.14.9 canvas/dialogs/help_dialog/tests/check_spans().(&lines[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., ["", "hello", ""]);
371 }
372
373 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
374 fn test_case_insensitiverust-analyzer cargo bottom 0.14.9 canvas/dialogs/help_dialog/tests/test_case_insensitive().() {
375 let mut lines = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
376 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(add_highlight_matchrust-analyzer cargo bottom 0.14.9 canvas/dialogs/help_dialog/add_highlight_match().(
377 "cpu",
378 "CPU widget",
379 &mut lines,
380 Stylerust-analyzer cargo ratatui-core 0.1.2 style/Style#::defaultrust-analyzer cargo ratatui-core 0.1.2 style/impl#[Style][Default]default().(),
381 Stylerust-analyzer cargo ratatui-core 0.1.2 style/Style#::defaultrust-analyzer cargo ratatui-core 0.1.2 style/impl#[Style][Default]default().()
382 ));
383 check_spansrust-analyzer cargo bottom 0.14.9 canvas/dialogs/help_dialog/tests/check_spans().(&lines[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., ["", "CPU", " widget"]);
384 }
385
386 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
387 fn test_unicode_in_targetrust-analyzer cargo bottom 0.14.9 canvas/dialogs/help_dialog/tests/test_unicode_in_target().() {
388 let mut lines = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
389 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(add_highlight_matchrust-analyzer cargo bottom 0.14.9 canvas/dialogs/help_dialog/add_highlight_match().(
390 "éléphants",
391 "J'adore les éléphants et les lapins.",
392 &mut lines,
393 Stylerust-analyzer cargo ratatui-core 0.1.2 style/Style#::defaultrust-analyzer cargo ratatui-core 0.1.2 style/impl#[Style][Default]default().(),
394 Stylerust-analyzer cargo ratatui-core 0.1.2 style/Style#::defaultrust-analyzer cargo ratatui-core 0.1.2 style/impl#[Style][Default]default().()
395 ));
396 check_spansrust-analyzer cargo bottom 0.14.9 canvas/dialogs/help_dialog/tests/check_spans().(&lines[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., ["J'adore les ", "éléphants", " et les lapins."]);
397 }
398
399 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
400 fn test_unicoderust-analyzer cargo bottom 0.14.9 canvas/dialogs/help_dialog/tests/test_unicode().() {
401 let mut lines = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
402 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(add_highlight_matchrust-analyzer cargo bottom 0.14.9 canvas/dialogs/help_dialog/add_highlight_match().(
403 "你",
404 "Hi 你好!🇨🇦",
405 &mut lines,
406 Stylerust-analyzer cargo ratatui-core 0.1.2 style/Style#::defaultrust-analyzer cargo ratatui-core 0.1.2 style/impl#[Style][Default]default().(),
407 Stylerust-analyzer cargo ratatui-core 0.1.2 style/Style#::defaultrust-analyzer cargo ratatui-core 0.1.2 style/impl#[Style][Default]default().()
408 ));
409 check_spansrust-analyzer cargo bottom 0.14.9 canvas/dialogs/help_dialog/tests/check_spans().(&lines[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., ["Hi ", "你", "好!🇨🇦"]);
410 }
411
412 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
413 fn test_unicode_2rust-analyzer cargo bottom 0.14.9 canvas/dialogs/help_dialog/tests/test_unicode_2().() {
414 let mut lines = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
415 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(add_highlight_matchrust-analyzer cargo bottom 0.14.9 canvas/dialogs/help_dialog/add_highlight_match().(
416 "🇨🇦",
417 "Hi 你好!🇨🇦",
418 &mut lines,
419 Stylerust-analyzer cargo ratatui-core 0.1.2 style/Style#::defaultrust-analyzer cargo ratatui-core 0.1.2 style/impl#[Style][Default]default().(),
420 Stylerust-analyzer cargo ratatui-core 0.1.2 style/Style#::defaultrust-analyzer cargo ratatui-core 0.1.2 style/impl#[Style][Default]default().()
421 ));
422 check_spansrust-analyzer cargo bottom 0.14.9 canvas/dialogs/help_dialog/tests/check_spans().(&lines[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., ["Hi 你好!", "🇨🇦", ""]);
423 }
424
425 /// Shows that we only match the first occurrence in the line. This is expected behaviour as we're passing
426 /// in separate strings.
427 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
428 fn test_unicode_3rust-analyzer cargo bottom 0.14.9 canvas/dialogs/help_dialog/tests/test_unicode_3().() {
429 let mut lines = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
430 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(add_highlight_matchrust-analyzer cargo bottom 0.14.9 canvas/dialogs/help_dialog/add_highlight_match().(
431 "🇨🇦",
432 "Hi 🇨🇦 你好!🇨🇦",
433 &mut lines,
434 Stylerust-analyzer cargo ratatui-core 0.1.2 style/Style#::defaultrust-analyzer cargo ratatui-core 0.1.2 style/impl#[Style][Default]default().(),
435 Stylerust-analyzer cargo ratatui-core 0.1.2 style/Style#::defaultrust-analyzer cargo ratatui-core 0.1.2 style/impl#[Style][Default]default().()
436 ));
437 check_spansrust-analyzer cargo bottom 0.14.9 canvas/dialogs/help_dialog/tests/check_spans().(&lines[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., ["Hi ", "🇨🇦", " 你好!🇨🇦"]);
438 }
439
440 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
441 fn test_unicode_case_insensitiverust-analyzer cargo bottom 0.14.9 canvas/dialogs/help_dialog/tests/test_unicode_case_insensitive().() {
442 let mut lines = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
443 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(add_highlight_matchrust-analyzer cargo bottom 0.14.9 canvas/dialogs/help_dialog/add_highlight_match().(
444 "éléphants",
445 "J'adore les Éléphants et les lapins.",
446 &mut lines,
447 Stylerust-analyzer cargo ratatui-core 0.1.2 style/Style#::defaultrust-analyzer cargo ratatui-core 0.1.2 style/impl#[Style][Default]default().(),
448 Stylerust-analyzer cargo ratatui-core 0.1.2 style/Style#::defaultrust-analyzer cargo ratatui-core 0.1.2 style/impl#[Style][Default]default().()
449 ));
450 check_spansrust-analyzer cargo bottom 0.14.9 canvas/dialogs/help_dialog/tests/check_spans().(&lines[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., ["J'adore les ", "Éléphants", " et les lapins."]);
451 }
452
453 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
454 fn test_accumulates_across_callsrust-analyzer cargo bottom 0.14.9 canvas/dialogs/help_dialog/tests/test_accumulates_across_calls().() {
455 let mut lines = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
456 add_highlight_matchrust-analyzer cargo bottom 0.14.9 canvas/dialogs/help_dialog/add_highlight_match().("a", "cat", &mut lines, Stylerust-analyzer cargo ratatui-core 0.1.2 style/Style#::defaultrust-analyzer cargo ratatui-core 0.1.2 style/impl#[Style][Default]default().(), Stylerust-analyzer cargo ratatui-core 0.1.2 style/Style#::defaultrust-analyzer cargo ratatui-core 0.1.2 style/impl#[Style][Default]default().()); // match
457 add_highlight_matchrust-analyzer cargo bottom 0.14.9 canvas/dialogs/help_dialog/add_highlight_match().("a", "dog", &mut lines, Stylerust-analyzer cargo ratatui-core 0.1.2 style/Style#::defaultrust-analyzer cargo ratatui-core 0.1.2 style/impl#[Style][Default]default().(), Stylerust-analyzer cargo ratatui-core 0.1.2 style/Style#::defaultrust-analyzer cargo ratatui-core 0.1.2 style/impl#[Style][Default]default().()); // no match
458 add_highlight_matchrust-analyzer cargo bottom 0.14.9 canvas/dialogs/help_dialog/add_highlight_match().("a", "rat", &mut lines, Stylerust-analyzer cargo ratatui-core 0.1.2 style/Style#::defaultrust-analyzer cargo ratatui-core 0.1.2 style/impl#[Style][Default]default().(), Stylerust-analyzer cargo ratatui-core 0.1.2 style/Style#::defaultrust-analyzer cargo ratatui-core 0.1.2 style/impl#[Style][Default]default().()); // match
459 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(lines.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 2);
460 }
461 }