-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
152 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,110 +1,6 @@ | ||
pub mod app; | ||
mod ui; | ||
|
||
use std::{io, time::Duration}; | ||
|
||
use anyhow::Result; | ||
use crossterm::{ | ||
cursor, | ||
event::{Event, KeyEventKind}, | ||
terminal::{EnterAlternateScreen, LeaveAlternateScreen}, | ||
}; | ||
use futures::{FutureExt, StreamExt}; | ||
use ratatui::{backend::CrosstermBackend as Backend, Terminal}; | ||
use tokio::{ | ||
sync::mpsc::{self, UnboundedReceiver, UnboundedSender}, | ||
task::JoinHandle, | ||
}; | ||
use tokio_util::sync::CancellationToken; | ||
|
||
pub struct Tui { | ||
pub terminal: Terminal<Backend<std::io::Stdout>>, | ||
pub task: JoinHandle<Result<()>>, | ||
pub cancellation_token: CancellationToken, | ||
pub event_rx: UnboundedReceiver<Event>, | ||
pub event_tx: UnboundedSender<Event>, | ||
} | ||
|
||
impl Tui { | ||
pub(crate) fn new() -> Result<Self> { | ||
let terminal = Terminal::new(Backend::new(std::io::stdout()))?; | ||
let (event_tx, event_rx) = mpsc::unbounded_channel(); | ||
let cancellation_token = CancellationToken::new(); | ||
let task = tokio::spawn(async { Ok(()) }); | ||
Ok(Self { | ||
terminal, | ||
task, | ||
cancellation_token, | ||
event_rx, | ||
event_tx, | ||
}) | ||
} | ||
|
||
fn handle_crossterm_event( | ||
event: Option<Result<Event, io::Error>>, | ||
event_tx: &UnboundedSender<Event>, | ||
) -> Result<()> { | ||
match event { | ||
Some(Ok(Event::Key(key))) => { | ||
if key.kind == KeyEventKind::Press { | ||
event_tx.send(Event::Key(key)).unwrap(); | ||
} | ||
} | ||
Some(Ok(Event::Resize(x, y))) => event_tx.send(Event::Resize(x, y)).unwrap(), | ||
Some(Err(e)) => Err(e)?, | ||
_ => (), | ||
} | ||
Ok(()) | ||
} | ||
|
||
pub(crate) fn enter(&mut self) -> Result<()> { | ||
crossterm::terminal::enable_raw_mode()?; | ||
crossterm::execute!(std::io::stdout(), EnterAlternateScreen, cursor::Hide)?; | ||
self.start()?; | ||
Ok(()) | ||
} | ||
|
||
pub fn start(&mut self) -> Result<()> { | ||
self.cancellation_token = CancellationToken::new(); | ||
let cancellation_token = self.cancellation_token.clone(); | ||
let event_tx = self.event_tx.clone(); | ||
|
||
self.task = tokio::spawn(async move { | ||
let mut reader = crossterm::event::EventStream::new(); | ||
loop { | ||
let crossterm_event = reader.next().fuse(); | ||
tokio::select! { | ||
_ = cancellation_token.cancelled() => break, | ||
event = crossterm_event => Self::handle_crossterm_event(event, &event_tx)?, | ||
} | ||
} | ||
Ok(()) | ||
}); | ||
Ok(()) | ||
} | ||
|
||
pub(crate) fn exit(&mut self) -> Result<()> { | ||
self.cancellation_token.cancel(); | ||
let mut counter = 0; | ||
while !self.task.is_finished() { | ||
std::thread::sleep(Duration::from_millis(1)); | ||
counter += 1; | ||
if counter > 50 { | ||
self.task.abort(); | ||
} | ||
if counter > 100 { | ||
break; | ||
} | ||
} | ||
if crossterm::terminal::is_raw_mode_enabled()? { | ||
self.terminal.flush()?; | ||
crossterm::execute!(std::io::stdout(), LeaveAlternateScreen, cursor::Show)?; | ||
crossterm::terminal::disable_raw_mode()?; | ||
} | ||
Ok(()) | ||
} | ||
|
||
pub async fn next(&mut self) -> Option<Event> { | ||
self.event_rx.recv().await | ||
} | ||
} | ||
mod components; | ||
mod global_popups; | ||
pub mod main_window; | ||
mod tabs; | ||
pub mod terminal; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...in/src/tui/ui/tabs/torrents/popups/mod.rs → rm-main/src/tui/tabs/torrents/popups/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...src/tui/ui/tabs/torrents/tasks/default.rs → ...in/src/tui/tabs/torrents/tasks/default.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.