From 5ea6a13ead2a5cab0f578c8af5f0e0be88c3a08c Mon Sep 17 00:00:00 2001 From: gennyble Date: Wed, 18 Dec 2024 00:27:34 -0600 Subject: Ahhhhh --- converge/Cargo.toml | 3 + converge/example.html | 185 +++++++++++++++++++++++++++++++++++++++++++++++++ converge/readme.md | 7 +- converge/src/main.rs | 39 +++++------ converge/src/timedb.rs | 97 ++++++++++++++++++++++++++ 5 files changed, 309 insertions(+), 22 deletions(-) mode change 100644 => 100755 converge/Cargo.toml create mode 100755 converge/example.html mode change 100644 => 100755 converge/readme.md mode change 100644 => 100755 converge/src/main.rs create mode 100755 converge/src/timedb.rs (limited to 'converge') diff --git a/converge/Cargo.toml b/converge/Cargo.toml old mode 100644 new mode 100755 index 4dc9e4b..98481f6 --- a/converge/Cargo.toml +++ b/converge/Cargo.toml @@ -6,6 +6,9 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +bempline = "0.8.1" camino = "1.1.6" cutie = { path = "../", version = "0.1.0" } thiserror = "1.0.52" +time = { version = "0.3.31", features = ["formatting", "macros"] } +scurvy = { path = "../../scurvy" } diff --git a/converge/example.html b/converge/example.html new file mode 100755 index 0000000..970cc06 --- /dev/null +++ b/converge/example.html @@ -0,0 +1,185 @@ +/Users/gen/src/inf/served/touching-grass.html +/Users/gen/src/inf/fixtures/post.html +/Users/gen/src/inf/fixtures/base.html +Looking for html +Looking for head +Looking for title + closed title + closed head +Looking for body +Looking for ul +Looking for li +Looking for a + closed a + closed li + closed ul +Looking for main + closed main +Looking for footer +Looking for ul +Looking for li + closed li +Looking for li +Looking for abbr + closed abbr + closed li +Looking for li +Looking for abbr + closed abbr + closed li + closed ul + closed footer + closed body + closed html +Looking for nav +Looking for a + closed a + closed nav +BEFORE +Looking for main + closed main +Looking for section +Looking for video + closed video +Looking for ul +Looking for li + closed li +Looking for li +Looking for a + closed a + closed li +Looking for li +Looking for a + closed a + closed li +Looking for li + closed li +Looking for li +Looking for input +Looking for label + closed label + closed input + closed li + closed ul + closed section +Looking for script + parse special +Looking for p + closed p +Looking for p + closed p +Looking for p +Looking for span + closed span +Looking for i + closed i +Looking for span + closed span + closed p +Looking for p + closed p + + + + + + + + + + + + + + + + + +
+ + +
+ + + +

+ I took this short video to send to a friend one day and accidentally + made a 106 frame masterpiece. Well, that's hyperbolic. But there's a + lot I enjoy about it. +

+ +

+ The contrast between my orange painted nails and the surprisingly + green grass is pretty pleasing. I think the gentle brown of the brick + in the bottom-left corner helps keep from an overwhelming greenery. + Thanks bricks :) +

+ +

+ The accidental camera movement is nice, too. I like the angle the camera is at and the way it wobbles. + It's clearly hand-held. At 1.3-ish-seconds + you can see I gently sway forward, but seem to be less wobbly. I'm braced; + I'm stable! I have-three-points-of-contact-with-the-ground! Then, at roughly + 2 seconds when the grass finally + yields, I get rocked back and wobbles resume. +

+ +

+ The sound! And the sound. The ripping of the grass. That planty matter finally giving way. The fibrous tearing. + I just like it; I enjoy it! I greatly appreciate it. +

