mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2026-02-21 10:39:03 +01:00
100 lines
2.8 KiB
Rust
100 lines
2.8 KiB
Rust
use crate::*;
|
|
|
|
/// The `Tui` struct (the *engine*) implements the
|
|
/// `tengri_input::Input` and `tengri_output::Out` traits.
|
|
/// At launch, the `Tui` engine spawns two threads, the render thread and the input thread.
|
|
/// the application may further spawn other threads. All threads communicate using shared ownership:
|
|
/// `Arc<RwLock<T>>` and `Arc<AtomicT>`. Thus, at launch the engine and application instances are expected to be wrapped in `Arc<RwLock>`.
|
|
pub struct Tui {
|
|
pub exited: Arc<AtomicBool>,
|
|
pub backend: CrosstermBackend<Stdout>,
|
|
pub buffer: Buffer,
|
|
pub area: [u16;4],
|
|
pub perf: PerfModel,
|
|
}
|
|
|
|
#[derive(Debug, Clone)] pub struct TuiIn {
|
|
/// Input event
|
|
pub event: TuiEvent,
|
|
/// Exit flag
|
|
pub exited: Arc<AtomicBool>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Eq, PartialEq, PartialOrd)] pub struct TuiEvent(pub Event);
|
|
|
|
#[derive(Debug, Clone, Eq, PartialEq, PartialOrd)] pub struct TuiKey(
|
|
pub Option<KeyCode>,
|
|
pub KeyModifiers
|
|
);
|
|
|
|
#[derive(Default)] pub struct TuiOut {
|
|
pub buffer: Buffer,
|
|
pub area: XYWH<u16>,
|
|
}
|
|
|
|
/// TUI buffer sized by `usize` instead of `u16`.
|
|
#[derive(Default)] pub struct BigBuffer {
|
|
pub width: usize,
|
|
pub height: usize,
|
|
pub content: Vec<Cell>
|
|
}
|
|
|
|
/// A color in OKHSL and RGB representations.
|
|
#[derive(Debug, Default, Copy, Clone, PartialEq)] pub struct ItemColor {
|
|
pub okhsl: Okhsl<f32>,
|
|
pub rgb: Color,
|
|
}
|
|
/// A color in OKHSL and RGB with lighter and darker variants.
|
|
#[derive(Debug, Default, Copy, Clone, PartialEq)] pub struct ItemTheme {
|
|
pub base: ItemColor,
|
|
pub light: ItemColor,
|
|
pub lighter: ItemColor,
|
|
pub lightest: ItemColor,
|
|
pub dark: ItemColor,
|
|
pub darker: ItemColor,
|
|
pub darkest: ItemColor,
|
|
}
|
|
|
|
pub struct Modify<T>(pub bool, pub Modifier, pub T);
|
|
|
|
pub struct Styled<T>(pub Option<Style>, pub T);
|
|
|
|
/// Displays an owned [str]-like with fixed maximum width.
|
|
///
|
|
/// Width is computed using [unicode_width].
|
|
pub struct TrimString<T: AsRef<str>>(pub u16, pub T);
|
|
|
|
/// Displays a borrowed [str]-like with fixed maximum width
|
|
///
|
|
/// Width is computed using [unicode_width].
|
|
pub struct TrimStringRef<'a, T: AsRef<str>>(pub u16, pub &'a T);
|
|
|
|
/// Thunks can be natural error boundaries!
|
|
pub struct ErrorBoundary<O: Out, T: Draw<O>>(
|
|
pub std::marker::PhantomData<O>,
|
|
pub Perhaps<T>
|
|
);
|
|
|
|
/// Repeat a string, e.g. for background
|
|
pub enum Repeat<'a> {
|
|
X(&'a str),
|
|
Y(&'a str),
|
|
XY(&'a str)
|
|
}
|
|
|
|
/// Scroll indicator
|
|
pub enum Scrollbar {
|
|
/// Horizontal scrollbar
|
|
X { offset: usize, length: usize, total: usize, },
|
|
/// Vertical scrollbar
|
|
Y { offset: usize, length: usize, total: usize, }
|
|
}
|
|
|
|
/// A cell that takes up 3 rows on its own,
|
|
/// but stacks, giving (N+1)*2 rows per N cells.
|
|
pub struct Phat<T> {
|
|
pub width: u16,
|
|
pub height: u16,
|
|
pub content: T,
|
|
pub colors: [Color;4],
|
|
}
|