diff options
author | metamuffin <yvchraiqi@protonmail.com> | 2022-06-10 17:02:31 +0200 |
---|---|---|
committer | metamuffin <yvchraiqi@protonmail.com> | 2022-06-10 17:02:31 +0200 |
commit | d65b915f3dfda28aad6f2806df38c8ad77135d8b (patch) | |
tree | 46c57595ec7d64156b909e515a65f20fc6c0c7ff /karlc | |
parent | ee1116ffb12887d1ad985b67887c910f58202c1f (diff) | |
download | karlender-d65b915f3dfda28aad6f2806df38c8ad77135d8b.tar karlender-d65b915f3dfda28aad6f2806df38c8ad77135d8b.tar.bz2 karlender-d65b915f3dfda28aad6f2806df38c8ad77135d8b.tar.zst |
more code
Diffstat (limited to 'karlc')
-rw-r--r-- | karlc/Cargo.toml | 1 | ||||
-rw-r--r-- | karlc/src/main.rs | 54 | ||||
-rw-r--r-- | karlc/src/pretty.rs | 39 |
3 files changed, 44 insertions, 50 deletions
diff --git a/karlc/Cargo.toml b/karlc/Cargo.toml index c49ecfe..f95dee0 100644 --- a/karlc/Cargo.toml +++ b/karlc/Cargo.toml @@ -12,3 +12,4 @@ serde_json = "1.0.81" env_logger = "0.9.0" log = "0.4.17" crossbeam-channel = "0.5.4" +chrono = { version = "0.4.19", features = ["serde"] } diff --git a/karlc/src/main.rs b/karlc/src/main.rs index c69f1b2..9a89de9 100644 --- a/karlc/src/main.rs +++ b/karlc/src/main.rs @@ -1,14 +1,11 @@ pub mod client; -pub mod pretty; - -use std::{os::unix::net::UnixStream, process::exit}; +use chrono::{NaiveDateTime, Utc}; use clap::{Parser, Subcommand}; use client::Client; use karlcommon::{socket_path, version, ClientboundPacket, ServerboundPacket}; use log::{error, info}; - -use crate::pretty::Pretty; +use std::{os::unix::net::UnixStream, process::exit}; /// CLI interface for karld #[derive(Parser)] @@ -22,8 +19,8 @@ struct Args { pub enum Action { /// Show version of the client and daemon Version, - /// List all taskss - ListTasks, + /// List all tasks + List, } fn main() { @@ -54,11 +51,46 @@ fn main() { error!("handshake is not the first packet") } } - Action::ListTasks => { - client.send(ServerboundPacket::Download); - if let ClientboundPacket::DownloadResponse(tasks) = client.receiver.recv().unwrap() { + Action::List => { + client.send(ServerboundPacket::ListTasks); + if let ClientboundPacket::TaskList(tasks) = client.receiver.recv().unwrap() { for t in tasks { - println!("{}", Pretty(t)) + print!( + " +- \x1b[4m\x1b[1mTASK {}\x1b[0m + \x1b[38;2;100;255;100mName:\x1b[0m {} + \x1b[38;2;100;255;100mDescription:\x1b[0m {} + \x1b[38;2;100;255;100mOccurence:\x1b[0m {:?} + \x1b[38;2;100;255;100mNext instances: \x1b[0m", + t.id, t.name, t.description, t.occurence + ); + client.send(ServerboundPacket::ListInstances { + task: t.id, + limit: 5, + range: Some(Utc::now().naive_local().timestamp())..None, + }); + if let ClientboundPacket::InstanceList(instances) = + client.receiver.recv().unwrap() + { + for i in instances { + println!( + "\x1b[19G{} - {}", + i.at.start + .map(|e| format!( + "{}", + NaiveDateTime::from_timestamp(e as i64, 0) + )) + .unwrap_or("...".to_string()), + i.at.end + .map(|e| format!( + "{}", + NaiveDateTime::from_timestamp(e as i64, 0) + )) + .unwrap_or("...".to_string()), + ); + } + } + println!(); } } } diff --git a/karlc/src/pretty.rs b/karlc/src/pretty.rs deleted file mode 100644 index ceb1bde..0000000 --- a/karlc/src/pretty.rs +++ /dev/null @@ -1,39 +0,0 @@ -use std::fmt::Display; - -use karlcommon::{Condition, Task}; - -pub struct Pretty<T>(pub T); - -impl Display for Pretty<Task> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.write_fmt(format_args!( - "- \x1b[4m\x1b[1mTASK {}\x1b[0m - \x1b[38;2;100;255;100mName:\x1b[0m {} - \x1b[38;2;100;255;100mDescription:\x1b[0m {} - \x1b[38;2;100;255;100mOccurence:\x1b[0m {}", - self.0.id, - self.0.name, - self.0.description, - Pretty(self.0.occurence.clone()) - )) - } -} - -impl<T> Display for Pretty<Option<T>> -where - T: Clone, - Pretty<T>: Display, -{ - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.0 { - Some(v) => Pretty(v.clone()).fmt(f), - None => Ok(()), - } - } -} - -impl Display for Pretty<Condition> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.write_fmt(format_args!("{:?}", self.0)) - } -} |