Skip to content

Commit 09a134e

Browse files
feat: wrapping for title and display nice markdown (#39)
* wip: parse task descriptions * feat: wrapping for titles and parse markdown * tests: fix test name * tests: update test * tests: add test for task widget (title wrapping) * fix: use header indent ratio to compute children's max width * fix: use parsed description length & parse headers too * fix: use config's header style on top of markdown's
1 parent ac7ea62 commit 09a134e

9 files changed

+398
-28
lines changed

Cargo.lock

Lines changed: 152 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ notify-rust = "4.11.3"
4747
lexical-sort = "0.3.1"
4848
winnow = "0.6.20"
4949
time = "0.3.37"
50+
ratskin = "0.2.0"
5051

5152
[dev-dependencies]
5253
insta = {version = "1.41.1", features = ["yaml"]}

src/components/calendar_tab.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ impl CalendarTab<'_> {
182182
} else {
183183
&vec![]
184184
};
185-
self.entries_list = TaskList::new(&self.config, tasks_to_preview, true);
185+
self.entries_list = TaskList::new(&self.config, tasks_to_preview, 200, true);
186186
self.task_list_widget_state.scroll_to_top(); // reset view
187187
self.tasks_to_events(self.tasks.clone().get(index_closest_task));
188188
}

src/components/explorer_tab.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ impl ExplorerTab<'_> {
243243
// If we have tasks, then render a TaskList widget
244244
match self.entries_right_view.first() {
245245
Some(VaultData::Task(_) | VaultData::Header(_, _, _)) => {
246-
TaskList::new(&self.config, &self.entries_right_view, false).render(
246+
TaskList::new(&self.config, &self.entries_right_view, area.width, false).render(
247247
area,
248248
frame.buffer_mut(),
249249
&mut self.task_list_widget_state,

src/components/filter_tab.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ impl Component for FilterTab<'_> {
276276
.iter()
277277
.map(|t| VaultData::Task(t.clone()))
278278
.collect::<Vec<VaultData>>(),
279+
areas.task_list.width,
279280
true,
280281
);
281282

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
source: src/widgets/task_list.rs
3+
expression: terminal.backend()
4+
---
5+
"Test────────────────────────────────────"
6+
" 1──────────────────────────────────────"
7+
" ┌✅ task 1───────────────────────────┐" Hidden by multi-width symbols: [(4, " ")]
8+
" │📅 2016/07/08 09:10:11 ❗5 │" Hidden by multi-width symbols: [(4, " "), (27, " ")]
9+
" │#tag #tag2 │"
10+
" │┌❌ subtask test with desc─────────┐│" Hidden by multi-width symbols: [(5, " ")]
11+
" ││test ││"
12+
" ││desc ││"
13+
" │└──────────────────────────────────┘│"
14+
" │┌❌ subtask test with tags─────────┐│" Hidden by multi-width symbols: [(5, " ")]
15+
" ││#tag #tag2 ││"
16+
" │└──────────────────────────────────┘│"
17+
" │┌──────────────────────────────────┐│"
18+
" ││❌ subtask test ││" Hidden by multi-width symbols: [(5, " ")]
19+
" │└──────────────────────────────────┘│"
20+
" └────────────────────────────────────┘"
21+
" 1.1───────────────────────────────────"
22+
" 1.1.1────────────────────────────────"
23+
" ┌❌ test 1.1.1─────────────────────┐" Hidden by multi-width symbols: [(6, " ")]
24+
" │test │"
25+
" │desc │"
26+
" │🥃 │" Hidden by multi-width symbols: [(6, " ")]
27+
" └──────────────────────────────────┘"
28+
" 2──────────────────────────────────────"
29+
" 2.1───────────────────────────────────"
30+
" 2.2───────────────────────────────────"
31+
" ┌❌ test 2.2────────────────────────┐" Hidden by multi-width symbols: [(5, " ")]
32+
" │test │"
33+
" │desc │"
34+
" │┌❌ subtask 2.2───────────────────┐│" Hidden by multi-width symbols: [(6, " ")]
35+
" ││📅 2016/07/08 09:10:11 ││" Hidden by multi-width symbols: [(6, " ")]
36+
" ││#tag #tag2 ││"
37+
" ││test ││"
38+
" ││desc ││"
39+
" │└─────────────────────────────────┘│"
40+
" └───────────────────────────────────┘"
41+
" "
42+
" "
43+
" "
44+
" "
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
source: src/widgets/task_list_item.rs
3+
expression: terminal.backend()
4+
---
5+
"┌✅ task with a very long title that ──┐" Hidden by multi-width symbols: [(2, " ")]
6+
"│should wrap to the next line │"
7+
"│📅 2016/07/08 09:10:11 ❗5 │" Hidden by multi-width symbols: [(2, " "), (25, " ")]
8+
"│#tag #tag2 │"
9+
"│┌❌ subtask with another long title ─┐│" Hidden by multi-width symbols: [(3, " ")]
10+
"││that should wrap around ││"
11+
"││test ││"
12+
"││desc ││"
13+
"│└────────────────────────────────────┘│"
14+
"│┌❌ subtask test─────────────────────┐│" Hidden by multi-width symbols: [(3, " ")]
15+
"││#tag #tag2 ││"
16+
"│└────────────────────────────────────┘│"
17+
"│┌❌ subtask test with a long title ──┐│" Hidden by multi-width symbols: [(3, " ")]
18+
"││123456789 1 2 3 ││"
19+
"││📅 2016/07/08 09:10:11 ❗5 ││" Hidden by multi-width symbols: [(3, " "), (26, " ")]
20+
"││test ││"
21+
"││desc ││"
22+
"│└────────────────────────────────────┘│"
23+
"│ │"
24+
"│ │"
25+
"│ │"
26+
"│ │"
27+
"│ │"
28+
"│ │"
29+
"│ │"
30+
"│ │"
31+
"│ │"
32+
"│ │"
33+
"│ │"
34+
"│ │"
35+
"│ │"
36+
"│ │"
37+
"│ │"
38+
"│ │"
39+
"│ │"
40+
"│ │"
41+
"│ │"
42+
"│ │"
43+
"│ │"
44+
"└──────────────────────────────────────┘"

src/widgets/task_list.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,20 @@ pub struct TaskList {
1414
}
1515

1616
impl TaskList {
17-
pub fn new(config: &Config, file_content: &[VaultData], display_filename: bool) -> Self {
17+
pub fn new(
18+
config: &Config,
19+
file_content: &[VaultData],
20+
max_width: u16,
21+
display_filename: bool,
22+
) -> Self {
1823
let content = file_content
1924
.iter()
2025
.map(|fc| {
2126
TaskListItem::new(
2227
fc.clone(),
2328
!config.tasks_config.use_american_format,
2429
config.tasks_config.pretty_symbols.clone(),
30+
max_width,
2531
display_filename,
2632
config.tasks_config.show_relative_due_dates,
2733
)
@@ -99,7 +105,7 @@ mod tests {
99105
use crate::{config::Config, widgets::task_list::TaskList};
100106

101107
#[test]
102-
fn test_render_search_bar() {
108+
fn test_task_list() {
103109
let test_vault = VaultData::Header(
104110
0,
105111
"Test".to_string(),
@@ -189,8 +195,9 @@ mod tests {
189195
// We don't want tests to be time dependent
190196
config.tasks_config.show_relative_due_dates = false;
191197

192-
let task_list = TaskList::new(&config, &[test_vault], true);
193-
let mut terminal = Terminal::new(TestBackend::new(40, 40)).unwrap();
198+
let max_width = 40;
199+
let task_list = TaskList::new(&config, &[test_vault], max_width, true);
200+
let mut terminal = Terminal::new(TestBackend::new(max_width, 40)).unwrap();
194201
terminal
195202
.draw(|frame| {
196203
frame.render_stateful_widget(task_list, frame.area(), &mut ScrollViewState::new());

0 commit comments

Comments
 (0)