preps for actually reading slides in from lisp

This commit is contained in:
Chris Cochrun 2024-11-20 14:05:22 -06:00
parent 11fb5ddc71
commit 53ba0385f5
2 changed files with 111 additions and 13 deletions

View file

@ -1,14 +1,85 @@
use crisp::{
env::Environment,
types::{Symbol, Value},
};
use crisp::types::{Symbol, Value};
use crate::{Slide, SlideBuilder};
use crate::Slide;
pub fn setup_env() {
let mut env = Environment::new();
env.insert_symbol(
Symbol::from("slide"),
Value::func(|args| Ok(Value::from(args))),
)
pub fn parse_lisp(value: Value, vector: Vec<Slide>) -> Vec<Slide> {
match &value {
Value::List(vec) => match &vec[0] {
Value::Symbol(Symbol(s)) if s == "slide" => {
let slide = Slide::from(value.clone());
vec![slide]
}
Value::Symbol(Symbol(s)) if s == "song" => {
vec![Slide::default()]
}
Value::Symbol(Symbol(s)) if s == "load" => {
vec![Slide::default()]
}
_ => todo!(),
},
_ => todo!(),
}
}
#[cfg(test)]
mod test {
use std::fs::read_to_string;
use crate::{Background, SlideBuilder, TextAlignment};
use super::*;
use pretty_assertions::assert_eq;
#[test]
fn test_parsing_lisp() {
let lisp =
read_to_string("./test_presentation.lisp").expect("oops");
let lisp_value = crisp::reader::read(&lisp);
let test_vec = vec![test_slide(), test_second_slide()];
match lisp_value {
Value::List(value) => {
let mut slide_vec = vec![];
for value in value {
let inner_vector = vec![];
let mut vec = parse_lisp(value, inner_vector);
slide_vec.append(&mut vec);
}
assert_eq!(slide_vec, test_vec)
}
_ => panic!("this should be a lisp"),
}
}
fn test_slide() -> Slide {
SlideBuilder::new()
.text("This is frodo")
.background(
Background::try_from("~/pics/frodo.jpg").unwrap(),
)
.font("Quicksand")
.font_size(70)
.text_alignment(TextAlignment::MiddleCenter)
.video_loop(false)
.video_start_time(0.0)
.video_end_time(0.0)
.build()
.unwrap()
}
fn test_second_slide() -> Slide {
SlideBuilder::new()
.text("")
.background(
Background::try_from("~/vids/test/camprules2024.mp4")
.unwrap(),
)
.font("Quicksand")
.font_size(0)
.text_alignment(TextAlignment::MiddleCenter)
.video_loop(false)
.video_start_time(0.0)
.video_end_time(0.0)
.build()
.unwrap()
}
}

View file

@ -13,8 +13,12 @@ use cosmic::widget::{
use cosmic::widget::{icon, slider};
use cosmic::{executor, Application, ApplicationExt, Element};
use cosmic::{widget::Container, Theme};
use crisp::types::Value;
use lisp::parse_lisp;
use miette::{miette, Result};
use std::fs::read_to_string;
use std::path::PathBuf;
use tracing::warn;
use tracing::{debug, level_filters::LevelFilter};
use tracing_subscriber::EnvFilter;
@ -144,6 +148,29 @@ impl cosmic::Application for App {
windows.push(core.main_window_id().unwrap());
}
let slides = match read_to_string(input.file) {
Ok(lisp) => {
let mut slide_vector = vec![];
let lisp = crisp::reader::read(&lisp);
match lisp {
Value::List(vec) => {
for value in vec {
let inner_vector = vec![];
let mut inner_vector =
parse_lisp(value, inner_vector);
slide_vector.append(&mut inner_vector);
}
}
_ => todo!(),
}
slide_vector
}
Err(e) => {
warn!("Missing file or could not read: {e}");
vec![]
}
};
let initial_slide = SlideBuilder::new()
.background(
Background::try_from(
@ -191,8 +218,8 @@ impl cosmic::Application for App {
.build()
.expect("oops slide");
let slides =
vec![initial_slide.clone(), second_slide, tetrary_slide];
// let slides =
// vec![initial_slide.clone(), second_slide, tetrary_slide];
let presenter = Presenter::with_slides(slides.clone());
let mut app = App {
presenter,