Advertisement
Guest User

main.lua

a guest
Aug 31st, 2015
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.98 KB | None | 0 0
  1. os.loadAPI("/blackboard/blackBoard")
  2.  
  3. function display(t)
  4.         local x, y = t.getSize()
  5.         t.clear()
  6.         t.setCursorPos(1, 1)
  7.         for i = 1, x do
  8.                 t.blit(" ", "0", "7")
  9.         end
  10.         t.setCursorPos(1, 1)
  11.         t.blit("id", "00", "77")
  12.         t.setCursorPos(4, 1)
  13.         t.blit("from", "0000", "7777")
  14.         t.setCursorPos(x / 4 + 4, 1)
  15.         t.blit("to", "00", "77")
  16.         t.setCursorPos(x / 2 + 3, 1)
  17.         t.blit("message", "0000000", "7777777")
  18.  
  19.         blackBoard.load("/todo.bb")
  20.         for i = 1, blackBoard.maxid() do
  21.                 local from, to, what = blackBoard.select(i)
  22.                 t.setCursorPos(1, i + 1)
  23.                 t.write(tostring(i))
  24.                 t.setCursorPos(4, i + 1)
  25.                 t.write(from)
  26.                 t.setCursorPos(x / 4 + 4, i + 1)
  27.                 t.write(to)
  28.                 t.setCursorPos(x / 2 + 3, i + 1)
  29.                 t.write(what)
  30.         end
  31.  
  32. end
  33.  
  34. function main()
  35.         local mon = peripheral.wrap("left")
  36.         mon.setTextScale(0.5)
  37.         display(mon)
  38.         display(term)
  39.         local x, y = term.getSize()
  40.         blackBoard.load("/todo.bb")
  41.         while true do
  42.                 term.setCursorPos(1, y)
  43.                 term.write("Command: ")
  44.                 local command = io.read()
  45.                 if command == "insert" then
  46.                         display(mon)
  47.                         display(term)
  48.                         term.setCursorPos(1, y)
  49.                         term.write("from: ")
  50.                         local from = io.read()
  51.                         display(mon)
  52.                         display(term)
  53.                         term.setCursorPos(1, y)
  54.                         term.write("to: ")
  55.                         local to = io.read()
  56.                         display(mon)
  57.                         display(term)
  58.                         term.setCursorPos(1, y)
  59.                         term.write("what: ")
  60.                         local what = io.read()
  61.                         blackBoard.insert(from, to, what)
  62.                 elseif command == "delete" then
  63.                         display(mon)
  64.                         display(term)
  65.                         term.setCursorPos(1, y)
  66.                         term.write("id: ")
  67.                         local id = io.read()
  68.                         blackBoard.delete(tonumber(id))
  69.                 elseif command == "update" then
  70.                         display(mon)
  71.                         display(term)
  72.                         term.setCursorPos(1, y)
  73.                         term.write("id: ")
  74.                         local id = io.read()
  75.                         display(mon)
  76.                         display(term)
  77.                         term.setCursorPos(1, y)
  78.                         term.write("from: ")
  79.                         local from = io.read()
  80.                         if from == "" then
  81.                                 from = nil
  82.                         end
  83.                         display(mon)
  84.                         display(term)
  85.                         term.setCursorPos(1, y)
  86.                         term.write("to: ")
  87.                         local to = io.read()
  88.                         if to == "" then
  89.                                 to = nil
  90.                         end
  91.                         display(mon)
  92.                         display(term)
  93.                         term.setCursorPos(1, y)
  94.                         term.write("what: ")
  95.                         local what = io.read()
  96.                         if what == "" then
  97.                                 what = nil
  98.                         end
  99.                         print(from)
  100.                         blackBoard.update(tonumber(id), from, to, what)
  101.                 elseif command == "exit" then
  102.                         mon.clear()
  103.                         term.clear()
  104.                         return
  105.                 end
  106.  
  107.                 display(mon)
  108.                 display(term)
  109.         end
  110. end
  111.  
  112.  
  113. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement