Repository navigation
Expand file tree
/
Copy pathclientColorFile.ml
More file actions
53 lines (45 loc) · 1.79 KB
/
Copy pathclientColorFile.ml
File metadata and controls
53 lines (45 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
(**
* Copyright (c) 2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the "hack" directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*)
open Core
open Ide_api_types
module C = Tty
(*****************************************************************************)
(* Section defining the colors we are going to use *)
(*****************************************************************************)
let err_clr = C.Bold C.Red (* Unchecked code *)
let checked_clr = C.Normal C.Green (* Checked code *)
let partial_clr = C.Normal C.Yellow (* Partially checked code *)
let default_color = C.Normal C.Default (* All the rest *)
let replace_color input =
match input with
| (Some Unchecked, str) -> (err_clr, str)
| (Some Checked, str) -> (checked_clr, str)
| (Some Partial, str) -> (partial_clr, str)
| (None, str) -> (default_color, str)
let replace_colors input =
List.map input replace_color
(*****************************************************************************)
(* The entry point. *)
(*****************************************************************************)
let go file_input output_json pos_level_l =
let str = match file_input with
| ServerUtils.FileName filename -> Sys_utils.cat filename
| ServerUtils.FileContent content -> content
in
let results = ColorFile.go str pos_level_l in
if output_json then
let open Ide_message in
let response = Coverage_levels_response
(Deprecated_text_span_coverage_levels_response results)
in
Nuclide_rpc_message_printer.print_json ~response
else if Unix.isatty Unix.stdout
then C.cprint (replace_colors results)
else print_endline str