@@ -24,6 +24,7 @@ use alloc::vec::Vec;
24
24
use crate :: fs;
25
25
use crate :: fs:: devfs;
26
26
use crate :: fs:: inode;
27
+ use crate :: rendy;
27
28
28
29
use crate :: fs:: inode:: INodeInterface ;
29
30
use crate :: mem:: paging:: VirtAddr ;
@@ -262,12 +263,12 @@ impl INodeInterface for Tty {
262
263
let winsize = VirtAddr :: new ( arg as u64 ) ;
263
264
let winsize = unsafe { & mut * ( winsize. as_mut_ptr :: < aero_syscall:: WinSize > ( ) ) } ;
264
265
265
- let ( rows, cols) = crate :: rendy:: get_rows_cols ( ) ;
266
+ let ( rows, cols) = rendy:: get_rows_cols ( ) ;
266
267
267
268
winsize. ws_row = rows as u16 ;
268
269
winsize. ws_col = cols as u16 ;
269
270
270
- let ( xpixel, ypixel) = crate :: rendy:: get_resolution ( ) ;
271
+ let ( xpixel, ypixel) = rendy:: get_resolution ( ) ;
271
272
272
273
winsize. ws_xpixel = xpixel as u16 ;
273
274
winsize. ws_ypixel = ypixel as u16 ;
@@ -371,7 +372,7 @@ impl KeyboardListener for Tty {
371
372
}
372
373
373
374
if termios. c_lflag . contains ( aero_syscall:: TermiosLFlag :: ECHO ) {
374
- crate :: rendy:: print!( "{}" , character) ;
375
+ rendy:: print!( "{}" , character) ;
375
376
}
376
377
} ;
377
378
@@ -381,7 +382,7 @@ impl KeyboardListener for Tty {
381
382
382
383
if stdin. back_buffer . pop ( ) . is_some ( ) {
383
384
if termios. c_lflag . contains ( aero_syscall:: TermiosLFlag :: ECHO ) {
384
- crate :: rendy:: backspace ( ) ;
385
+ rendy:: backspace ( ) ;
385
386
stdin. cursor -= 1 ;
386
387
}
387
388
}
@@ -428,7 +429,7 @@ impl KeyboardListener for Tty {
428
429
stdin. cursor = 0 ;
429
430
430
431
if termios. c_lflag . contains ( aero_syscall:: TermiosLFlag :: ECHO ) {
431
- crate :: rendy:: print!( "\n " ) ;
432
+ rendy:: print!( "\n " ) ;
432
433
}
433
434
434
435
self . block_queue . notify_complete ( ) ;
@@ -454,8 +455,8 @@ impl KeyboardListener for Tty {
454
455
return ;
455
456
}
456
457
457
- let ( x, y) = crate :: rendy:: get_cursor_position ( ) ;
458
- crate :: rendy:: set_cursor_position ( x - 1 , y) ;
458
+ let ( x, y) = rendy:: get_cursor_position ( ) ;
459
+ rendy:: set_cursor_position ( x - 1 , y) ;
459
460
460
461
stdin. cursor -= 1 ;
461
462
}
@@ -469,8 +470,8 @@ impl KeyboardListener for Tty {
469
470
return ;
470
471
}
471
472
472
- let ( x, y) = crate :: rendy:: get_cursor_position ( ) ;
473
- crate :: rendy:: set_cursor_position ( x + 1 , y) ;
473
+ let ( x, y) = rendy:: get_cursor_position ( ) ;
474
+ rendy:: set_cursor_position ( x + 1 , y) ;
474
475
475
476
stdin. advance_cursor ( ) ;
476
477
}
@@ -523,22 +524,22 @@ struct AnsiEscape;
523
524
524
525
impl vte:: Perform for AnsiEscape {
525
526
fn print ( & mut self , char : char ) {
526
- crate :: rendy:: print!( "{}" , char ) ;
527
+ rendy:: print!( "{}" , char ) ;
527
528
}
528
529
529
530
fn execute ( & mut self , byte : u8 ) {
530
531
let char = byte as char ;
531
532
532
533
match char {
533
- '\n' | '\t' => crate :: rendy:: print!( "{}" , char ) ,
534
+ '\n' | '\t' => rendy:: print!( "{}" , char ) ,
534
535
535
536
'\r' => {
536
- let ( _, y) = crate :: rendy:: get_cursor_position ( ) ;
537
- crate :: rendy:: set_cursor_position ( 0 , y)
537
+ let ( _, y) = rendy:: get_cursor_position ( ) ;
538
+ rendy:: set_cursor_position ( 0 , y)
538
539
}
539
540
540
541
'\u{8}' => {
541
- crate :: rendy:: backspace ( ) ;
542
+ rendy:: backspace ( ) ;
542
543
}
543
544
544
545
_ => { }
@@ -568,7 +569,7 @@ impl vte::Perform for AnsiEscape {
568
569
let mut x = if x != 0 { x - 1 } else { x } ;
569
570
let mut y = if y != 0 { y - 1 } else { y } ;
570
571
571
- let ( rows, cols) = crate :: rendy:: get_term_info ( ) ;
572
+ let ( rows, cols) = rendy:: get_term_info ( ) ;
572
573
573
574
// Make sure the provided coordinates are valid.
574
575
if x >= cols {
@@ -580,45 +581,43 @@ impl vte::Perform for AnsiEscape {
580
581
}
581
582
582
583
// Move the cursor to the position.
583
- crate :: rendy:: set_cursor_position ( x, y) ;
584
+ rendy:: set_cursor_position ( x, y) ;
584
585
}
585
586
586
587
'l' | 'h' => match params. iter ( ) . next ( ) {
587
588
Some ( [ 25 ] ) => {
588
589
// Disable the cursor if action == 'l` and enable it if action
589
590
// == 'h'.
590
- crate :: rendy:: set_cursor_visibility ( action == 'h' )
591
+ rendy:: set_cursor_visibility ( action == 'h' )
591
592
}
592
593
593
594
_ => unimplemented ! ( ) ,
594
595
} ,
595
596
596
597
// Clears parts of the screen.
597
598
'J' => {
598
- let mut iter = params. iter ( ) ;
599
-
600
599
// If `n` is missing, it defaults to 0.
601
- let n = iter. next ( ) . unwrap_or ( & [ 0 ] ) [ 0 ] as usize ;
600
+ let n = params . iter ( ) . next ( ) . unwrap_or ( & [ 0 ] ) [ 0 ] as usize ;
602
601
603
602
match n {
604
603
// If `n` is 0 (or missing), clear from cursor to end of screen.
605
604
0 => {
606
- let ( x, y) = crate :: rendy:: get_cursor_position ( ) ;
607
- let ( term_rows, term_cols) = crate :: rendy:: get_rows_cols ( ) ;
605
+ let ( x, y) = rendy:: get_cursor_position ( ) ;
606
+ let ( term_rows, term_cols) = rendy:: get_rows_cols ( ) ;
608
607
609
608
let rows_remaining = term_rows - ( y + 1 ) ;
610
609
let cols_diff = term_cols - ( x + 1 ) ;
611
610
let to_clear = rows_remaining * term_cols + cols_diff;
612
611
613
- crate :: rendy:: set_auto_flush ( false ) ;
612
+ rendy:: set_auto_flush ( false ) ;
614
613
615
614
for _ in 0 ..to_clear {
616
- crate :: rendy:: print!( " " ) ;
615
+ rendy:: print!( " " ) ;
617
616
}
618
617
619
- crate :: rendy:: set_cursor_position ( x, y) ;
620
- crate :: rendy:: double_buffer_flush ( ) ;
621
- crate :: rendy:: set_auto_flush ( true ) ;
618
+ rendy:: set_cursor_position ( x, y) ;
619
+ rendy:: double_buffer_flush ( ) ;
620
+ rendy:: set_auto_flush ( true ) ;
622
621
}
623
622
624
623
1 => unimplemented ! ( ) ,
@@ -627,21 +626,19 @@ impl vte::Perform for AnsiEscape {
627
626
//
628
627
// TODO(Andy-Python-Programmer): When we support scrollback buffer, if `n` is
629
628
// 3, clear the entire scrollback buffer as well.
630
- 2 | 3 => crate :: rendy:: clear_screen ( false ) ,
629
+ 2 | 3 => rendy:: clear_screen ( false ) ,
631
630
632
631
// Unknown value, do nothing.
633
632
_ => unimplemented ! ( ) ,
634
633
}
635
634
}
636
635
637
636
'C' => {
638
- let mut iter = params. iter ( ) ;
639
-
640
637
// If `n` is missing, it defaults to 1.
641
- let mut n = iter. next ( ) . unwrap_or ( & [ 1 ] ) [ 0 ] as usize ;
638
+ let mut n = params . iter ( ) . next ( ) . unwrap_or ( & [ 1 ] ) [ 0 ] as usize ;
642
639
643
- let ( x, y) = crate :: rendy:: get_cursor_position ( ) ;
644
- let ( _, term_cols) = crate :: rendy:: get_rows_cols ( ) ;
640
+ let ( x, y) = rendy:: get_cursor_position ( ) ;
641
+ let ( _, term_cols) = rendy:: get_rows_cols ( ) ;
645
642
646
643
if x + n > term_cols - 1 {
647
644
n = ( term_cols - 1 ) - x;
@@ -651,16 +648,61 @@ impl vte::Perform for AnsiEscape {
651
648
n = 1 ;
652
649
}
653
650
654
- crate :: rendy:: set_cursor_position ( x + n, y) ;
651
+ rendy:: set_cursor_position ( x + n, y) ;
655
652
}
656
653
657
- 'D' => {
658
- let mut iter = params. iter ( ) ;
654
+ 'K' => {
655
+ // If `n` is missing, it defaults to 0.
656
+ let n = params. iter ( ) . next ( ) . unwrap_or ( & [ 0 ] ) [ 0 ] as usize ;
657
+
658
+ // NOTE: The cursor position does not change.
659
+ match n {
660
+ // If `n` is 0 (or missing), clear from cursor to the end of the line.
661
+ 0 => {
662
+ let ( x, y) = rendy:: get_cursor_position ( ) ;
663
+ let ( _, term_cols) = rendy:: get_rows_cols ( ) ;
664
+
665
+ for _ in x..term_cols {
666
+ rendy:: print!( " " ) ;
667
+ }
668
+
669
+ rendy:: set_cursor_position ( x, y) ;
670
+ }
671
+
672
+ // If `n` is 1, clear from cursor to beginning of the line.
673
+ 1 => {
674
+ let ( x, y) = rendy:: get_cursor_position ( ) ;
675
+
676
+ rendy:: set_cursor_position ( 0 , y) ;
659
677
678
+ for _ in 0 ..x {
679
+ rendy:: print!( " " )
680
+ }
681
+ }
682
+
683
+ // If `n` is 2, clear entire line.
684
+ 2 => {
685
+ let ( _, term_cols) = rendy:: get_rows_cols ( ) ;
686
+ let ( x, y) = rendy:: get_cursor_position ( ) ;
687
+
688
+ rendy:: set_cursor_position ( 0 , y) ;
689
+
690
+ for _ in 0 ..term_cols {
691
+ rendy:: print!( " " )
692
+ }
693
+
694
+ rendy:: set_cursor_position ( x, y) ;
695
+ }
696
+
697
+ _ => unimplemented ! ( ) ,
698
+ }
699
+ }
700
+
701
+ 'D' => {
660
702
// If `n` is missing, it defaults to 1.
661
- let mut n = iter. next ( ) . unwrap_or ( & [ 1 ] ) [ 0 ] as usize ;
703
+ let mut n = params . iter ( ) . next ( ) . unwrap_or ( & [ 1 ] ) [ 0 ] as usize ;
662
704
663
- let ( x, y) = crate :: rendy:: get_cursor_position ( ) ;
705
+ let ( x, y) = rendy:: get_cursor_position ( ) ;
664
706
665
707
// If the cursor is already at the edge of the screen, this has no effect.
666
708
if n > x {
@@ -671,13 +713,12 @@ impl vte::Perform for AnsiEscape {
671
713
n = 1 ;
672
714
}
673
715
674
- crate :: rendy:: set_cursor_position ( x - n, y) ;
716
+ rendy:: set_cursor_position ( x - n, y) ;
675
717
}
676
718
677
719
// Sets colors and style of the characters following this code.
678
720
'm' => {
679
721
let mut piter = params. iter ( ) ;
680
-
681
722
let mut bright = false ;
682
723
683
724
while let Some ( param) = piter. next ( ) {
@@ -690,7 +731,7 @@ impl vte::Perform for AnsiEscape {
690
731
bright = false ;
691
732
// TODO: Turn off dim.
692
733
693
- crate :: rendy:: reset_default ( ) ;
734
+ rendy:: reset_default ( ) ;
694
735
}
695
736
696
737
// Bold or increased intensity:
@@ -726,7 +767,7 @@ impl vte::Perform for AnsiEscape {
726
767
ANSI_COLORS [ color as usize ]
727
768
} ;
728
769
729
- crate :: rendy:: set_text_fg ( ccode) ;
770
+ rendy:: set_text_fg ( ccode) ;
730
771
}
731
772
732
773
ParsedColor :: Background ( color) => {
@@ -736,7 +777,7 @@ impl vte::Perform for AnsiEscape {
736
777
ANSI_COLORS [ color as usize ]
737
778
} ;
738
779
739
- crate :: rendy:: set_text_bg ( ccode) ;
780
+ rendy:: set_text_bg ( ccode) ;
740
781
}
741
782
742
783
ParsedColor :: Unknown => {
@@ -787,17 +828,11 @@ impl vte::Perform for AnsiEscape {
787
828
788
829
// Background
789
830
if code == 48 {
790
- run_special_parser (
791
- crate :: rendy:: set_text_bg,
792
- & mut piter,
793
- ) ;
831
+ run_special_parser ( rendy:: set_text_bg, & mut piter) ;
794
832
}
795
833
// Foreground
796
834
else if code == 38 {
797
- run_special_parser (
798
- crate :: rendy:: set_text_fg,
799
- & mut piter,
800
- ) ;
835
+ run_special_parser ( rendy:: set_text_fg, & mut piter) ;
801
836
}
802
837
}
803
838
}
0 commit comments