aboutsummaryrefslogtreecommitdiff
path: root/karlc/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'karlc/src/main.rs')
-rw-r--r--karlc/src/main.rs75
1 files changed, 40 insertions, 35 deletions
diff --git a/karlc/src/main.rs b/karlc/src/main.rs
index ef56fd9..e95b5b7 100644
--- a/karlc/src/main.rs
+++ b/karlc/src/main.rs
@@ -1,4 +1,5 @@
pub mod client;
+pub mod pretty;
use chrono::{NaiveDateTime, Utc};
use clap::{Args, Parser, Subcommand};
@@ -7,6 +8,8 @@ use karlcommon::{socket_path, version, ClientboundPacket, ServerboundPacket, Tas
use log::{error, info};
use std::{os::unix::net::UnixStream, path::PathBuf, process::exit};
+use crate::pretty::fmt_condition;
+
/// CLI interface for karld
#[derive(Parser)]
#[clap(about, author, version)]
@@ -81,43 +84,45 @@ fn main() {
client.send(ServerboundPacket::ListTasks);
if let ClientboundPacket::TaskList(tasks) = client.receiver.recv().unwrap() {
for t in tasks {
- 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,
+ println!("- \x1b[4m\x1b[1mTASK {}\x1b[0m", t.id);
+ println!(" \x1b[38;2;100;255;100mName:\x1b[0m {}", t.name);
+ println!(
+ " \x1b[38;2;100;255;100mDescription:\x1b[0m {}",
t.description
- .unwrap_or("\x1b[3m\x1b[2m(no description)\x1b[0m".to_string()),
- t.occurence
+ .unwrap_or("\x1b[3m\x1b[2m(no description)\x1b[0m".to_string())
);
- 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()),
- );
+ if let Some(o) = t.occurence {
+ println!(
+ " \x1b[38;2;100;255;100mOccurence:\x1b[0m {}",
+ fmt_condition(&o)
+ );
+ print!(" \x1b[38;2;100;255;100mNext instances: \x1b[0m");
+
+ 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!();