WIP
This commit is contained in:
parent
a94d498c7e
commit
38912b506b
8 changed files with 47 additions and 16 deletions
|
@ -108,10 +108,11 @@ impl CleanupArgs {
|
|||
mod ui {
|
||||
use crate::cli::prelude::*;
|
||||
|
||||
#[derive(Parser)]
|
||||
#[derive(Parser, Debug)]
|
||||
pub struct Args {}
|
||||
|
||||
impl Args {
|
||||
#[instrument]
|
||||
pub async fn run(&self, tasks: SharedTasks) -> Result<()> {
|
||||
crate::tui::Tui::run(tasks).await
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ use reqwest_retry::{policies::ExponentialBackoff, RetryTransientMiddleware};
|
|||
use reqwest_tracing::TracingMiddleware;
|
||||
use serde::de;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Client {
|
||||
client: ClientWithMiddleware,
|
||||
base_url: Url,
|
||||
|
|
|
@ -6,6 +6,7 @@ use reqwest::{
|
|||
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct GitLab {
|
||||
client: Client,
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ use serde::Deserialize;
|
|||
use tokio::spawn;
|
||||
use tracing::debug;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Jira {
|
||||
client: Client,
|
||||
}
|
||||
|
|
|
@ -26,5 +26,7 @@ async fn main() -> Result<()> {
|
|||
// https://docs.rs/tracing-appender/latest/tracing_appender/non_blocking/struct.WorkerGuard.html
|
||||
let _log_guard = observe::setup_logging(&cli.logs_directory, &cli.tracing_env_filter)?;
|
||||
|
||||
info!("Starting taskr...");
|
||||
|
||||
cli.exec().await
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#![allow(unused_imports)]
|
||||
|
||||
pub use tracing::instrument;
|
||||
|
||||
pub use crate::config::Config;
|
||||
pub use crate::result::Result;
|
||||
pub use regex::Regex;
|
||||
|
|
|
@ -18,6 +18,7 @@ use crate::{gitlab::GitLab, jira::Jira, result::Result};
|
|||
|
||||
pub type Db = sled::Db;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Tasks {
|
||||
pub data_dir: PathBuf,
|
||||
pub config_file_path: PathBuf,
|
||||
|
@ -35,6 +36,7 @@ impl Tasks {
|
|||
where
|
||||
D: AsRef<Path>,
|
||||
{
|
||||
debug!("Creating Tasks instance...");
|
||||
let db = OnceLock::new();
|
||||
let config = OnceLock::new();
|
||||
let gitlab = OnceLock::new();
|
||||
|
|
51
src/tui.rs
51
src/tui.rs
|
@ -13,7 +13,7 @@ use ratatui::{
|
|||
};
|
||||
use signal_hook::consts::*;
|
||||
use signal_hook_tokio::Signals;
|
||||
use std::io::stdout;
|
||||
use std::io::{stdout, Stdout};
|
||||
|
||||
pub struct Tui {}
|
||||
|
||||
|
@ -21,17 +21,28 @@ enum Event {
|
|||
CrosstermEvent(crossterm::event::Event),
|
||||
// CrosstermError(Arc<dyn std::error::Error>),
|
||||
Quit,
|
||||
Tick,
|
||||
Update,
|
||||
Render,
|
||||
}
|
||||
|
||||
impl Tui {
|
||||
pub async fn run(tasks: SharedTasks) -> Result<()> {
|
||||
#[instrument]
|
||||
fn setup_screen() -> Result<()> {
|
||||
debug!("Setting up stdout for TUI...");
|
||||
stdout().execute(EnterAlternateScreen)?;
|
||||
enable_raw_mode()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn new_terminal() -> Result<Terminal<CrosstermBackend<Stdout>>> {
|
||||
debug!("Initializing TUI Terminal with Crossterm backend...");
|
||||
let mut terminal = Terminal::new(CrosstermBackend::new(stdout()))?;
|
||||
terminal.clear()?;
|
||||
|
||||
return Ok(terminal);
|
||||
}
|
||||
pub async fn run(tasks: SharedTasks) -> Result<()> {
|
||||
Self::setup_screen()?;
|
||||
let mut terminal = Self::new_terminal()?;
|
||||
let (tx, mut rx) = tokio::sync::mpsc::unbounded_channel::<Event>();
|
||||
|
||||
let mut signals = Signals::new(&[SIGHUP, SIGTERM, SIGINT, SIGQUIT])?;
|
||||
|
@ -39,13 +50,16 @@ impl Tui {
|
|||
let signal_sender = tx.clone();
|
||||
tokio::spawn(async move {
|
||||
// await a signal - once we receive one send the quit event
|
||||
signals.next().await;
|
||||
let sig = signals.next().await;
|
||||
eprintln!("{sig:#?}");
|
||||
println!("{sig:#?}");
|
||||
info!("{sig:#?}");
|
||||
signal_sender.send(Event::Quit).unwrap();
|
||||
});
|
||||
|
||||
let tick_rate = std::time::Duration::from_millis(1000);
|
||||
|
||||
let event_publisher_loop = tokio::spawn(async move {
|
||||
let _event_publisher_loop = tokio::spawn(async move {
|
||||
let mut crossterm_event_stream = crossterm::event::EventStream::new();
|
||||
let mut interval = tokio::time::interval(tick_rate);
|
||||
|
||||
|
@ -68,7 +82,7 @@ impl Tui {
|
|||
}
|
||||
}
|
||||
_ = delay => {
|
||||
tx.send(Event::Tick).unwrap();
|
||||
tx.send(Event::Update).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -77,6 +91,8 @@ impl Tui {
|
|||
loop {
|
||||
let event = rx.recv().await;
|
||||
|
||||
let mut should_draw = false;
|
||||
|
||||
match event {
|
||||
Some(Event::CrosstermEvent(e)) => match e {
|
||||
event::Event::Key(key) => {
|
||||
|
@ -92,18 +108,23 @@ impl Tui {
|
|||
}
|
||||
_ => {}
|
||||
},
|
||||
Some(Event::Tick) => {}
|
||||
Some(Event::Update) => {}
|
||||
Some(Event::Quit) => break,
|
||||
Some(Event::Render) => {
|
||||
should_draw = true;
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
|
||||
terminal.draw(|frame| {
|
||||
let area = frame.size();
|
||||
frame.render_widget(
|
||||
Paragraph::new("Hello Ratatui! (press 'q' to quit)").white(),
|
||||
area,
|
||||
);
|
||||
})?;
|
||||
if should_draw {
|
||||
terminal.draw(|frame| {
|
||||
let area = frame.size();
|
||||
frame.render_widget(
|
||||
Paragraph::new("Hello Ratatui! (press 'q' to quit)").white(),
|
||||
area,
|
||||
);
|
||||
})?;
|
||||
}
|
||||
}
|
||||
|
||||
signal_handle.close();
|
||||
|
|
Loading…
Reference in a new issue