summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Oram <dev@mitmaro.ca>2021-06-23 09:31:02 -0230
committerTim Oram <dev@mitmaro.ca>2021-07-05 16:27:53 -0230
commite24e3decdc61f797d8abc2eaf49cfbd6007a599c (patch)
tree1555da39023c5362744cca8137fc0129c3f3de38
parentc5eb66674c38d7ede92a52132d5f9fc314e35f21 (diff)
Inline module create functions
-rw-r--r--src/display/src/crossterm.rs15
-rw-r--r--src/display/src/lib.rs45
-rw-r--r--src/display/src/mockcrossterm.rs24
-rw-r--r--src/display/src/size.rs3
-rw-r--r--src/display/src/testutil.rs1
5 files changed, 72 insertions, 16 deletions
diff --git a/src/display/src/crossterm.rs b/src/display/src/crossterm.rs
index b0a3c82..3ddc4bc 100644
--- a/src/display/src/crossterm.rs
+++ b/src/display/src/crossterm.rs
@@ -33,10 +33,12 @@ pub struct CrossTerm {
}
impl Tui for CrossTerm {
+ #[inline]
fn get_color_mode(&self) -> ColorMode {
self.color_mode
}
+ #[inline]
fn reset(&mut self) -> Result<()> {
self.queue_command(ResetColor)?;
self.queue_command(SetAttribute(Attribute::Reset))?;
@@ -44,20 +46,24 @@ impl Tui for CrossTerm {
self.queue_command(MoveTo(0, 0))
}
+ #[inline]
fn flush(&mut self) -> Result<()> {
self.window
.flush()
.map_err(|err| anyhow!("{:#}", err).context("Unexpected Error"))
}
+ #[inline]
fn print(&mut self, s: &str) -> Result<()> {
self.queue_command(Print(s))
}
+ #[inline]
fn set_color(&mut self, colors: Colors) -> Result<()> {
self.queue_command(SetColors(colors))
}
+ #[inline]
fn set_dim(&mut self, dim: bool) -> Result<()> {
self.queue_command(SetAttribute(
if dim {
@@ -69,6 +75,7 @@ impl Tui for CrossTerm {
))
}
+ #[inline]
fn set_underline(&mut self, underline: bool) -> Result<()> {
self.queue_command(SetAttribute(
if underline {
@@ -80,6 +87,7 @@ impl Tui for CrossTerm {
))
}
+ #[inline]
fn set_reverse(&mut self, reverse: bool) -> Result<()> {
self.queue_command(SetAttribute(
if reverse {
@@ -91,6 +99,7 @@ impl Tui for CrossTerm {
))
}
+ #[inline]
fn read_event() -> Result<Option<Event>> {
if poll(Duration::from_millis(20)).unwrap_or(false) {
read().map(Some).map_err(Self::map_err)
@@ -100,6 +109,7 @@ impl Tui for CrossTerm {
}
}
+ #[inline]
fn get_size(&self) -> Size {
size().map_or_else(
|_| Size::new(0, 0),
@@ -107,14 +117,17 @@ impl Tui for CrossTerm {
)
}
+ #[inline]
fn move_to_column(&mut self, x: u16) -> Result<()> {
self.queue_command(MoveToColumn(x))
}
+ #[inline]
fn move_next_line(&mut self) -> Result<()> {
self.queue_command(MoveToNextLine(1))
}
+ #[inline]
fn start(&mut self) -> Result<()> {
self.queue_command(EnterAlternateScreen)?;
self.queue_command(DisableLineWrap)?;
@@ -124,6 +137,7 @@ impl Tui for CrossTerm {
self.flush()
}
+ #[inline]
fn end(&mut self) -> Result<()> {
self.queue_command(DisableMouseCapture)?;
self.queue_command(Show)?;
@@ -135,6 +149,7 @@ impl Tui for CrossTerm {
}
impl CrossTerm {
+ #[inline]
#[must_use]
pub fn new() -> Self {
Self {
diff --git a/src/display/src/lib.rs b/src/display/src/lib.rs
index e3fd0ff..f2bf203 100644
--- a/src/display/src/lib.rs
+++ b/src/display/src/lib.rs
@@ -47,7 +47,11 @@
)]
// enable all of Clippy's lints
#![deny(clippy::all, clippy::cargo, clippy::nursery, clippy::pedantic, clippy::restriction)]
-#![allow(clippy::blanket_clippy_restriction_lints)]
+#![allow(
+ clippy::blanket_clippy_restriction_lints,
+ clippy::implicit_return,
+ clippy::missing_docs_in_private_items,
+)]
#![deny(
rustdoc::bare_urls,
rustdoc::broken_intra_doc_links,
@@ -65,12 +69,9 @@
clippy::cast_possible_truncation,
clippy::default_numeric_fallback,
clippy::else_if_without_else,
- clippy::implicit_return,
clippy::integer_arithmetic,
clippy::integer_division,
- clippy::missing_docs_in_private_items,
clippy::missing_errors_doc,
- clippy::missing_inline_in_public_items,
clippy::missing_panics_doc,
clippy::new_without_default,
clippy::too_many_lines,
@@ -117,6 +118,7 @@ pub struct Display<T: Tui> {
}
impl<T: Tui> Display<T> {
+ #[inline]
pub fn new(tui: T, theme: &Theme) -> Self {
let color_mode = tui.get_color_mode();
let normal = register_selectable_color_pairs(
@@ -251,20 +253,24 @@ impl<T: Tui> Display<T> {
}
}
+ #[inline]
pub fn draw_str(&mut self, s: &str) -> Result<()> {
self.tui.print(s)
}
+ #[inline]
pub fn clear(&mut self) -> Result<()> {
self.color(DisplayColor::Normal, false)?;
self.set_style(false, false, false)?;
self.tui.reset()
}
+ #[inline]
pub fn refresh(&mut self) -> Result<()> {
self.tui.flush()
}
+ #[inline]
pub fn color(&mut self, color: DisplayColor, selected: bool) -> Result<()> {
self.tui.set_color(
if selected {
@@ -314,50 +320,57 @@ impl<T: Tui> Display<T> {
)
}
+ #[inline]
pub fn set_style(&mut self, dim: bool, underline: bool, reverse: bool) -> Result<()> {
self.set_dim(dim)?;
self.set_underline(underline)?;
self.set_reverse(reverse)
}
- fn set_dim(&mut self, on: bool) -> Result<()> {
- self.tui.set_dim(on)
- }
-
- fn set_underline(&mut self, on: bool) -> Result<()> {
- self.tui.set_underline(on)
- }
-
- fn set_reverse(&mut self, on: bool) -> Result<()> {
- self.tui.set_reverse(on)
- }
-
+ #[inline]
pub fn get_window_size(&self) -> Size {
self.tui.get_size()
}
+ #[inline]
pub fn ensure_at_line_start(&mut self) -> Result<()> {
self.tui.move_to_column(1)
}
+ #[inline]
pub fn move_from_end_of_line(&mut self, right: u16) -> Result<()> {
let width = self.get_window_size().width();
self.tui.move_to_column(width as u16 - right + 1)
}
+ #[inline]
pub fn next_line(&mut self) -> Result<()> {
self.tui.move_next_line()
}
+ #[inline]
pub fn start(&mut self) -> Result<()> {
self.tui.start()?;
self.tui.flush()
}
+ #[inline]
pub fn end(&mut self) -> Result<()> {
self.tui.end()?;
self.tui.flush()
}
+
+ fn set_dim(&mut self, on: bool) -> Result<()> {
+ self.tui.set_dim(on)
+ }
+
+ fn set_underline(&mut self, on: bool) -> Result<()> {
+ self.tui.set_underline(on)
+ }
+
+ fn set_reverse(&mut self, on: bool) -> Result<()> {
+ self.tui.set_reverse(on)
+ }
}
#[cfg(test)]
diff --git a/src/display/src/mockcrossterm.rs b/src/display/src/mockcrossterm.rs
index b898631..ab30a46 100644
--- a/src/display/src/mockcrossterm.rs
+++ b/src/display/src/mockcrossterm.rs
@@ -26,10 +26,12 @@ pub struct CrossTerm {
}
impl Tui for CrossTerm {
+ #[inline]
fn get_color_mode(&self) -> ColorMode {
self.color_mode
}
+ #[inline]
fn reset(&mut self) -> Result<()> {
self.attributes = Attributes::from(Attribute::Reset);
self.colors = Colors::new(Color::Reset, Color::Reset);
@@ -38,21 +40,25 @@ impl Tui for CrossTerm {
Ok(())
}
+ #[inline]
fn flush(&mut self) -> Result<()> {
self.dirty = false;
Ok(())
}
+ #[inline]
fn print(&mut self, s: &str) -> Result<()> {
self.output.push(String::from(s));
Ok(())
}
+ #[inline]
fn set_color(&mut self, colors: Colors) -> Result<()> {
self.colors = colors;
Ok(())
}
+ #[inline]
fn set_dim(&mut self, dim: bool) -> Result<()> {
if dim {
self.attributes.set(Attribute::Dim);
@@ -63,6 +69,7 @@ impl Tui for CrossTerm {
Ok(())
}
+ #[inline]
fn set_underline(&mut self, dim: bool) -> Result<()> {
if dim {
self.attributes.set(Attribute::Underlined);
@@ -73,6 +80,7 @@ impl Tui for CrossTerm {
Ok(())
}
+ #[inline]
fn set_reverse(&mut self, dim: bool) -> Result<()> {
if dim {
self.attributes.set(Attribute::Reverse);
@@ -83,19 +91,23 @@ impl Tui for CrossTerm {
Ok(())
}
+ #[inline]
fn read_event() -> Result<Option<Event>> {
Ok(None)
}
+ #[inline]
fn get_size(&self) -> Size {
self.size
}
+ #[inline]
fn move_to_column(&mut self, x: u16) -> Result<()> {
self.position.0 = x;
Ok(())
}
+ #[inline]
fn move_next_line(&mut self) -> Result<()> {
self.output.push(String::from("\n"));
self.position.0 = 0;
@@ -103,11 +115,13 @@ impl Tui for CrossTerm {
Ok(())
}
+ #[inline]
fn start(&mut self) -> Result<()> {
self.state = State::Normal;
Ok(())
}
+ #[inline]
fn end(&mut self) -> Result<()> {
self.state = State::Ended;
Ok(())
@@ -115,6 +129,7 @@ impl Tui for CrossTerm {
}
impl CrossTerm {
+ #[inline]
#[must_use]
pub fn new() -> Self {
Self {
@@ -129,45 +144,54 @@ impl CrossTerm {
}
}
+ #[inline]
#[must_use]
pub const fn get_output(&self) -> &Vec<String> {
&self.output
}
+ #[inline]
#[must_use]
pub const fn get_state(&self) -> State {
self.state
}
+ #[inline]
#[must_use]
pub fn is_colors_enabled(&self, colors: Colors) -> bool {
self.colors == colors
}
+ #[inline]
#[must_use]
pub fn is_dimmed(&self) -> bool {
self.attributes.has(Attribute::Dim)
}
+ #[inline]
#[must_use]
pub fn is_reverse(&self) -> bool {
self.attributes.has(Attribute::Reverse)
}
+ #[inline]
#[must_use]
pub fn is_underline(&self) -> bool {
self.attributes.has(Attribute::Underlined)
}
+ #[inline]
pub fn set_size(&mut self, size: Size) {
self.size = size;
}
+ #[inline]
#[must_use]
pub const fn get_position(&self) -> (u16, u16) {
self.position
}
+ #[inline]
#[must_use]
pub const fn is_dirty(&self) -> bool {
self.dirty
diff --git a/src/display/src/size.rs b/src/display/src/size.rs
index 5821433..f20d054 100644
--- a/src/display/src/size.rs
+++ b/src/display/src/size.rs
@@ -5,16 +5,19 @@ pub struct Size {
}
impl Size {
+ #[inline]
#[must_use]
pub const fn new(width: usize, height: usize) -> Self {
Self { width, height }
}
+ #[inline]
#[must_use]
pub const fn width(&self) -> usize {
self.width
}
+ #[inline]
#[must_use]
pub const fn height(&self) -> usize {
self.height
diff --git a/src/display/src/testutil.rs b/src/display/src/testutil.rs
index d972cae..8b2a926 100644
--- a/src/display/src/testutil.rs
+++ b/src/display/src/testutil.rs
@@ -1,6 +1,7 @@
pub use super::mockcrossterm::CrossTerm;
use super::*;
+#[inline]
pub fn assert_output(display: &Display<CrossTerm>, expected: &[&str]) {
assert_eq!(display.tui.get_output().join(""), format!("{}\n", expected.join("\n")));
}