Skip to content

Instantly share code, notes, and snippets.

@e-skri
Created July 14, 2023 14:49
Show Gist options
  • Save e-skri/cf6a5800f79aea4c31756dc0cf3657f9 to your computer and use it in GitHub Desktop.
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
---------------------------------------------------------------------------------
-- 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