Spike, not the final UI: it answers whether flare-ui can drive Alkane OS's on-box pages, and what it costs. What works: - schema/alkane-bb.json authors the sidebar as data (3 sections, 14 tabs); - src/bin/ui-spike.rs renders it through flare_ui::nav + flare_ui::shell, so the unified sidebar, ordering and surface filtering come from the schema rather than from hand-written HTML; - the render uses the shared bf- design tokens, the same ones the rest of the suite uses. Size, measured rather than assumed (armv7, release, stripped): ui-baseline 323 KiB (maud + serde_json, no flare-ui) ui-spike 771 KiB (flare-ui + wschema + sha2) marginal 448 KiB Vendoring: third-party/flare-ui is the full v0.2.9 tree pinned in flare-ui/flare-ui.lock (a partial archive does not compile, since the crate include_str!s assets from dash-editor/). vendor/ is re-generated as a cargo directory source with the new registry dependencies (maud, sha2, typenum, digest, generic-array, block-buffer, crypto-common, cfg-if, etc.) so the build still works offline. third-party/README.md records how to re-pin.
107 lines
2.6 KiB
Rust
107 lines
2.6 KiB
Rust
/// An example how to use the ANSI escape sequence parser.
|
|
use std::io::{Read, Result, Write};
|
|
|
|
use anes::{
|
|
self, execute,
|
|
parser::{KeyCode, Parser, Sequence},
|
|
queue,
|
|
};
|
|
use libc::termios as Termios;
|
|
|
|
const HELP: &str = r#"ANES parser example
|
|
|
|
* Hit `Esc` to quit
|
|
* Hit 'c' to ask for cursor position
|
|
* Use your mouse or type anything
|
|
"#;
|
|
|
|
fn main() -> Result<()> {
|
|
let mut w = std::io::stdout();
|
|
queue!(
|
|
w,
|
|
anes::SwitchBufferToAlternate,
|
|
anes::HideCursor,
|
|
anes::EnableMouseEvents
|
|
)?;
|
|
for line in HELP.split('\n') {
|
|
queue!(w, line, anes::MoveCursorToNextLine(1))?;
|
|
}
|
|
w.flush()?;
|
|
|
|
let saved_attributes = get_termios()?;
|
|
let mut attributes = saved_attributes;
|
|
make_raw(&mut attributes);
|
|
set_termios(attributes)?;
|
|
|
|
let mut stdin = std::io::stdin();
|
|
let mut stdin_buffer = [0u8; 1024];
|
|
let mut parser = Parser::default();
|
|
|
|
loop {
|
|
if let Ok(size) = stdin.read(&mut stdin_buffer) {
|
|
parser.advance(&stdin_buffer[..size], false);
|
|
|
|
let mut break_outer_loop = false;
|
|
|
|
while let Some(sequence) = parser.next() {
|
|
match sequence {
|
|
Sequence::Key(KeyCode::Esc, _) => {
|
|
break_outer_loop = true;
|
|
break;
|
|
}
|
|
Sequence::Key(KeyCode::Char('c'), _) => {
|
|
execute!(w, anes::ReportCursorPosition)?
|
|
}
|
|
_ => execute!(
|
|
w,
|
|
anes::ClearLine::Left,
|
|
anes::MoveCursorToColumn(1),
|
|
format!("{:?}", sequence),
|
|
)?,
|
|
}
|
|
}
|
|
|
|
if break_outer_loop {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
set_termios(saved_attributes)?;
|
|
|
|
execute!(
|
|
w,
|
|
anes::DisableMouseEvents,
|
|
anes::ShowCursor,
|
|
anes::SwitchBufferToNormal
|
|
)?;
|
|
Ok(())
|
|
}
|
|
|
|
//
|
|
// RAW mode
|
|
//
|
|
|
|
fn get_termios() -> Result<Termios> {
|
|
unsafe {
|
|
let mut termios = std::mem::zeroed();
|
|
if libc::tcgetattr(libc::STDIN_FILENO, &mut termios) != -1 {
|
|
Ok(termios)
|
|
} else {
|
|
Err(std::io::Error::last_os_error())
|
|
}
|
|
}
|
|
}
|
|
|
|
fn set_termios(termios: Termios) -> Result<()> {
|
|
if unsafe { libc::tcsetattr(libc::STDIN_FILENO, libc::TCSANOW, &termios) } != -1 {
|
|
Ok(())
|
|
} else {
|
|
Err(std::io::Error::last_os_error())
|
|
}
|
|
}
|
|
|
|
fn make_raw(termios: &mut Termios) {
|
|
unsafe { libc::cfmakeraw(termios) }
|
|
}
|