@@ -23,10 +23,10 @@ use wayland_client::{Display as WaylandDisplay, EventQueue};
23
23
use crossfont:: { self , Rasterize , Rasterizer } ;
24
24
25
25
use alacritty_terminal:: event:: { EventListener , OnResize } ;
26
- use alacritty_terminal:: index:: { Column , Direction , Point } ;
26
+ use alacritty_terminal:: grid:: Dimensions as _;
27
+ use alacritty_terminal:: index:: { Column , Direction , Line , Point } ;
27
28
use alacritty_terminal:: selection:: Selection ;
28
- use alacritty_terminal:: term:: { SizeInfo , Term , TermMode } ;
29
- use alacritty_terminal:: term:: { MIN_COLS , MIN_SCREEN_LINES } ;
29
+ use alacritty_terminal:: term:: { SizeInfo , Term , TermMode , MIN_COLS , MIN_SCREEN_LINES } ;
30
30
31
31
use crate :: config:: font:: Font ;
32
32
use crate :: config:: window:: Dimensions ;
@@ -460,21 +460,19 @@ impl Display {
460
460
let cursor = content. cursor ( ) ;
461
461
462
462
let visual_bell_intensity = terminal. visual_bell . intensity ( ) ;
463
+ let display_offset = terminal. grid ( ) . display_offset ( ) ;
463
464
let background_color = terminal. background_color ( ) ;
464
465
let cursor_point = terminal. grid ( ) . cursor . point ;
466
+ let total_lines = terminal. grid ( ) . total_lines ( ) ;
465
467
let metrics = self . glyph_cache . font_metrics ( ) ;
466
- let glyph_cache = & mut self . glyph_cache ;
467
468
let size_info = self . size_info ;
468
469
469
470
let selection = !terminal. selection . as_ref ( ) . map ( Selection :: is_empty) . unwrap_or ( true ) ;
470
471
let mouse_mode = terminal. mode ( ) . intersects ( TermMode :: MOUSE_MODE )
471
472
&& !terminal. mode ( ) . contains ( TermMode :: VI ) ;
472
473
473
- let vi_mode_cursor = if terminal. mode ( ) . contains ( TermMode :: VI ) {
474
- Some ( terminal. vi_mode_cursor )
475
- } else {
476
- None
477
- } ;
474
+ let vi_mode = terminal. mode ( ) . contains ( TermMode :: VI ) ;
475
+ let vi_mode_cursor = if vi_mode { Some ( terminal. vi_mode_cursor ) } else { None } ;
478
476
479
477
// Drop terminal as early as possible to free lock.
480
478
drop ( terminal) ;
@@ -490,6 +488,7 @@ impl Display {
490
488
{
491
489
let _sampler = self . meter . sampler ( ) ;
492
490
491
+ let glyph_cache = & mut self . glyph_cache ;
493
492
self . renderer . with_api ( & config. ui_config , & size_info, |mut api| {
494
493
// Iterate over all non-empty cells in the grid.
495
494
for mut cell in grid_cells {
@@ -539,11 +538,19 @@ impl Display {
539
538
}
540
539
}
541
540
542
- // Highlight URLs at the vi mode cursor position.
543
541
if let Some ( vi_mode_cursor) = vi_mode_cursor {
544
- if let Some ( url) = self . urls . find_at ( vi_mode_cursor. point ) {
542
+ // Highlight URLs at the vi mode cursor position.
543
+ let vi_mode_point = vi_mode_cursor. point ;
544
+ if let Some ( url) = self . urls . find_at ( vi_mode_point) {
545
545
rects. append ( & mut url. rects ( & metrics, & size_info) ) ;
546
546
}
547
+
548
+ // Indicate vi mode by showing the cursor's position in the top right corner.
549
+ let line = size_info. screen_lines ( ) + display_offset - vi_mode_point. line - 1 ;
550
+ self . draw_line_indicator ( config, & size_info, total_lines, Some ( vi_mode_point) , line. 0 ) ;
551
+ } else if search_active {
552
+ // Show current display offset in vi-less search to indicate match position.
553
+ self . draw_line_indicator ( config, & size_info, total_lines, None , display_offset) ;
547
554
}
548
555
549
556
// Push the cursor rects for rendering.
@@ -574,13 +581,13 @@ impl Display {
574
581
let start_line = size_info. screen_lines ( ) + search_offset;
575
582
let y = size_info. cell_height ( ) . mul_add ( start_line. 0 as f32 , size_info. padding_y ( ) ) ;
576
583
577
- let color = match message. ty ( ) {
584
+ let bg = match message. ty ( ) {
578
585
MessageType :: Error => config. colors . normal . red ,
579
586
MessageType :: Warning => config. colors . normal . yellow ,
580
587
} ;
581
588
582
589
let message_bar_rect =
583
- RenderRect :: new ( 0. , y, size_info. width ( ) , size_info. height ( ) - y, color , 1. ) ;
590
+ RenderRect :: new ( 0. , y, size_info. width ( ) , size_info. height ( ) - y, bg , 1. ) ;
584
591
585
592
// Push message_bar in the end, so it'll be above all other content.
586
593
rects. push ( message_bar_rect) ;
@@ -589,10 +596,12 @@ impl Display {
589
596
self . renderer . draw_rects ( & size_info, rects) ;
590
597
591
598
// Relay messages to the user.
599
+ let glyph_cache = & mut self . glyph_cache ;
592
600
let fg = config. colors . primary . background ;
593
601
for ( i, message_text) in text. iter ( ) . enumerate ( ) {
602
+ let point = Point :: new ( start_line + i, Column ( 0 ) ) ;
594
603
self . renderer . with_api ( & config. ui_config , & size_info, |mut api| {
595
- api. render_string ( glyph_cache, start_line + i , & message_text , fg , None ) ;
604
+ api. render_string ( glyph_cache, point , fg , bg , & message_text ) ;
596
605
} ) ;
597
606
}
598
607
} else {
@@ -681,10 +690,12 @@ impl Display {
681
690
// Assure text length is at least num_cols.
682
691
let text = format ! ( "{:<1$}" , text, num_cols) ;
683
692
693
+ let point = Point :: new ( size_info. screen_lines ( ) , Column ( 0 ) ) ;
684
694
let fg = config. colors . search_bar_foreground ( ) ;
685
695
let bg = config. colors . search_bar_background ( ) ;
696
+
686
697
self . renderer . with_api ( & config. ui_config , & size_info, |mut api| {
687
- api. render_string ( glyph_cache, size_info . screen_lines ( ) , & text , fg, Some ( bg ) ) ;
698
+ api. render_string ( glyph_cache, point , fg, bg , & text ) ;
688
699
} ) ;
689
700
}
690
701
@@ -693,17 +704,43 @@ impl Display {
693
704
if !config. ui_config . debug . render_timer {
694
705
return ;
695
706
}
707
+
696
708
let glyph_cache = & mut self . glyph_cache ;
697
709
698
710
let timing = format ! ( "{:.3} usec" , self . meter. average( ) ) ;
711
+ let point = Point :: new ( size_info. screen_lines ( ) - 2 , Column ( 0 ) ) ;
699
712
let fg = config. colors . primary . background ;
700
713
let bg = config. colors . normal . red ;
701
714
702
715
self . renderer . with_api ( & config. ui_config , & size_info, |mut api| {
703
- api. render_string ( glyph_cache, size_info . screen_lines ( ) - 2 , & timing [ .. ] , fg, Some ( bg ) ) ;
716
+ api. render_string ( glyph_cache, point , fg, bg , & timing ) ;
704
717
} ) ;
705
718
}
706
719
720
+ /// Draw an indicator for the position of a line in history.
721
+ fn draw_line_indicator (
722
+ & mut self ,
723
+ config : & Config ,
724
+ size_info : & SizeInfo ,
725
+ total_lines : usize ,
726
+ vi_mode_point : Option < Point > ,
727
+ line : usize ,
728
+ ) {
729
+ let text = format ! ( "[{}/{}]" , line, total_lines - 1 ) ;
730
+ let column = Column ( size_info. cols ( ) . 0 . saturating_sub ( text. len ( ) ) ) ;
731
+ let colors = & config. colors ;
732
+ let fg = colors. line_indicator . foreground . unwrap_or ( colors. primary . background ) ;
733
+ let bg = colors. line_indicator . background . unwrap_or ( colors. primary . foreground ) ;
734
+
735
+ // Do not render anything if it would obscure the vi mode cursor.
736
+ if vi_mode_point. map_or ( true , |point| point. line . 0 != 0 || point. col < column) {
737
+ let glyph_cache = & mut self . glyph_cache ;
738
+ self . renderer . with_api ( & config. ui_config , & size_info, |mut api| {
739
+ api. render_string ( glyph_cache, Point :: new ( Line ( 0 ) , column) , fg, bg, & text) ;
740
+ } ) ;
741
+ }
742
+ }
743
+
707
744
/// Requst a new frame for a window on Wayland.
708
745
#[ inline]
709
746
#[ cfg( all( feature = "wayland" , not( any( target_os = "macos" , windows) ) ) ) ]
0 commit comments