Make ansi::TermInfo strongly typed
The rows function has been renamed to lines, and it now returns `Line`. The cols function correspondingly returns `Column`.
This commit is contained in:
parent
6639e6f24f
commit
8a4f14188e
24
src/ansi.rs
24
src/ansi.rs
|
@ -30,6 +30,7 @@
|
||||||
//! aren't necessary for everyday terminal usage. If you feel like something that's not supported
|
//! aren't necessary for everyday terminal usage. If you feel like something that's not supported
|
||||||
//! should be, feel free to add it. Please try not to become overzealous and adding support for
|
//! should be, feel free to add it. Please try not to become overzealous and adding support for
|
||||||
//! sequences only used by folks trapped in 1988.
|
//! sequences only used by folks trapped in 1988.
|
||||||
|
use index::{Column, Line};
|
||||||
|
|
||||||
use ::Rgb;
|
use ::Rgb;
|
||||||
|
|
||||||
|
@ -41,8 +42,8 @@ pub enum Escape {
|
||||||
|
|
||||||
/// Trait that provides properties of terminal
|
/// Trait that provides properties of terminal
|
||||||
pub trait TermInfo {
|
pub trait TermInfo {
|
||||||
fn rows(&self) -> usize;
|
fn lines(&self) -> Line;
|
||||||
fn cols(&self) -> usize;
|
fn cols(&self) -> Column;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const CSI_ATTR_MAX: usize = 16;
|
pub const CSI_ATTR_MAX: usize = 16;
|
||||||
|
@ -399,12 +400,12 @@ impl Handler for DebugHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TermInfo for DebugHandler {
|
impl TermInfo for DebugHandler {
|
||||||
fn rows(&self) -> usize {
|
fn lines(&self) -> Line {
|
||||||
24
|
Line(24)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cols(&self) -> usize {
|
fn cols(&self) -> Column {
|
||||||
80
|
Column(80)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -746,7 +747,7 @@ impl Parser {
|
||||||
unknown!();
|
unknown!();
|
||||||
}
|
}
|
||||||
let top = arg_or_default!(args[0], 1);
|
let top = arg_or_default!(args[0], 1);
|
||||||
let bottom = arg_or_default!(args[1], handler.rows() as i64);
|
let bottom = arg_or_default!(args[1], *handler.lines() as i64);
|
||||||
|
|
||||||
handler.set_scrolling_region(top - 1, bottom - 1);
|
handler.set_scrolling_region(top - 1, bottom - 1);
|
||||||
},
|
},
|
||||||
|
@ -1104,6 +1105,7 @@ impl Default for State {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::io::{Cursor, Read};
|
use std::io::{Cursor, Read};
|
||||||
|
use index::{Line, Column};
|
||||||
use super::{Parser, Handler, Attr, DebugHandler, TermInfo};
|
use super::{Parser, Handler, Attr, DebugHandler, TermInfo};
|
||||||
use ::Rgb;
|
use ::Rgb;
|
||||||
|
|
||||||
|
@ -1119,12 +1121,12 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TermInfo for AttrHandler {
|
impl TermInfo for AttrHandler {
|
||||||
fn rows(&self) -> usize {
|
fn lines(&self) -> Line {
|
||||||
24
|
Line(24)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cols(&self) -> usize {
|
fn cols(&self) -> Column {
|
||||||
80
|
Column(80)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -395,13 +395,13 @@ impl fmt::Display for ScrollDirection {
|
||||||
|
|
||||||
impl ansi::TermInfo for Term {
|
impl ansi::TermInfo for Term {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn rows(&self) -> usize {
|
fn lines(&self) -> Line {
|
||||||
*self.grid.num_lines() as usize
|
self.grid.num_lines()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn cols(&self) -> usize {
|
fn cols(&self) -> Column {
|
||||||
*self.grid.num_cols() as usize
|
self.grid.num_cols()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue