Skip to content

Commit

Permalink
Fixing output when not terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenldl committed Mar 3, 2023
1 parent 0d503c8 commit 6692e38
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.1.2

- Fixed output text when output is not terminal

## 0.1.1

- Fixed checking of whether output is terminal
Expand Down
13 changes: 5 additions & 8 deletions src/notefd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ let file_read_limit = 2048

let first_n_lines_to_parse = 10

let empty_list_if_not_atty l =
let stylize_if_atty styles s =
if Unix.isatty Unix.stdout then
l
ANSITerminal.sprintf styles "%s" s
else
[]
s

let get_first_few_lines (path : string) : (string list, string) result =
try
Expand Down Expand Up @@ -344,18 +344,15 @@ let run
let colored_p formatter (i, s) =
if no_requirements || tag_matched.(i) then (
Fmt.pf formatter "%s"
ANSITerminal.(sprintf
(empty_list_if_not_atty [ Bold; red ]) "%s" s)
(stylize_if_atty ANSITerminal.[ Bold; red ] s)
) else (
Fmt.pf formatter "%s" s
)
in
Fmt.pr "@[<v>> @[<v>%s@,[ @[<hv>%a@] ]@,%@ %s@]@,@]"
(match header.title with
| None -> ""
| Some s ->
ANSITerminal.(sprintf
(empty_list_if_not_atty [ Bold; blue ]) "%s" s))
| Some s -> stylize_if_atty ANSITerminal.[ Bold; blue ] s)
Fmt.(seq ~sep:sp colored_p) (Array.to_seqi tag_arr)
header.path
)
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.1"
let s = "0.1.2"

0 comments on commit 6692e38

Please sign in to comment.