mirror of
https://codeberg.org/unspeaker/tek.git
synced 2026-10-08 18:56:42 +02:00
parent
f2443a4314
commit
6771b24f79
17 changed files with 105 additions and 96 deletions
88
src/tek.rs
88
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<Tui> {
|
||||
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<Tui> for App {
|
||||
fn view (&self) -> impl Draw<'_, Tui> {
|
||||
impl Draw<Tui> for App {
|
||||
fn draw (&self, to: &mut Tui) -> Drawn<u16> {
|
||||
//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<u16> {
|
||||
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<XYWH<u16>>> for App {
|
||||
fn interpret <L: Language + 'a> (&'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<Tui, Option<XYWH<u16>>> for App {
|
||||
fn interpret <L: Language> (&self, to: &mut Tui, dsl: L) -> Drawn<u16> {
|
||||
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<Tui> + 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<T>, _body: impl Draw<T>
|
||||
) -> impl Draw<T> {
|
||||
}
|
||||
|
||||
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<T>, _body: impl Draw<T>
|
||||
) -> impl Draw<T> {
|
||||
}
|
||||
|
||||
pub fn view_sessions <'a> () -> impl Draw<'a, Tui> {
|
||||
pub fn view_sessions <'a> () -> impl Draw<Tui> {
|
||||
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<Tui>)
|
||||
-> impl Draw<Tui>
|
||||
{
|
||||
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<Tui>
|
||||
{
|
||||
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<Tui> + 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<Tui>)
|
||||
-> impl Draw<Tui>
|
||||
{
|
||||
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<Tui>, label: impl Draw<Tui>, hide: bool)
|
||||
-> impl Draw<Tui>
|
||||
{
|
||||
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<Tui>,
|
||||
label: impl Draw<Tui>,
|
||||
value: impl Draw<Tui>,
|
||||
editing: bool,
|
||||
) -> impl Draw<'a, Tui> {
|
||||
) -> impl Draw<Tui> {
|
||||
let c1 = tui_orange();
|
||||
let c2 = tui_g(0);
|
||||
let c3 = tui_g(96);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue