aboutsummaryrefslogtreecommitdiff
path: root/karlc
diff options
context:
space:
mode:
authormetamuffin <yvchraiqi@protonmail.com>2022-06-10 18:12:57 +0200
committermetamuffin <yvchraiqi@protonmail.com>2022-06-10 18:12:57 +0200
commit4e7b383fe2c1ccea7871c708ff1b281451feddd0 (patch)
treeae547f130eac80ac44e3fb0febe5f03cef6a7754 /karlc
parent45f2d1651f17d7e155748cfd1e1cd9a96f3e530e (diff)
downloadkarlender-4e7b383fe2c1ccea7871c708ff1b281451feddd0.tar
karlender-4e7b383fe2c1ccea7871c708ff1b281451feddd0.tar.bz2
karlender-4e7b383fe2c1ccea7871c708ff1b281451feddd0.tar.zst
blub
Diffstat (limited to 'karlc')
-rw-r--r--karlc/src/main.rs75
-rw-r--r--karlc/src/pretty.rs35
2 files changed, 75 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!();
diff --git a/karlc/src/pretty.rs b/karlc/src/pretty.rs
new file mode 100644
index 0000000..bf9cf20
--- /dev/null
+++ b/karlc/src/pretty.rs
@@ -0,0 +1,35 @@
+use karlcommon::Condition;
+
+pub fn indent(s: &str) -> String {
+ s.replace("\n", "\n ")
+}
+
+pub fn fmt_condition(c: &Condition) -> String {
+ match c {
+ Condition::From(_) => todo!(),
+ Condition::Or(_) => todo!(),
+ Condition::And(cs) => cs
+ .iter()
+ .map(|e| fmt_condition(e))
+ .reduce(|a, b| format!("{} ∧ {}", a, b))
+ .unwrap_or("never".to_string()),
+ Condition::Invert(_) => todo!(),
+ Condition::Equal {
+ prop,
+ value,
+ modulus,
+ } => {
+ if let Some(m) = modulus {
+ format!("{:?} ≡ {} (mod {})", prop, value, m)
+ } else {
+ format!("{:?} = {}", prop, value)
+ }
+ }
+ Condition::Range {
+ prop: _,
+ min: _,
+ max: _,
+ modulus: _,
+ } => todo!(),
+ }
+}