Skip to content

Commit

Permalink
Add OpamConsole.utf8_symbol
Browse files Browse the repository at this point in the history
Move handling of UTF-8 to OpamConsole, instead of having hard-coded
UTF-8 sequences arbitrarily in code.

Using Uchar from the stdlib requires extlib-compat rather than extlib
(UChar.cmi mustn't be compiled on macOS or Windows).

Signed-off-by: David Allsopp <[email protected]>
  • Loading branch information
dra27 committed Apr 4, 2018
1 parent 6863809 commit 882fb75
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 30 deletions.
4 changes: 3 additions & 1 deletion .travis-ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ init-bootstrap () {
if [ "$OPAM_TEST" = "1" ]; then
opam switch create $OPAMBSSWITCH ocaml-system
eval $(opam env)
opam install cohttp-lwt-unix ssl cmdliner dose3 opam-file-format re 'jbuilder>=1.0+beta19' 'mccs>=1.1+5' --yes
# extlib is installed, since UChar.cmi causes problems with the search
# order. See also the removal of uChar and uTF8 in src_ext/jbuild-extlib-src
opam install cohttp-lwt-unix ssl cmdliner dose3 opam-file-format re extlib 'jbuilder>=1.0+beta19' 'mccs>=1.1+5' --yes
fi
rm -f "$OPAMBSROOT"/log/*
}
Expand Down
1 change: 1 addition & 0 deletions opam-core.opam
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ depends: [
"jbuilder" {build & >= "1.0+beta17"}
"cppo" {build}
]
conflicts: "extlib-compat"
available: ocaml-version >= "4.02.3"
37 changes: 18 additions & 19 deletions src/client/opamSolution.ml
Original file line number Diff line number Diff line change
Expand Up @@ -656,40 +656,39 @@ let parallel_apply t _action ~requested ?add_roots action_graph =
cleanup_artefacts successful;
let successful = PackageActionGraph.reduce successful in
let failed = PackageActionGraph.reduce (filter_graph failed) in
let print_actions filter color header ?empty actions =
let print_actions filter tint header ?empty actions =
let actions =
PackageActionGraph.fold_vertex (fun v acc ->
if filter v then v::acc else acc)
actions []
in
let actions = List.sort PackageAction.compare actions in
if actions <> [] then
OpamConsole.msg "%s%s\n%s%s\n"
(OpamConsole.colorise color
(if OpamConsole.utf8 ()
then "\xe2\x94\x8c\xe2\x94\x80 " (* U+250C U+2500 *)
else "+- "))
OpamConsole.(msg "%s%s\n%s%s\n"
(colorise tint
(Printf.sprintf "%s%s "
(utf8_symbol Symbols.box_drawings_light_down_and_right "+")
(utf8_symbol Symbols.box_drawings_light_horizontal "-")))
header
(OpamStd.Format.itemize
~bullet:(OpamConsole.colorise color
(if OpamConsole.utf8 ()
then "\xe2\x94\x82 " (* U+2503 *) else "| "))
~bullet:(colorise tint
(utf8_symbol Symbols.box_drawings_light_vertical "|" ^ " "))
(fun x -> x)
(List.map (String.concat " ") @@
OpamStd.Format.align_table
(PackageAction.to_aligned_strings actions)))
(OpamConsole.colorise color
(if OpamConsole.utf8 ()
then "\xe2\x94\x94\xe2\x94\x80 " (* U+2514 U+2500 *)
else "+- "))
(colorise tint
(Printf.sprintf "%s%s "
(utf8_symbol Symbols.box_drawings_light_up_and_right "+")
(utf8_symbol Symbols.box_drawings_light_horizontal "-"))))
else match empty with
| Some s ->
OpamConsole.msg "%s%s\n"
(OpamConsole.colorise color
(if OpamConsole.utf8 ()
then "\xe2\x95\xb6\xe2\x94\x80 " (* U+2576 U+2500 *)
else "- "))
s
OpamConsole.(msg "%s%s\n"
(colorise tint
(Printf.sprintf "%s%s "
(utf8_symbol Symbols.box_drawings_light_right "-")
(utf8_symbol Symbols.box_drawings_light_horizontal "")))
s)
| None -> ()
in
OpamConsole.msg "\n";
Expand Down
4 changes: 2 additions & 2 deletions src/client/opamSwitchCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ let list gt ~print_short =
let current = Some switch = OpamStateConfig.get_switch_opt () in
List.map
(if current then OpamConsole.colorise `bold else fun s -> s)
[ if current then if OpamConsole.utf8 ()
then "\xe2\x86\x92" (* U+2192 *) else "->"
[ if current then
OpamConsole.(utf8_symbol Symbols.rightwards_arrow "->")
else "";
OpamSwitch.to_string switch;
OpamStd.List.concat_map ","
Expand Down
23 changes: 23 additions & 0 deletions src/core/opamConsole.ml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,29 @@ let utf8, utf8_extended =
| `Always | `Never -> false
| `Auto -> Lazy.force auto && OpamStd.Sys.(os () = Darwin))

module Symbols = struct
let rightwards_arrow = Uchar.of_int 0x2192
let box_drawings_light_down_and_right = Uchar.of_int 0x250c
let box_drawings_light_horizontal = Uchar.of_int 0x2500
let box_drawings_light_vertical = Uchar.of_int 0x2502
let box_drawings_light_up_and_right = Uchar.of_int 0x2514
let box_drawings_light_right = Uchar.of_int 0x2576
let circled_division_slash = Uchar.of_int 0x2298
let asterisk_operator = Uchar.of_int 0x2217
let north_east_arrow = Uchar.of_int 0x2197
let south_east_arrow = Uchar.of_int 0x2198
let clockwise_open_circle_arrow = Uchar.of_int 0x21bb
let greek_small_letter_lambda = Uchar.of_int 0x03bb
end

let utf8_symbol c s =
if utf8 () then
let b = Buffer.create 4 in
Buffer.add_utf_8_uchar b c;
Buffer.contents b
else
s

let timer () =
if debug () then
let t = Unix.gettimeofday () in
Expand Down
17 changes: 17 additions & 0 deletions src/core/opamConsole.mli
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,23 @@ val colorise' : text_style list -> string -> string
val acolor : text_style -> unit -> string -> string
val acolor_w : int -> text_style -> out_channel -> string -> unit

module Symbols : sig
val rightwards_arrow : OpamCompat.Uchar.t
val box_drawings_light_down_and_right : OpamCompat.Uchar.t
val box_drawings_light_horizontal : OpamCompat.Uchar.t
val box_drawings_light_vertical : OpamCompat.Uchar.t
val box_drawings_light_up_and_right : OpamCompat.Uchar.t
val box_drawings_light_right : OpamCompat.Uchar.t
val circled_division_slash : OpamCompat.Uchar.t
val asterisk_operator : OpamCompat.Uchar.t
val north_east_arrow : OpamCompat.Uchar.t
val south_east_arrow : OpamCompat.Uchar.t
val clockwise_open_circle_arrow : OpamCompat.Uchar.t
val greek_small_letter_lambda : OpamCompat.Uchar.t
end

val utf8_symbol: OpamCompat.Uchar.t -> string -> string

(** Logging *)

(** Timers, only active when debug is on. Returns the time between the
Expand Down
18 changes: 12 additions & 6 deletions src/solver/opamActionGraph.ml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,18 @@ let name_of_action = function
| `Build _ -> "build"

let symbol_of_action = function
| `Remove _ -> "\xe2\x8a\x98 " (* U+2298 *)
| `Install _ -> "\xe2\x88\x97 " (* U+2217 *)
| `Change (`Up,_,_) -> "\xe2\x86\x97 " (* U+2197 *)
| `Change (`Down,_,_) -> "\xe2\x86\x98 " (* U+2198 *)
| `Reinstall _ -> "\xe2\x86\xbb " (* U+21BB *)
| `Build _ -> "\xce\xbb " (* U+03BB *)
| `Remove _ ->
OpamConsole.utf8_symbol OpamConsole.Symbols.circled_division_slash ""
| `Install _ ->
OpamConsole.utf8_symbol OpamConsole.Symbols.asterisk_operator ""
| `Change (`Up,_,_) ->
OpamConsole.utf8_symbol OpamConsole.Symbols.north_east_arrow ""
| `Change (`Down,_,_) ->
OpamConsole.utf8_symbol OpamConsole.Symbols.south_east_arrow ""
| `Reinstall _ ->
OpamConsole.utf8_symbol OpamConsole.Symbols.clockwise_open_circle_arrow ""
| `Build _ ->
OpamConsole.utf8_symbol OpamConsole.Symbols.greek_small_letter_lambda ""

let action_strings ?utf8 a =
if utf8 = None && (OpamConsole.utf8 ()) || utf8 = Some true
Expand Down
3 changes: 1 addition & 2 deletions src/solver/opamCudf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,7 @@ let cycle_conflict ~version_map univ cycle =

let arrow_concat sl =
let arrow =
if OpamConsole.utf8 () then " \xe2\x86\x92 " (* U+2192 *)
else " -> "
OpamConsole.utf8_symbol OpamConsole.Symbols.rightwards_arrow " -> "
in
String.concat (OpamConsole.colorise `yellow arrow) sl

Expand Down

0 comments on commit 882fb75

Please sign in to comment.