mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2026-09-18 13:26:42 +02:00
Compare commits
3 commits
ac9fd7dfba
...
cf67185ffd
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cf67185ffd | ||
|
|
39d3dacf1f | ||
|
|
b09719993a |
6 changed files with 38 additions and 21 deletions
|
|
@ -42,7 +42,9 @@ impl_keywords!(Tui, XYWH<u16>, State [
|
||||||
kw_push,
|
kw_push,
|
||||||
kw_tui_text,
|
kw_tui_text,
|
||||||
kw_tui_fg,
|
kw_tui_fg,
|
||||||
kw_tui_bg
|
kw_tui_bg,
|
||||||
|
kw_color_g,
|
||||||
|
kw_color_rgb,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
impl Interpret<Tui, Option<XYWH<u16>>> for State {
|
impl Interpret<Tui, Option<XYWH<u16>>> for State {
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,6 @@ fn_kw_layout!(kw_align |state, output, expr| {
|
||||||
draw(move|output: &mut O|{state.interpret(output, &expr.tail().head())}).align(
|
draw(move|output: &mut O|{state.interpret(output, &expr.tail().head())}).align(
|
||||||
eval_enum!("align", output, state,
|
eval_enum!("align", output, state,
|
||||||
expr.head().src()?.unwrap_or_default().split("/").skip(1).next(),
|
expr.head().src()?.unwrap_or_default().split("/").skip(1).next(),
|
||||||
expr.tail().head(),
|
|
||||||
Azimuth {
|
Azimuth {
|
||||||
"c" => C, "x" => X, "y" => Y,
|
"c" => C, "x" => X, "y" => Y,
|
||||||
"n" => N, "s" => S, "e" => E, "w" => W,
|
"n" => N, "s" => S, "e" => E, "w" => W,
|
||||||
|
|
@ -131,7 +130,7 @@ fn_kw_layout!(kw_split |state, output, expr| {
|
||||||
let head = expr.head();
|
let head = expr.head();
|
||||||
let mut frags = head.src()?.unwrap_or_default().split("/");
|
let mut frags = head.src()?.unwrap_or_default().split("/");
|
||||||
Ok(matches!(frags.next(), Some("bsp")).then(||{
|
Ok(matches!(frags.next(), Some("bsp")).then(||{
|
||||||
eval_enum!("bsp", output, state, frags.next(), expr.tail().head()?, Split {
|
eval_enum!("bsp", output, state, frags.next(), Split {
|
||||||
"n" => North,
|
"n" => North,
|
||||||
"s" => South,
|
"s" => South,
|
||||||
"e" => East,
|
"e" => East,
|
||||||
|
|
@ -140,10 +139,10 @@ fn_kw_layout!(kw_split |state, output, expr| {
|
||||||
"b" => Below
|
"b" => Below
|
||||||
}).stack(
|
}).stack(
|
||||||
draw(move|output: &mut O|{
|
draw(move|output: &mut O|{
|
||||||
state.interpret(output, &expr.tail().tail().head()?)
|
state.interpret(output, &expr.tail().head()?)
|
||||||
}),
|
}),
|
||||||
draw(move|output: &mut O|{
|
draw(move|output: &mut O|{
|
||||||
state.interpret(output, &expr.tail().tail().tail().head()?)
|
state.interpret(output, &expr.tail().tail().head()?)
|
||||||
}),
|
}),
|
||||||
).draw(output)
|
).draw(output)
|
||||||
}).transpose()?.flatten())
|
}).transpose()?.flatten())
|
||||||
|
|
|
||||||
|
|
@ -43,10 +43,23 @@ pub fn iter_east_fixed <'a, S: Screen, D: 'a, I: Iterator<Item = D>, U: Draw<S>>
|
||||||
draw(move|_to: &mut S|{ todo!() })
|
draw(move|_to: &mut S|{ todo!() })
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn iter_south <'a, S: Screen, D: 'a, I: Iterator<Item = D>, U: Draw<S>> (
|
pub fn iter_south <'a, S: Screen, D: Draw<S>, I: Iterator<Item = D>> (
|
||||||
_iter: impl Fn()->I, _draw: impl Fn(D, usize)->U,
|
iter: impl Fn()->I
|
||||||
) -> impl Draw<S> {
|
) -> impl Draw<S> {
|
||||||
draw(move|_to: &mut S|{ todo!() })
|
draw(move|to: &mut S|{
|
||||||
|
let XYWH(x, mut y, w, mut h) = to.area();
|
||||||
|
let h0 = h;
|
||||||
|
for item in iter() {
|
||||||
|
if let Some(used) = to.draw(Some(XYWH(x, y, w, h)), item)? {
|
||||||
|
y = y.add(used.y());
|
||||||
|
h = h.minus(used.y());
|
||||||
|
if h == S::Unit::zero() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(Some(XYWH(x, y, w, h)))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn iter_south_fixed <'a, S: Screen, D: 'a, I: Iterator<Item = D>, U: Draw<S>> (
|
pub fn iter_south_fixed <'a, S: Screen, D: 'a, I: Iterator<Item = D>, U: Draw<S>> (
|
||||||
|
|
|
||||||
10
src/lib.rs
10
src/lib.rs
|
|
@ -182,7 +182,7 @@ pub trait AsMutOpt<T> { fn as_mut_opt (&mut self) -> Option<&mut T>; }
|
||||||
/// Some layout operations exist in multiple variants that take a single argument.
|
/// Some layout operations exist in multiple variants that take a single argument.
|
||||||
/// Their handling in [eval_view] is uniform and goes like this:
|
/// Their handling in [eval_view] is uniform and goes like this:
|
||||||
macro_rules! eval_enum ((
|
macro_rules! eval_enum ((
|
||||||
$name:literal, $output:ident, $state:ident, $value:expr, $arg0:expr, $Enum:ident {
|
$name:literal, $output:ident, $state:ident, $value:expr, $Enum:ident {
|
||||||
$($v:literal => $V:ident),* $(,)?
|
$($v:literal => $V:ident),* $(,)?
|
||||||
}
|
}
|
||||||
) => {{
|
) => {{
|
||||||
|
|
@ -252,10 +252,11 @@ macro_rules! eval_xy (
|
||||||
#[cfg(feature = "exit")] pub use self::exit::*;
|
#[cfg(feature = "exit")] pub use self::exit::*;
|
||||||
#[cfg(feature = "exit")] mod exit {
|
#[cfg(feature = "exit")] mod exit {
|
||||||
use crate::*;
|
use crate::*;
|
||||||
use std::sync::{Arc, atomic::AtomicBool};
|
use std::sync::{Arc, atomic::{AtomicBool, Ordering::Relaxed}};
|
||||||
use crossterm::event::*;
|
use crossterm::event::*;
|
||||||
|
|
||||||
#[derive(Clone)] pub struct Exit(Arc<AtomicBool>);
|
#[derive(Clone, Default, Debug)]
|
||||||
|
pub struct Exit(Arc<AtomicBool>);
|
||||||
|
|
||||||
impl Exit {
|
impl Exit {
|
||||||
pub fn run <T> (run: impl FnOnce(Self)->Usually<T>) -> Usually<T> {
|
pub fn run <T> (run: impl FnOnce(Self)->Usually<T>) -> Usually<T> {
|
||||||
|
|
@ -269,6 +270,9 @@ macro_rules! eval_xy (
|
||||||
state: KeyEventState::NONE
|
state: KeyEventState::NONE
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
pub fn exit (&self) {
|
||||||
|
self.0.store(true, Relaxed)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsRef<Arc<AtomicBool>> for Exit {
|
impl AsRef<Arc<AtomicBool>> for Exit {
|
||||||
|
|
|
||||||
16
src/term.rs
16
src/term.rs
|
|
@ -145,16 +145,14 @@ impl Tui {
|
||||||
panic(info);
|
panic(info);
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
pub fn run_main <T> (state: Arc<RwLock<T>>) -> Usually<()> where
|
pub fn run_main <T> (exit: Exit, state: Arc<RwLock<T>>) -> Usually<()> where
|
||||||
T: View<Tui> + Apply<TuiEvent, Usually<()>> + Send + Sync + 'static
|
T: View<Tui> + Apply<TuiEvent, Usually<()>> + Send + Sync + 'static
|
||||||
{
|
{
|
||||||
Exit::run(|exit|{
|
let scan = Duration::from_millis(100);
|
||||||
let scan = Duration::from_millis(100);
|
let frame = Duration::from_millis(10);
|
||||||
let frame = Duration::from_millis(10);
|
let (_input, output) = Tui::io(exit.as_ref(), &state, scan, frame, std::io::stdout())?;
|
||||||
let (_input, output) = Tui::io(exit.as_ref(), &state, scan, frame, std::io::stdout())?;
|
let _ = output.join();
|
||||||
let _ = output.join();
|
Tui::teardown(&mut stdout())
|
||||||
Tui::teardown(&mut stdout())
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
/// Spawn the TUI input and output threadsl.
|
/// Spawn the TUI input and output threadsl.
|
||||||
pub fn io <
|
pub fn io <
|
||||||
|
|
@ -500,7 +498,7 @@ impl<T: Draw<Tui>> Draw<Tui> for ShowSizeOf<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "eval")] fn_kw_layout_tui!(kw_tui_text |state, output, expr| {
|
#[cfg(feature = "eval")] fn_kw_layout_tui!(kw_tui_text |_state, output, expr| {
|
||||||
Ok(matches!(expr.head()?, Some("text")).then(||{
|
Ok(matches!(expr.head()?, Some("text")).then(||{
|
||||||
if let Some(src) = expr.tail().src()? {
|
if let Some(src) = expr.tail().src()? {
|
||||||
src.draw(output)
|
src.draw(output)
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,8 @@ impl Tui {
|
||||||
if let Some(expr) = src.expr()? {
|
if let Some(expr) = src.expr()? {
|
||||||
match (expr.head()?, expr.tail()?) {
|
match (expr.head()?, expr.tail()?) {
|
||||||
(Some("g"), Some(tail)) => {
|
(Some("g"), Some(tail)) => {
|
||||||
let n: u8 = state.namespace(tail.head().map_err(Into::into))?.ok_or(LanguageError::Domain("not gray"))?;
|
let n: u8 = state.namespace(tail.head().map_err(Into::into))?
|
||||||
|
.ok_or(LanguageError::Domain("not gray"))?;
|
||||||
Ok(Some(Color::Rgb(n, n, n)))
|
Ok(Some(Color::Rgb(n, n, n)))
|
||||||
},
|
},
|
||||||
(Some("rgb"), Some(tail)) => {
|
(Some("rgb"), Some(tail)) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue