package console
Build not yet checked sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>
Colours, tables, trees and progress rows for the terminal
Install
dune-project
Dependency
Authors
Maintainers
Sources
console-0.10.1.tbz
sha256=37ad65f6833c65814b0673f009f6b656c5194608ca03519da2e63e1051d54f6e
sha512=7677067f1a3244779cdbc5c90a8b0e1eba30c3fd58281584ea3d4c46c3e219eef0668588ca0e2938799c61a3fa831ce2146eac73717214d7baf96b497bfcd892
doc/src/console/theme.ml.html
Source file theme.ml
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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330(*--------------------------------------------------------------------------- Copyright (c) 2026 Thomas Gazagnaire. All rights reserved. SPDX-License-Identifier: ISC ---------------------------------------------------------------------------*) type role = [ `Accent | `Succeeded | `Warning | `Failed | `Muted | `Header ] type mark = [ `Running | `Succeeded | `Failed | `Cancelled | `Info | `Warning | `Error | `Debug ] type bar = [ `Line | `Block | `Ascii ] type motion = [ `Rain | `Sweep | `Shimmer ] type t = { name : string; accent : Color.t; palette : Color.t list; succeeded : Color.t; warning : Color.t; failed : Color.t; muted : Color.t option; header : Style.t; background : Color.t option; border : Border.t; motion : motion option; guide : Guide.t; spinner : string list; bar : bar; marks : mark -> string; } let name t = t.name let accent t = t.accent let palette t = t.palette let succeeded t = t.succeeded let warning t = t.warning let failed t = t.failed let muted t = t.muted let header t = t.header let background t = t.background let border t = t.border let motion t = t.motion let guide t = t.guide let spinner t = t.spinner let bar t = t.bar let mark t m = Console_text.sanitize ~keep_newlines:false (t.marks m) let unicode_marks = function | `Running -> "\xe2\x80\xa2" | `Succeeded -> "\xe2\x9c\x93" | `Failed | `Error -> "\xe2\x9c\x97" | `Cancelled -> "\xe2\x97\x8b" | `Info -> "\xe2\x80\xba" | `Warning -> "!" | `Debug -> "\xc2\xb7" let ascii_marks = function | `Running -> "[-]" | `Succeeded -> "[+]" | `Failed -> "[x]" | `Cancelled -> "[~]" | `Info -> "#" | `Warning -> "!" | `Error -> "x" | `Debug -> "." (* Entries of the xterm 256-colour palette whose contrast is 3:1 or more on black and on white alike, for a terminal whose background is unknown. *) let teal = Color.ansi_256 30 let green = Color.ansi_256 28 let amber = Color.ansi_256 136 let red = Color.ansi_256 160 let blue = Color.ansi_256 63 let magenta = Color.ansi_256 164 (* The terminal's own named colours, which the user chose for the terminal's background, and faint text for muted parts. *) let default = { name = "default"; accent = Color.bright_blue; palette = [ Color.bright_blue ]; succeeded = Color.green; warning = Color.yellow; failed = Color.red; muted = None; header = Style.bold; background = None; border = Border.rounded; motion = None; guide = Guide.single; spinner = Frames.braille; bar = `Line; marks = unicode_marks; } let v ?(name = "custom") ?(accent = default.accent) ?palette ?(succeeded = default.succeeded) ?(warning = default.warning) ?(failed = default.failed) ?muted ?(header = default.header) ?background ?(border = default.border) ?motion ?(guide = default.guide) ?(spinner = default.spinner) ?(bar = default.bar) ?(marks = default.marks) () = let palette = match palette with None | Some [] -> [ accent ] | Some p -> p in let spinner = Frames.v "Theme.v" spinner in let muted = match muted with None -> default.muted | m -> m in { name; accent; palette; succeeded; warning; failed; muted; header; background; border; motion; guide; spinner; bar; marks; } let ascii = v ~name:"ascii" ~border:Border.ascii ~guide:Guide.ascii ~spinner:Frames.ascii ~bar:`Ascii ~marks:ascii_marks () let dos_amber = Color.rgb 0xff 0xb0 0x00 let dos = v ~name:"dos" ~accent:dos_amber ~succeeded:dos_amber ~warning:dos_amber ~failed:(Color.rgb 0xff 0x55 0x55) ~muted:(Color.rgb 0xa1 0x6c 0x00) ~header:Style.(bold + fg dos_amber) ~background:Color.black ~border:Border.dos ~guide:Guide.single ~spinner:Frames.ascii ~bar:`Block ~marks:ascii_marks () let matrix_green = Color.rgb 0x33 0xff 0x33 let matrix = v ~name:"matrix" ~accent:matrix_green ~succeeded:matrix_green ~warning:(Color.rgb 0xcc 0xff 0x66) ~failed:(Color.rgb 0xff 0x33 0x33) ~muted:(Color.rgb 0x1c 0x89 0x1c) ~header:Style.(bold + fg matrix_green) ~background:Color.black ~border:Border.single ~motion:`Rain () let rainbow = v ~name:"rainbow" ~accent:magenta ~palette:[ red; amber; green; teal; blue; magenta ] ~motion:`Sweep () let still t = { t with motion = None; spinner = Frames.still } (* The colours of each scheme come from the upstream source named next to it. The contrast on the scheme's background must be 4.5:1 for the main colour, the roles and the muted colour, and 3:1 for the palette. A colour below its contrast is written here moved to just above it. The muted colour moves towards the scheme's text. The other colours change only their lightness, and keep their hue and saturation. Headers are bold, in the accent unless [header] names another colour. Frames shimmer in the accent. *) (* [hex] reads the literals below, which are all valid. *) let hex s = match Color.of_hex s with Ok c -> c | Error (`Msg m) -> invalid_arg m let scheme ~name ~accent ~succeeded ~warning ~failed ~muted ?(header = accent) ~background () = v ~name ~accent:(hex accent) ~succeeded:(hex succeeded) ~warning:(hex warning) ~failed:(hex failed) ~muted:(hex muted) ~header:Style.(bold + fg (hex header)) ~background:(hex background) ~motion:`Shimmer () (* Dracula, by Zeno Rocha (MIT): draculatheme.com/spec. *) let dracula = scheme ~name:"dracula" ~accent:"#bd93f9" ~succeeded:"#50fa7b" ~warning:"#f1fa8c" ~failed:"#ff5555" ~muted:"#8692b7" ~background:"#282a36" () (* Nord, by Sven Greb (MIT): nordtheme/nord src/nord.css. *) let nord = scheme ~name:"nord" ~accent:"#88c0d0" ~succeeded:"#a3be8c" ~warning:"#ebcb8b" ~failed:"#cf8a90" ~muted:"#969ead" ~background:"#2e3440" () (* Solarized, by Ethan Schoonover (MIT): altercation/solarized. *) let solarized_dark = scheme ~name:"solarized-dark" ~accent:"#3094da" ~succeeded:"#859900" ~warning:"#b58900" ~failed:"#e56563" ~muted:"#839496" ~header:"#93a1a1" ~background:"#002b36" () (* Solarized, by Ethan Schoonover (MIT): altercation/solarized. *) let solarized_light = scheme ~name:"solarized-light" ~accent:"#2075b1" ~succeeded:"#687700" ~warning:"#8e6b00" ~failed:"#d82824" ~muted:"#5e7379" ~header:"#586e75" ~background:"#fdf6e3" () (* gruvbox, by Pavel Pertsev (MIT/X11): morhetz/gruvbox colors/gruvbox.vim. *) let gruvbox_dark = scheme ~name:"gruvbox-dark" ~accent:"#fe8019" ~succeeded:"#b8bb26" ~warning:"#fabd2f" ~failed:"#fb5642" ~muted:"#a89984" ~background:"#282828" () (* gruvbox, by Pavel Pertsev (MIT/X11): morhetz/gruvbox colors/gruvbox.vim. *) let gruvbox_light = scheme ~name:"gruvbox-light" ~accent:"#af3a03" ~succeeded:"#74700d" ~warning:"#966211" ~failed:"#9d0006" ~muted:"#665c54" ~background:"#fbf1c7" () (* Catppuccin, by the Catppuccin organisation (MIT): catppuccin/palette palette.json 1.8.0. *) let catppuccin_latte = scheme ~name:"catppuccin-latte" ~accent:"#8839ef" ~succeeded:"#327c22" ~warning:"#996114" ~failed:"#d20f39" ~muted:"#5c5f77" ~background:"#eff1f5" () (* Catppuccin, by the Catppuccin organisation (MIT): catppuccin/palette palette.json 1.8.0. *) let catppuccin_mocha = scheme ~name:"catppuccin-mocha" ~accent:"#cba6f7" ~succeeded:"#a6e3a1" ~warning:"#f9e2af" ~failed:"#f38ba8" ~muted:"#9399b2" ~background:"#1e1e2e" () (* Tokyo Night, by enkia (MIT), night palette of folke/tokyonight.nvim (Apache-2.0). *) let tokyo_night = scheme ~name:"tokyo-night" ~accent:"#7aa2f7" ~succeeded:"#9ece6a" ~warning:"#e0af68" ~failed:"#f7768e" ~muted:"#7b83ab" ~background:"#1a1b26" () (* One Dark, by GitHub (MIT): atom/atom packages/one-dark-syntax and packages/one-dark-ui. *) let one_dark = scheme ~name:"one-dark" ~accent:"#5990ff" ~succeeded:"#98c379" ~warning:"#e5c07b" ~failed:"#e17179" ~muted:"#8e95a2" ~header:"#61afef" ~background:"#282c34" () (* Monokai, by Wimer Hazenberg (no licence stated): the 2007 Monokai.tmTheme. *) let monokai = scheme ~name:"monokai" ~accent:"#66d9ef" ~succeeded:"#a6e22e" ~warning:"#e6db74" ~failed:"#fa4b8a" ~muted:"#939080" ~background:"#272822" () (* GitHub Dark, by GitHub (MIT): primer/github-vscode-theme. *) let github_dark = scheme ~name:"github-dark" ~accent:"#2f81f7" ~succeeded:"#3fb950" ~warning:"#d29922" ~failed:"#ff7b72" ~muted:"#8b949e" ~background:"#0d1117" () (* GitHub Light, by GitHub (MIT): primer/github-vscode-theme. *) let github_light = scheme ~name:"github-light" ~accent:"#0969da" ~succeeded:"#116329" ~warning:"#9a6700" ~failed:"#cf222e" ~muted:"#656d76" ~background:"#ffffff" () let all = List.map (fun t -> (t.name, t)) [ default; ascii; dos; matrix; rainbow; dracula; nord; solarized_dark; solarized_light; gruvbox_dark; gruvbox_light; catppuccin_latte; catppuccin_mocha; tokyo_night; one_dark; monokai; github_dark; github_light; ] let of_string s = match List.assoc_opt s all with | Some t -> Ok t | None -> Fmt.error_msg "unknown theme %S, expected one of: %s" s (String.concat ", " (List.map fst all)) (* The theme slot is not a setting ([Slot.unset]), so [Env.ensure] still sets up the colours of a formatter that has only a theme. *) let slot = Slot.v ~setting:false ~watched:true () let program_theme = Atomic.make default let program () = Atomic.get program_theme let set_program t = Atomic.set program_theme t; Slot.changed () let get ppf = match Slot.find slot ppf with Some t -> t | None -> program () let set ppf t = Slot.set slot ppf t let pp_motion ppf = function | None -> Fmt.string ppf "none" | Some `Rain -> Fmt.string ppf "rain" | Some `Sweep -> Fmt.string ppf "sweep" | Some `Shimmer -> Fmt.string ppf "shimmer" let pp ppf t = Fmt.pf ppf "@[<1>(theme %s@ accent=%a@ succeeded=%a@ warning=%a@ failed=%a@ \ motion=%a@ marks=%a)@]" t.name Color.pp t.accent Color.pp t.succeeded Color.pp t.warning Color.pp t.failed pp_motion t.motion Fmt.(list ~sep:(any " ") string) (List.map (mark t) [ `Running; `Succeeded; `Failed; `Cancelled; `Info; `Warning; `Error; `Debug; ])
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>