This commit is contained in:
@@ -34,6 +34,11 @@ pub fn render(frame: &mut Frame, app: &App) {
|
||||
} else {
|
||||
Style::default()
|
||||
};
|
||||
let devices_style = if app.view == View::Devices {
|
||||
active
|
||||
} else {
|
||||
Style::default()
|
||||
};
|
||||
let date = if app.view == View::Tasks {
|
||||
format!(" {} ", app.date)
|
||||
} else {
|
||||
@@ -45,6 +50,8 @@ pub fn render(frame: &mut Frame, app: &App) {
|
||||
Span::styled(" Routines ", routines_style),
|
||||
Span::raw(" "),
|
||||
Span::styled(" Archive ", archive_style),
|
||||
Span::raw(" "),
|
||||
Span::styled(" Devices ", devices_style),
|
||||
Span::raw(date),
|
||||
]))
|
||||
.block(Block::default().borders(Borders::ALL).title("Routine"));
|
||||
@@ -141,11 +148,34 @@ pub fn render(frame: &mut Frame, app: &App) {
|
||||
ListItem::new(lines)
|
||||
})
|
||||
.collect::<Vec<_>>(),
|
||||
View::Devices => app
|
||||
.devices
|
||||
.iter()
|
||||
.map(|device| {
|
||||
let mark = if device.status == "active" {
|
||||
"●"
|
||||
} else {
|
||||
"○"
|
||||
};
|
||||
let revoked = device
|
||||
.revoked_at
|
||||
.map(|timestamp| format!(" revoked:{timestamp}"))
|
||||
.unwrap_or_default();
|
||||
ListItem::new(Line::from(format!(
|
||||
"{mark} {:<10} {} {} created:{}{revoked}",
|
||||
device.status,
|
||||
device.name,
|
||||
short_recipient(&device.age_recipient),
|
||||
device.created_at,
|
||||
)))
|
||||
})
|
||||
.collect::<Vec<_>>(),
|
||||
};
|
||||
let title = match app.view {
|
||||
View::Tasks => "Tasks for selected day",
|
||||
View::Routines => "Daily, weekly, and monthly routines",
|
||||
View::Archive => "Archived tasks",
|
||||
View::Devices => "Encryption devices (public recipients only)",
|
||||
};
|
||||
let list = List::new(items)
|
||||
.block(Block::default().borders(Borders::ALL).title(title))
|
||||
@@ -157,10 +187,11 @@ pub fn render(frame: &mut Frame, app: &App) {
|
||||
|
||||
let help = match app.view {
|
||||
View::Tasks => {
|
||||
"q quit Tab routines h/l day t today j/k move a add Space complete s move x delete r refresh"
|
||||
"q quit Tab routines h/l day t today j/k move a add Space complete s move x archive r refresh"
|
||||
}
|
||||
View::Routines => "q quit Tab tasks j/k move a add routine r refresh",
|
||||
View::Archive => "q quit Tab tasks j/k move u restore x delete permanently r refresh",
|
||||
View::Devices => "q quit Tab tasks j/k move a register device x revoke r refresh",
|
||||
};
|
||||
let footer = Paragraph::new(vec![
|
||||
Line::from(help),
|
||||
@@ -178,6 +209,7 @@ pub fn render(frame: &mut Frame, app: &App) {
|
||||
FormKind::Task => format!("New task for {}", app.date),
|
||||
FormKind::Routine => "New routine".to_owned(),
|
||||
FormKind::Reschedule { .. } => "Reschedule task".to_owned(),
|
||||
FormKind::Device => "Register encryption device".to_owned(),
|
||||
};
|
||||
let lines = form
|
||||
.fields
|
||||
@@ -210,12 +242,15 @@ pub fn render(frame: &mut Frame, app: &App) {
|
||||
if let Some(pending) = &app.pending_action {
|
||||
let area = centered_rect(60, 7, frame.area());
|
||||
frame.render_widget(Clear, area);
|
||||
let (verb, title) = match pending.kind {
|
||||
PendingActionKind::Archive => ("Archive", "Confirm archive"),
|
||||
PendingActionKind::Delete => ("Permanently delete", "Confirm permanent deletion"),
|
||||
let (subject, verb, title) = match pending.kind {
|
||||
PendingActionKind::Archive => ("task", "Archive", "Confirm archive"),
|
||||
PendingActionKind::Delete => {
|
||||
("task", "Permanently delete", "Confirm permanent deletion")
|
||||
}
|
||||
PendingActionKind::RevokeDevice => ("device", "Revoke", "Confirm device revocation"),
|
||||
};
|
||||
let dialog = Paragraph::new(vec![
|
||||
Line::from(format!("{verb} task “{}”?", pending.title)),
|
||||
Line::from(format!("{verb} {subject} “{}”?", pending.title)),
|
||||
Line::from(""),
|
||||
Line::styled(
|
||||
"y: confirm • n/Esc: cancel",
|
||||
@@ -229,6 +264,23 @@ pub fn render(frame: &mut Frame, app: &App) {
|
||||
}
|
||||
}
|
||||
|
||||
fn short_recipient(recipient: &str) -> String {
|
||||
const EDGE: usize = 10;
|
||||
if recipient.chars().count() <= EDGE * 2 + 1 {
|
||||
return recipient.to_owned();
|
||||
}
|
||||
let start: String = recipient.chars().take(EDGE).collect();
|
||||
let end: String = recipient
|
||||
.chars()
|
||||
.rev()
|
||||
.take(EDGE)
|
||||
.collect::<String>()
|
||||
.chars()
|
||||
.rev()
|
||||
.collect();
|
||||
format!("{start}…{end}")
|
||||
}
|
||||
|
||||
fn centered_rect(width_percent: u16, height: u16, area: Rect) -> Rect {
|
||||
let vertical_margin = area.height.saturating_sub(height) / 2;
|
||||
let vertical = Layout::vertical([
|
||||
|
||||
Reference in New Issue
Block a user