1
1
pub mod grid;
2
2
pub mod renderable;
3
- mod title;
3
+ pub mod title;
4
4
5
5
use crate :: ansi:: CursorShape ;
6
6
use crate :: context:: grid:: ContextDimension ;
7
7
use crate :: context:: grid:: ContextGrid ;
8
8
use crate :: context:: grid:: Delta ;
9
+ use crate :: context:: title:: { update_title, ContextManagerTitles } ;
9
10
use crate :: event:: sync:: FairMutex ;
10
11
use crate :: event:: RioEvent ;
11
12
use crate :: ime:: Ime ;
@@ -21,7 +22,6 @@ use rio_backend::event::WindowId;
21
22
use rio_backend:: selection:: SelectionRange ;
22
23
use rio_backend:: sugarloaf:: { font:: SugarloafFont , Object , SugarloafErrors } ;
23
24
use std:: borrow:: Cow ;
24
- use std:: collections:: HashMap ;
25
25
use std:: error:: Error ;
26
26
use std:: sync:: Arc ;
27
27
use std:: time:: { Duration , Instant } ;
@@ -130,43 +130,7 @@ pub struct ContextManagerConfig {
130
130
pub is_native : bool ,
131
131
pub should_update_titles : bool ,
132
132
pub split_color : [ f32 ; 4 ] ,
133
- }
134
-
135
- pub struct ContextManagerTitles {
136
- last_title_update : Option < Instant > ,
137
- pub titles : HashMap < usize , [ String ; 3 ] > ,
138
- pub key : String ,
139
- }
140
-
141
- impl ContextManagerTitles {
142
- pub fn new (
143
- idx : usize ,
144
- program : String ,
145
- terminal_title : String ,
146
- path : String ,
147
- ) -> ContextManagerTitles {
148
- ContextManagerTitles {
149
- key : format ! ( "{}{}{};" , idx, program, terminal_title) ,
150
- titles : HashMap :: from ( [ ( idx, [ program, terminal_title, path] ) ] ) ,
151
- last_title_update : None ,
152
- }
153
- }
154
-
155
- #[ inline]
156
- pub fn set_key_val (
157
- & mut self ,
158
- idx : usize ,
159
- program : String ,
160
- terminal_title : String ,
161
- path : String ,
162
- ) {
163
- self . titles . insert ( idx, [ program, terminal_title, path] ) ;
164
- }
165
-
166
- #[ inline]
167
- pub fn set_key ( & mut self , key : String ) {
168
- self . key = key;
169
- }
133
+ pub title : rio_backend:: config:: title:: Title ,
170
134
}
171
135
172
136
pub struct ContextManager < T : EventListener > {
@@ -236,7 +200,7 @@ pub fn create_mock_context<
236
200
is_native : false ,
237
201
should_update_titles : false ,
238
202
use_current_path : false ,
239
- split_color : [ 0. , 0. , 0. , 0. ] ,
203
+ .. ContextManagerConfig :: default ( )
240
204
} ;
241
205
ContextManager :: create_context (
242
206
( & Cursor :: default ( ) , false ) ,
@@ -408,7 +372,6 @@ impl<T: EventListener + Clone + std::marker::Send + 'static> ContextManager<T> {
408
372
let titles = ContextManagerTitles :: new (
409
373
0 ,
410
374
String :: from ( "tab" ) ,
411
- String :: new ( ) ,
412
375
ctx_config. working_dir . clone ( ) . unwrap_or_default ( ) ,
413
376
) ;
414
377
@@ -462,7 +425,7 @@ impl<T: EventListener + Clone + std::marker::Send + 'static> ContextManager<T> {
462
425
is_native : false ,
463
426
should_update_titles : false ,
464
427
use_current_path : false ,
465
- split_color : [ 0. , 0. , 0. , 0. ] ,
428
+ .. ContextManagerConfig :: default ( )
466
429
} ;
467
430
let initial_context = ContextManager :: create_context (
468
431
( & Cursor :: default ( ) , false ) ,
@@ -474,8 +437,7 @@ impl<T: EventListener + Clone + std::marker::Send + 'static> ContextManager<T> {
474
437
& config,
475
438
) ?;
476
439
477
- let titles =
478
- ContextManagerTitles :: new ( 0 , String :: new ( ) , String :: new ( ) , String :: new ( ) ) ;
440
+ let titles = ContextManagerTitles :: new ( 0 , String :: new ( ) , String :: new ( ) ) ;
479
441
480
442
Ok ( ContextManager {
481
443
current_index : 0 ,
@@ -693,64 +655,29 @@ impl<T: EventListener + Clone + std::marker::Send + 'static> ContextManager<T> {
693
655
. unwrap_or ( true )
694
656
{
695
657
self . titles . last_title_update = Some ( Instant :: now ( ) ) ;
696
- #[ cfg( unix) ]
697
- {
698
- let mut id = String :: default ( ) ;
699
- for ( i, context) in self . contexts . iter_mut ( ) . enumerate ( ) {
700
- let program = teletypewriter:: foreground_process_name (
701
- * context. current ( ) . main_fd ,
702
- context. current ( ) . shell_pid ,
703
- ) ;
704
-
705
- let path = teletypewriter:: foreground_process_path (
706
- * context. current ( ) . main_fd ,
707
- context. current ( ) . shell_pid ,
708
- )
709
- . map ( |p| p. to_string_lossy ( ) . to_string ( ) )
710
- . unwrap_or_default ( ) ;
711
-
712
- let terminal_title = {
713
- let terminal = context. current ( ) . terminal . lock ( ) ;
714
- terminal. title . to_string ( )
715
- } ;
716
-
717
- let window_title = if terminal_title. is_empty ( ) {
718
- program. to_owned ( )
719
- } else {
720
- format ! ( "{} ({})" , terminal_title, program)
721
- } ;
722
-
723
- if cfg ! ( target_os = "macos" ) {
724
- self . event_proxy . send_event (
725
- RioEvent :: TitleWithSubtitle ( window_title, path. clone ( ) ) ,
726
- self . window_id ,
727
- ) ;
728
- } else {
729
- self . event_proxy
730
- . send_event ( RioEvent :: Title ( window_title) , self . window_id ) ;
731
- }
658
+ let mut id = String :: default ( ) ;
659
+ for ( i, context) in self . contexts . iter_mut ( ) . enumerate ( ) {
660
+ let content = update_title ( & self . config . title . content , context. current ( ) ) ;
661
+
662
+ #[ cfg( unix) ]
663
+ let path = teletypewriter:: foreground_process_path (
664
+ * context. current ( ) . main_fd ,
665
+ context. current ( ) . shell_pid ,
666
+ )
667
+ . map ( |p| p. to_string_lossy ( ) . to_string ( ) )
668
+ . unwrap_or_default ( ) ;
732
669
733
- id. push_str ( & format ! ( "{}{}{};" , i, program, terminal_title) ) ;
734
- self . titles . set_key_val ( i, program, terminal_title, path) ;
735
- }
736
- self . titles . set_key ( id) ;
737
- }
670
+ #[ cfg( not( unix) ) ]
671
+ let path = String :: default ( ) ;
738
672
739
- #[ cfg( not( unix) ) ]
740
- {
741
- let mut id = String :: from ( "" ) ;
742
- for ( i, _context) in self . contexts . iter ( ) . enumerate ( ) {
743
- let program = self . config . shell . program . to_owned ( ) ;
744
- id. push_str ( & format ! ( "{}{}{};" , i, program, String :: default ( ) ) ) ;
745
- self . titles . set_key_val (
746
- i,
747
- program,
748
- String :: default ( ) ,
749
- String :: default ( ) ,
750
- ) ;
751
- }
752
- self . titles . set_key ( id) ;
673
+ self . event_proxy
674
+ . send_event ( RioEvent :: Title ( content. to_owned ( ) ) , self . window_id ) ;
675
+
676
+ id. push_str ( & format ! ( "{}{};" , i, content) ) ;
677
+ self . titles . set_key_val ( i, content, path) ;
753
678
}
679
+
680
+ self . titles . set_key ( id) ;
754
681
}
755
682
}
756
683
@@ -985,6 +912,7 @@ impl<T: EventListener + Clone + std::marker::Send + 'static> ContextManager<T> {
985
912
should_update_titles : !( config. navigation . is_collapsed_mode ( )
986
913
&& config. navigation . color_automation . is_empty ( ) ) ,
987
914
split_color : config. colors . split ,
915
+ title : config. title ,
988
916
} ;
989
917
990
918
self . acc_current_route += 1 ;
0 commit comments