wip: updating tests
Some checks are pending
/ build (push) Waiting to run

This commit is contained in:
🪞👃🪞 2025-06-12 21:17:08 +03:00
parent 21832453d9
commit 17506726cb
36 changed files with 280 additions and 271 deletions

View file

@ -1,6 +1,6 @@
use tengri::{self, Usually, Perhaps, input::*, output::*, tui::*, dsl::*};
use std::sync::{Arc, RwLock};
use crossterm::event::{*, KeyCode::*};
//use crossterm::event::{*, KeyCode::*};
use crate::ratatui::style::Color;
fn main () -> Usually<()> {
@ -13,23 +13,23 @@ fn main () -> Usually<()> {
const KEYMAP: &str = "(@left prev) (@right next)";
const EXAMPLES: &'static [&'static str] = &[
include_str!("edn01.edn"),
include_str!("edn02.edn"),
include_str!("edn03.edn"),
include_str!("edn04.edn"),
include_str!("edn05.edn"),
include_str!("edn06.edn"),
include_str!("edn07.edn"),
include_str!("edn08.edn"),
include_str!("edn09.edn"),
include_str!("edn10.edn"),
include_str!("edn11.edn"),
include_str!("edn12.edn"),
//include_str!("edn13.edn"),
include_str!("edn14.edn"),
include_str!("edn15.edn"),
include_str!("edn16.edn"),
include_str!("edn17.edn"),
include_str!("edn/edn01.edn"),
include_str!("edn/edn02.edn"),
include_str!("edn/edn03.edn"),
include_str!("edn/edn04.edn"),
include_str!("edn/edn05.edn"),
include_str!("edn/edn06.edn"),
include_str!("edn/edn07.edn"),
include_str!("edn/edn08.edn"),
include_str!("edn/edn09.edn"),
include_str!("edn/edn10.edn"),
include_str!("edn/edn11.edn"),
include_str!("edn/edn12.edn"),
//include_str!("edn/edn13.edn"),
include_str!("edn/edn14.edn"),
include_str!("edn/edn15.edn"),
include_str!("edn/edn16.edn"),
include_str!("edn/edn17.edn"),
];
handle!(TuiIn: |self: Example, input|{
@ -63,7 +63,7 @@ impl ExampleCommand {
}
}
view!(TuiOut: |self: Example|{
content!(TuiOut: |self: Example|{
let index = self.0 + 1;
let wh = self.1.wh();
let src = EXAMPLES.get(self.0).unwrap_or(&"");
@ -72,12 +72,29 @@ view!(TuiOut: |self: Example|{
let code = Tui::bg(Color::Rgb(10, 60, 10), Push::y(2, Align::n(format!("{}", src))));
let content = Tui::bg(Color::Rgb(10, 10, 60), View(self, TokenIter::new(src)));
self.1.of(Bsp::s(title, Bsp::n(""/*code*/, content)))
}; {
":title" => Tui::bg(Color::Rgb(60, 10, 10), Push::y(1, Align::n(format!("Example {}/{}:", self.0 + 1, EXAMPLES.len())))).boxed(),
":code" => Tui::bg(Color::Rgb(10, 60, 10), Push::y(2, Align::n(format!("{}", EXAMPLES[self.0])))).boxed(),
":hello" => Tui::bg(Color::Rgb(10, 100, 10), "Hello").boxed(),
":world" => Tui::bg(Color::Rgb(100, 10, 10), "world").boxed(),
":hello-world" => "Hello world!".boxed(),
":map-e" => Map::east(5u16, ||0..5u16, |n, i|format!("{n}")).boxed(),
":map-s" => Map::south(5u16, ||0..5u16, |n, i|format!("{n}")).boxed(),
});
#[tengri_proc::view(TuiOut)]
impl Example {
pub fn title (&self) -> impl Content<TuiOut> + use<'_> {
Tui::bg(Color::Rgb(60, 10, 10), Push::y(1, Align::n(format!("Example {}/{}:", self.0 + 1, EXAMPLES.len())))).boxed()
}
pub fn code (&self) -> impl Content<TuiOut> + use<'_> {
Tui::bg(Color::Rgb(10, 60, 10), Push::y(2, Align::n(format!("{}", EXAMPLES[self.0])))).boxed()
}
pub fn hello (&self) -> impl Content<TuiOut> + use<'_> {
Tui::bg(Color::Rgb(10, 100, 10), "Hello").boxed()
}
pub fn world (&self) -> impl Content<TuiOut> + use<'_> {
Tui::bg(Color::Rgb(100, 10, 10), "world").boxed()
}
pub fn hello_world (&self) -> impl Content<TuiOut> + use<'_> {
"Hello world!".boxed()
}
pub fn map_e (&self) -> impl Content<TuiOut> + use<'_> {
Map::east(5u16, ||0..5u16, |n, _i|format!("{n}")).boxed()
}
pub fn map_s (&self) -> impl Content<TuiOut> + use<'_> {
Map::south(5u16, ||0..5u16, |n, _i|format!("{n}")).boxed()
}
}

