rainbowify include background and foreground
This commit is contained in:
parent
73b46b2a99
commit
3c92a89190
@ -1,13 +1,13 @@
|
||||
--!strict
|
||||
|
||||
local function rainbowify(message: string): string
|
||||
local function rainbowify_foreground(message: string): string
|
||||
local parsed_terminal_message: {string} = {}
|
||||
local color_map = {
|
||||
TERMINAL.OUT.STYLE.RED,
|
||||
TERMINAL.OUT.STYLE.YELLOW,
|
||||
TERMINAL.OUT.STYLE.GREEN,
|
||||
TERMINAL.OUT.STYLE.BLUE,
|
||||
TERMINAL.OUT.STYLE.MAGENTA,
|
||||
TERMINAL.OUT.STYLE.FOREGROUND.RED,
|
||||
TERMINAL.OUT.STYLE.FOREGROUND.YELLOW,
|
||||
TERMINAL.OUT.STYLE.FOREGROUND.GREEN,
|
||||
TERMINAL.OUT.STYLE.FOREGROUND.BLUE,
|
||||
TERMINAL.OUT.STYLE.FOREGROUND.MAGENTA,
|
||||
}
|
||||
|
||||
for i, char in message:split('') do
|
||||
@ -16,5 +16,22 @@ local function rainbowify(message: string): string
|
||||
return table.concat(parsed_terminal_message)
|
||||
end
|
||||
|
||||
print(rainbowify("rainbow text"))
|
||||
print(rainbowify("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."))
|
||||
local function rainbowify_background(message: string): string
|
||||
local parsed_terminal_message: {string} = {}
|
||||
local color_map = {
|
||||
TERMINAL.OUT.STYLE.BACKGROUND.RED,
|
||||
TERMINAL.OUT.STYLE.BACKGROUND.YELLOW,
|
||||
TERMINAL.OUT.STYLE.BACKGROUND.GREEN,
|
||||
TERMINAL.OUT.STYLE.BACKGROUND.BLUE,
|
||||
TERMINAL.OUT.STYLE.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
|
||||
|
||||
print(rainbowify_background("Rainbow background"))
|
||||
print(rainbowify_foreground("Rainbow foreground"))
|
||||
print(rainbowify_background(rainbowify_foreground("Rainbow background and foreground")))
|
Loading…
x
Reference in New Issue
Block a user