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