8
8
//! of text around to handle text insertion.
9
9
10
10
use crate :: pager:: { PageRendering , Pager } ;
11
- use crate :: threads :: MainThread ;
11
+ use std :: cell :: RefCell ;
12
12
use std:: collections:: LinkedList ;
13
13
use std:: ffi:: { CStr , CString } ;
14
14
use std:: io:: Write ;
@@ -177,7 +177,7 @@ pub struct Screen {
177
177
pub autosuggestion_is_truncated : bool ,
178
178
179
179
/// Receiver for our output.
180
- outp : & ' static MainThread < Outputter > ,
180
+ outp : & ' static RefCell < Outputter > ,
181
181
182
182
/// The internal representation of the desired screen contents.
183
183
desired : ScreenData ,
@@ -638,9 +638,9 @@ impl Screen {
638
638
// Either issue a cr to go back to the beginning of this line, or a nl to go to the
639
639
// beginning of the next one, depending on what we think is more efficient.
640
640
if new_y <= zelf. actual . cursor . y {
641
- zelf. outp . with_mut ( |outp| outp . push ( b'\r' ) ) ;
641
+ zelf. outp . borrow_mut ( ) . push ( b'\r' ) ;
642
642
} else {
643
- zelf. outp . with_mut ( |outp| outp . push ( b'\n' ) ) ;
643
+ zelf. outp . borrow_mut ( ) . push ( b'\n' ) ;
644
644
zelf. actual . cursor . y += 1 ;
645
645
}
646
646
// Either way we're not in the first column.
@@ -674,16 +674,14 @@ impl Screen {
674
674
None
675
675
} ;
676
676
677
- zelf. outp . with_mut ( |outp| {
678
- for _ in 0 ..y_steps. abs_diff ( 0 ) {
679
- outp. tputs_if_some ( & s) ;
680
- }
681
- } ) ;
677
+ for _ in 0 ..y_steps. abs_diff ( 0 ) {
678
+ zelf. outp . borrow_mut ( ) . tputs_if_some ( & s) ;
679
+ }
682
680
683
681
let mut x_steps =
684
682
isize:: try_from ( new_x) . unwrap ( ) - isize:: try_from ( zelf. actual . cursor . x ) . unwrap ( ) ;
685
683
if x_steps != 0 && new_x == 0 {
686
- zelf. outp . with_mut ( |outp| outp . push ( b'\r' ) ) ;
684
+ zelf. outp . borrow_mut ( ) . push ( b'\r' ) ;
687
685
x_steps = 0 ;
688
686
}
689
687
@@ -703,10 +701,10 @@ impl Screen {
703
701
multi_str. as_ref ( ) . unwrap ( ) ,
704
702
i32:: try_from ( x_steps. abs_diff ( 0 ) ) . unwrap ( ) ,
705
703
) ;
706
- zelf. outp . with_mut ( |outp| outp . tputs_if_some ( & multi_param) ) ;
704
+ zelf. outp . borrow_mut ( ) . tputs_if_some ( & multi_param) ;
707
705
} else {
708
706
for _ in 0 ..x_steps. abs_diff ( 0 ) {
709
- zelf. outp . with_mut ( |outp| outp . tputs_if_some ( & s) ) ;
707
+ zelf. outp . borrow_mut ( ) . tputs_if_some ( & s) ;
710
708
}
711
709
}
712
710
@@ -718,7 +716,7 @@ impl Screen {
718
716
fn write_char ( & mut self , c : char , width : isize ) {
719
717
let mut zelf = self . scoped_buffer ( ) ;
720
718
zelf. actual . cursor . x = zelf. actual . cursor . x . wrapping_add ( width as usize ) ;
721
- zelf. outp . with_mut ( |outp| outp . writech ( c) ) ;
719
+ zelf. outp . borrow_mut ( ) . writech ( c) ;
722
720
if Some ( zelf. actual . cursor . x ) == zelf. actual . screen_width && allow_soft_wrap ( ) {
723
721
zelf. soft_wrap_location = Some ( Cursor {
724
722
x : 0 ,
@@ -735,16 +733,16 @@ impl Screen {
735
733
736
734
/// Send the specified string through tputs and append the output to the screen's outputter.
737
735
fn write_mbs ( & mut self , s : & CStr ) {
738
- self . outp . with_mut ( |outp| outp . tputs ( s) ) ;
736
+ self . outp . borrow_mut ( ) . tputs ( s) ;
739
737
}
740
738
741
739
fn write_mbs_if_some ( & mut self , s : & Option < impl AsRef < CStr > > ) -> bool {
742
- self . outp . with_mut ( |outp| outp . tputs_if_some ( s) )
740
+ self . outp . borrow_mut ( ) . tputs_if_some ( s)
743
741
}
744
742
745
743
/// Convert a wide string to a multibyte string and append it to the buffer.
746
744
fn write_str ( & mut self , s : & wstr ) {
747
- self . outp . with_mut ( |outp| outp . write_wstr ( s) ) ;
745
+ self . outp . borrow_mut ( ) . write_wstr ( s) ;
748
746
}
749
747
750
748
/// Update the cursor as if soft wrapping had been performed.
@@ -769,9 +767,9 @@ impl Screen {
769
767
}
770
768
771
769
fn scoped_buffer ( & mut self ) -> impl ScopeGuarding < Target = & mut Screen > {
772
- self . outp . with_mut ( Outputter :: begin_buffering) ;
770
+ self . outp . borrow_mut ( ) . begin_buffering ( ) ;
773
771
ScopeGuard :: new ( self , |zelf| {
774
- zelf. outp . with_mut ( Outputter :: end_buffering) ;
772
+ zelf. outp . borrow_mut ( ) . end_buffering ( ) ;
775
773
} )
776
774
}
777
775
@@ -782,7 +780,7 @@ impl Screen {
782
780
let mut set_color = |zelf : & mut Self , c| {
783
781
let fg = color_resolver. resolve_spec ( & c, false , vars) ;
784
782
let bg = color_resolver. resolve_spec ( & c, true , vars) ;
785
- zelf. outp . with_mut ( |outp| outp . set_color ( fg, bg) ) ;
783
+ zelf. outp . borrow_mut ( ) . set_color ( fg, bg) ;
786
784
} ;
787
785
788
786
let mut cached_layouts = LAYOUT_CACHE_SHARED . lock ( ) . unwrap ( ) ;
@@ -837,9 +835,9 @@ impl Screen {
837
835
let mut start = 0 ;
838
836
for line_break in left_prompt_layout. line_breaks {
839
837
zelf. write_str ( & left_prompt[ start..line_break] ) ;
840
- zelf. outp . with_mut ( |outp| {
841
- outp . tputs_if_some ( & term . and_then ( |term| term . clr_eol . as_ref ( ) ) ) ;
842
- } ) ;
838
+ zelf. outp
839
+ . borrow_mut ( )
840
+ . tputs_if_some ( & term . and_then ( |term| term . clr_eol . as_ref ( ) ) ) ;
843
841
start = line_break;
844
842
}
845
843
zelf. write_str ( & left_prompt[ start..] ) ;
@@ -1071,9 +1069,9 @@ impl Screen {
1071
1069
1072
1070
/// Issues an immediate clr_eos.
1073
1071
pub fn screen_force_clear_to_end ( ) {
1074
- Outputter :: stdoutput ( ) . with_mut ( |outp| {
1075
- outp . tputs_if_some ( & term ( ) . unwrap ( ) . clr_eos ) ;
1076
- } ) ;
1072
+ Outputter :: stdoutput ( )
1073
+ . borrow_mut ( )
1074
+ . tputs_if_some ( & term ( ) . unwrap ( ) . clr_eos ) ;
1077
1075
}
1078
1076
1079
1077
/// Information about the layout of a prompt.
0 commit comments