Commit
Author: Kevin Schoon [kevinschoon@gmail.com]
Hash: f90815eef0cec75db444dd0f9d9eeb06983d5683
Timestamp: Wed, 16 Jun 2021 19:08:17 +0000 (3 years ago)

+7 -10 +/-2 browse
count lines instead of words
1diff --git a/lib/config.ml b/lib/config.ml
2index 30d3ec4..280cd2d 100644
3--- a/lib/config.ml
4+++ b/lib/config.ml
5 @@ -132,20 +132,20 @@ module StylePair = struct
6 end
7
8 module Column = struct
9- type t = [ `Title | `Description | `Tags | `WordCount | `Slug ]
10+ type t = [ `Title | `Description | `Tags | `LineCount | `Slug ]
11
12 let to_string = function
13 | `Title -> "title"
14 | `Description -> "description"
15 | `Tags -> "tags"
16- | `WordCount -> "words"
17+ | `LineCount -> "lines"
18 | `Slug -> "slug"
19
20 let of_string = function
21 | "title" -> `Title
22 | "description" -> `Description
23 | "tags" -> `Tags
24- | "words" -> `WordCount
25+ | "lines" -> `LineCount
26 | "slug" -> `Slug
27 | key -> failwith (sprintf "unsupported column type: %s" key)
28 end
29 @@ -250,7 +250,7 @@ let of_string str =
30 match Ezjsonm.find_opt json [ Key.to_string `ColumnList ] with
31 | Some column_list ->
32 List.map ~f:Column.of_string (Ezjsonm.get_strings column_list)
33- | None -> [ `Title; `Tags; `WordCount; `Slug ]
34+ | None -> [ `Title; `Tags; `LineCount; `Slug ]
35 and styles =
36 match Ezjsonm.find_opt json [ Key.to_string `Styles ] with
37 | Some values -> StylePair.of_json values
38 diff --git a/lib/display.ml b/lib/display.ml
39index 7f518f7..03d63a1 100644
40--- a/lib/display.ml
41+++ b/lib/display.ml
42 @@ -72,12 +72,9 @@ let to_cells ?(paint = false) ~columns ~styles (notes : Note.note list) =
43 in
44 let text_value = String.concat ~sep:"|" tags in
45 (text_value, text_length, default_padding)
46- | `WordCount ->
47- let text_value =
48- Core.sprintf "%d"
49- (List.length
50- (to_words [] (note.content |> Omd.of_string)))
51- in
52+ | `LineCount ->
53+ let count = note.content |> String.split_lines |> List.length in
54+ let text_value = count |> Core.sprintf "%d" in
55 (text_value, String.length text_value, default_padding))
56 columns;
57 ])