aboutsummaryrefslogtreecommitdiff
path: root/src/term.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/term.rs')
-rw-r--r--src/term.rs84
1 files changed, 31 insertions, 53 deletions
diff --git a/src/term.rs b/src/term.rs
index 898251d7..a2b6aa3c 100644
--- a/src/term.rs
+++ b/src/term.rs
@@ -21,9 +21,7 @@ use ansi::{self, Attr, Handler};
use grid::{Grid, ClearRegion};
use index::{Cursor, Column, Line};
use tty;
-use config::Config;
-
-use ::Rgb;
+use ansi::Color;
/// RAII type which manages grid state for render
///
@@ -90,20 +88,26 @@ pub mod cell {
}
}
- #[derive(Clone, Debug, Copy)]
+ #[derive(Debug, Clone, PartialEq, Eq)]
+ pub enum Color {
+ Rgb(Rgb),
+ Ansi(::ansi::Color),
+ }
+
+ #[derive(Clone, Debug)]
pub struct Cell {
pub c: char,
- pub fg: Rgb,
- pub bg: Rgb,
+ pub fg: Color,
+ pub bg: Color,
pub flags: Flags,
}
impl Cell {
- pub fn new(c: char) -> Cell {
+ pub fn new(c: char, fg: Color, bg: Color) -> Cell {
Cell {
c: c.into(),
- bg: Default::default(),
- fg: Default::default(),
+ bg: bg,
+ fg: fg,
flags: Flags::empty(),
}
}
@@ -111,13 +115,7 @@ pub mod cell {
#[inline]
pub fn reset(&mut self, template: &Cell) {
// memcpy template to self
- unsafe {
- ::std::ptr::copy_nonoverlapping(
- template as *const Cell,
- self as *mut Cell,
- 1
- );
- }
+ *self = template.clone();
}
}
}
@@ -165,12 +163,6 @@ pub struct Term {
/// Alt cursor
alt_cursor: Cursor,
- /// Active foreground color
- pub fg: Rgb,
-
- /// Active background color
- pub bg: Rgb,
-
/// Tabstops
tabs: Vec<bool>,
@@ -189,9 +181,6 @@ pub struct Term {
/// Empty cell
empty_cell: Cell,
- /// Text colors
- colors: [Rgb; 16],
-
pub dirty: bool,
}
@@ -225,7 +214,6 @@ impl SizeInfo {
impl Term {
pub fn new(
- config: &Config,
width: f32,
height: f32,
cell_width: f32,
@@ -238,20 +226,18 @@ impl Term {
cell_height: cell_height as f32,
};
- let mut template = Cell::new(' ');
- template.flags = cell::Flags::empty();
- template.bg = config.bg_color();
- template.fg = config.fg_color();
+ let template = Cell::new(
+ ' ',
+ cell::Color::Ansi(Color::Foreground),
+ cell::Color::Ansi(Color::Background)
+ );
let num_cols = size.cols();
let num_lines = size.lines();
println!("num_cols, num_lines = {}, {}", num_cols, num_lines);
- println!("bg: {:?}, fg: {:?}", template.bg, template.fg);
- println!("colors: {:?}", config.color_list());
-
- let grid = Grid::new(num_lines, num_cols, &Cell::new(' '));
+ let grid = Grid::new(num_lines, num_cols, &template);
let tty = tty::new(*num_lines as u8, *num_cols as u8);
tty.resize(*num_lines as usize, *num_cols as usize, size.width as usize, size.height as usize);
@@ -272,16 +258,13 @@ impl Term {
alt: false,
cursor: Cursor::default(),
alt_cursor: Cursor::default(),
- fg: config.fg_color(),
- bg: config.bg_color(),
tty: tty,
tabs: tabs,
mode: Default::default(),
scroll_region: scroll_region,
size_info: size,
- template_cell: template,
+ template_cell: template.clone(),
empty_cell: template,
- colors: config.color_list(),
}
}
@@ -323,8 +306,9 @@ impl Term {
println!("num_cols, num_lines = {}, {}", num_cols, num_lines);
// Resize grids to new size
- self.grid.resize(num_lines, num_cols, &Cell::new(' '));
- self.alt_grid.resize(num_lines, num_cols, &Cell::new(' '));
+ let template = self.template_cell.clone();
+ self.grid.resize(num_lines, num_cols, &template);
+ self.alt_grid.resize(num_lines, num_cols, &template);
// Ensure cursor is in-bounds
self.cursor.line = limit(self.cursor.line, Line(0), num_lines);
@@ -462,7 +446,7 @@ impl ansi::Handler for Term {
}
let cell = &mut self.grid[&self.cursor];
- *cell = self.template_cell;
+ *cell = self.template_cell.clone();
cell.c = c;
self.cursor.col += 1;
}
@@ -779,27 +763,21 @@ impl ansi::Handler for Term {
fn terminal_attribute(&mut self, attr: Attr) {
debug_println!("Set Attribute: {:?}", attr);
match attr {
- Attr::DefaultForeground => {
- self.template_cell.fg = self.fg;
- },
- Attr::DefaultBackground => {
- self.template_cell.bg = self.bg;
- },
Attr::Foreground(named_color) => {
- self.template_cell.fg = self.colors[named_color as usize];
+ self.template_cell.fg = cell::Color::Ansi(named_color);
},
Attr::Background(named_color) => {
- self.template_cell.bg = self.colors[named_color as usize];
+ self.template_cell.bg = cell::Color::Ansi(named_color);
},
Attr::ForegroundSpec(rgb) => {
- self.template_cell.fg = rgb;
+ self.template_cell.fg = cell::Color::Rgb(rgb);
},
Attr::BackgroundSpec(rgb) => {
- self.template_cell.bg = rgb;
+ self.template_cell.bg = cell::Color::Rgb(rgb);
},
Attr::Reset => {
- self.template_cell.fg = self.fg;
- self.template_cell.bg = self.bg;
+ self.template_cell.fg = cell::Color::Ansi(Color::Foreground);
+ self.template_cell.bg = cell::Color::Ansi(Color::Background);
self.template_cell.flags = cell::Flags::empty();
},
Attr::Reverse => self.template_cell.flags.insert(cell::INVERSE),