Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- term = require("term")
- io = require("io")
- --| username : bob | | credits : 67099928834288838 |
- --===============================================================================
- --| id | stock name | buy price | sell price | quantity |
- --------------------------------------------------------------------------------
- --| 555444 | big name of a random item lalal | 127743000 | 9997581984 | 00990099 |
- function fill(width, length)
- fillercount = width - length
- fillerspace = ""
- for i=1, fillercount do
- fillerspace = fillerspace.." "
- end
- return fillerspace
- end
- function split(inputstr, sep)
- local t={} ; i=1
- for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
- t[i] = str
- i = i + 1
- end
- return t
- end
- function printUserInfo(info)
- fillerspace = fill(52, string.len(info["name"]) + string.len(info["credits"]))
- print("| username : "..info["name"]..fillerspace.."| credits : "..info["credits"].." |")
- end
- function printTableHeader()
- print("===============================================================================")
- print("| id | stock name | buy price | sell price | quantity |")
- print("-------------------------------------------------------------------------------")
- end
- function printItems(data, start, stop)
- for i, item in pairs(data) do
- if i >= start then
- if i >= stop then return end
- line = ""
- line = line.."| "..item["id"]..fill(6,string.len(item["id"])).." "
- line = line.."| "..item["name"]..fill(30,string.len(item["name"])).." "
- line = line.."| "..item["buy_price"]..fill(9,string.len(item["buy_price"])).." "
- line = line.."| "..item["sell_price"]..fill(10,string.len(item["sell_price"])).." "
- line = line.."| "..item["qty"]..fill(8,string.len(item["qty"])).." |"
- print(line)
- end
- end
- end
- function isValidCmd(cm)
- cmd = split(cm, " ")
- return cmd[1] == "r" or cmd[1] == "q" or cmd[1] == "b" or cmd[1] == "s" or cmd[1] == "n" or cmd[1] == "p"
- end
- function drawMain(data, user_info, page)
- term.clear()
- printUserInfo(user_info)
- printTableHeader()
- printItems(data, (20 * page) - 19, (20 * page) - 1)
- print("===============================================================================")
- io.write("refresh (r) next (n) prev (p) buy (b) sell (s) quit (q): ")
- end
- function handleLogin()
- term.clear()
- io.write("login : ")
- name = io.read()
- io.write("password : ")
- pass = io.read()
- return name, pass
- end
- --printUserInfo(info)
- --printTableHeader()
- --printItems(data)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement