Skip to content

Commit

Permalink
refactor: move Tui to intuitils (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
micielski authored Oct 31, 2024
1 parent 5a4d5c7 commit 4f2b1a1
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 132 deletions.
8 changes: 6 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ license = "GPL-3.0-or-later"
rm-config = { version = "0.5", path = "rm-config" }
rm-shared = { version = "0.5", path = "rm-shared" }

intuitils = "0.0.3"
intuitils = "0.0.4"

magnetease = "0.3"
anyhow = "1"
Expand Down
23 changes: 12 additions & 11 deletions rm-main/src/tui/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::{
tui::components::Component,
};

use intuitils::Terminal;
use rm_config::CONFIG;
use rm_shared::action::{Action, UpdateAction};

Expand All @@ -13,7 +14,7 @@ use crossterm::event::{Event, KeyCode, KeyModifiers};
use tokio::sync::mpsc::{self, UnboundedReceiver, UnboundedSender};
use transmission_rpc::{types::SessionGet, TransClient};

use super::{components::CurrentTab, main_window::MainWindow, terminal::Tui};
use super::{components::CurrentTab, main_window::MainWindow};

#[derive(Clone)]
pub struct Ctx {
Expand Down Expand Up @@ -96,22 +97,22 @@ impl App {
}

pub async fn run(&mut self) -> Result<()> {
let mut tui = Tui::new()?;
let mut terminal = Terminal::new()?;

tui.enter()?;
terminal.init()?;

self.render(&mut tui)?;
self.render(&mut terminal)?;

self.main_loop(&mut tui).await?;
self.main_loop(&mut terminal).await?;

tui.exit()?;
terminal.exit()?;
Ok(())
}

async fn main_loop(&mut self, tui: &mut Tui) -> Result<()> {
async fn main_loop(&mut self, terminal: &mut Terminal) -> Result<()> {
let mut interval = tokio::time::interval(tokio::time::Duration::from_millis(250));
loop {
let tui_event = tui.next();
let tui_event = terminal.next();
let action = self.action_rx.recv();
let update_action = self.update_rx.recv();
let tick_action = interval.tick();
Expand All @@ -130,7 +131,7 @@ impl App {
action = action => {
if let Some(action) = action {
if action.is_render() {
self.render(tui)?;
self.render(terminal)?;
} else {
self.handle_user_action(action).await
}
Expand All @@ -144,8 +145,8 @@ impl App {
}
}

fn render(&mut self, tui: &mut Tui) -> Result<()> {
tui.terminal.draw(|f| {
fn render(&mut self, terminal: &mut Terminal) -> Result<()> {
terminal.draw(|f| {
self.main_window.render(f, f.area());
})?;
Ok(())
Expand Down
1 change: 0 additions & 1 deletion rm-main/src/tui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ mod components;
mod global_popups;
pub mod main_window;
mod tabs;
pub mod terminal;
117 changes: 0 additions & 117 deletions rm-main/src/tui/terminal.rs

This file was deleted.

0 comments on commit 4f2b1a1

Please sign in to comment.