Advertisement
Guest User

gui.lua

a guest
Oct 29th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.55 KB | None | 0 0
  1. term = require("term")
  2. io = require("io")
  3.  
  4. --| username : bob |                               | credits : 67099928834288838 |
  5. --===============================================================================
  6. --|   id   |            stock name           | buy price | sell price | quantity |                              
  7. --------------------------------------------------------------------------------
  8. --| 555444 | big name of a random item lalal | 127743000 | 9997581984 | 00990099 |
  9.  
  10. function fill(width, length)
  11.   fillercount = width - length
  12.   fillerspace = ""
  13.   for i=1, fillercount do
  14.     fillerspace = fillerspace.." "
  15.   end
  16.   return fillerspace
  17. end
  18.  
  19. function split(inputstr, sep)
  20.   local t={} ; i=1
  21.   for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
  22.     t[i] = str
  23.   i = i + 1
  24.   end
  25.   return t
  26. end
  27.  
  28. function printUserInfo(info)
  29.   fillerspace = fill(52, string.len(info["name"]) + string.len(info["credits"]))
  30.   print("| username : "..info["name"]..fillerspace.."| credits : "..info["credits"].." |")
  31. end
  32.  
  33. function printTableHeader()
  34.   print("===============================================================================")
  35.   print("|   id   |           stock name           | buy price | sell price | quantity |")
  36.   print("-------------------------------------------------------------------------------")
  37. end
  38.  
  39. function printItems(data, start, stop)
  40.   for i, item in pairs(data) do
  41.     if i >= start then
  42.       if i >= stop then return end
  43.       line = ""
  44.       line = line.."| "..item["id"]..fill(6,string.len(item["id"])).." "
  45.       line = line.."| "..item["name"]..fill(30,string.len(item["name"])).." "
  46.       line = line.."| "..item["buy_price"]..fill(9,string.len(item["buy_price"])).." "
  47.       line = line.."| "..item["sell_price"]..fill(10,string.len(item["sell_price"])).." "
  48.       line = line.."| "..item["qty"]..fill(8,string.len(item["qty"])).." |"
  49.       print(line)
  50.     end
  51.   end
  52. end
  53.  
  54. function isValidCmd(cm)
  55.   cmd = split(cm, " ")  
  56.   return cmd[1] == "r" or cmd[1] == "q" or cmd[1] == "b" or cmd[1] == "s" or cmd[1] == "n" or cmd[1] == "p"
  57. end
  58.  
  59. function drawMain(data, user_info, page)
  60.   term.clear()
  61.   printUserInfo(user_info)
  62.   printTableHeader()
  63.   printItems(data, (20 * page) - 19, (20 * page) - 1)
  64. print("===============================================================================")
  65.   io.write("refresh (r) next (n) prev (p) buy (b) sell (s) quit (q): ")
  66. end
  67.  
  68. function handleLogin()
  69.   term.clear()
  70.   io.write("login : ")
  71.   name = io.read()
  72.   io.write("password : ")
  73.   pass = io.read()
  74.   return name, pass  
  75. end
  76.  
  77. --printUserInfo(info)
  78. --printTableHeader()
  79. --printItems(data)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement