Author: Kevin Schoon [kevinschoon@gmail.com]
Hash: 59322853af5b035e76f10a4ade3d1b65458bfc2c
Timestamp: Wed, 16 Sep 2020 17:17:15 +0000 (4 years ago)

+21 -9 +/-2 browse
add -encoding raw option for terminal based markdown renderers
1diff --git a/lib/cmd.ml b/lib/cmd.ml
2index 597d2a6..963f8d5 100644
3--- a/lib/cmd.ml
4+++ b/lib/cmd.ml
5 @@ -11,14 +11,14 @@ let init_config path =
6 let get_notes =
7 let open Config in
8 let cfg = init_config None in
9- let state_dir = (get_exn cfg "state_dir") in
10- List.map ~f: (
11- fun slug ->
12- let data = In_channel.read_all (Slug.get_path slug) in
13- Note.of_string ~data: data slug
14- ) (Slug.load state_dir)
15+ let state_dir = get_exn cfg "state_dir" in
16+ List.map
17+ ~f:(fun slug ->
18+ let data = In_channel.read_all (Slug.get_path slug) in
19+ Note.of_string ~data slug)
20+ (Slug.load state_dir)
21
22- type encoding = Json | Yaml | Text
23+ type encoding = Json | Yaml | Text | Raw
24
25 let encoding_argument =
26 Command.Arg_type.create (fun encoding_str ->
27 @@ -26,6 +26,7 @@ let encoding_argument =
28 | "Json" | "json" | "JSON" -> Json
29 | "Yaml" | "yaml" | "YAML" -> Yaml
30 | "Text" | "text" | "TEXT" -> Text
31+ | "Raw" | "raw" | "RAW" -> Raw
32 | _ -> failwith "unsupported encoding type")
33
34 let filter_arg =
35 @@ -44,6 +45,7 @@ let filter_arg =
36 type value = Config of Config.t | Note of Note.t
37
38 let encode_value value = function
39+ (* TODO: move all of this into the note module *)
40 | Json -> (
41 match value with
42 | Config config -> Ezjsonm.to_string (Config.to_json config)
43 @@ -56,6 +58,13 @@ let encode_value value = function
44 match value with
45 | Config config -> Config.to_string config
46 | Note note -> Note.to_string note )
47+ | Raw -> (
48+ match value with
49+ | Config config -> Config.to_string config
50+ | Note note ->
51+ (In_channel.read_all (Note.get_path note))
52+
53+ )
54
55 (*
56 * commands
57 @@ -196,7 +205,9 @@ note delete fuubar
58 let open Note.Filter in
59 let filter_kind = if fulltext then Fulltext else Keys in
60 let notes = get_notes in
61- let note = Note.Filter.find_one ~strategy:filter_kind ~args:filter_args notes in
62+ let note =
63+ Note.Filter.find_one ~strategy:filter_kind ~args:filter_args notes
64+ in
65 match note with
66 | Some note ->
67 Io.delete
68 @@ -227,7 +238,7 @@ note edit fuubar
69 let cfg = init_config None in
70 let open Note.Filter in
71 let filter_kind = if fulltext then Fulltext else Keys in
72- let note = find_one ~strategy: filter_kind ~args: filter_args get_notes in
73+ let note = find_one ~strategy:filter_kind ~args:filter_args get_notes in
74 match note with
75 | Some note ->
76 Io.edit
77 diff --git a/lib/note.ml b/lib/note.ml
78index 6fef4ff..8a24927 100644
79--- a/lib/note.ml
80+++ b/lib/note.ml
81 @@ -272,4 +272,5 @@ module Display = struct
82 let widths = fix_right (fixed_spacing cells) in
83 let spaced = apply widths cells in
84 List.iter ~f:(fun spaced_row -> print_endline spaced_row) spaced
85+
86 end