myeon 0.5.0

myeon is a minimalist, keyboard-driven TUI Kanban board
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
use crate::app::{App, EditField, InputMode};
use crate::data::{Priority, Task, TaskStatus};
use ratatui::style::Modifier;
use ratatui::{
    Frame,
    layout::{Constraint, Direction, Layout, Rect},
    style::{Color, Style},
    text::{Line, Span},
    widgets::{Block, BorderType, Borders, List, ListItem, Paragraph},
};

pub const BG_DEEP: Color = Color::Rgb(54, 52, 58);
pub const FG_PRIMARY: Color = Color::Rgb(224, 224, 224);
pub const FG_MUTED: Color = Color::Rgb(176, 176, 176);
pub const BORDER_ACTIVE: Color = Color::Rgb(90, 155, 128);
pub const BORDER_QUIET: Color = Color::Rgb(31, 31, 31);
pub const ACCENT_URGENT: Color = Color::Rgb(179, 95, 95);

pub fn render(f: &mut Frame, app: &App) {
    let main_chunks = Layout::default()
        .direction(Direction::Vertical)
        .constraints(if matches!(app.input_mode, InputMode::Editing) {
            [
                Constraint::Length(3),
                Constraint::Min(0),
                Constraint::Length(3),
            ]
            .as_ref()
        } else {
            [
                Constraint::Length(3),
                Constraint::Min(0),
                Constraint::Length(0),
            ]
            .as_ref()
        })
        .split(f.area());

    render_header(f, app, main_chunks[0]);
    render_columns(f, app, main_chunks[1]);

    if matches!(app.input_mode, InputMode::Editing) {
        render_input_area(f, app, main_chunks[2]);
    }
}

fn render_header(f: &mut Frame, app: &App, area: Rect) {
    let header_text = match app.input_mode {
        InputMode::Normal => format!(" myeon | Context: [{}]", app.current_context.to_uppercase()),
        InputMode::Editing => " Adding Task (Tab to switch fields, Enter to submit) ".to_string(),
    };

    let header_style = if matches!(app.input_mode, InputMode::Editing) {
        Style::default().fg(BORDER_ACTIVE)
    } else {
        Style::default().fg(FG_MUTED)
    };

    let header = Paragraph::new(header_text).style(header_style).block(
        Block::default()
            .borders(Borders::BOTTOM)
            .border_style(header_style),
    );
    f.render_widget(header, area);
}

fn render_columns(f: &mut Frame, app: &App, area: Rect) {
    let columns = Layout::default()
        .direction(Direction::Horizontal)
        .constraints([
            Constraint::Percentage(25),
            Constraint::Percentage(25),
            Constraint::Percentage(25),
            Constraint::Percentage(25),
        ])
        .split(area);

    let doing_tasks = app.tasks_by_status(TaskStatus::Doing);
    let doing_override = if doing_tasks.len() > 3 {
        Some(ACCENT_URGENT)
    } else {
        None
    };

    render_column(
        f,
        columns[0],
        "Ideas",
        &app.tasks_by_status(TaskStatus::Idea),
        app.column_index == 0,
        app.selected_task_index,
        None,
        app.column_index != 0, // is_dimmed
    );
    render_column(
        f,
        columns[1],
        "To Do",
        &app.tasks_by_status(TaskStatus::Todo),
        app.column_index == 1,
        app.selected_task_index,
        None,
        app.column_index != 1, // is_dimmed
    );
    render_column(
        f,
        columns[2],
        "Doing",
        &doing_tasks,
        app.column_index == 2,
        app.selected_task_index,
        doing_override,
        app.column_index != 2, // is_dimmed
    );
    render_column(
        f,
        columns[3],
        "Done",
        &app.tasks_by_status(TaskStatus::Done),
        app.column_index == 3,
        app.selected_task_index,
        None,
        app.column_index != 3, // is_dimmed
    );
}

