Advertisement
jordyvl

Disk program ComputerCraft

May 13th, 2014
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.73 KB | None | 0 0
  1. local termWidth, termHeight = term.getSize()
  2. local selectedItem = 1
  3. local onMainMenu = true
  4.  
  5. function Choice1()
  6.  term.clear()
  7.  term.setCursorPos(1,1)
  8.  print("Check ID")
  9.  sleep(2)
  10.  term.clear()
  11.  term.setCursorPos(1,1)
  12.  i = disk.getID("left")
  13.  print(i)
  14.  print"Press Any Key To Continue"
  15.  os.pullEvent("key")
  16. end
  17.  
  18. function Choice2()
  19. term.clear()
  20. term.setCursorPos(1,1)
  21. if disk.isPresent("left") == true then
  22. print"Do you want to label this Disk"
  23. a = read()
  24. if a == "yes" then
  25. term.clear()
  26. term.setCursorPos(1,1)
  27. print"What should the label be?"
  28. label = read()
  29. term.clear()
  30. term.setCursorPos(1,1)
  31. print(label)
  32. print"This will be the label is that good?"
  33. c = read()
  34. if c == "yes" then
  35. disk.setLabel("left", ""..label.."")
  36. sleep(1)
  37. end
  38. end
  39. end
  40. end
  41.  
  42. function Exit()
  43.  term.clear()
  44.  term.setCursorPos(1,1)
  45.  onMainMenu = false
  46. end
  47.  
  48. mainMenu = {
  49. [1] = { text = "Check ID", handler = Choice1 },
  50. [2] = { text = "Set Disk Label", handler = Choice2 },
  51. [3] = { text = "Exit", handler = Exit }
  52. }
  53.  
  54. function printMenu( menu )
  55.  for i=1,#menu do
  56.   if i == selectedItem then
  57.    print(">> "..menu[i].text)
  58.   else
  59.    print("   "..menu[i].text)
  60.   end
  61.  end
  62. end
  63.  
  64. function onKeyPressed( key, menu )
  65.  if key == keys.enter then
  66.   onItemSelected(menu)
  67.  elseif key == keys.up then
  68.   if selectedItem > 1 then
  69.    selectedItem = selectedItem - 1
  70.   end
  71.  elseif key == keys.down then
  72.   if selectedItem < #menu then
  73.    selectedItem = selectedItem + 1
  74.   end
  75.  end
  76. end
  77.  
  78. function onItemSelected( menu )
  79.  menu[selectedItem].handler()
  80. end
  81.  
  82. function main()
  83.  while onMainMenu do
  84.   term.clear()
  85.   term.setCursorPos(1,1)
  86.   printMenu(mainMenu)
  87.   event, key = os.pullEvent("key")
  88.   onKeyPressed(key,mainMenu)
  89.  end
  90. end
  91.  
  92. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement