-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprintf.lua
More file actions
31 lines (24 loc) · 938 Bytes
/
Copy pathprintf.lua
File metadata and controls
31 lines (24 loc) · 938 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
--[[
printf = function(s,...)
return io.write(s:format(...))
end
--]]
function printf(...)
local function wrapper(...) io.write(string.format(...)) end
local status, result = pcall(wrapper, ...)
if not status then error(result, 2) end
end
----- printf in color
----- cprintf.red( ... ) -- regular red text
----- cprintf.Red( ... ) -- bold red text
colorize_write = require 'trepl.colorize'
local colorize_allColors = {'black', 'blue', 'cyan', 'green', 'magenta', 'red', 'white', 'yellow',
'Black', 'Blue', 'Cyan', 'Green', 'Magenta', 'Red', 'White', 'Yellow', 'none'}
cprintf = {}
for col_i, color in ipairs(colorize_allColors) do
cprintf[color] = function(...)
local function wrapper(...) io.write( colorize_write[color]( string.format(...)) ) end
local status, result = pcall(wrapper, ...)
if not status then error(result, 2) end
end
end