aboutsummaryrefslogtreecommitdiff
path: root/karlc
diff options
context:
space:
mode:
authormetamuffin <yvchraiqi@protonmail.com>2022-06-11 14:32:45 +0200
committermetamuffin <yvchraiqi@protonmail.com>2022-06-11 14:32:45 +0200
commitc2699d114c921ab2ceb1f467b32a26257dddcf3d (patch)
tree0e886d333d944094c8c66905cac36a21cd010405 /karlc
parent9769c17c0b4c271c1cfbe726b19a6d3f9250c7c8 (diff)
downloadkarlender-c2699d114c921ab2ceb1f467b32a26257dddcf3d.tar
karlender-c2699d114c921ab2ceb1f467b32a26257dddcf3d.tar.bz2
karlender-c2699d114c921ab2ceb1f467b32a26257dddcf3d.tar.zst
changing the protocol again
Diffstat (limited to 'karlc')
-rw-r--r--karlc/Cargo.toml2
-rw-r--r--karlc/src/main.rs82
-rw-r--r--karlc/src/pretty.rs24
3 files changed, 64 insertions, 44 deletions
diff --git a/karlc/Cargo.toml b/karlc/Cargo.toml
index 653933a..3bad351 100644
--- a/karlc/Cargo.toml
+++ b/karlc/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "karlc"
-version = "0.1.0"
+version = "0.1.1"
edition = "2021"
[dependencies]
diff --git a/karlc/src/main.rs b/karlc/src/main.rs
index e95b5b7..55bb974 100644
--- a/karlc/src/main.rs
+++ b/karlc/src/main.rs
@@ -4,7 +4,9 @@ pub mod pretty;
use chrono::{NaiveDateTime, Utc};
use clap::{Args, Parser, Subcommand};
use client::Client;
-use karlcommon::{socket_path, version, ClientboundPacket, ServerboundPacket, Task};
+use karlcommon::{
+ socket_path, version, ClientboundPacket, Condition, Schedule, ServerboundPacket, Task,
+};
use log::{error, info};
use std::{os::unix::net::UnixStream, path::PathBuf, process::exit};
@@ -91,37 +93,49 @@ fn main() {
t.description
.unwrap_or("\x1b[3m\x1b[2m(no description)\x1b[0m".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");
+ if !t.tags.is_empty() {
+ println!(" \x1b[38;2;100;255;100mTags:\x1b[0m {}", t.tags.join(", "));
+ }
+ print!(" \x1b[38;2;100;255;100mSchedule: \x1b[0m",);
+ match t.schedule {
+ Schedule::Never => println!("\x1b[3m\x1b[2m(never)\x1b[0m"),
+ Schedule::Dynamic { .. } => todo!(),
+ Schedule::Static(t) => {
+ println!(
+ "from {} to {}",
+ NaiveDateTime::from_timestamp(t.start, 0),
+ NaiveDateTime::from_timestamp(t.end, 0)
+ )
+ }
+ Schedule::Condition(o) => {
+ println!("when {}", 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()),
- );
+ 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, 0)
+ ))
+ .unwrap_or("...".to_string()),
+ i.at.end
+ .map(|e| format!(
+ "{}",
+ NaiveDateTime::from_timestamp(e, 0)
+ ))
+ .unwrap_or("...".to_string()),
+ );
+ }
}
}
}
@@ -156,11 +170,7 @@ impl TaskSpec {
name: self.name,
description: self.description,
tags: self.tags,
- priority: 0.0,
- completed: None,
- scheduled: None,
- occurence: None,
- deadline: None,
+ schedule: Schedule::Never,
}
}
}
diff --git a/karlc/src/pretty.rs b/karlc/src/pretty.rs
index bf9cf20..abd5f96 100644
--- a/karlc/src/pretty.rs
+++ b/karlc/src/pretty.rs
@@ -7,10 +7,14 @@ pub fn indent(s: &str) -> String {
pub fn fmt_condition(c: &Condition) -> String {
match c {
Condition::From(_) => todo!(),
- Condition::Or(_) => todo!(),
+ Condition::Or(cs) => cs
+ .iter()
+ .map(|e| format!("{{ {} }}", fmt_condition(e)))
+ .reduce(|a, b| format!("{} ∨ {}", a, b))
+ .unwrap_or("never".to_string()),
Condition::And(cs) => cs
.iter()
- .map(|e| fmt_condition(e))
+ .map(|e| format!("{{ {} }}", fmt_condition(e)))
.reduce(|a, b| format!("{} ∧ {}", a, b))
.unwrap_or("never".to_string()),
Condition::Invert(_) => todo!(),
@@ -26,10 +30,16 @@ pub fn fmt_condition(c: &Condition) -> String {
}
}
Condition::Range {
- prop: _,
- min: _,
- max: _,
- modulus: _,
- } => todo!(),
+ prop,
+ min,
+ max,
+ modulus,
+ } => {
+ if let Some(m) = modulus {
+ format!("{} < {:?} < {} (mod {})", min, prop, max, m)
+ } else {
+ format!("{} < {:?} < {}", min, prop, max)
+ }
+ }
}
}