@@ -108,7 +108,11 @@ impl TerminalSession {
108108 self . stdout,
109109 MoveTo ( 0 , 0 ) ,
110110 Clear ( ClearType :: All ) ,
111- Print ( content_to_lines( content, size) )
111+ Print ( content_to_lines(
112+ content,
113+ size. content_height( ) . max( 1 ) ,
114+ size. width
115+ ) )
112116 )
113117 . context ( "drawing terminal frame" ) ?;
114118 if size. height > 0 {
@@ -118,6 +122,45 @@ impl TerminalSession {
118122 Ok ( ( ) )
119123 }
120124
125+ pub ( crate ) fn draw_frame_with_readout (
126+ & mut self ,
127+ content : & str ,
128+ readout : & ChromeLine ,
129+ status : & str ,
130+ ) -> Result < ( ) > {
131+ let size = self . size ( ) ?;
132+ let content_rows = size. height . saturating_sub ( 2 ) . max ( 1 ) ;
133+ queue ! (
134+ self . stdout,
135+ MoveTo ( 0 , 0 ) ,
136+ Clear ( ClearType :: All ) ,
137+ Print ( content_to_lines( content, content_rows, size. width) )
138+ )
139+ . context ( "drawing terminal frame with readout" ) ?;
140+ if size. height > 1 {
141+ draw_chrome_line (
142+ & mut self . stdout ,
143+ size. height . saturating_sub ( 2 ) ,
144+ size. width . max ( 1 ) ,
145+ PLOT_CHROME_BG ,
146+ Color :: Rgb {
147+ r : 41 ,
148+ g : 54 ,
149+ b : 57 ,
150+ } ,
151+ readout,
152+ )
153+ . context ( "drawing terminal frame readout" ) ?;
154+ }
155+ if size. height > 0 {
156+ self . draw_status_line ( size, status) ?;
157+ }
158+ self . stdout
159+ . flush ( )
160+ . context ( "flushing terminal frame with readout" ) ?;
161+ Ok ( ( ) )
162+ }
163+
121164 pub ( crate ) fn draw_protocol_frame ( & mut self , payload : & str , status : & str ) -> Result < ( ) > {
122165 let size = self . size ( ) ?;
123166 queue ! ( self . stdout, MoveTo ( 0 , 0 ) , Print ( payload) ) . context ( "drawing protocol payload" ) ?;
@@ -139,6 +182,7 @@ impl TerminalSession {
139182 self . draw_plot_dynamic_chrome ( size, & frame) ?;
140183 self . draw_plot_axis_labels ( & frame) ?;
141184 if size. height > 0 {
185+ self . draw_plot_readout_line ( size, & frame) ?;
142186 self . draw_plot_status_line ( size, & frame. chrome . dynamic_layer . status ) ?;
143187 }
144188 queue ! (
@@ -202,6 +246,17 @@ impl TerminalSession {
202246 . context ( "painting plot x-axis row" ) ?;
203247 }
204248
249+ if frame. chrome . dynamic_layer . readout_row < size. height . saturating_sub ( 1 ) {
250+ paint_row (
251+ & mut self . stdout ,
252+ 0 ,
253+ frame. chrome . dynamic_layer . readout_row ,
254+ size. width ,
255+ PLOT_CHROME_BG ,
256+ )
257+ . context ( "painting plot readout row" ) ?;
258+ }
259+
205260 Ok ( ( ) )
206261 }
207262
@@ -334,6 +389,30 @@ impl TerminalSession {
334389 Ok ( ( ) )
335390 }
336391
392+ fn draw_plot_readout_line (
393+ & mut self ,
394+ size : TerminalSize ,
395+ frame : & PlotProtocolFrame < ' _ > ,
396+ ) -> Result < ( ) > {
397+ if frame. chrome . dynamic_layer . readout_row >= size. height . saturating_sub ( 1 ) {
398+ return Ok ( ( ) ) ;
399+ }
400+ draw_chrome_line (
401+ & mut self . stdout ,
402+ frame. chrome . dynamic_layer . readout_row ,
403+ size. width . max ( 1 ) ,
404+ PLOT_CHROME_BG ,
405+ Color :: Rgb {
406+ r : 41 ,
407+ g : 54 ,
408+ b : 57 ,
409+ } ,
410+ & frame. chrome . dynamic_layer . readout ,
411+ )
412+ . context ( "drawing plot readout line" ) ?;
413+ Ok ( ( ) )
414+ }
415+
337416 pub ( crate ) fn stop ( & mut self ) -> Result < ( ) > {
338417 if !self . active {
339418 return Ok ( ( ) ) ;
@@ -373,17 +452,17 @@ impl Drop for TerminalSession {
373452 }
374453}
375454
376- fn content_to_lines ( content : & str , size : TerminalSize ) -> String {
377- let width = usize:: from ( size . width . max ( 1 ) ) ;
378- let content_rows = usize:: from ( size . content_height ( ) . max ( 1 ) ) ;
455+ fn content_to_lines ( content : & str , content_rows : u16 , width : u16 ) -> String {
456+ let width = usize:: from ( width. max ( 1 ) ) ;
457+ let content_rows = usize:: from ( content_rows . max ( 1 ) ) ;
379458 let mut output = String :: new ( ) ;
380459 for ( row, line) in content. lines ( ) . take ( content_rows) . enumerate ( ) {
381460 if line. contains ( '\u{1b}' ) {
382461 output. push_str ( line) ;
383462 } else {
384463 output. push_str ( & trim_to_width ( line, width) ) ;
385464 }
386- if row + 1 < content_rows || size . height > 1 {
465+ if row + 1 < content_rows {
387466 output. push_str ( "\r \n " ) ;
388467 }
389468 }
@@ -421,13 +500,7 @@ mod tests {
421500
422501 #[ test]
423502 fn frame_content_uses_crlf_for_raw_terminal_mode ( ) {
424- let output = content_to_lines (
425- "alpha\n beta" ,
426- TerminalSize {
427- width : 8 ,
428- height : 3 ,
429- } ,
430- ) ;
503+ let output = content_to_lines ( "alpha\n beta" , 2 , 8 ) ;
431504
432505 assert ! ( output. contains( "alpha \r \n beta" ) ) ;
433506 assert ! ( !output. contains( "alpha \n beta" ) ) ;
0 commit comments