-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For now all help messages will use the default color scheme copied from gleam. In a future change it will become possible to configure the colours. Signed-off-by: Stephen Sherratt <[email protected]>
- Loading branch information
Showing
7 changed files
with
190 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
open Import | ||
|
||
module Color = struct | ||
type t = | ||
[ `Red | ||
| `Green | ||
| `Yellow | ||
| `Blue | ||
| `Magenta | ||
| `Cyan | ||
] | ||
end | ||
|
||
type t = | ||
{ bold : bool | ||
; underline : bool | ||
; color : Color.t option | ||
} | ||
|
||
let default = { bold = false; underline = false; color = None } | ||
let reset = "\x1b[0m" | ||
|
||
let escape { bold; underline; color } = | ||
let effects = | ||
List.append (if bold then [ ";1" ] else []) (if underline then [ ";4" ] else []) | ||
in | ||
let color_code = | ||
match (color : Color.t option) with | ||
| None -> 0 | ||
| Some `Red -> 31 | ||
| Some `Green -> 32 | ||
| Some `Yellow -> 33 | ||
| Some `Blue -> 34 | ||
| Some `Magenta -> 35 | ||
| Some `Cyan -> 36 | ||
in | ||
Printf.sprintf "\x1b[%d%sm" color_code (String.concat ~sep:"" effects) | ||
;; | ||
|
||
let pp_with_style t ppf ~f = | ||
Format.pp_print_string ppf (escape t); | ||
f ppf; | ||
Format.pp_print_string ppf reset | ||
;; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module Color : sig | ||
type t = | ||
[ `Red | ||
| `Green | ||
| `Yellow | ||
| `Blue | ||
| `Magenta | ||
| `Cyan | ||
] | ||
end | ||
|
||
type t = | ||
{ bold : bool | ||
; underline : bool | ||
; color : Color.t option | ||
} | ||
|
||
val default : t | ||
val pp_with_style : t -> Format.formatter -> f:(Format.formatter -> unit) -> unit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.