Skip to content

Commit dd19866

Browse files
committed
refactor(Tty): clean up
1 parent 3d79eed commit dd19866

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

src/tty/Tty.ml

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,27 @@ let[@tail_mod_cons] rec drop_last_empty =
1818
| [""] -> []
1919
| x :: xs -> x :: (drop_last_empty[@tailcall]) xs
2020

21+
let indent_decorations len i =
22+
match len, i with
23+
| 1, _ -> ""
24+
| _, 0 -> ""
25+
| n, i when i = n-1 -> ""
26+
| _ -> ""
27+
2128
let highlight fmt = "@<0>%s" ^^ fmt ^^ "@<0>%s"
2229

2330
let indentf ~param fmt =
2431
Format.kasprintf @@ fun s ->
2532
let lines = drop_last_empty @@ String.split_on_char '\n' s in
33+
let num_lines = List.length lines in
2634
let p m line =
27-
Format.fprintf fmt (" " ^^ highlight "%s" ^^ "%s@.")
35+
Format.fprintf fmt (" " ^^ highlight "@<1>%s" ^^ "%s@.")
2836
(Ansi.style_string ~param TtyStyle.indentation)
2937
m
3038
(Ansi.reset_string ~param TtyStyle.indentation)
3139
line
3240
in
33-
match lines with
34-
| [] -> ()
35-
| [line] -> p "" line
36-
| line :: lines -> p "" line;
37-
let rec go =
38-
function
39-
| [] -> assert false
40-
| [line] -> p "" line;
41-
| line :: lines -> p "" line;
42-
go lines
43-
in
44-
go lines
41+
List.iteri (fun i line -> p (indent_decorations num_lines i) line) lines
4542

4643
(* different parts of the display *)
4744

@@ -133,7 +130,7 @@ let render_unlocated_tag ~severity ~ansi fmt ((_, text) as tag) =
133130
text
134131
(Ansi.reset_string ~param:ansi st)
135132

136-
module TopLevelRenderer :
133+
module DiagnosticRenderer :
137134
sig
138135
type param =
139136
{
@@ -200,9 +197,9 @@ struct
200197
let d = if show_backtrace then d else {d with Diagnostic.backtrace = Emp} in
201198
let d = Diagnostic.map Message.short_code d in
202199
let ansi = Ansi.Test.guess ?use_ansi ?use_color output in
203-
let param = {TopLevelRenderer.line_breaking; block_splitting_threshold; tab_size; ansi} in
200+
let param = {DiagnosticRenderer.line_breaking; block_splitting_threshold; tab_size; ansi} in
204201
let fmt = Format.formatter_of_out_channel output in
205202
SourceReader.run @@ fun () ->
206-
TopLevelRenderer.render_diagnostic ~param fmt d;
203+
DiagnosticRenderer.render_diagnostic ~param fmt d;
207204
Format.pp_print_newline fmt ()
208205
end

0 commit comments

Comments
 (0)