diff options
author | Christian Duerr <chrisduerr@users.noreply.github.com> | 2019-03-13 18:55:18 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-13 18:55:18 +0000 |
commit | b1032bcc6b79135f87f327548e43563da05657fb (patch) | |
tree | 94915b15d11094006dcd3381b8ff0d0d3ed5de9b /src/term | |
parent | 0b9ae4ce936dfafbf5ea1929a170c97391cdea0b (diff) | |
download | alacritty-b1032bcc6b79135f87f327548e43563da05657fb.tar.gz alacritty-b1032bcc6b79135f87f327548e43563da05657fb.zip |
Add text reflow
Alacritty will now automatically reflow lines and shrink them when they
would usually exceed the new width of the terminal instead of
truncation.
If a line had to be truncated, it will also be reflown into the previous
line after growing the terminal width.
The reflow behavior when not at the bottom of the history is similar to
that of VTE and aims to keep the viewport stationary whenever possible.
Opposed to VTE, reflow will also be performed in the alternate screen
buffer.
There will be bugs when resizing the terminal emulator to a size smaller
than the prompt, though these issues were present in all terminal
emulators with reflow support.
This fixes #591.
Diffstat (limited to 'src/term')
-rw-r--r-- | src/term/cell.rs | 36 | ||||
-rw-r--r-- | src/term/mod.rs | 14 |
2 files changed, 38 insertions, 12 deletions
diff --git a/src/term/cell.rs b/src/term/cell.rs index 5d3b7036..88f9d7a1 100644 --- a/src/term/cell.rs +++ b/src/term/cell.rs @@ -14,7 +14,7 @@ use bitflags::bitflags; use crate::ansi::{NamedColor, Color}; -use crate::grid; +use crate::grid::{self, GridCell}; use crate::index::Column; // Maximum number of zerowidth characters which will be stored per cell. @@ -62,6 +62,32 @@ impl Default for Cell { } +impl GridCell for Cell { + #[inline] + fn is_empty(&self) -> bool { + (self.c == ' ' || self.c == '\t') + && self.extra[0] == ' ' + && self.bg == Color::Named(NamedColor::Background) + && !self + .flags + .intersects(Flags::INVERSE | Flags::UNDERLINE | Flags::STRIKEOUT | Flags::WRAPLINE) + } + + #[inline] + fn is_wrap(&self) -> bool { + self.flags.contains(Flags::WRAPLINE) + } + + #[inline] + fn set_wrap(&mut self, wrap: bool) { + if wrap { + self.flags.insert(Flags::WRAPLINE); + } else { + self.flags.remove(Flags::WRAPLINE); + } + } +} + /// Get the length of occupied cells in a line pub trait LineLength { /// Calculate the occupied line length @@ -114,14 +140,6 @@ impl Cell { } #[inline] - pub fn is_empty(&self) -> bool { - (self.c == ' ' || self.c == '\t') - && self.extra[0] == ' ' - && self.bg == Color::Named(NamedColor::Background) - && !self.flags.intersects(Flags::INVERSE | Flags::UNDERLINE | Flags::STRIKEOUT) - } - - #[inline] pub fn reset(&mut self, template: &Cell) { // memcpy template to self *self = *template; diff --git a/src/term/mod.rs b/src/term/mod.rs index f48ad699..f2c0b18b 100644 --- a/src/term/mod.rs +++ b/src/term/mod.rs @@ -23,7 +23,10 @@ use unicode_width::UnicodeWidthChar; use font::{self, Size}; use crate::ansi::{self, Color, NamedColor, Attr, Handler, CharsetIndex, StandardCharset, CursorStyle}; -use crate::grid::{BidirectionalIterator, Grid, Indexed, IndexRegion, DisplayIter, Scroll, ViewportPosition}; +use crate::grid::{ + BidirectionalIterator, DisplayIter, Grid, GridCell, IndexRegion, Indexed, Scroll, + ViewportPosition, +}; use crate::index::{self, Point, Column, Line, IndexRange, Contains, RangeInclusive, Linear}; use crate::selection::{self, Selection, Locations}; use crate::config::{Config, VisualBellAnimation}; @@ -1246,8 +1249,13 @@ impl Term { debug!("New num_cols is {} and num_lines is {}", num_cols, num_lines); // Resize grids to new size - self.grid.resize(num_lines, num_cols, &Cell::default()); - self.alt_grid.resize(num_lines, num_cols, &Cell::default()); + let alt_cursor_point = if self.mode.contains(TermMode::ALT_SCREEN) { + &mut self.cursor_save.point + } else { + &mut self.cursor_save_alt.point + }; + self.grid.resize(num_lines, num_cols, &mut self.cursor.point, &Cell::default()); + self.alt_grid.resize(num_lines, num_cols, alt_cursor_point, &Cell::default()); // Reset scrolling region to new size self.scroll_region = Line(0)..self.grid.num_lines(); |