Skip to content

Commit 20076ad

Browse files
csi_dispatch: implememnt action K
Signed-off-by: Andy-Python-Programmer <[email protected]>
1 parent 8eddf9c commit 20076ad

File tree

1 file changed

+86
-51
lines changed
  • src/aero_kernel/src/drivers

1 file changed

+86
-51
lines changed

src/aero_kernel/src/drivers/tty.rs

Lines changed: 86 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use alloc::vec::Vec;
2424
use crate::fs;
2525
use crate::fs::devfs;
2626
use crate::fs::inode;
27+
use crate::rendy;
2728

2829
use crate::fs::inode::INodeInterface;
2930
use crate::mem::paging::VirtAddr;
@@ -262,12 +263,12 @@ impl INodeInterface for Tty {
262263
let winsize = VirtAddr::new(arg as u64);
263264
let winsize = unsafe { &mut *(winsize.as_mut_ptr::<aero_syscall::WinSize>()) };
264265

265-
let (rows, cols) = crate::rendy::get_rows_cols();
266+
let (rows, cols) = rendy::get_rows_cols();
266267

267268
winsize.ws_row = rows as u16;
268269
winsize.ws_col = cols as u16;
269270

270-
let (xpixel, ypixel) = crate::rendy::get_resolution();
271+
let (xpixel, ypixel) = rendy::get_resolution();
271272

272273
winsize.ws_xpixel = xpixel as u16;
273274
winsize.ws_ypixel = ypixel as u16;
@@ -371,7 +372,7 @@ impl KeyboardListener for Tty {
371372
}
372373

373374
if termios.c_lflag.contains(aero_syscall::TermiosLFlag::ECHO) {
374-
crate::rendy::print!("{}", character);
375+
rendy::print!("{}", character);
375376
}
376377
};
377378

@@ -381,7 +382,7 @@ impl KeyboardListener for Tty {
381382

382383
if stdin.back_buffer.pop().is_some() {
383384
if termios.c_lflag.contains(aero_syscall::TermiosLFlag::ECHO) {
384-
crate::rendy::backspace();
385+
rendy::backspace();
385386
stdin.cursor -= 1;
386387
}
387388
}
@@ -428,7 +429,7 @@ impl KeyboardListener for Tty {
428429
stdin.cursor = 0;
429430

430431
if termios.c_lflag.contains(aero_syscall::TermiosLFlag::ECHO) {
431-
crate::rendy::print!("\n");
432+
rendy::print!("\n");
432433
}
433434

434435
self.block_queue.notify_complete();
@@ -454,8 +455,8 @@ impl KeyboardListener for Tty {
454455
return;
455456
}
456457

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);
459460

460461
stdin.cursor -= 1;
461462
}
@@ -469,8 +470,8 @@ impl KeyboardListener for Tty {
469470
return;
470471
}
471472

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);
474475

475476
stdin.advance_cursor();
476477
}
@@ -523,22 +524,22 @@ struct AnsiEscape;
523524

