@@ -32,6 +32,7 @@ pub enum FloatingTextMode {
32
32
33
33
pub struct FloatingText {
34
34
pub src : Vec < String > ,
35
+ name : Option < String > ,
35
36
max_line_width : usize ,
36
37
v_scroll : usize ,
37
38
h_scroll : usize ,
@@ -130,7 +131,7 @@ fn get_lines_owned(s: &str) -> Vec<String> {
130
131
}
131
132
132
133
impl FloatingText {
133
- pub fn new ( text : String , mode : FloatingTextMode ) -> Self {
134
+ pub fn new ( text : String , name : Option < String > , mode : FloatingTextMode ) -> Self {
134
135
let src = get_lines ( & text)
135
136
. into_iter ( )
136
137
. map ( |s| s. to_string ( ) )
@@ -139,19 +140,25 @@ impl FloatingText {
139
140
let max_line_width = max_width ! ( src) ;
140
141
Self {
141
142
src,
143
+ name,
142
144
mode_title : Self :: get_mode_title ( mode) ,
143
145
max_line_width,
144
146
v_scroll : 0 ,
145
147
h_scroll : 0 ,
146
148
}
147
149
}
148
150
149
- pub fn from_command ( command : & Command , mode : FloatingTextMode ) -> Option < Self > {
151
+ pub fn from_command (
152
+ command : & Command ,
153
+ name : Option < String > ,
154
+ mode : FloatingTextMode ,
155
+ ) -> Option < Self > {
150
156
let ( max_line_width, src) = match command {
151
157
Command :: Raw ( cmd) => {
152
158
// just apply highlights directly
153
159
( max_width ! ( get_lines( cmd) ) , Some ( cmd. clone ( ) ) )
154
160
}
161
+
155
162
Command :: LocalFile { file, .. } => {
156
163
// have to read from tmp dir to get cmd src
157
164
let raw = std:: fs:: read_to_string ( file)
@@ -169,6 +176,7 @@ impl FloatingText {
169
176
170
177
Some ( Self {
171
178
src,
179
+ name,
172
180
mode_title : Self :: get_mode_title ( mode) ,
173
181
max_line_width,
174
182
h_scroll : 0 ,
@@ -211,10 +219,16 @@ impl FloatingText {
211
219
212
220
impl FloatContent for FloatingText {
213
221
fn top_title ( & self ) -> Option < Line < ' _ > > {
214
- let title_text = format ! ( " {} " , self . mode_title) ;
222
+ let mut title_text = format ! ( " {} " , self . mode_title) ;
223
+
224
+ if let Some ( ref name) = self . name {
225
+ title_text = format ! ( "{}- {} " , title_text, name) ;
226
+ }
227
+
215
228
let title_line = Line :: from ( title_text)
216
229
. centered ( )
217
230
. style ( Style :: default ( ) . reversed ( ) ) ;
231
+
218
232
Some ( title_line)
219
233
}
220
234
0 commit comments