Created
August 1, 2013 13:52
-
-
Save higemaru/6131554 to your computer and use it in GitHub Desktop.
CUI bar graph sample
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
#!/usr/bin/lua | |
maxnum = tonumber(arg[1]) or 40 | |
max, min = 0, 0 | |
lines = io.stdin:lines() | |
arrays = {} | |
for line in lines do | |
-- split | |
local tmps = {} | |
for c in string.gmatch(line,'[^%s]+') do | |
table.insert(tmps, c) | |
end | |
num = tonumber(tmps[2]) | |
if #tmps == 2 and num then | |
table.insert(arrays, {tmps[1], num}) | |
if max < num then max = num end | |
if min > num then min = num end | |
end | |
end | |
for k,v in pairs(arrays) do | |
num = math.floor(maxnum * v[2] / max) | |
print( string.format('%s\t%s\t%s', v[1], v[2], string.rep('*', num) ) ) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment