-- Drawing palette: each entry is a named 256-colour index. local M = {} -- Each entry carries the ANSI 256-colour index used by the terminal editor -- and the RGB triplet used by the windowed one. M.entries = { { name = "nuit", index = 17, rgb = { 24, 32, 84 } }, { name = "gris", index = 240, rgb = { 120, 120, 126 } }, { name = "blanc", index = 231, rgb = { 245, 245, 245 } }, { name = "rouge", index = 196, rgb = { 214, 40, 60 } }, { name = "orange", index = 208, rgb = { 235, 130, 35 } }, { name = "jaune", index = 226, rgb = { 245, 215, 60 } }, { name = "vert", index = 46, rgb = { 50, 205, 70 } }, { name = "cyan", index = 51, rgb = { 60, 215, 215 } }, { name = "bleu", index = 33, rgb = { 50, 120, 220 } }, { name = "violet", index = 129, rgb = { 140, 90, 220 } }, { name = "rose", index = 205, rgb = { 240, 110, 165 } }, { name = "brun", index = 94, rgb = { 140, 95, 55 } }, } M.background_rgb = { 26, 28, 34 } M.default_slot = 4 -- rouge function M.count() return #M.entries end function M.is_valid_slot(slot) return type(slot) == "number" and slot >= 1 and slot <= #M.entries end function M.index_of_slot(slot) if not M.is_valid_slot(slot) then return 0 end return M.entries[slot].index end function M.label(slot) if not M.is_valid_slot(slot) then return "?" end return M.entries[slot].name end function M.slot_of(name) for slot = 1, #M.entries do if M.entries[slot].name == name then return slot end end return nil end -- RGB of a cell colour: index 0 is the empty canvas background. function M.rgb_of(index) if index == 0 or index == nil then return M.background_rgb end for slot = 1, #M.entries do if M.entries[slot].index == index then return M.entries[slot].rgb end end return M.background_rgb end function M.next_slot(slot) local next_slot = slot + 1 if next_slot > #M.entries then next_slot = 1 end return next_slot end function M.previous_slot(slot) local previous = slot - 1 if previous < 1 then previous = #M.entries end return previous end return M