mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
This commit is contained in:
parent
34070de5f7
commit
07894e094e
4 changed files with 29 additions and 41 deletions
|
|
@ -2,19 +2,15 @@ use crate::*;
|
|||
|
||||
impl Content<TuiOut> for App {
|
||||
fn content (&self) -> impl Render<TuiOut> + '_ {
|
||||
Stack::above(move|add|for dsl in self.mode.view.iter() {
|
||||
add(&Fill::xy(self.view(dsl.as_ref())));
|
||||
})
|
||||
let mode = self.mode.clone();
|
||||
Stack::above(move|add|for dsl in mode.view.iter() { add(&self.view(dsl)) })
|
||||
}
|
||||
}
|
||||
|
||||
impl App {
|
||||
fn view <'t, D: Dsl> (&'t self, index: D) -> TuiBox<'t> {
|
||||
match index.src() {
|
||||
Ok(Some(src)) => render_dsl(self, src),
|
||||
Ok(None) => Box::new(Tui::fg(Color::Rgb(192, 192, 192), "empty view")),
|
||||
Err(e) => Box::new(format!("{e}")),
|
||||
}
|
||||
fn view <'t> (&'t self, dsl: impl Dsl) -> impl Render<TuiOut> + 't {
|
||||
let view: TuiBox<'t> = self.from(dsl).unwrap().unwrap();
|
||||
view
|
||||
}
|
||||
pub fn update_clock (&self) {
|
||||
ViewCache::update_clock(&self.project.clock.view_cache, self.clock(), self.size.w() > 80)
|
||||
|
|
@ -23,28 +19,22 @@ impl App {
|
|||
|
||||
type TuiBox<'t> = Box<dyn Render<TuiOut> + 't>;
|
||||
|
||||
fn render_dsl <'t> (
|
||||
state: &'t impl DslNs<'t, TuiBox<'t>>,
|
||||
src: &str
|
||||
) -> TuiBox<'t> {
|
||||
let err: Option<Box<dyn Error>> = match state.from(&src) {
|
||||
Ok(Some(value)) => return value, Ok(None) => None, Err(e) => Some(e),
|
||||
};
|
||||
fn render_error (err: impl Error, src: &str) -> impl Render<TuiOut> {
|
||||
let (fg_1, bg_1) = (Color::Rgb(240, 160, 100), Color::Rgb(48, 0, 0));
|
||||
let (fg_2, bg_2) = (Color::Rgb(250, 200, 180), Color::Rgb(48, 0, 0));
|
||||
let (fg_3, bg_3) = (Color::Rgb(250, 200, 120), Color::Rgb(0, 0, 0));
|
||||
let bg = Color::Rgb(24, 0, 0);
|
||||
Box::new(col! {
|
||||
col! {
|
||||
Tui::fg(bg, Fixed::y(1, Fill::x(RepeatH("▄")))),
|
||||
Tui::bg(bg, col! {
|
||||
Fill::x(Bsp::e(
|
||||
Tui::bold(true, Tui::fg_bg(fg_1, bg_1, " Render error: ")),
|
||||
Tui::fg_bg(fg_2, bg_2, err.map(|e|format!(" {e} "))),
|
||||
Tui::fg_bg(fg_2, bg_2, format!(" {err} ")),
|
||||
)),
|
||||
Fill::x(Align::x(Tui::fg_bg(fg_3, bg_3, format!(" {src} ")))),
|
||||
}),
|
||||
Tui::fg(bg, Fixed::y(1, Fill::x(RepeatH("▀")))),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<'t> DslNs<'t, TuiBox<'t>> for App {
|
||||
|
|
@ -169,7 +159,7 @@ impl<'t> DslNs<'t, TuiBox<'t>> for App {
|
|||
Fill::x(Tui::bg(bg, Bsp::e(lb, Bsp::w(rb, "FIXME device name")))) }))) },
|
||||
});
|
||||
/// Resolve an expression if known.
|
||||
fn from_expr <D: Dsl> (&self, dsl: &D) -> Perhaps<TuiBox<'t>> {
|
||||
fn from_expr (&self, dsl: impl Dsl) -> Perhaps<TuiBox<'t>> {
|
||||
if let Some(head) = dsl.expr().head()? {
|
||||
for (key, value) in Self::EXPRS.0.iter() {
|
||||
if head == *key {
|
||||
|
|
@ -180,13 +170,13 @@ impl<'t> DslNs<'t, TuiBox<'t>> for App {
|
|||
return Ok(None)
|
||||
}
|
||||
/// Resolve a symbol if known.
|
||||
fn from_word <D: Dsl> (&self, dsl: &D) -> Perhaps<TuiBox<'t>> {
|
||||
fn from_word (&self, dsl: impl Dsl) -> Perhaps<TuiBox<'t>> {
|
||||
if let Some(dsl) = dsl.word()? {
|
||||
let views = self.config.views.read().unwrap();
|
||||
if let Some(view) = views.get(dsl) {
|
||||
let view = view.clone();
|
||||
std::mem::drop(views);
|
||||
return Ok(Some(render_dsl(self, view.as_ref())))
|
||||
return Ok(Some(self.view(view.as_ref())))
|
||||
}
|
||||
for (word, get) in Self::WORDS.0 {
|
||||
if dsl == *word {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue