mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-06 03:36:42 +01:00
This commit is contained in:
parent
21832453d9
commit
17506726cb
36 changed files with 280 additions and 271 deletions
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue