aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2023-03-08 21:25:28 -0500
committerJesse Luehrs <doy@tozt.net>2023-03-09 00:15:22 -0500
commit939fd8bed87dd67de9d0e00ba151ef637ef1c16a (patch)
treec7253a2e7da5fff361850debfcd248ebc0bf2137
parente5bdee42da0cf6f74db46fca4bcc6c6a32c7a639 (diff)
downloadvt100-rust-939fd8bed87dd67de9d0e00ba151ef637ef1c16a.tar.gz
vt100-rust-939fd8bed87dd67de9d0e00ba151ef637ef1c16a.zip
simplify
-rw-r--r--src/cell.rs4
-rw-r--r--src/grid.rs15
-rw-r--r--src/parser.rs8
-rw-r--r--src/row.rs16
-rw-r--r--src/screen.rs50
-rw-r--r--src/term.rs78
6 files changed, 77 insertions, 94 deletions
diff --git a/src/cell.rs b/src/cell.rs
index baa99bb..240ddf9 100644
--- a/src/cell.rs
+++ b/src/cell.rs
@@ -118,13 +118,13 @@ impl Cell {
/// Returns the foreground color of the cell.
#[must_use]
- pub fn fgcolor(&self) -> crate::attrs::Color {
+ pub fn fgcolor(&self) -> crate::Color {
self.attrs.fgcolor
}
/// Returns the background color of the cell.
#[must_use]
- pub fn bgcolor(&self) -> crate::attrs::Color {
+ pub fn bgcolor(&self) -> crate::Color {
self.attrs.bgcolor
}
diff --git a/src/grid.rs b/src/grid.rs
index a6a41df..dee4e10 100644
--- a/src/grid.rs
+++ b/src/grid.rs
@@ -76,7 +76,7 @@ impl Grid {
self.size = size;
for row in &mut self.rows {
- row.resize(size.cols, crate::cell::Cell::default());
+ row.resize(size.cols, crate::Cell::default());
}
self.rows.resize(usize::from(size.rows), self.new_row());
@@ -156,18 +156,15 @@ impl Grid {
.unwrap()
}
- pub fn visible_cell(&self, pos: Pos) -> Option<&crate::cell::Cell> {
+ pub fn visible_cell(&self, pos: Pos) -> Option<&crate::Cell> {
self.visible_row(pos.row).and_then(|r| r.get(pos.col))
}
- pub fn drawing_cell(&self, pos: Pos) -> Option<&crate::cell::Cell> {
+ pub fn drawing_cell(&self, pos: Pos) -> Option<&crate::Cell> {
self.drawing_row(pos.row).and_then(|r| r.get(pos.col))
}
- pub fn drawing_cell_mut(
- &mut self,
- pos: Pos,
- ) -> Option<&mut crate::cell::Cell> {
+ pub fn drawing_cell_mut(&mut self, pos: Pos) -> Option<&mut crate::Cell> {
self.drawing_row_mut(pos.row)
.and_then(|r| r.get_mut(pos.col))
}
@@ -499,7 +496,7 @@ impl Grid {
if wide {
row.get_mut(pos.col).unwrap().set_wide_continuation(false);
}
- row.insert(pos.col, crate::cell::Cell::default());
+ row.insert(pos.col, crate::Cell::default());
if wide {
row.get_mut(pos.col).unwrap().set_wide_continuation(true);
}
@@ -514,7 +511,7 @@ impl Grid {
for _ in 0..(count.min(size.cols - pos.col)) {
row.remove(pos.col);
}
- row.resize(size.cols, crate::cell::Cell::default());
+ row.resize(size.cols, crate::Cell::default());
}
pub fn erase_cells(&mut self, count: u16, attrs: crate::attrs::Attrs) {
diff --git a/src/parser.rs b/src/parser.rs
index 673e0d9..01ba019 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -2,7 +2,7 @@
/// the terminal contents.
pub struct Parser {
parser: vte::Parser,
- screen: crate::screen::Screen,
+ screen: crate::Screen,
}
impl Parser {
@@ -12,7 +12,7 @@ impl Parser {
pub fn new(rows: u16, cols: u16, scrollback_len: usize) -> Self {
Self {
parser: vte::Parser::new(),
- screen: crate::screen::Screen::new(
+ screen: crate::Screen::new(
crate::grid::Size { rows, cols },
scrollback_len,
),
@@ -30,14 +30,14 @@ impl Parser {
/// Returns a reference to a `Screen` object containing the terminal
/// state.
#[must_use]
- pub fn screen(&self) -> &crate::screen::Screen {
+ pub fn screen(&self) -> &crate::Screen {
&self.screen
}
/// Returns a mutable reference to a `Screen` object containing the
/// terminal state.
#[must_use]
- pub fn screen_mut(&mut self) -> &mut crate::screen::Screen {
+ pub fn screen_mut(&mut self) -> &mut crate::Screen {
&mut self.screen
}
}
diff --git a/src/row.rs b/src/row.rs
index 6ef0a80..def12f6 100644
--- a/src/row.rs
+++ b/src/row.rs
@@ -2,14 +2,14 @@ use crate::term::BufWrite as _;
#[derive(Clone, Debug)]
pub struct Row {
- cells: Vec<crate::cell::Cell>,
+ cells: Vec<crate::Cell>,
wrapped: bool,
}
impl Row {
pub fn new(cols: u16) -> Self {
Self {
- cells: vec![crate::cell::Cell::default(); usize::from(cols)],
+ cells: vec![crate::Cell::default(); usize::from(cols)],
wrapped: false,
}
}
@@ -29,19 +29,19 @@ impl Row {
self.wrapped = false;
}
- fn cells(&self) -> impl Iterator<Item = &crate::cell::Cell> {
+ fn cells(&self) -> impl Iterator<Item = &crate::Cell> {
self.cells.iter()
}
- pub fn get(&self, col: u16) -> Option<&crate::cell::Cell> {
+ pub fn get(&self, col: u16) -> Option<&crate::Cell> {
self.cells.get(usize::from(col))
}
- pub fn get_mut(&mut self, col: u16) -> Option<&mut crate::cell::Cell> {
+ pub fn get_mut(&mut self, col: u16) -> Option<&mut crate::Cell> {
self.cells.get_mut(usize::from(col))
}
- pub fn insert(&mut self, i: u16, cell: crate::cell::Cell) {
+ pub fn insert(&mut self, i: u16, cell: crate::Cell) {
self.cells.insert(usize::from(i), cell);
self.wrapped = false;
}
@@ -70,7 +70,7 @@ impl Row {
}
}
- pub fn resize(&mut self, len: u16, cell: crate::cell::Cell) {
+ pub fn resize(&mut self, len: u16, cell: crate::Cell) {
self.cells.resize(usize::from(len), cell);
self.wrapped = false;
}
@@ -145,7 +145,7 @@ impl Row {
prev_attrs: Option<crate::attrs::Attrs>,
) -> (crate::grid::Pos, crate::attrs::Attrs) {
let mut prev_was_wide = false;
- let default_cell = crate::cell::Cell::default();
+ let default_cell = crate::Cell::default();
let mut prev_pos = prev_pos.unwrap_or_else(|| {
if wrapping {
diff --git a/src/screen.rs b/src/screen.rs
index cc89c20..fe4e5cc 100644
--- a/src/screen.rs
+++ b/src/screen.rs
@@ -608,7 +608,7 @@ impl Screen {
/// Returns the `Cell` object at the given location in the terminal, if it
/// exists.
#[must_use]
- pub fn cell(&self, row: u16, col: u16) -> Option<&crate::cell::Cell> {
+ pub fn cell(&self, row: u16, col: u16) -> Option<&crate::Cell> {
self.grid().visible_cell(crate::grid::Pos { row, col })
}
@@ -712,13 +712,13 @@ impl Screen {
/// Returns the currently active foreground color.
#[must_use]
- pub fn fgcolor(&self) -> crate::attrs::Color {
+ pub fn fgcolor(&self) -> crate::Color {
self.attrs.fgcolor
}
/// Returns the currently active background color.
#[must_use]
- pub fn bgcolor(&self) -> crate::attrs::Color {
+ pub fn bgcolor(&self) -> crate::Color {
self.attrs.bgcolor
}
@@ -1418,30 +1418,25 @@ impl Screen {
&[24] => self.attrs.set_underline(false),
&[27] => self.attrs.set_inverse(false),
&[n] if (30..=37).contains(&n) => {
- self.attrs.fgcolor =
- crate::attrs::Color::Idx(to_u8!(n) - 30);
+ self.attrs.fgcolor = crate::Color::Idx(to_u8!(n) - 30);
}
&[38, 2, r, g, b] => {
- self.attrs.fgcolor = crate::attrs::Color::Rgb(
- to_u8!(r),
- to_u8!(g),
- to_u8!(b),
- );
+ self.attrs.fgcolor =
+ crate::Color::Rgb(to_u8!(r), to_u8!(g), to_u8!(b));
}
&[38, 5, i] => {
- self.attrs.fgcolor = crate::attrs::Color::Idx(to_u8!(i));
+ self.attrs.fgcolor = crate::Color::Idx(to_u8!(i));
}
&[38] => match next_param!() {
&[2] => {
let r = next_param_u8!();
let g = next_param_u8!();
let b = next_param_u8!();
- self.attrs.fgcolor =
- crate::attrs::Color::Rgb(r, g, b);
+ self.attrs.fgcolor = crate::Color::Rgb(r, g, b);
}
&[5] => {
self.attrs.fgcolor =
- crate::attrs::Color::Idx(next_param_u8!());
+ crate::Color::Idx(next_param_u8!());
}
ns => {
if log::log_enabled!(log::Level::Debug) {
@@ -1461,33 +1456,28 @@ impl Screen {
}
},
&[39] => {
- self.attrs.fgcolor = crate::attrs::Color::Default;
+ self.attrs.fgcolor = crate::Color::Default;
}
&[n] if (40..=47).contains(&n) => {
- self.attrs.bgcolor =
- crate::attrs::Color::Idx(to_u8!(n) - 40);
+ self.attrs.bgcolor = crate::Color::Idx(to_u8!(n) - 40);
}
&[48, 2, r, g, b] => {
- self.attrs.bgcolor = crate::attrs::Color::Rgb(
- to_u8!(r),
- to_u8!(g),
- to_u8!(b),
- );
+ self.attrs.bgcolor =
+ crate::Color::Rgb(to_u8!(r), to_u8!(g), to_u8!(b));
}
&[48, 5, i] => {
- self.attrs.bgcolor = crate::attrs::Color::Idx(to_u8!(i));
+ self.attrs.bgcolor = crate::Color::Idx(to_u8!(i));
}
&[48] => match next_param!() {
&[2] => {
let r = next_param_u8!();
let g = next_param_u8!();
let b = next_param_u8!();
- self.attrs.bgcolor =
- crate::attrs::Color::Rgb(r, g, b);
+ self.attrs.bgcolor = crate::Color::Rgb(r, g, b);
}
&[5] => {
self.attrs.bgcolor =
- crate::attrs::Color::Idx(next_param_u8!());
+ crate::Color::Idx(next_param_u8!());
}
ns => {
if log::log_enabled!(log::Level::Debug) {
@@ -1507,15 +1497,13 @@ impl Screen {
}
},
&[49] => {
- self.attrs.bgcolor = crate::attrs::Color::Default;
+ self.attrs.bgcolor = crate::Color::Default;
}
&[n] if (90..=97).contains(&n) => {
- self.attrs.fgcolor =
- crate::attrs::Color::Idx(to_u8!(n) - 82);
+ self.attrs.fgcolor = crate::Color::Idx(to_u8!(n) - 82);
}
&[n] if (100..=107).contains(&n) => {
- self.attrs.bgcolor =
- crate::attrs::Color::Idx(to_u8!(n) - 92);
+ self.attrs.bgcolor = crate::Color::Idx(to_u8!(n) - 92);
}
ns => {
if log::log_enabled!(log::Level::Debug) {
diff --git a/src/term.rs b/src/term.rs
index ef44e46..ffa3ecb 100644
--- a/src/term.rs
+++ b/src/term.rs
@@ -107,8 +107,8 @@ impl BufWrite for ClearAttrs {
#[derive(Default, Debug)]
#[must_use = "this struct does nothing unless you call write_buf"]
pub struct Attrs {
- fgcolor: Option<crate::attrs::Color>,
- bgcolor: Option<crate::attrs::Color>,
+ fgcolor: Option<crate::Color>,
+ bgcolor: Option<crate::Color>,
bold: Option<bool>,
italic: Option<bool>,
underline: Option<bool>,
@@ -116,12 +116,12 @@ pub struct Attrs {
}
impl Attrs {
- pub fn fgcolor(mut self, fgcolor: crate::attrs::Color) -> Self {
+ pub fn fgcolor(mut self, fgcolor: crate::Color) -> Self {
self.fgcolor = Some(fgcolor);
self
}
- pub fn bgcolor(mut self, bgcolor: crate::attrs::Color) -> Self {
+ pub fn bgcolor(mut self, bgcolor: crate::Color) -> Self {
self.bgcolor = Some(bgcolor);
self
}
@@ -177,10 +177,10 @@ impl BufWrite for Attrs {
if let Some(fgcolor) = self.fgcolor {
match fgcolor {
- crate::attrs::Color::Default => {
+ crate::Color::Default => {
write_param!(39);
}
- crate::attrs::Color::Idx(i) => {
+ crate::Color::Idx(i) => {
if i < 8 {
write_param!(i + 30);
} else if i < 16 {
@@ -191,7 +191,7 @@ impl BufWrite for Attrs {
write_param!(i);
}
}
- crate::attrs::Color::Rgb(r, g, b) => {
+ crate::Color::Rgb(r, g, b) => {
write_param!(38);
write_param!(2);
write_param!(r);
@@ -203,10 +203,10 @@ impl BufWrite for Attrs {
if let Some(bgcolor) = self.bgcolor {
match bgcolor {
- crate::attrs::Color::Default => {
+ crate::Color::Default => {
write_param!(49);
}
- crate::attrs::Color::Idx(i) => {
+ crate::Color::Idx(i) => {
if i < 8 {
write_param!(i + 40);
} else if i < 16 {
@@ -217,7 +217,7 @@ impl BufWrite for Attrs {
write_param!(i);
}
}
- crate::attrs::Color::Rgb(r, g, b) => {
+ crate::Color::Rgb(r, g, b) => {
write_param!(48);
write_param!(2);
write_param!(r);
@@ -513,14 +513,14 @@ impl BufWrite for BracketedPaste {
#[derive(Default, Debug)]
#[must_use = "this struct does nothing unless you call write_buf"]
pub struct MouseProtocolMode {
- mode: crate::screen::MouseProtocolMode,
- prev: crate::screen::MouseProtocolMode,
+ mode: crate::MouseProtocolMode,
+ prev: crate::MouseProtocolMode,
}
impl MouseProtocolMode {
pub fn new(
- mode: crate::screen::MouseProtocolMode,
- prev: crate::screen::MouseProtocolMode,
+ mode: crate::MouseProtocolMode,
+ prev: crate::MouseProtocolMode,
) -> Self {
Self { mode, prev }
}
@@ -533,31 +533,31 @@ impl BufWrite for MouseProtocolMode {
}
match self.mode {
- crate::screen::MouseProtocolMode::None => match self.prev {
- crate::screen::MouseProtocolMode::None => {}
- crate::screen::MouseProtocolMode::Press => {
+ crate::MouseProtocolMode::None => match self.prev {
+ crate::MouseProtocolMode::None => {}
+ crate::MouseProtocolMode::Press => {
buf.extend_from_slice(b"\x1b[?9l");
}
- crate::screen::MouseProtocolMode::PressRelease => {
+ crate::MouseProtocolMode::PressRelease => {
buf.extend_from_slice(b"\x1b[?1000l");
}
- crate::screen::MouseProtocolMode::ButtonMotion => {
+ crate::MouseProtocolMode::ButtonMotion => {
buf.extend_from_slice(b"\x1b[?1002l");
}
- crate::screen::MouseProtocolMode::AnyMotion => {
+ crate::MouseProtocolMode::AnyMotion => {
buf.extend_from_slice(b"\x1b[?1003l");
}
},
- crate::screen::MouseProtocolMode::Press => {
+ crate::MouseProtocolMode::Press => {
buf.extend_from_slice(b"\x1b[?9h");
}
- crate::screen::MouseProtocolMode::PressRelease => {
+ crate::MouseProtocolMode::PressRelease => {
buf.extend_from_slice(b"\x1b[?1000h");
}
- crate::screen::MouseProtocolMode::ButtonMotion => {
+ crate::MouseProtocolMode::ButtonMotion => {
buf.extend_from_slice(b"\x1b[?1002h");
}
- crate::screen::MouseProtocolMode::AnyMotion => {
+ crate::MouseProtocolMode::AnyMotion => {
buf.extend_from_slice(b"\x1b[?1003h");
}
}
@@ -567,14 +567,14 @@ impl BufWrite for MouseProtocolMode {
#[derive(Default, Debug)]
#[must_use = "this struct does nothing unless you call write_buf"]
pub struct MouseProtocolEncoding {
- encoding: crate::screen::MouseProtocolEncoding,
- prev: crate::screen::MouseProtocolEncoding,
+ encoding: crate::MouseProtocolEncoding,
+ prev: crate::MouseProtocolEncoding,
}
impl MouseProtocolEncoding {
pub fn new(
- encoding: crate::screen::MouseProtocolEncoding,
- prev: crate::screen::MouseProtocolEncoding,
+ encoding: crate::MouseProtocolEncoding,
+ prev: crate::MouseProtocolEncoding,
) -> Self {
Self { encoding, prev }
}
@@ -587,21 +587,19 @@ impl BufWrite for MouseProtocolEncoding {
}
match self.encoding {
- crate::screen::MouseProtocolEncoding::Default => {
- match self.prev {
- crate::screen::MouseProtocolEncoding::Default => {}
- crate::screen::MouseProtocolEncoding::Utf8 => {
- buf.extend_from_slice(b"\x1b[?1005l");
- }
- crate::screen::MouseProtocolEncoding::Sgr => {
- buf.extend_from_slice(b"\x1b[?1006l");
- }
+ crate::MouseProtocolEncoding::Default => match self.prev {
+ crate::MouseProtocolEncoding::Default => {}
+ crate::MouseProtocolEncoding::Utf8 => {
+ buf.extend_from_slice(b"\x1b[?1005l");
}
- }
- crate::screen::MouseProtocolEncoding::Utf8 => {
+ crate::MouseProtocolEncoding::Sgr => {
+ buf.extend_from_slice(b"\x1b[?1006l");
+ }
+ },
+ crate::MouseProtocolEncoding::Utf8 => {
buf.extend_from_slice(b"\x1b[?1005h");
}
- crate::screen::MouseProtocolEncoding::Sgr => {
+ crate::MouseProtocolEncoding::Sgr => {
buf.extend_from_slice(b"\x1b[?1006h");
}
}