Skip to content

Commit

Permalink
Upgraded --tags and --ltags output
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenldl committed Mar 5, 2023
1 parent 6692e38 commit 3f76061
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
32 changes: 27 additions & 5 deletions src/notefd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 "@[<v>%c - @[<hv>%a@]@,@]" c Fmt.(list ~sep:sp string) l
)
) table;
) else (
Fmt.pr "@[<v>%a@]"
Fmt.(seq ~sep:cut string)
s
)

let run
(fuzzy_max_edit_distance : int)
Expand Down
2 changes: 1 addition & 1 deletion src/version_string.ml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
let s = "0.1.2"
let s = "0.1.3"

0 comments on commit 3f76061

Please sign in to comment.