From 6692e3853a1e5d84dc1ac924a2872392b79d1e8e Mon Sep 17 00:00:00 2001 From: Daren Ldl Date: Fri, 3 Mar 2023 14:42:36 +1100 Subject: [PATCH] Fixing output when not terminal --- CHANGELOG.md | 4 ++++ src/notefd.ml | 13 +++++-------- src/version_string.ml | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c8a0df..b082f83 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/notefd.ml b/src/notefd.ml index 8fd6350..c4870df 100644 --- a/src/notefd.ml +++ b/src/notefd.ml @@ -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 @@ -344,8 +344,7 @@ 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 ) @@ -353,9 +352,7 @@ let run Fmt.pr "@[> @[%s@,[ @[%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 ) diff --git a/src/version_string.ml b/src/version_string.ml index 82ef81c..cf3860f 100644 --- a/src/version_string.ml +++ b/src/version_string.ml @@ -1 +1 @@ -let s = "0.1.1" +let s = "0.1.2"