mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
55 lines
2.3 KiB
Rust
55 lines
2.3 KiB
Rust
//! Inital setup dialog (TODO: make this the options dialog too?)
|
|
|
|
use crate::*;
|
|
|
|
/// Appears on first run (i.e. if state dir is missing).
|
|
pub struct SetupModal(pub Option<Arc<XdgApp>>, pub bool);
|
|
|
|
render!(SetupModal |self, buf, area| {
|
|
for cell in buf.content.iter_mut() {
|
|
cell.fg = ratatui::style::Color::Gray;
|
|
cell.modifier = ratatui::style::Modifier::DIM;
|
|
}
|
|
let lines = [
|
|
(" ", Style::default().white().on_black().not_dim().bold()),
|
|
(" Welcome to TEK! ", Style::default().white().on_black().not_dim().bold()),
|
|
(" ", Style::default().white().on_black().not_dim().bold()),
|
|
(" Press ENTER to create the ", Style::default().white().on_black().not_dim()),
|
|
(" following directories: ", Style::default().white().on_black().not_dim()),
|
|
(" ", Style::default().white().on_black().not_dim().bold()),
|
|
(" Configuration directory: ", Style::default().white().on_black().not_dim()),
|
|
(" ~/.config/tek ", Style::default().white().on_black().not_dim().bold()),
|
|
(" ", Style::default().white().on_black().not_dim()),
|
|
(" Data directory: ", Style::default().white().on_black().not_dim()),
|
|
(" ~/.local/share/tek ", Style::default().white().on_black().not_dim().bold()),
|
|
(" ", Style::default().white().on_black().not_dim().bold()),
|
|
(" Or press CTRL-C to exit. ", Style::default().white().on_black().not_dim()),
|
|
(" ", Style::default().white().on_black().not_dim()),
|
|
];
|
|
let width = lines[0].0.len() as u16;
|
|
let x = area.x + (area.width - width) / 2;
|
|
for (i, (line, style)) in lines.iter().enumerate() {
|
|
line.blit(buf, x, area.y + area.height / 2 - (lines.len() / 2) as u16 + i as u16, Some(*style))?;
|
|
}
|
|
Ok(area)
|
|
});
|
|
handle!(SetupModal |self, e| {
|
|
if let AppEvent::Input(Event::Key(KeyEvent {
|
|
code: KeyCode::Enter,
|
|
..
|
|
})) = e {
|
|
AppPaths::new(&self.0.as_ref().unwrap())?.create()?;
|
|
self.exit();
|
|
Ok(true)
|
|
} else {
|
|
Ok(false)
|
|
}
|
|
});
|
|
impl Exit for SetupModal {
|
|
fn exited (&self) -> bool {
|
|
self.1
|
|
}
|
|
fn exit (&mut self) {
|
|
self.1 = true
|
|
}
|
|
}
|