Last active
August 21, 2016 20:08
-
-
Save viluon/a5a56036989620e63a7ab7690d6c68a7 to your computer and use it in GitHub Desktop.
A way of encoding ComputerCraft terminal colours inside strings.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Made by viluon, copyright 2016 under the MIT License (https://opensource.org/licenses/MIT) | |
local str = [[ | |
@t5Hello@ta World! | |
@tf@b0How are you people? | |
I am viluon;@b1@t0 <@tdviluon@t0\@@tbespiv.net@t0>]] | |
local pos, escape = 1 | |
local set_fg = term.setTextColour | |
local set_bg = term.setBackgroundColour | |
while pos <= #str do | |
local char = str:sub( pos, pos ) | |
if not escape and char == "@" then | |
pos = pos + 1 | |
local command = str:sub( pos, pos ) | |
pos = pos + 1 | |
local colour = 2 ^ tonumber( str:sub( pos, pos ), 16 ) | |
if command == "t" then | |
set_fg( colour ) | |
elseif command == "b" then | |
set_bg( colour ) | |
end | |
elseif not escape and char == "\\" then | |
escape = true | |
else | |
write( char ) | |
escape = false | |
end | |
pos = pos + 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment