summaryrefslogtreecommitdiffstats
path: root/src/term.rs
diff options
context:
space:
mode:
authorrabite <rabite@posteo.de>2019-01-21 14:44:34 +0100
committerrabite <rabite@posteo.de>2019-01-21 15:02:14 +0100
commit67c973c0af1d35f0f832d4eb594c12868ef78008 (patch)
treeefa11d04f19aec6bd269c931b0ce6a54e42a9371 /src/term.rs
First commit, did some refactoring around widgets, etc, etc
Diffstat (limited to 'src/term.rs')
-rw-r--r--src/term.rs84
1 files changed, 84 insertions, 0 deletions
diff --git a/src/term.rs b/src/term.rs
new file mode 100644
index 0000000..c559ad8
--- /dev/null
+++ b/src/term.rs
@@ -0,0 +1,84 @@
+use std::io::{Stdout, Write};
+use termion;
+use termion::screen::AlternateScreen;
+
+pub trait ScreenExt: Write {
+ fn cursor_hide(&mut self) {
+ write!(self, "{}", termion::cursor::Hide).unwrap();
+ }
+ fn cursor_show(&mut self) {
+ write!(self, "{}", termion::cursor::Show).unwrap();
+ }
+ fn reset(&mut self) {
+ write!(self, "{}", termion::style::Reset).unwrap();
+ }
+}
+
+impl ScreenExt for AlternateScreen<Box<Stdout>> {}
+
+pub fn xsize() -> usize {
+ let (xsize, _) = termion::terminal_size().unwrap();
+ xsize as usize
+}
+
+pub fn ysize() -> usize {
+ let (_, ysize) = termion::terminal_size().unwrap();
+ ysize as usize
+}
+
+pub fn highlight_color() -> String {
+ format!(
+ "{}{}",
+ termion::color::Fg(termion::color::LightGreen),
+ termion::color::Bg(termion::color::Black)
+ )
+}
+
+pub fn normal_color() -> String {
+ format!(
+ "{}{}",
+ termion::color::Fg(termion::color::LightBlue),
+ termion::color::Bg(termion::color::Black)
+ )
+}
+
+pub fn cursor_left(n: usize) -> String {
+ format!("{}", termion::cursor::Left(n as u16))
+}
+
+pub fn gotoy(y: usize) -> String {
+ format!("{}", termion::cursor::Goto(1, y as u16))
+}
+
+pub fn goto_xy(x: u16, y: u16) -> String {
+ format!("{}", termion::cursor::Goto(x, y))
+}
+
+// pub fn move_top() -> String {
+// gotoy(1)
+// }
+
+pub fn move_bottom() -> String {
+ gotoy(ysize())
+}
+
+pub fn reset() -> String {
+ format!("{}", termion::style::Reset)
+}
+
+pub fn invert() -> String {
+ format!("{}", termion::style::Invert)
+}
+
+pub fn header_color() -> String {
+ format!(
+ "{}{}",
+ termion::color::Fg(termion::color::White),
+ termion::color::Bg(termion::color::Blue)
+ )
+}
+
+pub fn status_bg() -> String {
+ format!("{}", termion::color::Bg(termion::color::LightBlue))
+}
+