fn render_column(
    f: &mut Frame,
    area: Rect,
    title: &str,
    items: &[&Task],
    is_active: bool,
    selected_index: usize,
    override_color: Option<Color>,
    is_dimmed: bool,
) {
    let border_color = override_color.unwrap_or(BORDER_ACTIVE);

    let border_style = if is_dimmed {
        Style::default()
            .fg(border_color)
            .add_modifier(Modifier::DIM)
    } else {
        Style::default().fg(border_color)
    };

    let fg_primary = if is_dimmed {
        Color::Rgb(80, 80, 80)
    } else {
        FG_PRIMARY
    };
    let fg_muted = if is_dimmed {
        Color::Rgb(50, 50, 50)
    } else {
        FG_MUTED
    };

    let column_block = Block::default()
        .borders(Borders::ALL)
        .title(format!(" {} ", title))
        .border_type(BorderType::Thick)
        .border_style(border_style);

    let inner_area = column_block.inner(area);
    f.render_widget(column_block, area);

    let mut y_offset = 0u16;

    for (i, task) in items.iter().enumerate() {
        let content_width = inner_area.width.saturating_sub(4) as usize;
        let wrapped_title = wrap_text(&task.title, content_width.saturating_sub(1));
        let description = task.description.clone().unwrap_or_default();
        let wrapped_desc = wrap_text(&description, content_width);

        // Calculate height: borders (2) + title lines + description lines
        let title_lines = wrapped_title.lines().count().max(1) as u16;
        let desc_lines = if wrapped_desc.is_empty() {
            0
        } else {
            wrapped_desc.lines().count() as u16
        };
        let card_height = 2 + title_lines + desc_lines; // 2 for top/bottom border

        if y_offset + card_height > inner_area.height {
            break;
        }

        let card_area = Rect {
            x: inner_area.x,
            y: inner_area.y + y_offset,
            width: inner_area.width,
            height: card_height,
        };
        let is_selected = is_active && i == selected_index;

        let (indicator, indicator_color) = match task.priority {
            Priority::High => (
                "▌",
                if is_dimmed {
                    Color::Rgb(60, 40, 40)
                } else {
                    ACCENT_URGENT
                },
            ),
            Priority::Medium => (
                "▌",
                if is_dimmed {
                    Color::Rgb(60, 50, 30)
                } else {
                    Color::Rgb(192, 138, 62)
                },
            ),
            Priority::Low => ("▌", fg_muted),
        };

        let card_border_color = if is_selected {
            BORDER_ACTIVE
        } else if is_dimmed {
            Color::Rgb(40, 40, 40)
        } else {
            BORDER_QUIET
        };

        let mut lines: Vec<Line> = wrapped_title
            .lines()
            .enumerate()
            .map(|(idx, line)| {
                if idx == 0 {
                    Line::from(vec![
                        Span::styled(indicator, Style::default().fg(indicator_color)),
                        Span::styled(line.to_string(), Style::default().fg(fg_primary)),
                    ])
                } else {
                    Line::from(Span::styled(
                        format!(" {}", line),
                        Style::default().fg(fg_primary),
                    ))
                }
            })
            .collect();

        if !wrapped_desc.is_empty() {
            for line in wrapped_desc.lines() {
                lines.push(Line::from(Span::styled(
                    format!(" {}", line),
                    Style::default().fg(fg_muted),
                )));
            }
        }

        let card = Paragraph::new(lines).block(
            Block::default()
                .borders(Borders::ALL)
                .border_type(BorderType::Rounded)
                .border_style(Style::default().fg(card_border_color))
                .style(Style::default().bg(BG_DEEP)),
        );

        f.render_widget(card, card_area);
        y_offset += card_height + 1; // +1 for spacing between cards
    }
}

fn wrap_text(text: &str, max_width: usize) -> String {
    if max_width == 0 || text.is_empty() {
        return text.to_string();
    }

    let mut result = String::new();
    let mut current_line_len = 0;

    for word in text.split_whitespace() {
        let word_len = word.chars().count();

        if current_line_len + word_len + 1 > max_width && current_line_len > 0 {
            result.push('\n');
            current_line_len = 0;
        }

        if current_line_len > 0 {
            result.push(' ');
            current_line_len += 1;
        }

        result.push_str(word);
        current_line_len += word_len;
    }

    result
}

