mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
113 lines
3.3 KiB
Rust
113 lines
3.3 KiB
Rust
pub use ::tek_input;
|
|
pub(crate) use tek_input::*;
|
|
|
|
pub use ::tek_output;
|
|
pub(crate) use tek_output::*;
|
|
|
|
pub use ::tek_edn;
|
|
pub(crate) use ::tek_edn::*;
|
|
|
|
mod tui_engine; pub use self::tui_engine::*;
|
|
mod tui_content; pub use self::tui_content::*;
|
|
mod tui_input; pub use self::tui_input::*;
|
|
mod tui_output; pub use self::tui_output::*;
|
|
mod tui_run; pub use self::tui_run::*;
|
|
|
|
mod tui_color; pub use self::tui_color::*;
|
|
mod tui_style; pub use self::tui_style::*;
|
|
mod tui_theme; pub use self::tui_theme::*;
|
|
mod tui_border; pub use self::tui_border::*;
|
|
mod tui_field; pub use self::tui_field::*;
|
|
mod tui_buffer; pub use self::tui_buffer::*;
|
|
mod tui_file; pub use self::tui_file::*;
|
|
|
|
mod tui_edn_keymap; pub use self::tui_edn_keymap::*;
|
|
|
|
pub(crate) use std::sync::{Arc, RwLock, atomic::{AtomicUsize, AtomicBool, Ordering::*}};
|
|
pub(crate) use std::io::{stdout, Stdout};
|
|
pub(crate) use std::error::Error;
|
|
pub(crate) use std::path::PathBuf;
|
|
pub(crate) use std::ffi::OsString;
|
|
|
|
/// Prototypal case of implementor macro.
|
|
/// Saves 4loc per data pats.
|
|
#[macro_export] macro_rules! from {
|
|
($(<$($lt:lifetime),+>)?|$state:ident:$Source:ty|$Target:ty=$cb:expr) => {
|
|
impl $(<$($lt),+>)? From<$Source> for $Target {
|
|
fn from ($state:$Source) -> Self { $cb }
|
|
}
|
|
};
|
|
}
|
|
|
|
pub trait Gettable<T> {
|
|
/// Returns current value
|
|
fn get (&self) -> T;
|
|
}
|
|
|
|
pub trait Mutable<T>: Gettable<T> {
|
|
/// Sets new value, returns old
|
|
fn set (&mut self, value: T) -> T;
|
|
}
|
|
|
|
pub trait InteriorMutable<T>: Gettable<T> {
|
|
/// Sets new value, returns old
|
|
fn set (&self, value: T) -> T;
|
|
}
|
|
|
|
impl Gettable<bool> for AtomicBool {
|
|
fn get (&self) -> bool { self.load(Relaxed) }
|
|
}
|
|
|
|
impl InteriorMutable<bool> for AtomicBool {
|
|
fn set (&self, value: bool) -> bool { self.swap(value, Relaxed) }
|
|
}
|
|
|
|
impl Gettable<usize> for AtomicUsize {
|
|
fn get (&self) -> usize { self.load(Relaxed) }
|
|
}
|
|
|
|
impl InteriorMutable<usize> for AtomicUsize {
|
|
fn set (&self, value: usize) -> usize { self.swap(value, Relaxed) }
|
|
}
|
|
|
|
pub use ::better_panic; pub(crate) use better_panic::{Settings, Verbosity};
|
|
pub use ::palette; pub(crate) use ::palette::{*, convert::*, okhsl::*};
|
|
|
|
pub use ::crossterm;
|
|
pub(crate) use crossterm::{
|
|
ExecutableCommand,
|
|
terminal::{EnterAlternateScreen, LeaveAlternateScreen, enable_raw_mode, disable_raw_mode},
|
|
event::{KeyCode, KeyModifiers, KeyEvent, KeyEventKind, KeyEventState},
|
|
};
|
|
|
|
pub use ::ratatui;
|
|
pub(crate) use ratatui::{
|
|
prelude::{Color, Style, Buffer},
|
|
style::Modifier,
|
|
backend::{Backend, CrosstermBackend, ClearType},
|
|
layout::{Size, Rect},
|
|
buffer::Cell
|
|
};
|
|
|
|
|
|
#[cfg(test)] #[test] fn test_tui_engine () -> Usually<()> {
|
|
use crate::*;
|
|
use std::sync::{Arc, RwLock};
|
|
struct TestComponent(String);
|
|
impl Content<TuiOut> for TestComponent {
|
|
fn content (&self) -> Option<impl Content<TuiOut>> {
|
|
Some(self.0.as_str())
|
|
}
|
|
}
|
|
impl Handle<TuiIn> for TestComponent {
|
|
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));
|
|
engine.run(&state)?;
|
|
Ok(())
|
|
}
|