wip: framework rework
Some checks failed
/ build (push) Has been cancelled

This commit is contained in:
🪞👃🪞 2025-05-25 22:48:48 +03:00
parent 287983c140
commit ed848c2669
3 changed files with 43 additions and 41 deletions

View file

@ -327,16 +327,16 @@ pub struct Configuration {
/// Description of configuration /// Description of configuration
pub info: Option<Arc<str>>, pub info: Option<Arc<str>>,
/// View definition /// View definition
pub view: TokenIter<'static>, pub view: Cst,
// Input keymap // Input keymap
pub keys: InputMap<'static, App, AppCommand, TuiIn, TokenIter<'static>>, pub keys: InputMap<App, AppCommand, TuiIn, Cst>,
} }
impl Configuration { impl Configuration {
pub fn new (path: &impl AsRef<Path>, _watch: bool) -> Usually<Self> { pub fn new (path: &impl AsRef<Path>, _watch: bool) -> Usually<Self> {
let text = read_and_leak(path.as_ref())?; let text = read_and_leak(path.as_ref())?;
let [name, info, view, keys] = Self::parse(TokenIter::from(text))?; let [name, info, view, keys] = Self::parse(Cst::from(text))?;
Ok(Self { Ok(Self {
path: path.as_ref().into(), path: path.as_ref().into(),
info: info.map(Self::parse_info).flatten(), info: info.map(Self::parse_info).flatten(),
@ -346,11 +346,11 @@ impl Configuration {
}) })
} }
fn parse (iter: TokenIter) -> Usually<[Option<TokenIter>;4]> { fn parse (iter: Cst) -> Usually<[Option<Cst>;4]> {
let mut name: Option<TokenIter> = None; let mut name: Option<Cst> = None;
let mut info: Option<TokenIter> = None; let mut info: Option<Cst> = None;
let mut view: Option<TokenIter> = None; let mut view: Option<Cst> = None;
let mut keys: Option<TokenIter> = None; let mut keys: Option<Cst> = None;
for token in iter { for token in iter {
match token.value { match token.value {
Value::Exp(_, mut exp) => { Value::Exp(_, mut exp) => {
@ -378,7 +378,7 @@ impl Configuration {
Ok([name, info, view, keys]) Ok([name, info, view, keys])
} }
fn parse_info (mut iter: TokenIter) -> Option<Arc<str>> { fn parse_info (mut iter: Cst) -> Option<Arc<str>> {
iter.next().and_then(|x|if let Value::Str(x) = x.value { iter.next().and_then(|x|if let Value::Str(x) = x.value {
Some(x.into()) Some(x.into())
} else { } else {
@ -386,7 +386,7 @@ impl Configuration {
}) })
} }
fn parse_name (mut iter: TokenIter) -> Option<Arc<str>> { fn parse_name (mut iter: Cst) -> Option<Arc<str>> {
iter.next().and_then(|x|if let Value::Str(x) = x.value { iter.next().and_then(|x|if let Value::Str(x) = x.value {
Some(x.into()) Some(x.into())
} else { } else {
@ -394,7 +394,7 @@ impl Configuration {
}) })
} }
fn parse_view (iter: Option<TokenIter>) -> Usually<TokenIter> { fn parse_view (iter: Option<Cst>) -> Usually<Cst> {
if let Some(view) = iter { if let Some(view) = iter {
Ok(view) Ok(view)
} else { } else {
@ -402,8 +402,8 @@ impl Configuration {
} }
} }
fn parse_keys (base: &impl AsRef<Path>, iter: Option<TokenIter<'static>>) fn parse_keys (base: &impl AsRef<Path>, iter: Option<Cst>)
-> Usually<InputMap<'static, App, AppCommand, TuiIn, TokenIter<'static>>> -> Usually<InputMap<App, AppCommand, TuiIn, Cst>>
{ {
if iter.is_none() { if iter.is_none() {
return Err(format!("missing keys definition").into()) return Err(format!("missing keys definition").into())

View file

@ -24,45 +24,47 @@ impl<T: Content<TuiOut>> Content<TuiOut> for ErrorBoundary<TuiOut, T> {
impl App { impl App {
pub fn view (model: &Self) -> impl Content<TuiOut> + '_ { pub fn view (model: &Self) -> impl Content<TuiOut> + '_ {
ErrorBoundary::new(Ok(Some(Tui::bg(Black, "give or take")))) ErrorBoundary::new(Ok(Some(Tui::bg(Black, model.view_nil()))))
//ErrorBoundary::new(Take::take(model, &mut model.config.view.clone())) //ErrorBoundary::new(Take::take(model, &mut model.config.view.clone()))
//ErrorBoundary::new(Give::give(model, &mut model.config.view.clone())) //ErrorBoundary::new(Give::give(model, &mut model.config.view.clone()))
} }
} }
content!(TuiOut: |self: App| ErrorBoundary::new(Ok(Some(Tui::bg(Black, self.view_nil())))));
#[tengri_proc::view(TuiOut)] #[tengri_proc::view(TuiOut)]
impl App { impl App {
//pub fn view_nil (model: &Self) -> impl Content<TuiOut> { pub fn view_nil (&self) -> impl Content<TuiOut> + '_ {
//"nil" "nil"
//} }
//pub fn view_dialog (model: &Self) -> impl Content<TuiOut> + use<'_> { pub fn view_dialog (&self) -> impl Content<TuiOut> + use<'_> {
//model.dialog.as_ref().map(|dialog|Bsp::b("", self.dialog.as_ref().map(|dialog|Bsp::b("",
//Fixed::xy(70, 23, Tui::fg_bg(Rgb(255,255,255), Rgb(16,16,16), Bsp::b( Fixed::xy(70, 23, Tui::fg_bg(Rgb(255,255,255), Rgb(16,16,16), Bsp::b(
//Repeat(" "), Outer(true, Style::default().fg(Tui::g(96))) Repeat(" "), Outer(true, Style::default().fg(Tui::g(96)))
//.enclose(dialog)))))) .enclose(dialog))))))
//} }
//pub fn view_meters_input (model: &Self) -> impl Content<TuiOut> + use<'_> { //pub fn view_meters_input (&self) -> impl Content<TuiOut> + use<'_> {
//model.project.sampler().map(|s| //self.project.sampler().map(|s|
//s.view_meters_input()) //s.view_meters_input())
//} //}
//pub fn view_meters_output (model: &Self) -> impl Content<TuiOut> + use<'_> { //pub fn view_meters_output (&self) -> impl Content<TuiOut> + use<'_> {
//model.project.sampler().map(|s| //self.project.sampler().map(|s|
//s.view_meters_output()) //s.view_meters_output())
//} //}
//pub fn view_history (model: &Self) -> impl Content<TuiOut> { //pub fn view_history (&self) -> impl Content<TuiOut> {
//Fixed::y(1, Fill::x(Align::w(FieldH(model.color, //Fixed::y(1, Fill::x(Align::w(FieldH(self.color,
//format!("History ({})", model.history.len()), //format!("History ({})", self.history.len()),
//model.history.last().map(|last|Fill::x(Align::w(format!("{:?}", last.0)))))))) //self.history.last().map(|last|Fill::x(Align::w(format!("{:?}", last.0))))))))
//} //}
//pub fn view_status_h2 (model: &Self) -> impl Content<TuiOut> { //pub fn view_status_h2 (&self) -> impl Content<TuiOut> {
//model.update_clock(); //self.update_clock();
//let theme = model.color; //let theme = self.color;
//let clock = model.clock(); //let clock = self.clock();
//let playing = clock.is_rolling(); //let playing = clock.is_rolling();
//let cache = clock.view_cache.clone(); //let cache = clock.view_cache.clone();
////let selection = model.selection().describe(model.tracks(), model.scenes()); ////let selection = self.selection().describe(self.tracks(), self.scenes());
//let hist_len = model.history.len(); //let hist_len = self.history.len();
//let hist_last = model.history.last(); //let hist_last = self.history.last();
//Fixed::y(2, Stack::east(move|add: &mut dyn FnMut(&dyn Render<TuiOut>)|{ //Fixed::y(2, Stack::east(move|add: &mut dyn FnMut(&dyn Render<TuiOut>)|{
//add(&Fixed::x(5, Tui::bg(if playing { Rgb(0, 128, 0) } else { Rgb(128, 64, 0) }, //add(&Fixed::x(5, Tui::bg(if playing { Rgb(0, 128, 0) } else { Rgb(128, 64, 0) },
//Either::new(false, // TODO //Either::new(false, // TODO
@ -97,8 +99,8 @@ impl App {
////hist_last.map(|last|Fill::x(Align::w(format!("{:?}", last.0))))))), ////hist_last.map(|last|Fill::x(Align::w(format!("{:?}", last.0))))))),
////"" ////""
////)); ////));
//////if let Some(last) = model.history.last() { //////if let Some(last) = self.history.last() {
//////add(&FieldV(theme, format!("History ({})", model.history.len()), //////add(&FieldV(theme, format!("History ({})", self.history.len()),
//////Fill::x(Align::w(format!("{:?}", last.0))))); //////Fill::x(Align::w(format!("{:?}", last.0)))));
//////} //////}
//} //}

2
deps/tengri vendored

@ -1 +1 @@
Subproject commit 31e84bf5b3a44fb0b51f853f135109ea184ace84 Subproject commit f1b24d436a890b75cf98aaa0f2d29d10ed660106