524525
impl vte::Perform for AnsiEscape {
525526
fn print(&mut self, char: char) {
526-
crate::rendy::print!("{}", char);
527+
rendy::print!("{}", char);
527528
}
528529

529530
fn execute(&mut self, byte: u8) {
530531
let char = byte as char;
531532

532533
match char {
533-
'\n' | '\t' => crate::rendy::print!("{}", char),
534+
'\n' | '\t' => rendy::print!("{}", char),
534535

535536
'\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)
538539
}
539540

540541
'\u{8}' => {
541-
crate::rendy::backspace();
542+
rendy::backspace();
542543
}
543544

544545
_ => {}
@@ -568,7 +569,7 @@ impl vte::Perform for AnsiEscape {
568569
let mut x = if x != 0 { x - 1 } else { x };
569570
let mut y = if y != 0 { y - 1 } else { y };
570571

571-
let (rows, cols) = crate::rendy::get_term_info();
572+
let (rows, cols) = rendy::get_term_info();
572573

573574
// Make sure the provided coordinates are valid.
574575
if x >= cols {
@@ -580,45 +581,43 @@ impl vte::Perform for AnsiEscape {
580581
}
581582

582583
// Move the cursor to the position.
583-
crate::rendy::set_cursor_position(x, y);
584+
rendy::set_cursor_position(x, y);
584585
}
585586

586587
'l' | 'h' => match params.iter().next() {
587588
Some([25]) => {
588589
// Disable the cursor if action == 'l` and enable it if action
589590
// == 'h'.
590-
crate::rendy::set_cursor_visibility(action == 'h')
591+
rendy::set_cursor_visibility(action == 'h')
591592
}
592593

593594
_ => unimplemented!(),
594595
},
595596

596597
// Clears parts of the screen.
597598
'J' => {
598-
let mut iter = params.iter();
599-
600599
// 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;
602601

603602
match n {
604603
// If `n` is 0 (or missing), clear from cursor to end of screen.
605604
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();
608607

609608
let rows_remaining = term_rows - (y + 1);
610609
let cols_diff = term_cols - (x + 1);
611610
let to_clear = rows_remaining * term_cols + cols_diff;
612611

613-
crate::rendy::set_auto_flush(false);
612+
rendy::set_auto_flush(false);
614613

615614
for _ in 0..to_clear {
616-
crate::rendy::print!(" ");
615+
rendy::print!(" ");
617616
}
618617

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);
622621
}
623622

624623
1 => unimplemented!(),
@@ -627,21 +626,19 @@ impl vte::Perform for AnsiEscape {
627626
//
628627
// TODO(Andy-Python-Programmer): When we support scrollback buffer, if `n` is
629628
// 3, clear the entire scrollback buffer as well.
630-
2 | 3 => crate::rendy::clear_screen(false),
629+
2 | 3 => rendy::clear_screen(false),
631630

632631
// Unknown value, do nothing.
633632
_ => unimplemented!(),
634633
}
635634
}
636635

637636
'C' => {
638-
let mut iter = params.iter();
639-
640637
// 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;
642639

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();
645642

646643
if x + n > term_cols - 1 {
647644
n = (term_cols - 1) - x;
@@ -651,16 +648,61 @@ impl vte::Perform for AnsiEscape {
651648
n = 1;
652649
}
653650

654-
crate::rendy::set_cursor_position(x + n, y);
651+
rendy::set_cursor_position(x + n, y);
655652
}
656653

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);
659677

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' => {
660702
// 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;
662704

663-
let (x, y) = crate::rendy::get_cursor_position();
705+
let (x, y) = rendy::get_cursor_position();
664706

665707
// If the cursor is already at the edge of the screen, this has no effect.
666708
if n > x {
@@ -671,13 +713,12 @@ impl vte::Perform for AnsiEscape {
671713
n = 1;
672714
}
673715

674-
crate::rendy::set_cursor_position(x - n, y);
716+
rendy::set_cursor_position(x - n, y);
675717
}
676718

677719
// Sets colors and style of the characters following this code.
678720
'm' => {
679721
let mut piter = params.iter();
680-
681722
let mut bright = false;
682723

683724
while let Some(param) = piter.next() {
@@ -690,7 +731,7 @@ impl vte::Perform for AnsiEscape {
690731
bright = false;
691732
// TODO: Turn off dim.
692733

693-
crate::rendy::reset_default();
734+
rendy::reset_default();
694735
}
695736

696737
// Bold or increased intensity:
@@ -726,7 +767,7 @@ impl vte::Perform for AnsiEscape {
726767
ANSI_COLORS[color as usize]
727768
};
728769

729-
crate::rendy::set_text_fg(ccode);
770+
rendy::set_text_fg(ccode);
730771
}
731772

732773
ParsedColor::Background(color) => {
@@ -736,7 +777,7 @@ impl vte::Perform for AnsiEscape {
736777
ANSI_COLORS[color as usize]
737778
};
738779

739-
crate::rendy::set_text_bg(ccode);
780+
rendy::set_text_bg(ccode);
740781
}
741782

742783
ParsedColor::Unknown => {
@@ -787,17 +828,11 @@ impl vte::Perform for AnsiEscape {
787828

788829
// Background
789830
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);
794832
}
795833
// Foreground
796834
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);
801836
}
802837
}
803838
}

0 commit comments

Comments
 (0)