Commit
+30 -25 +/-3 browse
1 | diff --git a/lib/cmd.ml b/lib/cmd.ml |
2 | index 1e9b74d..1d7df88 100644 |
3 | --- a/lib/cmd.ml |
4 | +++ b/lib/cmd.ml |
5 | @@ -228,6 +228,12 @@ note ls |
6 | (ListStyle.of_string (value_to_string (get load `ListStyle))) |
7 | (Arg_type.create ListStyle.of_string)) |
8 | ~doc:"list style [fixed | wide | simple]" |
9 | + and columns = |
10 | + flag "columns" |
11 | + (optional_with_default |
12 | + (Column.of_string_list (value_to_string (get load `ColumnList))) |
13 | + (Arg_type.create Column.of_string_list)) |
14 | + ~doc:"columns to include in output" |
15 | in |
16 | fun () -> |
17 | let open Note.Filter in |
18 | @@ -236,7 +242,7 @@ note ls |
19 | Note.Filter.find_many ?strategy:filter_kind ~args:filter_args |
20 | get_notes |
21 | in |
22 | - to_stdout ~style notes] |
23 | + to_stdout ~columns: columns ~style notes] |
24 | |
25 | let run = |
26 | Command.run ~version:"%%VERSION%%" |
27 | diff --git a/lib/note.ml b/lib/note.ml |
28 | index c51c85f..2d61ab9 100644 |
29 | --- a/lib/note.ml |
30 | +++ b/lib/note.ml |
31 | @@ -44,7 +44,7 @@ let get_description t = |
32 | | None -> None ) |
33 | | None -> None |
34 | in |
35 | - match description with Some description -> description | None -> "" |
36 | + match description with Some description -> description | None -> "" |
37 | |
38 | let get_tags t = |
39 | match t.frontmatter with |
40 | @@ -211,28 +211,27 @@ module Display = struct |
41 | |
42 | type row = cell list |
43 | |
44 | - let to_cells notes = |
45 | - [ |
46 | - [ |
47 | - ("title", [ Bold; Underlined ]); |
48 | - ("description", [ Bold; Underlined ]); |
49 | - ("tags", [ Bold; Underlined ]); |
50 | - ("words", [ Bold; Underlined ]); |
51 | - ("slug", [ Bold; Underlined ]); |
52 | - ]; |
53 | - ] |
54 | - @ List.fold ~init:[] |
55 | - ~f:(fun accm note -> |
56 | - let title = (get_title note, [ Reset ]) in |
57 | - let tags = (String.concat ~sep:"|" (get_tags note), [ Reset ]) in |
58 | - let description = (get_description note, [Reset]) in |
59 | - let word_count = |
60 | + let to_cells columns notes = |
61 | + let header = |
62 | + List.map ~f:(fun column -> (Config.Column.to_string column, [ Bold; Underlined ])) columns |
63 | + in |
64 | + let note_cells = List.fold ~init: [] ~f: (fun accm note -> |
65 | + accm @ [ List.map ~f: (fun column -> |
66 | + match column with |
67 | + | `Title -> |
68 | + ((get_title note), [Reset]) |
69 | + | `Description -> |
70 | + ((get_description note), [Reset]) |
71 | + | `Tags ->(String.concat ~sep:"|" (get_tags note), [ Reset ]) |
72 | + | `WordCount -> |
73 | ( Core.sprintf "%d" (List.length (Util.to_words note.markdown)), |
74 | [ Reset ] ) |
75 | - in |
76 | - let slug = (Slug.to_string note.slug, [ Reset ]) in |
77 | - accm @ [ [ title; description; tags; word_count; slug ] ]) |
78 | - notes |
79 | + | `Slug -> (Slug.to_string note.slug, [Reset]) |
80 | + ) columns ] |
81 | + ) notes in |
82 | + |
83 | + [ header ] @ note_cells |
84 | + |
85 | |
86 | let fixed_spacing cells = |
87 | (* find the maximum column length for all cells *) |
88 | @@ -271,8 +270,8 @@ module Display = struct |
89 | ]) |
90 | cells |
91 | |
92 | - let to_stdout ~style notes = |
93 | - let cells = to_cells notes in |
94 | + let to_stdout ~columns ~style notes = |
95 | + let cells = to_cells columns notes in |
96 | match style with |
97 | | `Simple -> |
98 | List.iter |
99 | diff --git a/lib/note.mli b/lib/note.mli |
100 | index 6f4dd30..fa8d118 100644 |
101 | --- a/lib/note.mli |
102 | +++ b/lib/note.mli |
103 | @@ -35,5 +35,5 @@ module Display : sig |
104 | |
105 | type row = cell list |
106 | |
107 | - val to_stdout : style:[< `Fixed | `Simple | `Wide ] -> t list -> unit |
108 | + val to_stdout : columns: Config.Column.t list -> style:[< `Fixed | `Simple | `Wide ] -> t list -> unit |
109 | end |