+ + + + + diff --git a/converge/readme.md b/converge/readme.md old mode 100644 new mode 100755 index 5a778c3..7fcecb5 --- a/converge/readme.md +++ b/converge/readme.md @@ -6,4 +6,9 @@ Setup: {directions} content -{directions} content \ No newline at end of file +{directions} content + +**variables converge tries to fill** + +- `{file_time_created}`: time the file was created +- `{file_time_modified}`: time the file was modified \ No newline at end of file diff --git a/converge/src/main.rs b/converge/src/main.rs old mode 100644 new mode 100755 index 20f2683..74abe67 --- a/converge/src/main.rs +++ b/converge/src/main.rs @@ -1,32 +1,30 @@ use std::str::FromStr; use camino::Utf8PathBuf; +use scurvy::Argument; fn main() { - let mut args = std::env::args().skip(1); - let argc = args.len(); - if argc == 0 { - eprintln!("usage: converge [supporting files ...]"); - return; + let arguments = [ + Argument::arg("timdb", "path").help("time database generated with whenwasit"), + Argument::arg("part", "path").help("part converge is supposed to build"), + ]; + let cli = scurvy::parse(&arguments); + + let content: Utf8PathBuf = cli.parse_opt_or_die("part"); + let supporting: Vec = cli.free_opts().into_iter().map(Utf8PathBuf::from).collect(); + + let time = std::time::Instant::now(); + for idx in 0..100 { + let supporting = supporting.clone(); + let html = process(content.clone(), supporting); } + println!("{}ms for 100", time.elapsed().as_millis()); - let content = match args.next() { - None => { - eprintln!("usage: converge [supporting files ...]"); - return; - } - Some(path) => Utf8PathBuf::from(path), - }; - - let supporting = args.map(Utf8PathBuf::from).collect(); - - let html = process(content, supporting); - println!("{html}") + //println!("{html}") } fn process(content_file: Utf8PathBuf, mut supporting: Vec) -> cutie::Html { - println!("{content_file}"); - let raw = std::fs::read_to_string(&content_file).unwrap(); + let raw = std::fs::read_to_string(content_file).unwrap(); match Part::from_str(&raw) { Err(PartError::NoSetup) => cutie::Html::parse(raw), @@ -73,7 +71,7 @@ fn process(content_file: Utf8PathBuf, mut supporting: Vec) -> cutie html: &'a mut cutie::Html, ident: &str, ) -> &'a mut cutie::Tag { - match html.get_parent_that_contains_tag_name_mut(&ident) { + match html.get_parent_that_contains_tag_name_mut(ident) { None => { eprintln!("error processing file"); eprintln!("failed to find element with tag {ident}"); @@ -93,7 +91,6 @@ fn process(content_file: Utf8PathBuf, mut supporting: Vec) -> cutie tag.children.extend(content_html.nodes); } Opcode::Before => { - println!("BEFORE"); let predicate = |node: &cutie::Node| -> bool { if let cutie::Node::Tag(tag) = node { if tag.name == ident { diff --git a/converge/src/timedb.rs b/converge/src/timedb.rs new file mode 100755 index 0000000..718115d --- /dev/null +++ b/converge/src/timedb.rs @@ -0,0 +1,97 @@ +use std::path::Path; + +use time::OffsetDateTime; + +#[derive(Debug)] +pub struct TimeDb { + data: Vec, +} + +impl TimeDb { + pub fn load>(path: P) -> Self { + let file = std::fs::read_to_string(path).unwrap(); + + let mut data = vec![]; + for line in file.lines() { + let it = TimedFile::parse_line(line); + data.push(it); + } + + Self { data } + } + + pub fn get_times(&self, path: &str) -> Option<&TimedFile> { + for file in &self.data { + if &file.path == path { + return Some(file); + } + } + + None + } +} + +#[derive(Debug)] +pub struct TimedFile { + path: String, + pub creation: Option, + pub modification: Option, + pub access: Option, +} + +impl TimedFile { + pub fn parse_line>(raw: S) -> Self { + let mut values = raw.as_ref().rsplitn(4, ",").collect::>(); + values.reverse(); + + let to_odt = |str: &&str| -> Option { + str.parse::() + .ok() + .map(|t| OffsetDateTime::from_unix_timestamp(t as i64).unwrap()) + }; + + let path = unescape(values[0]); + let creation = values.get(1).map(to_odt).flatten(); + let modification = values.get(2).map(to_odt).flatten(); + let access = values.get(3).map(to_odt).flatten(); + + Self { + path, + creation, + modification, + access, + } + } +} + +// Permissive unescape. Everything that's not \\ or \, is passed +// unchanged, while those get their slash removed +fn unescape>(raw: S) -> String { + let raw = raw.as_ref(); + + if !raw.contains('\\') { + return raw.to_owned(); + } + + let mut unescape = String::with_capacity(raw.len()); + let mut escaped = false; + for ch in raw.chars() { + match (escaped, ch) { + (false, '\\') => { + escaped = true; + } + (false, c) => unescape.push(c), + (true, '\\') | (true, ',') => { + unescape.push(ch); + escaped = false; + } + (true, c) => { + unescape.push('\\'); + unescape.push(c); + escaped = false; + } + } + } + + unescape +} -- cgit 1.4.1-3-g733a5