summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorqkzk <qu3nt1n@gmail.com>2022-11-20 11:47:03 +0100
committerqkzk <qu3nt1n@gmail.com>2022-11-20 11:47:03 +0100
commit98e91dc2e58dd7534a4b2cde9f87875584095921 (patch)
tree53e9f001f45487a1b58d12b8290e2fc48a217fe3
parent07a6a66e04af2b7836849e11f1692ac4f14180a2 (diff)
separate display from event reader
-rw-r--r--src/lib.rs2
-rw-r--r--src/main.rs5
-rw-r--r--src/term_manager.rs (renamed from src/display.rs)35
3 files changed, 26 insertions, 16 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 90a07a8..49e60dc 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -7,7 +7,6 @@ pub mod compress;
pub mod config;
pub mod content_window;
pub mod copy_move;
-pub mod display;
pub mod event_char;
pub mod fileinfo;
pub mod filter;
@@ -25,4 +24,5 @@ pub mod shortcut;
pub mod skim;
pub mod status;
pub mod tab;
+pub mod term_manager;
pub mod visited;
diff --git a/src/main.rs b/src/main.rs
index da9b694..e249ee0 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -7,10 +7,10 @@ use tuikit::term::Term;
use fm::actioner::Actioner;
use fm::args::Args;
use fm::config::load_config;
-use fm::display::Display;
use fm::fm_error::FmResult;
use fm::log::set_logger;
use fm::status::Status;
+use fm::term_manager::{Display, EventReader};
static CONFIG_PATH: &str = "~/.config/fm/config.yaml";
@@ -31,10 +31,11 @@ fn main() -> FmResult<()> {
let config = load_config(CONFIG_PATH);
let term = Arc::new(init_term()?);
let actioner = Actioner::new(&config.keybindings, term.clone());
+ let term_manager = EventReader::new(term.clone());
let mut display = Display::new(term.clone(), config.colors.clone());
let mut status = Status::new(Args::parse(), config, display.height()?, term)?;
- while let Ok(event) = display.poll_event() {
+ while let Ok(event) = term_manager.poll_event() {
actioner.read_event(&mut status, event)?;
display.display_all(&status)?;
diff --git a/src/display.rs b/src/term_manager.rs
index 687b4ca..55d6dfc 100644
--- a/src/display.rs
+++ b/src/term_manager.rs
@@ -18,6 +18,20 @@ use crate::preview::Preview;
use crate::status::Status;
use crate::tab::Tab;
+pub struct EventReader {
+ term: Arc<Term>,
+}
+
+impl EventReader {
+ pub fn new(term: Arc<Term>) -> Self {
+ Self { term }
+ }
+
+ pub fn poll_event(&self) -> FmResult<Event> {
+ Ok(self.term.poll_event()?)
+ }
+}
+
/// Is responsible for displaying content in the terminal.
/// It uses an already created terminal.
pub struct Display {
@@ -28,15 +42,6 @@ pub struct Display {
/// system info
sys: System,
}
-
-const fn color_to_attr(color: Color) -> Attr {
- Attr {
- fg: color,
- bg: Color::Default,
- effect: Effect::empty(),
- }
-}
-
impl Display {
/// Returns a new `Display` instance from a `tuikit::term::Term` object.
pub fn new(term: Arc<Term>, colors: Colors) -> Self {
@@ -51,10 +56,6 @@ impl Display {
Ok(self.term.show_cursor(true)?)
}
- pub fn poll_event(&self) -> FmResult<Event> {
- Ok(self.term.poll_event()?)
- }
-
const EDIT_BOX_OFFSET: usize = 10;
const SORT_CURSOR_OFFSET: usize = 36;
const ATTR_LINE_NR: Attr = color_to_attr(Color::CYAN);
@@ -473,3 +474,11 @@ impl Display {
fn format_line_nr_hex(line_nr: usize, width: usize) -> String {
format!("{:0width$x}", line_nr)
}
+
+const fn color_to_attr(color: Color) -> Attr {
+ Attr {
+ fg: color,
+ bg: Color::Default,
+ effect: Effect::empty(),
+ }
+}