This commit is contained in:
@@ -5,7 +5,7 @@ use ratatui::widgets::{Block, Borders, Clear, List, ListItem, ListState, Paragra
|
||||
use ratatui::Frame;
|
||||
|
||||
use crate::app::{App, FormKind, PendingActionKind, View};
|
||||
use crate::model::schedule_label;
|
||||
use crate::model::{schedule_label, Task};
|
||||
|
||||
pub fn render(frame: &mut Frame, app: &App) {
|
||||
let rows = Layout::vertical([
|
||||
@@ -59,36 +59,10 @@ pub fn render(frame: &mut Frame, app: &App) {
|
||||
|
||||
let items = match app.view {
|
||||
View::Tasks => app
|
||||
.tasks
|
||||
.overdue_tasks
|
||||
.iter()
|
||||
.map(|task| {
|
||||
let mark = if task.status == "completed" {
|
||||
"✓"
|
||||
} else {
|
||||
"○"
|
||||
};
|
||||
let reminder = task
|
||||
.reminder_time
|
||||
.as_deref()
|
||||
.map(|time| format!(" @{time}"))
|
||||
.unwrap_or_default();
|
||||
let source = task.routine_id.map(|_| " ↻").unwrap_or_default();
|
||||
let completed = task.completed_at.map(|_| " done").unwrap_or_default();
|
||||
let lock = if task.decryption_failed { " 🔒" } else { "" };
|
||||
let mut lines = vec![Line::from(format!(
|
||||
"{mark} {:<8} {:<8} {}{reminder}{source}{completed}{lock}",
|
||||
task.section,
|
||||
task.priority,
|
||||
task.visible_title()
|
||||
))];
|
||||
if let Some(notes) = task.visible_notes() {
|
||||
lines.push(Line::styled(
|
||||
format!(" {notes}"),
|
||||
Style::default().fg(Color::DarkGray),
|
||||
));
|
||||
}
|
||||
ListItem::new(lines)
|
||||
})
|
||||
.map(|task| task_list_item(task, true))
|
||||
.chain(app.tasks.iter().map(|task| task_list_item(task, false)))
|
||||
.collect::<Vec<_>>(),
|
||||
View::Routines => app
|
||||
.routines
|
||||
@@ -105,13 +79,15 @@ pub fn render(frame: &mut Frame, app: &App) {
|
||||
} else {
|
||||
""
|
||||
};
|
||||
let mut lines = vec![Line::from(format!(
|
||||
"{enabled} {:<8} {:<8} {} — {}{reminder}{lock}",
|
||||
routine.section,
|
||||
routine.priority,
|
||||
routine.visible_title(),
|
||||
schedule_label(&routine.schedule)
|
||||
))];
|
||||
let mut lines = vec![Line::from(vec![
|
||||
Span::raw(format!("{enabled} {:<8} ", routine.section)),
|
||||
priority_span(&routine.priority),
|
||||
Span::raw(format!(
|
||||
" {} — {}{reminder}{lock}",
|
||||
routine.visible_title(),
|
||||
schedule_label(&routine.schedule)
|
||||
)),
|
||||
])];
|
||||
if let Some(notes) = routine.visible_notes() {
|
||||
lines.push(Line::styled(
|
||||
format!(" {notes}"),
|
||||
@@ -132,13 +108,11 @@ pub fn render(frame: &mut Frame, app: &App) {
|
||||
.unwrap_or_default();
|
||||
let source = task.routine_id.map(|_| " ↻").unwrap_or_default();
|
||||
let lock = if task.decryption_failed { " 🔒" } else { "" };
|
||||
let mut lines = vec![Line::from(format!(
|
||||
"▣ {} {:<8} {:<8} {}{reminder}{source}{lock}",
|
||||
task.scheduled_date,
|
||||
task.section,
|
||||
task.priority,
|
||||
task.visible_title()
|
||||
))];
|
||||
let mut lines = vec![Line::from(vec![
|
||||
Span::raw(format!("▣ {} {:<8} ", task.scheduled_date, task.section)),
|
||||
priority_span(&task.priority),
|
||||
Span::raw(format!(" {}{reminder}{source}{lock}", task.visible_title())),
|
||||
])];
|
||||
if let Some(notes) = task.visible_notes() {
|
||||
lines.push(Line::styled(
|
||||
format!(" {notes}"),
|
||||
@@ -172,10 +146,16 @@ pub fn render(frame: &mut Frame, app: &App) {
|
||||
.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)",
|
||||
View::Tasks if !app.overdue_tasks.is_empty() => {
|
||||
format!(
|
||||
"Overdue ({}) • Tasks for selected day",
|
||||
app.overdue_tasks.len()
|
||||
)
|
||||
}
|
||||
View::Tasks => "Tasks for selected day".to_owned(),
|
||||
View::Routines => "Daily, weekly, and monthly routines".to_owned(),
|
||||
View::Archive => "Archived tasks".to_owned(),
|
||||
View::Devices => "Encryption devices (public recipients only)".to_owned(),
|
||||
};
|
||||
let list = List::new(items)
|
||||
.block(Block::default().borders(Borders::ALL).title(title))
|
||||
@@ -265,6 +245,59 @@ pub fn render(frame: &mut Frame, app: &App) {
|
||||
}
|
||||
}
|
||||
|
||||
fn task_list_item(task: &Task, overdue: bool) -> ListItem<'static> {
|
||||
let mark = if task.status == "completed" {
|
||||
"✓"
|
||||
} else {
|
||||
"○"
|
||||
};
|
||||
let reminder = task
|
||||
.reminder_time
|
||||
.as_deref()
|
||||
.map(|time| format!(" @{time}"))
|
||||
.unwrap_or_default();
|
||||
let source = task.routine_id.map(|_| " ↻").unwrap_or_default();
|
||||
let completed = task.completed_at.map(|_| " done").unwrap_or_default();
|
||||
let lock = if task.decryption_failed { " 🔒" } else { "" };
|
||||
let prefix = if overdue {
|
||||
Span::styled(
|
||||
format!("⚠ {} {:<8} ", task.scheduled_date, task.section),
|
||||
Style::default().fg(Color::Red).add_modifier(Modifier::BOLD),
|
||||
)
|
||||
} else {
|
||||
Span::raw(format!("{mark} {:<8} ", task.section))
|
||||
};
|
||||
let mut lines = vec![Line::from(vec![
|
||||
prefix,
|
||||
priority_span(&task.priority),
|
||||
Span::raw(format!(
|
||||
" {}{reminder}{source}{completed}{lock}",
|
||||
task.visible_title()
|
||||
)),
|
||||
])];
|
||||
if let Some(notes) = task.visible_notes() {
|
||||
lines.push(Line::styled(
|
||||
format!(" {notes}"),
|
||||
Style::default().fg(Color::DarkGray),
|
||||
));
|
||||
}
|
||||
ListItem::new(lines)
|
||||
}
|
||||
|
||||
fn priority_span(priority: &str) -> Span<'static> {
|
||||
Span::styled(format!("{priority:<8}"), priority_style(priority))
|
||||
}
|
||||
|
||||
fn priority_style(priority: &str) -> Style {
|
||||
let color = match priority {
|
||||
"must" => Color::Red,
|
||||
"should" => Color::Yellow,
|
||||
"optional" => Color::Green,
|
||||
_ => Color::Reset,
|
||||
};
|
||||
Style::default().fg(color).add_modifier(Modifier::BOLD)
|
||||
}
|
||||
|
||||
fn short_recipient(recipient: &str) -> String {
|
||||
const EDGE: usize = 10;
|
||||
if recipient.chars().count() <= EDGE * 2 + 1 {
|
||||
@@ -298,3 +331,15 @@ fn centered_rect(width_percent: u16, height: u16, area: Rect) -> Rect {
|
||||
])
|
||||
.split(vertical[1])[1]
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn priorities_have_distinct_colors() {
|
||||
assert_eq!(priority_style("must").fg, Some(Color::Red));
|
||||
assert_eq!(priority_style("should").fg, Some(Color::Yellow));
|
||||
assert_eq!(priority_style("optional").fg, Some(Color::Green));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user