From d65b915f3dfda28aad6f2806df38c8ad77135d8b Mon Sep 17 00:00:00 2001 From: metamuffin Date: Fri, 10 Jun 2022 17:02:31 +0200 Subject: more code --- karlc/src/main.rs | 54 +++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 43 insertions(+), 11 deletions(-) (limited to 'karlc/src/main.rs') 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!(); } } } -- cgit v1.2.3-70-g09d2