diff options
author | Michael Gattozzi <mgattozzi@gmail.com> | 2019-11-27 17:57:29 -0500 |
---|---|---|
committer | Michael Gattozzi <mgattozzi@gmail.com> | 2019-12-02 15:06:03 -0500 |
commit | 0caa9551a904a1ba675fbde70435de6fb0a176d6 (patch) | |
tree | 1b6224f031e13e20358f00081ef1ec91f8b118a9 /ticket/src/actions.rs | |
parent | fc072f0656ceb99994f1217325aa11f932881d55 (diff) |
Add a tui for ticket
This commit sets up a basic tui for the current functionality. It's
traversable by keyboard and by mouse and shows the ticket state via tab,
info in a row, and the description in it's own box when selected. This
is necessary for a good user experience for in repo tools. Files are
fine, but interactivity is better.
Diffstat (limited to 'ticket/src/actions.rs')
-rw-r--r-- | ticket/src/actions.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/ticket/src/actions.rs b/ticket/src/actions.rs new file mode 100644 index 0000000..381c9f7 --- /dev/null +++ b/ticket/src/actions.rs @@ -0,0 +1,36 @@ +use crate::Ticket; +use anyhow::Result; +use log::*; +use shared::find_root; +use std::{ + fs, + path::PathBuf, +}; + +pub fn get_open_tickets() -> Result<Vec<Ticket>> { + get_tickets(ticket_root()?.join("open")) +} + +pub fn get_closed_tickets() -> Result<Vec<Ticket>> { + get_tickets(ticket_root()?.join("closed")) +} + +fn get_tickets(path: PathBuf) -> Result<Vec<Ticket>> { + let mut out = Vec::new(); + debug!("Looking for ticket."); + for entry in fs::read_dir(&path)? { + let entry = entry?; + let path = entry.path(); + trace!("Looking at entry {}.", path.display()); + if path.is_file() { + trace!("Entry is a file."); + out.push(toml::from_slice::<Ticket>(&fs::read(&path)?)?); + } + } + out.sort_by(|a, b| a.number.cmp(&b.number)); + Ok(out) +} + +pub fn ticket_root() -> Result<PathBuf> { + Ok(find_root()?.join(".dev-suite").join("ticket")) +} |