Skip to content

Instantly share code, notes, and snippets.

@x8x
Last active October 22, 2018 20:52
Show Gist options
  • Save x8x/afc2006f245a961ddfa9131bdf15485b to your computer and use it in GitHub Desktop.
Save x8x/afc2006f245a961ddfa9131bdf15485b to your computer and use it in GitHub Desktop.
Console colors
Red []
join: func ["Concatenate values"
a "Coerced to string if not a series, map, or object"
b {Single value or block of values; reduced if a is not an object or map}
][
if all [block? :b not object? :a not map? :a] [b: reduce b]
case [
series? :a [append copy a :b]
map? :a [extend copy a :b]
object? :a [make a :b]
'else [append form :a :b]
]
]
colors: [black red green yellow blue magenta cyan white]
;https://en.wikipedia.org/wiki/ANSI_escape_code
color: function [s f /bg b /space][
o: clear {}
s: form s
if space [s: rejoin [{ } s { }]]
if t: find colors f [
append o join {3} (index? t) - 1
]
if all [bg t: find colors b] [
append o join {;4} (index? t) - 1
]
unless empty? o [
s: rejoin [{^[[} o {m} s {^[[0m}]
]
s
]
warn: function[n][loop n [print {^[[?5h^[[F} wait .05 print {^[[?5l^[[F} wait .05] exit]
beep: does [warn 3]
blink: function[s][
insert r: form s {^[[5m}
unless find/last r {^[[0m} [append r {^[[0m}]
r
]
alert: func [s][beep print blink color/bg/space s 'white 'red]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment