diff options
author | Michael Brumlow <mbrumlow@gmail.com> | 2017-01-07 17:13:42 -0600 |
---|---|---|
committer | Michael Brumlow <mbrumlow@gmail.com> | 2017-01-07 17:13:42 -0600 |
commit | 24453fa698150e4e980339a11ecc3fbdb2ee4914 (patch) | |
tree | 839160c41e0f4c9651ff92110f52d35fb5d7d0ef | |
parent | b88fd8a23e2a079e84f44044be915cb0186d632b (diff) | |
download | alacritty-24453fa698150e4e980339a11ecc3fbdb2ee4914.tar.gz alacritty-24453fa698150e4e980339a11ecc3fbdb2ee4914.zip |
Implementing line wrapping.
This implementation of line wrapping ensures self.cursor.col is never out
of bounds, thus not requiring checking.
-rw-r--r-- | src/term/mod.rs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/term/mod.rs b/src/term/mod.rs index 63715479..878229e2 100644 --- a/src/term/mod.rs +++ b/src/term/mod.rs @@ -202,6 +202,9 @@ pub struct Term { /// The grid grid: Grid<Cell>, + /// Wrap on next input + wrap: bool, + /// Alternate grid alt_grid: Grid<Cell>, @@ -297,6 +300,7 @@ impl Term { Term { dirty: false, + wrap: false, grid: grid, alt_grid: alt, alt: false, @@ -613,6 +617,31 @@ impl ansi::Handler for Term { #[inline] fn input(&mut self, c: char) { + if self.wrap { + + debug_println!("wrapping"); + + { + let location = Point { + line: self.cursor.line, + col: self.cursor.col + }; + + let cell = &mut self.grid[&location]; + cell.flags.insert(cell::WRAPLINE); + } + + if (self.cursor.line + 1) >= self.scroll_region.end { + self.linefeed(); + } else { + self.cursor.line += 1; + } + + self.cursor.col = Column(0); + self.wrap = false; + } + + { let cell = &mut self.grid[&self.cursor]; *cell = self.template_cell; @@ -621,6 +650,8 @@ impl ansi::Handler for Term { if (self.cursor.col + 1) < self.grid.num_cols() { self.cursor.col += 1; + } else { + self.wrap = true; } // TODO handle auto wrap if auto wrap is enabled. @@ -633,18 +664,21 @@ impl ansi::Handler for Term { debug_println!("goto: line={}, col={}", line, col); self.cursor.line = cmp::min(line, self.grid.num_lines() - 1); self.cursor.col = cmp::min(col, self.grid.num_cols() - 1); + self.wrap = false; } #[inline] fn goto_line(&mut self, line: Line) { debug_println!("goto_line: {}", line); self.cursor.line = cmp::min(line, self.grid.num_lines() - 1); + self.wrap = false; } #[inline] fn goto_col(&mut self, col: Column) { debug_println!("goto_col: {}", col); self.cursor.col = cmp::min(col, self.grid.num_cols() - 1); + self.wrap = false; } #[inline] @@ -692,6 +726,7 @@ impl ansi::Handler for Term { fn move_forward(&mut self, cols: Column) { debug_println!("move_forward: {}", cols); self.cursor.col = cmp::min(self.cursor.col + cols, self.grid.num_cols() - 1); + self.wrap = false; } #[inline] @@ -699,6 +734,7 @@ impl ansi::Handler for Term { debug_println!("move_backward: {}", cols); let cols = cmp::min(self.cursor.col, cols); self.cursor.col = cmp::min(self.cursor.col - cols, self.grid.num_cols() - 1); + self.wrap = false; } #[inline] @@ -732,6 +768,7 @@ impl ansi::Handler for Term { } self.cursor.col = col; + self.wrap = false; } /// Backspace `count` characters @@ -740,6 +777,7 @@ impl ansi::Handler for Term { debug_println!("backspace"); if self.cursor.col > Column(0) { self.cursor.col -= 1; + self.wrap = false; } } @@ -748,6 +786,7 @@ impl ansi::Handler for Term { fn carriage_return(&mut self) { debug_println!("carriage_return"); self.cursor.col = Column(0); + self.wrap = false; } /// Linefeed |