Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ pub mod reset;

pub mod agent;

pub mod symbols;

pub fn iwd_network_name(name: &str) -> String {
match name
.chars()
Expand Down
46 changes: 46 additions & 0 deletions src/symbols.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
use std::sync::OnceLock;

static SYMBOL_RENDERER: OnceLock<fn(Symbol) -> &'static str> = OnceLock::new();

pub enum Symbol {
Up,
Down,
Left,
Right,
Tab,
Enter,
Spacebar,
SignalStrength(u8),
Esc,
}

pub fn render_unicode(sym: Symbol) -> &'static str {
match sym {
Symbol::Up => "↑",
Symbol::Esc => "󱊷",
}
}

pub fn render_ascii(sym: Symbol) -> &'static str {
match sym {
Symbol::Up => "ARROW_UP",
Symbol::Esc => "ESC",
}
}

pub fn render(sym: Symbol) -> &'static str {
SYMBOL_RENDERER
.get()
.expect("symbol renderer not initialized")(sym)
}

pub fn init_renderer(use_unicode: bool) {
let renderer = if use_unicode {
render_unicode
} else {
render_ascii
};
SYMBOL_RENDERER
.set(renderer)
.expect("symbol renderer already initialized");
}