Commit
+28 -12 +/-3 browse
1 | diff --git a/lib/cmd.ml b/lib/cmd.ml |
2 | index a3729b2..27672e4 100644 |
3 | --- a/lib/cmd.ml |
4 | +++ b/lib/cmd.ml |
5 | @@ -11,13 +11,12 @@ let init_config path = |
6 | type encoding = Json | Yaml | Text |
7 | |
8 | let encoding_argument = |
9 | - Command.Arg_type.create |
10 | - (fun encoding_str -> |
11 | - match encoding_str with |
12 | - | "Json" | "json" | "JSON" -> Json |
13 | - | "Yaml" | "yaml" | "YAML" -> Yaml |
14 | - | "Text" | "text" | "TEXT" -> Text |
15 | - | _ -> failwith "unsupported encoding type") |
16 | + Command.Arg_type.create (fun encoding_str -> |
17 | + match encoding_str with |
18 | + | "Json" | "json" | "JSON" -> Json |
19 | + | "Yaml" | "yaml" | "YAML" -> Yaml |
20 | + | "Text" | "text" | "TEXT" -> Text |
21 | + | _ -> failwith "unsupported encoding type") |
22 | |
23 | type value = Config of Config.t | Note of Note.t |
24 | |
25 | @@ -35,6 +34,15 @@ let encode_value value = function |
26 | | Config config -> Config.to_string config |
27 | | Note note -> Note.to_string note ) |
28 | |
29 | + let format_note note = |
30 | + let open ANSITerminal in |
31 | + let title = Note.get_title note in |
32 | + printf [ANSITerminal.Bold] "%s\n" title |
33 | + |
34 | + (* |
35 | + * commands |
36 | + *) |
37 | + |
38 | let create_note = |
39 | let open Command.Let_syntax in |
40 | Command.basic ~summary:"create a new note" |
41 | @@ -91,8 +99,12 @@ let show_config = |
42 | note config -get state_dir\n\n\n\ |
43 | \ ") |
44 | [%map_open |
45 | - let key = flag "get" (optional string) ~doc:"get a config value" |
46 | - and encoding = flag "encoding" (optional_with_default Json encoding_argument) ~doc: "encoding" in |
47 | + let key = flag "get" (optional string) ~doc:"get a config value" |
48 | + and encoding = |
49 | + flag "encoding" |
50 | + (optional_with_default Json encoding_argument) |
51 | + ~doc:"encoding" |
52 | + in |
53 | fun () -> |
54 | let open Config in |
55 | let cfg = init_config None in |
56 | @@ -126,7 +138,7 @@ let list_notes = |
57 | slugs |
58 | in |
59 | let notes = Note.filter (Note.read_notes paths) filters in |
60 | - List.iter ~f:(fun x -> print_endline (Note.get_title x)) notes] |
61 | + List.iter ~f:(fun note -> (format_note note)) notes] |
62 | |
63 | let cat_note = |
64 | let open Command.Let_syntax in |
65 | @@ -141,7 +153,10 @@ let cat_note = |
66 | \ ") |
67 | [%map_open |
68 | let filters = anon (sequence ("filter" %: string)) |
69 | - and encoding = flag "encoding" (optional_with_default Text encoding_argument) ~doc: "encoding format" |
70 | + and encoding = |
71 | + flag "encoding" |
72 | + (optional_with_default Text encoding_argument) |
73 | + ~doc:"encoding format" |
74 | in |
75 | fun () -> |
76 | let open Config in |
77 | diff --git a/lib/dune b/lib/dune |
78 | index 0c5fa95..0c98991 100644 |
79 | --- a/lib/dune |
80 | +++ b/lib/dune |
81 | @@ -2,4 +2,4 @@ |
82 | (name note_lib) |
83 | (preprocess |
84 | (pps ppx_jane)) |
85 | - (libraries base core ezjsonm omd stdio yaml)) |
86 | + (libraries ANSITerminal base core ezjsonm omd stdio yaml)) |
87 | diff --git a/note.opam b/note.opam |
88 | index 9cfd4db..0b893ea 100644 |
89 | --- a/note.opam |
90 | +++ b/note.opam |
91 | @@ -9,6 +9,7 @@ license: "AGPL3" |
92 | homepage: "https://github.com/kevinschoon/note" |
93 | bug-reports: "https://github.com/kevinschoon/note/issues" |
94 | depends: [ |
95 | + "ANSITerminal" {>= "0.8.2"} |
96 | "base" {>= "v0.14.0"} |
97 | "core" {>= "v0.14.0"} |
98 | "dune" {>= "2.7" & >= "2.7"} |