From 3f760610991d7b41ba58174eac8f3e119a234285 Mon Sep 17 00:00:00 2001 From: Daren Ldl Date: Sun, 5 Mar 2023 13:16:05 +1100 Subject: [PATCH] Upgraded --tags and --ltags output --- CHANGELOG.md | 8 ++++++++ src/notefd.ml | 32 +++++++++++++++++++++++++++----- src/version_string.ml | 2 +- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b082f83..062f8b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## 0.1.3 + +- Upgraded `--tags` and `--ltags` output to be more human readable + when output is terminal + + - Changed behavior to output each tag in individual line when output + is not terminal + ## 0.1.2 - Fixed output text when output is not terminal diff --git a/src/notefd.ml b/src/notefd.ml index c4870df..233ed54 100644 --- a/src/notefd.ml +++ b/src/notefd.ml @@ -8,8 +8,11 @@ let file_read_limit = 2048 let first_n_lines_to_parse = 10 +let stdout_is_terminal () = + Unix.isatty Unix.stdout + let stylize_if_atty styles s = - if Unix.isatty Unix.stdout then + if stdout_is_terminal () then ANSITerminal.sprintf styles "%s" s else s @@ -218,10 +221,29 @@ let lowercase_set_of_tags (tags : string list) : String_set.t = tags let print_tag_set (tags : String_set.t) = - String_set.to_seq tags - |> Seq.iter (fun s -> - Fmt.pr "%s@ " s - ) + let s = String_set.to_seq tags in + if stdout_is_terminal () then ( + let table = Array.make 256 [] in + Seq.iter (fun s -> + let row = Char.code s.[0] in + table.(row) <- s :: table.(row) + ) s; + Array.iteri (fun i l -> + table.(i) <- List.rev l + ) table; + Array.iteri (fun i l -> + match l with + | [] -> () + | _ -> ( + let c = Char.chr i in + Fmt.pr "@[%c - @[%a@]@,@]" c Fmt.(list ~sep:sp string) l + ) + ) table; + ) else ( + Fmt.pr "@[%a@]" + Fmt.(seq ~sep:cut string) + s + ) let run (fuzzy_max_edit_distance : int) diff --git a/src/version_string.ml b/src/version_string.ml index cf3860f..cb81e22 100644 --- a/src/version_string.ml +++ b/src/version_string.ml @@ -1 +1 @@ -let s = "0.1.2" +let s = "0.1.3"