fn render_input_area(f: &mut Frame, app: &App, area: Rect) {
    let chunks = Layout::default()
        .direction(Direction::Horizontal)
        .constraints([
            Constraint::Percentage(30),
            Constraint::Percentage(30),
            Constraint::Percentage(20),
            Constraint::Percentage(20),
        ])
        .split(area);

    render_input_field(
        f,
        " Title ",
        &app.input,
        matches!(app.active_edit_field, EditField::Title),
        chunks[0],
    );
    render_input_field(
        f,
        " Description ",
        &app.editing_description,
        matches!(app.active_edit_field, EditField::Description),
        chunks[1],
    );

    let context_display = if app.editing_context.is_empty() {
        "↑↓ select".to_string()
    } else {
        app.editing_context.clone()
    };
    render_input_field(
        f,
        " Context ",
        &context_display,
        matches!(app.active_edit_field, EditField::Context),
        chunks[2],
    );

    let priority_display = format!("{:?}", app.editing_priority);
    render_input_field(
        f,
        " Priority ",
        &priority_display,
        matches!(app.active_edit_field, EditField::Priority),
        chunks[3],
    );

    if matches!(app.active_edit_field, EditField::Context) {
        render_context_popup(f, app, chunks[2]);
    }
    if matches!(app.active_edit_field, EditField::Priority) {
        render_priority_popup(f, app, chunks[3]);
    }
}

fn render_input_field(f: &mut Frame, title: &str, content: &str, is_active: bool, area: Rect) {
    let style = if is_active {
        Style::default().fg(BORDER_ACTIVE)
    } else {
        Style::default().fg(FG_MUTED)
    };
    let input = Paragraph::new(content).block(
        Block::default()
            .borders(Borders::ALL)
            .title(title)
            .border_style(style),
    );
    f.render_widget(input, area);
}

fn render_context_popup(f: &mut Frame, app: &App, anchor: Rect) {
    let contexts = app.get_task_contexts();
    if contexts.is_empty() {
        return;
    }

    let popup_height = (contexts.len() as u16 + 2).min(8);
    let popup_area = Rect {
        x: anchor.x,
        y: anchor.y.saturating_sub(popup_height),
        width: anchor.width,
        height: popup_height,
    };

    let items: Vec<ListItem> = contexts
        .iter()
        .enumerate()
        .map(|(i, ctx)| {
            let style = if i == app.context_list_index {
                Style::default().fg(Color::Black).bg(BORDER_ACTIVE)
            } else {
                Style::default().fg(FG_PRIMARY)
            };
            ListItem::new(format!(" {}", ctx)).style(style)
        })
        .collect();

    let list = List::new(items).block(
        Block::default()
            .borders(Borders::ALL)
            .title(" Contexts ")
            .border_style(Style::default().fg(BORDER_ACTIVE))
            .style(Style::default().bg(BG_DEEP)),
    );
    f.render_widget(ratatui::widgets::Clear, popup_area);
    f.render_widget(list, popup_area);
}

fn render_priority_popup(f: &mut Frame, app: &App, anchor: Rect) {
    let priorities = App::get_priorities();
    let popup_height = (priorities.len() as u16 + 2).min(6);
    let popup_area = Rect {
        x: anchor.x,
        y: anchor.y.saturating_sub(popup_height),
        width: anchor.width,
        height: popup_height,
    };

    let items: Vec<ListItem> = priorities
        .iter()
        .enumerate()
        .map(|(i, p)| {
            let style = if i == app.priority_list_index {
                Style::default().fg(Color::Black).bg(BORDER_ACTIVE)
            } else {
                Style::default().fg(FG_PRIMARY)
            };
            ListItem::new(format!(" {:?}", p)).style(style)
        })
        .collect();

    let list = List::new(items).block(
        Block::default()
            .borders(Borders::ALL)
            .title(" Priority ")
            .border_style(Style::default().fg(BORDER_ACTIVE))
            .style(Style::default().bg(BG_DEEP)),
    );
    f.render_widget(ratatui::widgets::Clear, popup_area);
    f.render_widget(list, popup_area);
}