View file

@ -36,7 +36,7 @@ pub(crate) use std::io::{stdout, Stdout};
#[cfg(test)] #[test] fn test_tui_engine () -> Usually<()> {
use crate::*;
use std::sync::{Arc, RwLock};
//use std::sync::{Arc, RwLock};
struct TestComponent(String);
impl Content<TuiOut> for TestComponent {
fn content (&self) -> impl Render<TuiOut> {
@ -44,21 +44,21 @@ pub(crate) use std::io::{stdout, Stdout};
}
}
impl Handle<TuiIn> for TestComponent {
fn handle (&mut self, from: &TuiIn) -> Perhaps<bool> {
fn handle (&mut self, _from: &TuiIn) -> Perhaps<bool> {
Ok(None)
}
}
let engine = Tui::new()?;
engine.read().unwrap().exited.store(true, std::sync::atomic::Ordering::Relaxed);
let state = TestComponent("hello world".into());
let state = std::sync::Arc::new(std::sync::RwLock::new(state));
let _state = std::sync::Arc::new(std::sync::RwLock::new(state));
//engine.run(&state)?;
Ok(())
}
#[cfg(test)] #[test] fn test_parse_key () {
use KeyModifiers as Mods;
let test = |x: &str, y|assert_eq!(KeyMatcher::new(x).build(), Some(Event::Key(y)));
//use KeyModifiers as Mods;
let _test = |x: &str, y|assert_eq!(KeyMatcher::new(x).build(), Some(Event::Key(y)));
//test(":x",
//KeyEvent::new(KeyCode::Char('x'), Mods::NONE));
//test(":ctrl-x",

View file

@ -60,7 +60,7 @@ impl<T, U> Field<T, U> {
value_align: None,
}
}
fn label <L> (
pub fn label <L> (
self,
label: Option<L>,
align: Option<Direction>,
@ -75,7 +75,7 @@ impl<T, U> Field<T, U> {
..self
}
}
fn value <V> (
pub fn value <V> (
self,
value: Option<V>,
align: Option<Direction>,

View file

@ -1,5 +1,5 @@
use crate::*;
render!(TuiOut: |self: u64, to|todo!());
render!(TuiOut: |self: u64, _to|todo!());
render!(TuiOut: |self: f64, to|todo!());
render!(TuiOut: |self: f64, _to|todo!());

View file

@ -56,13 +56,13 @@ impl TuiIn {
}
}
#[cfg(feature = "dsl")]
impl DslInput for TuiIn {
fn matches_dsl (&self, token: &str) -> bool {
if let Some(event) = KeyMatcher::new(token).build() {
&event == self.event()
} else {
false
}
}
}
//#[cfg(feature = "dsl")]
//impl DslInput for TuiIn {
//fn matches_dsl (&self, token: &str) -> bool {
//if let Some(event) = KeyMatcher::new(token).build() {
//&event == self.event()
//} else {
//false
//}
//}
//}