@@ -191,52 +191,37 @@ fn draw_input_field<B: Backend>(f: &mut Frame<B>, rect: Rect, app: &mut App) {
191
191
192
192
let mut highlighter = HighlightLines :: new ( * SH_SYNTAX , & THEME ) ;
193
193
194
- let lines = if app. cached_command_part . is_none ( ) {
195
- app. input_state
196
- . content_lines ( )
197
- . iter ( )
194
+ // cut off lines at the input field width, adding ...
195
+ let lines: Vec < String > = app
196
+ . input_state
197
+ . content_lines ( )
198
+ . iter ( )
199
+ . map ( |line| truncate_with_ellipsis ( line. clone ( ) , rect. width as usize ) )
200
+ . collect_vec ( ) ;
201
+
202
+ let joined_lines = lines. join ( "\n " ) ;
203
+ let styled_lines = if app. config . highlighting_enabled {
204
+ LinesWithEndings :: from ( joined_lines. as_ref ( ) )
198
205
. map ( |line| {
199
- let mut line = line. clone ( ) ;
200
- if line. len ( ) > rect. width as usize - 5 {
201
- line. truncate ( rect. width as usize - 5 ) ;
202
- line. push_str ( "..." ) ;
203
- }
204
- line
206
+ highlighter
207
+ . highlight ( line, & SYNTAX_SET )
208
+ . iter ( )
209
+ . map ( |( style, part) | Span :: styled ( * part, highlight_style_to_tui_style ( & style) ) )
210
+ . collect_vec ( )
205
211
} )
206
- . collect :: < Vec < String > > ( )
207
- } else {
208
- app. input_state . content_lines ( ) . clone ( )
209
- } ;
210
-
211
- let ( cached_part, non_cached_part) = match app. cached_command_part {
212
- Some ( CachedCommandPart { end_line, end_col, .. } ) => lines. split_strings_at_offset ( end_line, end_col) ,
213
- _ => ( Vec :: new ( ) , lines) ,
214
- } ;
215
- let ( cached_part, non_cached_part) = ( cached_part. join ( "\n " ) , non_cached_part. join ( "\n " ) ) ;
216
-
217
- let cached_part_styled = vec ! [ Span :: styled(
218
- Cow :: Borrowed ( cached_part. as_ref( ) ) ,
219
- Style :: default ( ) . bg( Color :: DarkGray ) . fg( Color :: White ) ,
220
- ) ] ;
221
-
222
- let mut non_cached_part_styled = if app. config . highlighting_enabled {
223
- LinesWithEndings :: from ( & non_cached_part)
224
- . flat_map ( |line| highlighter. highlight ( line, & SYNTAX_SET ) )
225
- . map ( |( style, part) | Span :: styled ( Cow :: Borrowed ( part) , highlight_style_to_tui_style ( & style) ) )
226
- . collect :: < Vec < Span > > ( )
212
+ . map ( Spans :: from)
213
+ . collect_vec ( )
227
214
} else {
228
- vec ! [ Span :: raw( non_cached_part ) ]
215
+ lines . iter ( ) . map ( Span :: raw) . map ( Spans :: from ) . collect_vec ( )
229
216
} ;
230
217
231
- let mut full_styled = cached_part_styled;
232
- full_styled. append ( & mut non_cached_part_styled) ;
233
-
234
218
let is_bookmarked = app. bookmarks . entries ( ) . contains ( & app. input_state . content_to_commandentry ( ) ) ;
235
219
236
220
let input_block_title = format ! (
237
- "Command{}{}{}" ,
221
+ "Command{}{}{}{} " ,
238
222
if is_bookmarked { " [Bookmarked]" } else { "" } ,
239
223
if app. autoeval_mode { " [Autoeval]" } else { "" } ,
224
+ if app. cached_command_part. is_some( ) { " [Caching]" } else { "" } ,
240
225
if app. autoeval_mode && app. paranoid_history_mode {
241
226
" [Paranoid]"
242
227
} else {
@@ -245,11 +230,19 @@ fn draw_input_field<B: Backend>(f: &mut Frame<B>, rect: Rect, app: &mut App) {
245
230
) ;
246
231
247
232
f. render_widget (
248
- Paragraph :: new ( Spans :: from ( full_styled ) ) . block ( make_default_block ( & input_block_title, true ) ) ,
233
+ Paragraph :: new ( Text :: from ( styled_lines ) ) . block ( make_default_block ( & input_block_title, true ) ) ,
249
234
rect,
250
235
) ;
251
236
}
252
237
238
+ fn truncate_with_ellipsis ( mut line : String , length : usize ) -> String {
239
+ if line. len ( ) > length - 5 {
240
+ line. truncate ( length - 5 ) ;
241
+ line. push_str ( "..." ) ;
242
+ }
243
+ line
244
+ }
245
+
253
246
fn apply_graphics_mode_to_style ( style : & mut Style , modes : & [ u32 ] ) {
254
247
fn ansi_to_color ( bright : bool , n : u32 ) -> Color {
255
248
match ( bright, n) {
0 commit comments