mirror of
https://github.com/kdheepak/taskwarrior-tui.git
synced 2025-08-24 23:46:41 +02:00
Format files
This commit is contained in:
parent
ac5c00760b
commit
0cc6946d83
2 changed files with 43 additions and 25 deletions
52
src/app.rs
52
src/app.rs
|
@ -5,13 +5,13 @@ use std::cmp::Ordering;
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
|
use task_hookrs::date::Date;
|
||||||
use task_hookrs::import::import;
|
use task_hookrs::import::import;
|
||||||
use task_hookrs::task::Task;
|
use task_hookrs::task::Task;
|
||||||
use task_hookrs::uda::UDAValue;
|
use task_hookrs::uda::UDAValue;
|
||||||
use task_hookrs::date::Date;
|
|
||||||
use unicode_width::UnicodeWidthStr;
|
use unicode_width::UnicodeWidthStr;
|
||||||
|
|
||||||
use chrono::{Local, DateTime, TimeZone, Duration, NaiveDateTime};
|
use chrono::{DateTime, Duration, Local, NaiveDateTime, TimeZone};
|
||||||
|
|
||||||
use tui::{
|
use tui::{
|
||||||
backend::{Backend, TermionBackend},
|
backend::{Backend, TermionBackend},
|
||||||
|
@ -19,7 +19,7 @@ use tui::{
|
||||||
style::{Color, Modifier, Style},
|
style::{Color, Modifier, Style},
|
||||||
terminal::Frame,
|
terminal::Frame,
|
||||||
text::Text,
|
text::Text,
|
||||||
widgets::{BarChart, Block, Borders, Row, Paragraph, Table, TableState},
|
widgets::{BarChart, Block, Borders, Paragraph, Row, Table, TableState},
|
||||||
Terminal,
|
Terminal,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -90,11 +90,14 @@ impl App {
|
||||||
|
|
||||||
pub fn draw(&mut self, f: &mut Frame<impl Backend>) {
|
pub fn draw(&mut self, f: &mut Frame<impl Backend>) {
|
||||||
let rects = Layout::default()
|
let rects = Layout::default()
|
||||||
.constraints([
|
.constraints(
|
||||||
Constraint::Percentage(48),
|
[
|
||||||
Constraint::Percentage(48),
|
Constraint::Percentage(48),
|
||||||
Constraint::Max(3),
|
Constraint::Percentage(48),
|
||||||
].as_ref())
|
Constraint::Max(3),
|
||||||
|
]
|
||||||
|
.as_ref(),
|
||||||
|
)
|
||||||
.split(f.size());
|
.split(f.size());
|
||||||
self.draw_task_report(f, rects[0]);
|
self.draw_task_report(f, rects[0]);
|
||||||
self.draw_task_details(f, rects[1]);
|
self.draw_task_details(f, rects[1]);
|
||||||
|
@ -121,7 +124,12 @@ impl App {
|
||||||
|
|
||||||
fn draw_task_details(&mut self, f: &mut Frame<impl Backend>, rect: Rect) {
|
fn draw_task_details(&mut self, f: &mut Frame<impl Backend>, rect: Rect) {
|
||||||
if self.tasks.len() == 0 {
|
if self.tasks.len() == 0 {
|
||||||
f.render_widget(Block::default().borders(Borders::ALL).title("Task not found"), rect);
|
f.render_widget(
|
||||||
|
Block::default()
|
||||||
|
.borders(Borders::ALL)
|
||||||
|
.title("Task not found"),
|
||||||
|
rect,
|
||||||
|
);
|
||||||
return ();
|
return ();
|
||||||
}
|
}
|
||||||
let selected = self.state.selected().unwrap_or_default();
|
let selected = self.state.selected().unwrap_or_default();
|
||||||
|
@ -130,11 +138,17 @@ impl App {
|
||||||
.arg(format!("{}", task_id))
|
.arg(format!("{}", task_id))
|
||||||
.output()
|
.output()
|
||||||
.expect(
|
.expect(
|
||||||
&format!("Unable to show details for `task {}`. Check documentation for more information", task_id)[..]
|
&format!(
|
||||||
);
|
"Unable to show details for `task {}`. Check documentation for more information",
|
||||||
|
task_id
|
||||||
|
)[..],
|
||||||
|
);
|
||||||
let data = String::from_utf8(output.stdout).unwrap();
|
let data = String::from_utf8(output.stdout).unwrap();
|
||||||
let p = Paragraph::new(Text::from(&data[..]))
|
let p = Paragraph::new(Text::from(&data[..])).block(
|
||||||
.block(Block::default().borders(Borders::ALL).title(format!("Task {}", task_id)));
|
Block::default()
|
||||||
|
.borders(Borders::ALL)
|
||||||
|
.title(format!("Task {}", task_id)),
|
||||||
|
);
|
||||||
f.render_widget(p, rect);
|
f.render_widget(p, rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,7 +160,10 @@ impl App {
|
||||||
|
|
||||||
let (tasks, headers, widths) = self.task_report();
|
let (tasks, headers, widths) = self.task_report();
|
||||||
if tasks.len() == 0 {
|
if tasks.len() == 0 {
|
||||||
f.render_widget(Block::default().borders(Borders::ALL).title("Task next"), rect);
|
f.render_widget(
|
||||||
|
Block::default().borders(Borders::ALL).title("Task next"),
|
||||||
|
rect,
|
||||||
|
);
|
||||||
return ();
|
return ();
|
||||||
}
|
}
|
||||||
let header = headers.iter();
|
let header = headers.iter();
|
||||||
|
@ -155,7 +172,9 @@ impl App {
|
||||||
.map(|i| Row::StyledData(i.iter(), normal_style));
|
.map(|i| Row::StyledData(i.iter(), normal_style));
|
||||||
let constraints: Vec<Constraint> = widths
|
let constraints: Vec<Constraint> = widths
|
||||||
.iter()
|
.iter()
|
||||||
.map(|i| Constraint::Percentage(std::cmp::min(50, std::cmp::max(*i, 5)).try_into().unwrap()))
|
.map(|i| {
|
||||||
|
Constraint::Percentage(std::cmp::min(50, std::cmp::max(*i, 5)).try_into().unwrap())
|
||||||
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let t = Table::new(header, rows)
|
let t = Table::new(header, rows)
|
||||||
|
@ -344,9 +363,8 @@ impl App {
|
||||||
self.tasks = i;
|
self.tasks = i;
|
||||||
self.tasks.sort_by(cmp);
|
self.tasks.sort_by(cmp);
|
||||||
}
|
}
|
||||||
_ => ()
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
16
src/main.rs
16
src/main.rs
|
@ -7,7 +7,8 @@ mod util;
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
mod app;
|
mod app;
|
||||||
|
|
||||||
use crate::util::{Event, Events, Config};
|
use crate::util::{Config, Event, Events};
|
||||||
|
use std::time::Duration;
|
||||||
use std::{error::Error, io};
|
use std::{error::Error, io};
|
||||||
use termion::{
|
use termion::{
|
||||||
event::Key,
|
event::Key,
|
||||||
|
@ -17,7 +18,6 @@ use termion::{
|
||||||
};
|
};
|
||||||
use tui::{backend::TermionBackend, Terminal};
|
use tui::{backend::TermionBackend, Terminal};
|
||||||
use unicode_width::UnicodeWidthStr;
|
use unicode_width::UnicodeWidthStr;
|
||||||
use std::time::Duration;
|
|
||||||
|
|
||||||
use app::App;
|
use app::App;
|
||||||
use app::InputMode;
|
use app::InputMode;
|
||||||
|
@ -37,7 +37,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||||
let mut terminal = setup_terminal()?;
|
let mut terminal = setup_terminal()?;
|
||||||
|
|
||||||
// Setup event handlers
|
// Setup event handlers
|
||||||
let events = Events::with_config(Config{
|
let events = Events::with_config(Config {
|
||||||
exit_key: Key::Char('q'),
|
exit_key: Key::Char('q'),
|
||||||
tick_rate: Duration::from_secs(5),
|
tick_rate: Duration::from_secs(5),
|
||||||
});
|
});
|
||||||
|
@ -53,16 +53,16 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||||
match app.input_mode {
|
match app.input_mode {
|
||||||
InputMode::Normal => match input {
|
InputMode::Normal => match input {
|
||||||
Key::Ctrl('c') | Key::Char('q') => break,
|
Key::Ctrl('c') | Key::Char('q') => break,
|
||||||
Key::Char('r') => app.update(),
|
Key::Char('r') => app.update(),
|
||||||
Key::Down | Key::Char('j') => app.next(),
|
Key::Down | Key::Char('j') => app.next(),
|
||||||
Key::Up | Key::Char('k') => app.previous(),
|
Key::Up | Key::Char('k') => app.previous(),
|
||||||
Key::Char('i') => {
|
Key::Char('i') => {
|
||||||
app.input_mode = InputMode::Command;
|
app.input_mode = InputMode::Command;
|
||||||
}
|
}
|
||||||
_ => {},
|
_ => {}
|
||||||
},
|
},
|
||||||
InputMode::Command => match input {
|
InputMode::Command => match input {
|
||||||
Key::Char('\n') | Key::Esc => {
|
Key::Char('\n') | Key::Esc => {
|
||||||
app.input_mode = InputMode::Normal;
|
app.input_mode = InputMode::Normal;
|
||||||
}
|
}
|
||||||
Key::Char(c) => {
|
Key::Char(c) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue