From 6636cf6b9fa03a711f8c3aa2d6ca43248fecfc0f Mon Sep 17 00:00:00 2001 From: Joe Wilm Date: Mon, 6 Jun 2016 15:13:45 -0700 Subject: Minor updates to terminal handling Properly handles goto_col and goto_row. Additionally, input wrapping is handled. Truecolor specs are now set appropriately. --- src/term.rs | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'src/term.rs') diff --git a/src/term.rs b/src/term.rs index 2838c668..5b00acfd 100644 --- a/src/term.rs +++ b/src/term.rs @@ -149,6 +149,11 @@ impl Term { /// Set character in current cursor position fn set_char(&mut self, c: char) { + if self.cursor.x == self.grid.num_cols() as u16 { + self.cursor.y += 1; + self.cursor.x = 0; + } + let cell = &mut self.grid[self.cursor]; cell.c = c; cell.fg = self.fg; @@ -175,8 +180,17 @@ impl ansi::Handler for Term { println!("goto: x={}, y={}", x, y); self.cursor.goto(x as u16, y as u16); } - fn goto_row(&mut self, y: i64) { println!("goto_row: {}", y); } - fn goto_col(&mut self, x: i64) { println!("goto_col: {}", x); } + fn goto_row(&mut self, y: i64) { + println!("goto_row: {}", y); + let x = self.cursor_x(); + self.cursor.goto(x, y as u16); + } + fn goto_col(&mut self, x: i64) { + println!("goto_col: {}", x); + let y = self.cursor_y(); + self.cursor.goto(x as u16, y); + } + fn insert_blank(&mut self, num: i64) { println!("insert_blank: {}", num); } fn move_up(&mut self, rows: i64) { @@ -325,6 +339,12 @@ impl ansi::Handler for Term { Attr::Background(named_color) => { self.bg = COLORS[named_color as usize]; }, + Attr::ForegroundSpec(rgb) => { + self.fg = rgb; + }, + Attr::BackgroundSpec(rgb) => { + self.bg = rgb; + }, Attr::Reset => { self.fg = DEFAULT_FG; self.bg = DEFAULT_BG; -- cgit