aboutsummaryrefslogtreecommitdiff
path: root/karlc/src/main.rs
diff options
context:
space:
mode:
authormetamuffin <yvchraiqi@protonmail.com>2022-06-10 17:02:31 +0200
committermetamuffin <yvchraiqi@protonmail.com>2022-06-10 17:02:31 +0200
commitd65b915f3dfda28aad6f2806df38c8ad77135d8b (patch)
tree46c57595ec7d64156b909e515a65f20fc6c0c7ff /karlc/src/main.rs
parentee1116ffb12887d1ad985b67887c910f58202c1f (diff)
downloadkarlender-d65b915f3dfda28aad6f2806df38c8ad77135d8b.tar
karlender-d65b915f3dfda28aad6f2806df38c8ad77135d8b.tar.bz2
karlender-d65b915f3dfda28aad6f2806df38c8ad77135d8b.tar.zst
more code
Diffstat (limited to 'karlc/src/main.rs')
-rw-r--r--karlc/src/main.rs54
1 files changed, 43 insertions, 11 deletions
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!();
}
}
}