diff --git a/src/config.rs b/src/config.rs index 208a123b..bd8d7dbb 100644 --- a/src/config.rs +++ b/src/config.rs @@ -148,7 +148,7 @@ pub fn load_view <'a> (views: &Views, expr: impl Language) -> UsuallyRef<'a, ()> pub fn load_bind <'a> (binds: &Binds, expr: impl Language) -> UsuallyRef<'a, ()> { let name = expr.head()?.ok_or("bind: missing name")?; - let body = expr.tail()?.ok_or("bind: missing body")?; + let body = expr.tail()?.unwrap_or(""); binds.write().unwrap().insert(name.into(), { let mut map = Bind::new(); body.each((), |_, item: &str|if item.expr().head() == Ok(Some("see")) { diff --git a/src/device/arrange/clip.rs b/src/device/arrange/clip.rs index f3ccdf86..aaed1248 100644 --- a/src/device/arrange/clip.rs +++ b/src/device/arrange/clip.rs @@ -70,7 +70,7 @@ impl ClipsView for T {} pub trait ClipsView: TracksView + ScenesView { /// Draw clips per scene - fn view_scenes_clips (&self) -> impl Draw<'_, Tui> { + fn view_scenes_clips (&self) -> impl Draw { let select = self.selection(); let editor = self.editor(); let size = self.clips_size(); @@ -105,7 +105,7 @@ pub trait ClipsView: TracksView + ScenesView { fg_bg(o, b, "".full_wh()), fg_bg(f, b, bold(true, name)).align_nw().full_wh(), ), - when(is_selected, editor.map(|e|e.view())).full_wh() + when(is_selected, editor).full_wh() ).full_wh() ).exact_wh(w, y) })).full_h().exact_w(track.width as u16) diff --git a/src/device/arrange/port.rs b/src/device/arrange/port.rs index 48b6a0c1..38ae3997 100644 --- a/src/device/arrange/port.rs +++ b/src/device/arrange/port.rs @@ -5,24 +5,24 @@ impl_has!(Vec: |self: Arrangement| self.midi_outs); impl_has!(Vec: |self: App|self.project.midi_ins); impl_has!(Vec: |self: App|self.project.midi_outs); -pub fn view_midi_ins_status (theme: ItemTheme, track: Option<&Track>) -> impl Draw<'_, Tui> { +pub fn view_midi_ins_status (theme: ItemTheme, track: Option<&Track>) -> impl Draw { track.map(move|track|view_ports_status(theme, "MIDI ins: ", &track.sequencer.midi_ins)) } -pub fn view_midi_outs_status (theme: ItemTheme, track: Option<&Track>) -> impl Draw<'_, Tui> { +pub fn view_midi_outs_status (theme: ItemTheme, track: Option<&Track>) -> impl Draw { track.map(move|track|view_ports_status(theme, "MIDI outs: ", &track.sequencer.midi_outs)) } -pub fn view_audio_ins_status (theme: ItemTheme, track: Option<&Track>) -> impl Draw<'_, Tui> { +pub fn view_audio_ins_status (theme: ItemTheme, track: Option<&Track>) -> impl Draw { track.map(move|track|view_ports_status(theme, "Audio ins: ", &track.audio_ins())) } -pub fn view_audio_outs_status (theme: ItemTheme, track: Option<&Track>) -> impl Draw<'_, Tui> { +pub fn view_audio_outs_status (theme: ItemTheme, track: Option<&Track>) -> impl Draw { track.map(move|track|view_ports_status(theme, "Audio outs:", &track.audio_outs())) } pub fn view_ports_status <'a, T: JackPort> (theme: ItemTheme, title: &'a str, ports: &'a [T]) - -> impl Draw<'a, Tui> + use<'a, T> + -> impl Draw + use<'a, T> { let ins = ports.len() as u16; let frame = Outer(true, Style::default().fg(g(96))); @@ -35,7 +35,7 @@ pub fn view_ports_status <'a, T: JackPort> (theme: ItemTheme, title: &'a str, po pub fn view_io_ports <'a, T: PortsSizes<'a>> ( fg: Color, bg: Color, items: impl Fn()->T + Send + Sync + 'a -) -> impl Draw<'a, Tui> + 'a { +) -> impl Draw + 'a { type Item<'a> = (usize, &'a Arc, &'a [Connect], usize, usize); iter(items, move|(_index, name, connections, y, y2): Item<'a>, _| south( @@ -48,9 +48,9 @@ pub fn view_io_ports <'a, T: PortsSizes<'a>> ( pub struct Junction(T); -impl View for Junction { - fn view (&self) -> impl Draw<'_, Tui> { - T::KIND +impl Draw for Junction { + fn draw (&self, to: &mut Tui) -> Drawn { + T::KIND.draw(to) } } diff --git a/src/device/arrange/scene.rs b/src/device/arrange/scene.rs index 99295d09..6de330c9 100644 --- a/src/device/arrange/scene.rs +++ b/src/device/arrange/scene.rs @@ -203,7 +203,7 @@ pub trait ScenesView: HasEditor + HasSelection + HasSceneScroll + HasClipsSize + fn w_side (&self) -> u16; fn w_mid (&self) -> u16; - fn view_scenes_names (&self) -> impl Draw<'_, Tui> { + fn view_scenes_names (&self) -> impl Draw { let select = self.selection(); let editor = self.editor(); let editing = self.is_editing(); @@ -281,7 +281,7 @@ pub fn view_scene_name <'a> ( index: usize, scene: &Scene, editing: bool -) -> impl Draw<'a, Tui> { +) -> impl Draw { let h = if select.scene() == Some(index) && let Some(_editor) = editor { 7 } else { diff --git a/src/device/arrange/track.rs b/src/device/arrange/track.rs index c6d9712d..fc694fce 100644 --- a/src/device/arrange/track.rs +++ b/src/device/arrange/track.rs @@ -46,10 +46,10 @@ impl Track { pub fn audio_outs (&self) -> &[AudioOutput] { self.devices.last().map(|x|x.audio_outs()).unwrap_or_default() } - pub fn per <'a, T: Draw<'a, Tui> + 'a, U: TracksSizes<'a>> ( + pub fn per <'a, T: Draw + 'a, U: TracksSizes<'a>> ( tracks: impl Fn() -> U + Send + Sync + 'a, callback: &'a (impl Fn(usize, &'a Track)->T + Send + Sync + 'a) - ) -> impl Draw<'a, Tui> { + ) -> impl Draw { iter_east(move||tracks().map(|(index, track, x1, x2): (usize, &Track, usize, usize)|{ fg_bg( track.color.lightest.term, @@ -343,7 +343,7 @@ pub trait TracksView: HasTracks + ScenesView + HasMidiIns + HasMidiOuts + HasTra } /// Draw name of each track - fn view_track_names (&self, theme: ItemTheme) -> impl Draw<'_, Tui> { + fn view_track_names (&self, theme: ItemTheme) -> impl Draw { let selected = self.selection(); east( south( @@ -397,7 +397,7 @@ pub trait TracksView: HasTracks + ScenesView + HasMidiIns + HasMidiOuts + HasTra } /// Draw outputs per track - fn view_track_outputs <'a> (&'a self, theme: ItemTheme, _h: u16) -> impl Draw<'a, Tui> { + fn view_track_outputs <'a> (&'a self, theme: ItemTheme, _h: u16) -> impl Draw { view_track_row_section(theme, south(button_2("o", "utput", false).align_w().full_w(), draw(|to: &mut Tui|{ @@ -432,7 +432,7 @@ pub trait TracksView: HasTracks + ScenesView + HasMidiIns + HasMidiOuts + HasTra } /// Draw inputs per track - fn view_track_inputs <'a> (&'a self, theme: ItemTheme) -> impl Draw<'a, Tui> { + fn view_track_inputs <'a> (&'a self, theme: ItemTheme) -> impl Draw { let mut height = 0u16; for track in self.tracks().iter() { height = height.max(track.sequencer.midi_ins.len() as u16); @@ -460,7 +460,7 @@ pub trait TracksView: HasTracks + ScenesView + HasMidiIns + HasMidiOuts + HasTra }).align_w())) } - fn view_track_devices (&self, theme: ItemTheme) -> impl Draw<'_, Tui> { + fn view_track_devices (&self, theme: ItemTheme) -> impl Draw { let height = self.tracks_devices_height(); let btn1 = button_3("d", "evice", self.track().map(|t|t.devices.len()).unwrap_or(0), false); let btn2 = button_2("D", "+", false); @@ -489,7 +489,7 @@ pub trait TracksView: HasTracks + ScenesView + HasMidiIns + HasMidiOuts + HasTra h as u16 } - fn view_inputs (&self, _theme: ItemTheme) -> impl Draw<'_, Tui> + '_ { + fn view_inputs (&self, _theme: ItemTheme) -> impl Draw + '_ { let title_1 = button_3("i", "nput ", self.midi_ins().len(), false).align_w().exact_wh(20, 1); let title_2 = button_2("I", "+", false).exact_wh(4, 1); east(title_1, west(title_2, draw(move|to: &mut Tui|{ @@ -533,7 +533,7 @@ pub trait TracksView: HasTracks + ScenesView + HasMidiIns + HasMidiOuts + HasTra h as u16 } - fn view_outputs (&self, theme: ItemTheme) -> impl Draw<'_, Tui> { + fn view_outputs (&self, theme: ItemTheme) -> impl Draw { let height = self.outputs_height(); let list = south( button_3( @@ -633,10 +633,10 @@ impl HasTrackScroll for App { fn view_track_row_section <'a> ( _theme: ItemTheme, - button: impl Draw<'a, Tui>, - button_add: impl Draw<'a, Tui>, - content: impl Draw<'a, Tui>, -) -> impl Draw<'a, Tui> { + button: impl Draw, + button_add: impl Draw, + content: impl Draw, +) -> impl Draw { west( button_add.align_nw().exact_w(4).full_h(), east( diff --git a/src/device/browse.rs b/src/device/browse.rs index 74269e57..be3bb3ec 100644 --- a/src/device/browse.rs +++ b/src/device/browse.rs @@ -118,7 +118,7 @@ impl Browse { unreachable!() }) } - //fn tui (&self) -> impl Draw<'_, Tui> { + //fn tui (&self) -> impl Draw { //iter_south_fixed(1, ||self.tui_entries(), |entry, _index|entry.origin_w().full_w()) //} //fn tui_entries (&self) -> EntriesIterator<'_, Tui> { @@ -133,7 +133,7 @@ impl Browse { } //impl<'a> Iterator for EntriesIterator<'a, Tui> { - //type Item = impl Draw<'_, Tui>; + //type Item = impl Draw; //fn next (&mut self) -> Option { //let dirs = self.browser.dirs.len(); //let files = self.browser.files.len(); @@ -179,7 +179,7 @@ pub fn scan (dir: &PathBuf) -> Usually<(Vec, Vec)> { Ok((subdirs, files)) } -pub fn view_browse_title (state: &App) -> impl Draw<'_, Tui> { +pub fn view_browse_title (state: &App) -> impl Draw { field_v(ItemTheme::default(), match state.dialog.browser_target().unwrap() { BrowseTarget::SaveProject => "Save project:", BrowseTarget::LoadProject => "Load project:", diff --git a/src/device/clock.rs b/src/device/clock.rs index 808ce214..b058e24a 100644 --- a/src/device/clock.rs +++ b/src/device/clock.rs @@ -462,7 +462,7 @@ impl_time_unit!(LaunchSync); /// let _ = tek::view_transport(true, x.as_ref(), x.as_ref(), x.as_ref()); /// let _ = tek::view_transport(false, x.as_ref(), x.as_ref(), x.as_ref()); /// ``` -pub fn view_transport <'a> (play: bool, bpm: &str, beat: &str, time: &str) -> impl Draw<'a, Tui> { +pub fn view_transport <'a> (play: bool, bpm: &str, beat: &str, time: &str) -> impl Draw { let theme = ItemTheme::G[96]; bg(Black, east!(above( button_play_pause(play, false).align_w(), @@ -479,7 +479,7 @@ pub fn view_transport <'a> (play: bool, bpm: &str, beat: &str, time: &str) -> im /// let _ = tek::view_status(None, x.as_ref(), x.as_ref(), x.as_ref()); /// let _ = tek::view_status(Some("".into()), x.as_ref(), x.as_ref(), x.as_ref()); /// ``` -pub fn view_status <'a> (sel: Option<&str>, sr: &str, buf: &str, lat: &str) -> impl Draw<'a, Tui> { +pub fn view_status <'a> (sel: Option<&str>, sr: &str, buf: &str, lat: &str) -> impl Draw { let theme = ItemTheme::G[96]; let sr = field_h(theme, "SR", sr); let buf = field_h(theme, "Buf", buf); @@ -496,7 +496,7 @@ pub fn view_status <'a> (sel: Option<&str>, sr: &str, buf: &str, lat: &str) -> i /// let _ = tek::button_play_pause(false, true); /// let _ = tek::button_play_pause(false, false); /// ``` -pub fn button_play_pause <'a> (playing: bool, compact: bool) -> impl Draw<'a, Tui> { +pub fn button_play_pause <'a> (playing: bool, compact: bool) -> impl Draw { bg(if playing { Rgb(0, 128, 0) } else { Rgb(128, 64, 0) }, either(compact, draw(move|to: &mut Tui|either(playing, diff --git a/src/device/dialog.rs b/src/device/dialog.rs index cc8913fd..03941dcb 100644 --- a/src/device/dialog.rs +++ b/src/device/dialog.rs @@ -1,7 +1,7 @@ use crate::{*, device::*}; pub fn draw_dialog <'a> (to: &mut Tui, mut frags: std::str::Split<&str>, state: &App) - -> Drawn<'a, u16> + -> Drawn { match frags.next() { Some("menu") => if let Dialog::Menu(selected, items) = &state.dialog { diff --git a/src/device/editor.rs b/src/device/editor.rs index 3efdf235..b06107d4 100644 --- a/src/device/editor.rs +++ b/src/device/editor.rs @@ -268,7 +268,7 @@ impl MidiEditor { self.get_time_pos().overflowing_sub(1) .0.min(self.clip_length().saturating_sub(1)) } - pub fn clip_status (&self) -> impl Draw<'_, Tui> + '_ { + pub fn clip_status (&self) -> impl Draw + '_ { let (_color, name, length, looped) = if let Some(clip) = self.clip().as_ref().map(|p|p.read().unwrap()) { (clip.color, clip.name.clone(), clip.length, clip.looped) } else { (ItemTheme::G[64], String::new().into(), 0, false) }; @@ -281,7 +281,7 @@ impl MidiEditor { .origin_w().full_w(), ).exact_w(20) } - pub fn edit_status (&self) -> impl Draw<'_, Tui> + '_ { + pub fn edit_status (&self) -> impl Draw + '_ { let (_color, length) = if let Some(clip) = self.clip().as_ref().map(|p|p.read().unwrap()) { (clip.color, clip.length) } else { (ItemTheme::G[64], 0) }; @@ -425,11 +425,11 @@ impl MidiViewer for MidiEditor { fn set_clip (&mut self, p: Option<&Arc>>) { self.mode.set_clip(p) } } -impl View for MidiEditor { - fn view (&self) -> impl Draw<'_, Tui> { +impl Draw for MidiEditor { + fn draw (&self, to: &mut Tui) -> Drawn { self.autoscroll(); /*self.autozoom();*/ - self.size.of(self.mode.view()) + self.size.of(&self.mode).draw(to) } } diff --git a/src/device/editor/octave.rs b/src/device/editor/octave.rs index 46642120..21124e98 100644 --- a/src/device/editor/octave.rs +++ b/src/device/editor/octave.rs @@ -19,7 +19,7 @@ impl OctaveVertical { } impl OctaveVertical { - pub fn tui (&self) -> impl Draw<'_, Tui> { + pub fn tui (&self) -> impl Draw { east!( fg_bg(self.color(0), self.color(1), "▙"), fg_bg(self.color(2), self.color(3), "▙"), diff --git a/src/device/editor/piano.rs b/src/device/editor/piano.rs index b26a8f28..7a6ee3aa 100644 --- a/src/device/editor/piano.rs +++ b/src/device/editor/piano.rs @@ -24,8 +24,8 @@ pub struct PianoHorizontal { impl_has!(Sizer: |self: PianoHorizontal| self.size); -impl View for PianoHorizontal { - fn view (&self) -> impl Draw<'_, Tui> { +impl Draw for PianoHorizontal { + fn draw (&self, to: &mut Tui) -> Drawn { south( east( format!("{}x{}", self.size.w(), self.size.h()).exact_w(5), @@ -35,7 +35,7 @@ impl View for PianoHorizontal { self.keys(), self.size.of(below(self.notes().full_wh(), self.cursor().full_wh())) ), - ) + ).draw(to) } } @@ -132,7 +132,7 @@ impl PianoHorizontal { } } - fn notes (&self) -> impl Draw<'_, Tui> { + fn notes (&self) -> impl Draw { let time_start = self.get_time_start(); let note_lo = self.get_note_lo(); let note_hi = self.get_note_hi(); @@ -168,7 +168,7 @@ impl PianoHorizontal { }) } - fn cursor (&self) -> impl Draw<'_, Tui> { + fn cursor (&self) -> impl Draw { let note_hi = self.get_note_hi(); let note_lo = self.get_note_lo(); let note_pos = self.get_note_pos(); @@ -202,7 +202,7 @@ impl PianoHorizontal { }) } - fn keys (&self) -> impl Draw<'_, Tui> { + fn keys (&self) -> impl Draw { let state = self; let color = state.color; let note_lo = state.get_note_lo(); @@ -229,7 +229,7 @@ impl PianoHorizontal { }).exact_w(self.keys_width).full_h() } - fn timeline (&self) -> impl Draw<'_, Tui> + '_ { + fn timeline (&self) -> impl Draw + '_ { draw(move|to: &mut Tui|{ let xywh = to.area().into(); let XYWH(x, y, w, _h) = xywh; diff --git a/src/device/meter.rs b/src/device/meter.rs index 23e72649..52c17949 100644 --- a/src/device/meter.rs +++ b/src/device/meter.rs @@ -40,7 +40,7 @@ impl_draw!(|self: Log10Meter, to: Tui| { Ok(Some(to.area().into())) }); -fn draw_meters (meters: &[f32]) -> impl Draw<'_, Tui> + use<'_> { +fn draw_meters (meters: &[f32]) -> impl Draw + use<'_> { bg(Black, iter_east_fixed(1, ||meters.iter(), |value, _index|{ RmsMeter(*value).full_h() }).exact_w(2)) diff --git a/src/device/sampler.rs b/src/device/sampler.rs index 426e8a85..f9203341 100644 --- a/src/device/sampler.rs +++ b/src/device/sampler.rs @@ -330,7 +330,7 @@ fn draw_list_item (sample: &Option>>) -> String { } } -fn draw_viewer (sample: Option<&Arc>>) -> impl Draw<'_, Tui> + use<'_> { +fn draw_viewer (sample: Option<&Arc>>) -> impl Draw + use<'_> { let min_db = -64.0; draw(move|to: &mut Tui|{ let xywh = to.area().into(); @@ -750,7 +750,7 @@ fn read_sample_data (_: &str) -> Usually<(usize, Vec>)> { todo!(); } -pub fn view_sample_info (sample: Option<&Arc>>) -> impl Draw<'_, Tui> + use<'_> { +pub fn view_sample_info (sample: Option<&Arc>>) -> impl Draw + use<'_> { when(sample.is_some(), draw(move|to: &mut Tui|{ let sample = sample.unwrap().read().unwrap(); let theme = sample.color; @@ -765,7 +765,7 @@ pub fn view_sample_info (sample: Option<&Arc>>) -> impl Draw<'_, })) } -pub fn view_sample_info_v (sample: Option<&Arc>>) -> impl Draw<'_, Tui> + use<'_> { +pub fn view_sample_info_v (sample: Option<&Arc>>) -> impl Draw + use<'_> { let a = draw(move|to: &mut Tui|{ let sample = sample.unwrap().read().unwrap(); let theme = sample.color; @@ -788,7 +788,7 @@ pub fn view_sample_info_v (sample: Option<&Arc>>) -> impl Draw<'_ either(sample.is_some(), a, b) } -pub fn view_sample_status (sample: Option<&Arc>>) -> impl Draw<'_, Tui> { +pub fn view_sample_status (sample: Option<&Arc>>) -> impl Draw { bold(true, fg(g(224), sample .map(|sample|{ let sample = sample.read().unwrap(); diff --git a/src/device/sequence.rs b/src/device/sequence.rs index 302c8392..1ccc1d9d 100644 --- a/src/device/sequence.rs +++ b/src/device/sequence.rs @@ -113,7 +113,7 @@ pub trait HasPlayClip: HasClock { *self.reset_mut() = true; } - fn play_status (&self) -> impl Draw<'_, Tui> { + fn play_status (&self) -> impl Draw { let (name, color): (Arc, ItemTheme) = if let Some((_, Some(clip))) = self.play_clip() { let MidiClip { ref name, color, .. } = *clip.read().unwrap(); (name.clone(), color) @@ -130,7 +130,7 @@ pub trait HasPlayClip: HasClock { .into() } - fn next_status (&self) -> impl Draw<'_, Tui> { + fn next_status (&self) -> impl Draw { let mut time: Arc = String::from("--.-.--").into(); let mut name: Arc = String::from("").into(); let mut color = ItemTheme::G[64]; diff --git a/src/tek.edn b/src/tek.edn index 5330b32c..2698ee44 100644 --- a/src/tek.edn +++ b/src/tek.edn @@ -1,7 +1,4 @@ -(view :logo (bsp/s (bg (rgb 100 70 40) (text ~~ ╓─╥─╖ ╓──╖ ╥ ╖ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ )) - (bsp/s (bg (rgb 90 70 50) (text ~~~~ ║ ~ ╟─╌ ~╟─< ~~ heatwave is the new darkwave ~~ )) - (bsp/s (bg (rgb 80 70 60) (text ~~~~ ╨ ~ ╙──╜ ╨ ╜ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ )) - (align/x (text .)))))) +(view :logo (text tek)) (view :browse (bsp/s (padding 3 1 :browse-title) diff --git a/src/tek.rs b/src/tek.rs index 38f1cc18..185eed13 100644 --- a/src/tek.rs +++ b/src/tek.rs @@ -856,7 +856,7 @@ mod device { } } - pub fn view_device <'a> (state: &'a App) -> impl Draw<'a, Tui> { + pub fn view_device <'a> (state: &'a App) -> impl Draw { let selected = state.dialog.device_kind().unwrap(); south( bold(true, "Add device"), @@ -892,15 +892,13 @@ mod draw { /// /// If there is an error, the error is displayed. FIXME: overlay it /// Then, every top-level form of the DSL description is rendered. - impl View for App { - fn view (&self) -> impl Draw<'_, Tui> { + impl Draw for App { + fn draw (&self, to: &mut Tui) -> Drawn { //self.perf.cycle(&mut |_|{ - draw(|to: &mut Tui|{ - self.draw_error(to)?; - self.draw_modes(to)?; - //self.draw_debug(to)?; - Ok(Some(to.area().into())) - }) + self.draw_error(to)?; + self.draw_modes(to)?; + //self.draw_debug(to)?; + Ok(Some(to.area().into())) //}) } } @@ -913,7 +911,7 @@ mod draw { Ok(()) } - fn draw_modes <'a> (&'a self, to: &mut Tui) -> UsuallyRef<'a, ()> { + fn draw_modes (&self, to: &mut Tui) -> Usually<()> { if let Some(mode) = self.mode.as_ref().and_then(|m|self.config.get_mode(m)) { let mut error = false; for (index, dsl) in mode.view.iter().enumerate() { @@ -942,7 +940,7 @@ mod draw { Ok(()) } - #[allow(unused)] fn draw_debug (&self, to: &mut Tui) -> Drawn<'_, u16> { + #[allow(unused)] fn draw_debug (&self, to: &mut Tui) -> Drawn { east( format!("{}x{} ", self.size.0.load(Relaxed), self.size.1.load(Relaxed)), format!("{}% {} ", self.perf.percentage().unwrap_or_default(), self.perf.clock.raw() / 1000000000), @@ -950,15 +948,29 @@ mod draw { } } - impl<'a> Interpret<'a, Tui, Option>> for App { - fn interpret (&'a self, to: &mut Tui, dsl: L) -> Drawn<'a, u16> { - if let Some(expr) = dsl.expr()? { - interpret_keyword!(self, to, &expr, [ - kw_when, kw_either, kw_split, kw_align, kw_exact, kw_min, kw_max, kw_push, kw_full, - kw_tui_text, kw_tui_fg, kw_tui_bg - ]); - Err(format!("interpret_expr: unexpected: {expr:?}").into()) - } else if let Some(word) = dsl.word()? { + impl Interpret>> for App { + fn interpret (&self, to: &mut Tui, dsl: L) -> Drawn { + if let Ok(Some(expr)) = dsl.expr() { + ok_flat(expr.head()?.map(|head|{ + match head.split('/').next() { + Some("when") => kw_when(self, to, expr), + Some("either") => kw_either(self, to, expr), + Some("bsp") => kw_split(self, to, expr), + Some("split") => kw_split(self, to, expr), + Some("align") => kw_align(self, to, expr), + Some("full") => kw_full(self, to, expr), + Some("exact") => kw_exact(self, to, expr), + Some("min") => kw_min(self, to, expr), + Some("max") => kw_max(self, to, expr), + Some("push") => kw_push(self, to, expr), + Some("pull") => kw_pull(self, to, expr), + Some("text") => kw_tui_text(self, to, expr), + Some("fg") => kw_tui_fg(self, to, expr), + Some("bg") => kw_tui_bg(self, to, expr), + _ => Err(format!("interpret_expr: unexpected: {expr:?}").into()) + } + })) + } else if let Ok(Some(word)) = dsl.word() { let mut frags = word.src()?.unwrap().split("/"); match frags.next() { //Some(":logo") => view_logo().draw(to), @@ -1013,7 +1025,7 @@ mod draw { } pub fn view_templates <'a> (_frags: std::str::Split<&str>, state: &'a App) - -> impl Draw<'a, Tui> + use<'a> + -> impl Draw + use<'a> { let height = (state.config.modes.len() * 2) as u16; draw(move |to: &mut Tui|{ @@ -1036,16 +1048,16 @@ mod draw { } pub fn field_h <'a, T: Screen> ( - _theme: ItemTheme, _head: impl Draw<'a, T>, _body: impl Draw<'a, T> - ) -> impl Draw<'a, T> { + _theme: ItemTheme, _head: impl Draw, _body: impl Draw + ) -> impl Draw { } pub fn field_v <'a, T: Screen> ( - _theme: ItemTheme, _head: impl Draw<'a, T>, _body: impl Draw<'a, T> - ) -> impl Draw<'a, T> { + _theme: ItemTheme, _head: impl Draw, _body: impl Draw + ) -> impl Draw { } - pub fn view_sessions <'a> () -> impl Draw<'a, Tui> { + pub fn view_sessions <'a> () -> impl Draw { let h = 6; let w = Some(30); let f = Rgb(224, 192, 128); @@ -1065,8 +1077,8 @@ mod draw { /// let fg = tengri::ratatui::style::Color::Green; /// let _ = tek::view_wrap(bg, fg, "and then blue, too!"); /// ``` - pub fn view_wrap <'a> (bg: Color, fg: Color, content: impl Draw<'a, Tui>) - -> impl Draw<'a, Tui> + pub fn view_wrap <'a> (bg: Color, fg: Color, content: impl Draw) + -> impl Draw { let left = fg_bg(bg, Reset, y_repeat("▐").exact_w(1)); let right = fg_bg(bg, Reset, y_repeat("▌").exact_w(1)); @@ -1078,7 +1090,7 @@ mod draw { /// let _ = tek::view_meters(&[0.0, 0.0]); /// ``` pub fn view_meter <'a> (label: &'a str, value: f32) - -> impl Draw<'a, Tui> + -> impl Draw { let f = field_h(ItemTheme::G[128], label, format!("{:>+9.3}", value)); let w = if value >= 0.0 { 13 } @@ -1101,14 +1113,14 @@ mod draw { south!(f, bg(c, ()).exact_wh(w, 1)) } - pub fn view_meters (values: &[f32;2]) -> impl Draw<'_, Tui> + use<'_> { + pub fn view_meters (values: &[f32;2]) -> impl Draw + use<'_> { let left = format!("L/{:>+9.3}", values[0]); let right = format!("R/{:>+9.3}", values[1]); south(left, right) } - pub fn view_track_header <'a> (theme: ItemTheme, content: impl Draw<'a, Tui>) - -> impl Draw<'a, Tui> + pub fn view_track_header <'a> (theme: ItemTheme, content: impl Draw) + -> impl Draw { bg(theme.darker.term, content.align_e().full_w()).exact_w(12) } @@ -1117,8 +1129,8 @@ mod draw { /// let _ = tek::button_2("", "", true); /// let _ = tek::button_2("", "", false); /// ``` - pub fn button_2 <'a> (key: impl Draw<'a, Tui>, label: impl Draw<'a, Tui>, hide: bool) - -> impl Draw<'a, Tui> + pub fn button_2 <'a> (key: impl Draw, label: impl Draw, hide: bool) + -> impl Draw { let c1 = tui_orange(); let c2 = tui_g(0); @@ -1133,11 +1145,11 @@ mod draw { /// let _ = tek::button_3("", "", "", false); /// ``` pub fn button_3 <'a> ( - key: impl Draw<'a, Tui>, - label: impl Draw<'a, Tui>, - value: impl Draw<'a, Tui>, + key: impl Draw, + label: impl Draw, + value: impl Draw, editing: bool, - ) -> impl Draw<'a, Tui> { + ) -> impl Draw { let c1 = tui_orange(); let c2 = tui_g(0); let c3 = tui_g(96); diff --git a/tengri b/tengri index 41ef6214..4172fa25 160000 --- a/tengri +++ b/tengri @@ -1 +1 @@ -Subproject commit 41ef62146bd74e3e69fa48eae5b8f1581acee149 +Subproject commit 4172fa257776f5c6c7b406429b2244d630702458