rainbowify tweak
This commit is contained in:
parent
542f0533e5
commit
e59cefa041
@ -1,39 +1,39 @@
|
|||||||
--!strict
|
--!strict
|
||||||
|
|
||||||
|
type term_color_func = (string) -> string
|
||||||
|
|
||||||
|
local function rainbowify(str: string, color_map: {term_color_func}): string
|
||||||
|
local chars = str:split('')
|
||||||
|
for i, char in chars do
|
||||||
|
chars[i] = char ~= ' ' and color_map[i%5+1](char) or char
|
||||||
|
end
|
||||||
|
return table.concat(chars)
|
||||||
|
end
|
||||||
|
|
||||||
local function rainbowify_foreground(message: string): string
|
local function rainbowify_foreground(message: string): string
|
||||||
local parsed_terminal_message: {string} = {}
|
return rainbowify(message, {
|
||||||
local color_map = {
|
|
||||||
TERMINAL.OUT.FOREGROUND.RED,
|
TERMINAL.OUT.FOREGROUND.RED,
|
||||||
TERMINAL.OUT.FOREGROUND.YELLOW,
|
TERMINAL.OUT.FOREGROUND.YELLOW,
|
||||||
TERMINAL.OUT.FOREGROUND.GREEN,
|
TERMINAL.OUT.FOREGROUND.GREEN,
|
||||||
TERMINAL.OUT.FOREGROUND.BLUE,
|
TERMINAL.OUT.FOREGROUND.BLUE,
|
||||||
TERMINAL.OUT.FOREGROUND.MAGENTA,
|
TERMINAL.OUT.FOREGROUND.MAGENTA,
|
||||||
}
|
})
|
||||||
|
|
||||||
for i, char in message:split('') do
|
|
||||||
table.insert(parsed_terminal_message, char ~= ' ' and color_map[i%5+1](char) or char)
|
|
||||||
end
|
|
||||||
return table.concat(parsed_terminal_message)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function rainbowify_background(message: string): string
|
local function rainbowify_background(message: string): string
|
||||||
local parsed_terminal_message: {string} = {}
|
return rainbowify(message, {
|
||||||
local color_map = {
|
|
||||||
TERMINAL.OUT.BACKGROUND.RED,
|
TERMINAL.OUT.BACKGROUND.RED,
|
||||||
TERMINAL.OUT.BACKGROUND.YELLOW,
|
TERMINAL.OUT.BACKGROUND.YELLOW,
|
||||||
TERMINAL.OUT.BACKGROUND.GREEN,
|
TERMINAL.OUT.BACKGROUND.GREEN,
|
||||||
TERMINAL.OUT.BACKGROUND.BLUE,
|
TERMINAL.OUT.BACKGROUND.BLUE,
|
||||||
TERMINAL.OUT.BACKGROUND.MAGENTA,
|
TERMINAL.OUT.BACKGROUND.MAGENTA,
|
||||||
}
|
})
|
||||||
|
|
||||||
for i, char in message:split('') do
|
|
||||||
table.insert(parsed_terminal_message, char ~= ' ' and color_map[i%5+1](char) or char)
|
|
||||||
end
|
|
||||||
return table.concat(parsed_terminal_message)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
print(rainbowify_foreground("Rainbow foreground"))
|
print(rainbowify_foreground("Rainbow foreground"))
|
||||||
print(rainbowify_background("Rainbow background"))
|
print(
|
||||||
|
TERMINAL.OUT.FOREGROUND.BLACK(rainbowify_background("Rainbow background with black text"))
|
||||||
|
)
|
||||||
print(
|
print(
|
||||||
TERMINAL.OUT.BACKGROUND.DARK_GREY(rainbowify_foreground("Rainbow foreground on a dark grey background"))
|
TERMINAL.OUT.BACKGROUND.DARK_GREY(rainbowify_foreground("Rainbow foreground on a dark grey background"))
|
||||||
)
|
)
|
Loading…
x
Reference in New Issue
Block a user