mirror of
https://github.com/kdheepak/taskwarrior-tui.git
synced 2025-08-26 12:17:19 +02:00
Refactor code
This commit is contained in:
parent
025f780093
commit
7cbc20b43a
4 changed files with 30 additions and 27 deletions
|
@ -2,12 +2,12 @@ use crate::calendar::Calendar;
|
||||||
use crate::config;
|
use crate::config;
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
use crate::context::Context;
|
use crate::context::Context;
|
||||||
|
use crate::event::Key;
|
||||||
|
use crate::event::{Event, Events};
|
||||||
use crate::help::Help;
|
use crate::help::Help;
|
||||||
use crate::keyconfig::KeyConfig;
|
use crate::keyconfig::KeyConfig;
|
||||||
use crate::table::{Row, Table, TableMode, TableState};
|
use crate::table::{Row, Table, TableMode, TableState};
|
||||||
use crate::task_report::TaskReportTable;
|
use crate::task_report::TaskReportTable;
|
||||||
use crate::util::Key;
|
|
||||||
use crate::util::{Event, Events};
|
|
||||||
|
|
||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
|
@ -38,9 +38,7 @@ use anyhow::Result;
|
||||||
use async_std::prelude::*;
|
use async_std::prelude::*;
|
||||||
use async_std::stream::StreamExt;
|
use async_std::stream::StreamExt;
|
||||||
use async_std::task;
|
use async_std::task;
|
||||||
use futures::future::join_all;
|
|
||||||
use futures::stream::FuturesOrdered;
|
use futures::stream::FuturesOrdered;
|
||||||
use futures::{join, try_join};
|
|
||||||
|
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
use crossterm::{
|
use crossterm::{
|
||||||
cursor,
|
|
||||||
event::{self, DisableMouseCapture, EnableMouseCapture, EventStream},
|
event::{self, DisableMouseCapture, EnableMouseCapture, EventStream},
|
||||||
execute,
|
execute,
|
||||||
terminal::{disable_raw_mode, enable_raw_mode, Clear, ClearType, EnterAlternateScreen, LeaveAlternateScreen},
|
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
|
||||||
};
|
};
|
||||||
use tui::{backend::CrosstermBackend, Terminal};
|
use tui::{backend::CrosstermBackend, Terminal};
|
||||||
|
|
||||||
|
@ -51,21 +50,6 @@ pub enum Event<I> {
|
||||||
Tick,
|
Tick,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn setup_terminal() -> Terminal<CrosstermBackend<io::Stdout>> {
|
|
||||||
enable_raw_mode().unwrap();
|
|
||||||
let mut stdout = io::stdout();
|
|
||||||
execute!(stdout, EnterAlternateScreen).unwrap();
|
|
||||||
execute!(stdout, Clear(ClearType::All)).unwrap();
|
|
||||||
let backend = CrosstermBackend::new(stdout);
|
|
||||||
Terminal::new(backend).unwrap()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn destruct_terminal() {
|
|
||||||
disable_raw_mode().unwrap();
|
|
||||||
execute!(io::stdout(), LeaveAlternateScreen, DisableMouseCapture).unwrap();
|
|
||||||
execute!(io::stdout(), cursor::Show).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct Events {
|
pub struct Events {
|
||||||
pub rx: async_std::channel::Receiver<Event<Key>>,
|
pub rx: async_std::channel::Receiver<Event<Key>>,
|
||||||
}
|
}
|
|
@ -1,7 +1,6 @@
|
||||||
#![allow(clippy::eval_order_dependence)]
|
#![allow(clippy::eval_order_dependence)]
|
||||||
use crate::util::Key;
|
use crate::event::Key;
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use futures::join;
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
|
30
src/main.rs
30
src/main.rs
|
@ -6,19 +6,19 @@ mod app;
|
||||||
mod calendar;
|
mod calendar;
|
||||||
mod config;
|
mod config;
|
||||||
mod context;
|
mod context;
|
||||||
|
mod event;
|
||||||
mod help;
|
mod help;
|
||||||
mod history;
|
mod history;
|
||||||
mod keyconfig;
|
mod keyconfig;
|
||||||
mod table;
|
mod table;
|
||||||
mod task_report;
|
mod task_report;
|
||||||
mod util;
|
|
||||||
|
|
||||||
use crate::util::{destruct_terminal, setup_terminal, Event, EventConfig, Events};
|
use crate::event::{Event, EventConfig, Events, Key};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use clap::{App, Arg};
|
use clap::{App, Arg};
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::io::Write;
|
use std::io::{self, Write};
|
||||||
use std::panic;
|
use std::panic;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
|
@ -27,12 +27,34 @@ use async_std::sync::{Arc, Mutex};
|
||||||
use async_std::task;
|
use async_std::task;
|
||||||
use futures::stream::{FuturesUnordered, StreamExt};
|
use futures::stream::{FuturesUnordered, StreamExt};
|
||||||
|
|
||||||
use crate::util::Key;
|
use crossterm::{
|
||||||
|
cursor,
|
||||||
|
event::{DisableMouseCapture, EnableMouseCapture, EventStream},
|
||||||
|
execute,
|
||||||
|
terminal::{disable_raw_mode, enable_raw_mode, Clear, ClearType, EnterAlternateScreen, LeaveAlternateScreen},
|
||||||
|
};
|
||||||
|
use tui::{backend::CrosstermBackend, Terminal};
|
||||||
|
|
||||||
use app::{AppMode, TaskwarriorTuiApp};
|
use app::{AppMode, TaskwarriorTuiApp};
|
||||||
|
|
||||||
const APP_VERSION: &str = env!("CARGO_PKG_VERSION");
|
const APP_VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||||
const APP_NAME: &str = env!("CARGO_PKG_NAME");
|
const APP_NAME: &str = env!("CARGO_PKG_NAME");
|
||||||
|
|
||||||
|
pub fn setup_terminal() -> Terminal<CrosstermBackend<io::Stdout>> {
|
||||||
|
enable_raw_mode().unwrap();
|
||||||
|
let mut stdout = io::stdout();
|
||||||
|
execute!(stdout, EnterAlternateScreen).unwrap();
|
||||||
|
execute!(stdout, Clear(ClearType::All)).unwrap();
|
||||||
|
let backend = CrosstermBackend::new(stdout);
|
||||||
|
Terminal::new(backend).unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn destruct_terminal() {
|
||||||
|
disable_raw_mode().unwrap();
|
||||||
|
execute!(io::stdout(), LeaveAlternateScreen, DisableMouseCapture).unwrap();
|
||||||
|
execute!(io::stdout(), cursor::Show).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
better_panic::install();
|
better_panic::install();
|
||||||
let matches = App::new(APP_NAME)
|
let matches = App::new(APP_NAME)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue