@@ -24,18 +24,12 @@ use tree_sitter_bash as hl_bash;
24
24
use tree_sitter_highlight:: { self as hl, HighlightEvent } ;
25
25
use zips:: zip_result;
26
26
27
- pub enum FloatingTextMode {
28
- Preview ,
29
- Description ,
30
- ActionsGuide ,
31
- }
32
-
33
27
pub struct FloatingText {
34
28
pub src : Vec < String > ,
35
29
max_line_width : usize ,
36
30
v_scroll : usize ,
37
31
h_scroll : usize ,
38
- mode_title : & ' static str ,
32
+ mode_title : String ,
39
33
}
40
34
41
35
macro_rules! style {
@@ -130,7 +124,7 @@ fn get_lines_owned(s: &str) -> Vec<String> {
130
124
}
131
125
132
126
impl FloatingText {
133
- pub fn new ( text : String , mode : FloatingTextMode ) -> Self {
127
+ pub fn new ( text : String , title : & str ) -> Self {
134
128
let src = get_lines ( & text)
135
129
. into_iter ( )
136
130
. map ( |s| s. to_string ( ) )
@@ -139,14 +133,14 @@ impl FloatingText {
139
133
let max_line_width = max_width ! ( src) ;
140
134
Self {
141
135
src,
142
- mode_title : Self :: get_mode_title ( mode ) ,
136
+ mode_title : title . to_string ( ) ,
143
137
max_line_width,
144
138
v_scroll : 0 ,
145
139
h_scroll : 0 ,
146
140
}
147
141
}
148
142
149
- pub fn from_command ( command : & Command , mode : FloatingTextMode ) -> Option < Self > {
143
+ pub fn from_command ( command : & Command , title : String ) -> Option < Self > {
150
144
let ( max_line_width, src) = match command {
151
145
Command :: Raw ( cmd) => {
152
146
// just apply highlights directly
@@ -169,21 +163,13 @@ impl FloatingText {
169
163
170
164
Some ( Self {
171
165
src,
172
- mode_title : Self :: get_mode_title ( mode ) ,
166
+ mode_title : title ,
173
167
max_line_width,
174
168
h_scroll : 0 ,
175
169
v_scroll : 0 ,
176
170
} )
177
171
}
178
172
179
- fn get_mode_title ( mode : FloatingTextMode ) -> & ' static str {
180
- match mode {
181
- FloatingTextMode :: Preview => "Command Preview" ,
182
- FloatingTextMode :: Description => "Command Description" ,
183
- FloatingTextMode :: ActionsGuide => "Important Actions Guide" ,
184
- }
185
- }
186
-
187
173
fn scroll_down ( & mut self ) {
188
174
if self . v_scroll + 1 < self . src . len ( ) {
189
175
self . v_scroll += 1 ;
@@ -214,7 +200,7 @@ impl FloatContent for FloatingText {
214
200
// Define the Block with a border and background color
215
201
let block = Block :: default ( )
216
202
. borders ( Borders :: ALL )
217
- . title ( self . mode_title )
203
+ . title ( self . mode_title . clone ( ) )
218
204
. title_alignment ( ratatui:: layout:: Alignment :: Center )
219
205
. title_style ( Style :: default ( ) . reversed ( ) )
220
206
. style ( Style :: default ( ) ) ;
@@ -292,7 +278,7 @@ impl FloatContent for FloatingText {
292
278
293
279
fn get_shortcut_list ( & self ) -> ( & str , Box < [ Shortcut ] > ) {
294
280
(
295
- self . mode_title ,
281
+ & self . mode_title ,
296
282
Box :: new ( [
297
283
Shortcut :: new ( "Scroll down" , [ "j" , "Down" ] ) ,
298
284
Shortcut :: new ( "Scroll up" , [ "k" , "Up" ] ) ,
0 commit comments