use abstracttui::prelude::*;
use abstracttui::widgets::{ColWidth, Column};
fn main() -> abstracttui::base::Result<()> {
if !abstracttui::term::have_tty() {
println!("activate: needs an interactive terminal — skipping cleanly");
return Ok(());
}
if let Ok(id) = std::env::var("ABSTRACTTUI_THEME") {
set_theme_by_id(&id);
}
let mut app = App::new(Size::new(80, 24));
let quitter = app.quitter();
app.mount(move |cx| {
let last = cx.signal(String::from(
"select a row (click / arrows), then commit it (Enter / the mouse gesture)",
));
let themes: Vec<&str> = vec![
"abstract-dark",
"nord",
"rose-pine",
"catppuccin-mocha",
"gruvbox",
"solarized-dark",
];
let names = themes.clone();
let list = List::of(themes.clone())
.on_select(move |i| last.set(format!("list: selected row {i} — browsing")))
.on_activate(move |i| {
set_theme_by_id(names[i]);
last.set(format!("list: ACTIVATED row {i} — theme applied"));
})
.view(cx);
let table = Table::new(vec![
Column::new("session", ColWidth::Flex(1.0)),
Column::new("state", ColWidth::Cells(10)),
])
.rows(
(1..=6)
.map(|n| {
vec![
format!("run-{n:02}"),
if n % 2 == 0 { "waiting" } else { "done" }.to_string(),
]
})
.collect(),
)
.on_select(move |i| last.set(format!("table: selected row {i} — browsing")))
.on_activate(move |i| last.set(format!("table: ACTIVATED row {i} — double-click or Enter")))
.view(cx);
Element::new()
.style(LayoutStyle::column().gap(1).padding(Edges::all(1)))
.shortcut(KeyChord::plain(Key::Char('q')), move |_| quitter.quit())
.child(text(
"selection follows movement — activation is the explicit commit",
))
.child(
Element::new()
.style(LayoutStyle::row().gap(2).grow(1.0))
.child(
Element::new()
.style(LayoutStyle::column().gap(1).grow(1.0))
.child(text("List — click the selected row to apply the theme"))
.child(list)
.build(),
)
.child(
Element::new()
.style(LayoutStyle::column().gap(1).grow(1.0))
.child(text("Table — double-click a row to open it"))
.child(table)
.build(),
)
.build(),
)
.child(dyn_view(LayoutStyle::line(1), move || {
text(format!("» {}", last.get()))
}))
.child(text(
"Tab pane · arrows select · Enter/Space activate · double-click (table) · q quit",
))
.build()
})?;
app.run()
}