Created
July 14, 2023 14:49
-
-
Save e-skri/cf6a5800f79aea4c31756dc0cf3657f9 to your computer and use it in GitHub Desktop.
Display 256 colors in Windows cmd.exe using ANSI color control sequences
This file contains hidden or 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
--------------------------------------------------------------------------------- | |
-- Display 256 colors in Windows cmd.exe using ANSI color control sequences | |
--------------------------------------------------------------------------------- | |
-- How to run: | |
-- lua.exe 256_colors.lua | |
-- Inspired by similar program in Ruby | |
-- https://github.com/gawin/bash-colors-256/blob/master/colors | |
os.execute"" | |
for i = 0, 255 do | |
-- Print color code in a background and foregroud color | |
io.write("\27[48;5;"..i.."m\27[38;5;15m"..(" %03d "):format(i)) | |
io.write("\27[33;5;0m\27[38;5;"..i.."m"..(" %03d "):format(i)) | |
local i = i + 1 | |
if i <= 16 and i % 8 == 0 or i > 16 and (i-16) % 6 == 0 then | |
io.write("\27[0m\n") | |
end | |
if i <= 16 and i % 16 == 0 or i > 16 and (i-16) % 36 == 0 then | |
io.write("\n") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment