Advertisement
DOGGYWOOF

Untitled

Jul 25th, 2024
9
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.84 KB | None | 0 0
  1. term.clear()
  2.  
  3. -- Function to get the terminal dimensions
  4. function getTerminalSize()
  5. local width, height = term.getSize()
  6. return width, height
  7. end
  8.  
  9. -- Function to draw the loading bar centered
  10. function drawLoadingBar(current, total, message)
  11. local width, _ = getTerminalSize()
  12. local barLength = 30 -- Length of the loading bar
  13. local filledLength = math.floor((current / total) * barLength)
  14. local emptyLength = barLength - filledLength
  15. local bar = "[" .. string.rep("=", filledLength) .. string.rep(" ", emptyLength) .. "]"
  16.  
  17. -- Calculate the position to center the bar
  18. local barPos = math.floor((width - barLength - 2) / 2)
  19.  
  20. -- Move the UI down by adjusting the row numbers
  21. local barRow = 8
  22. local messageRow = 10
  23.  
  24. -- Clear the previous loading bar and message
  25. term.setCursorPos(1, barRow)
  26. term.write(string.rep(" ", width)) -- Clear the previous bar
  27. term.setCursorPos(1, messageRow)
  28. term.write(string.rep(" ", width)) -- Clear the previous message
  29.  
  30. term.setCursorPos(barPos, barRow)
  31. term.write(bar .. " " .. math.floor((current / total) * 100) .. "%")
  32.  
  33. -- Print the current message centered below the bar
  34. if message then
  35. term.setCursorPos(math.floor((width - #message) / 2), messageRow)
  36. term.write(message)
  37. end
  38. end
  39.  
  40. -- Function to center and stylize text
  41. function printCenteredText(text, row)
  42. local width, _ = getTerminalSize()
  43. local textLength = #text
  44. local pos = math.floor((width - textLength) / 2)
  45. term.setCursorPos(pos, row)
  46. term.write(text)
  47. end
  48.  
  49. -- Function to display an error message
  50. function showError(message)
  51. term.clear()
  52. local width, height = getTerminalSize()
  53. local errorMessage = "Error: " .. message
  54. local midHeight = math.floor(height / 2)
  55.  
  56. term.setCursorPos(1, midHeight)
  57. term.write(string.rep(" ", width)) -- Clear the row
  58. term.setCursorPos(math.floor((width - #errorMessage) / 2), midHeight)
  59. term.write(errorMessage)
  60.  
  61. term.setCursorPos(1, midHeight + 1)
  62. term.write("Press any key to exit...")
  63. os.pullEvent("key") -- Wait for any key press
  64. term.clear()
  65. end
  66.  
  67. -- Print the initial status messages
  68. printCenteredText("Installing...", 4) -- Moved down to row 4
  69. printCenteredText("DO NOT Interrupt Install", 6) -- Moved down to row 6
  70.  
  71. -- Define installation steps with updated messages
  72. local steps = {
  73. { message = "Setup copying files...", action = function() fs.copy("/disk/", "/root") end },
  74. { message = "Unmounting installation disk...", action = function()
  75. disk.eject("top")
  76. disk.eject("bottom")
  77. disk.eject("left")
  78. disk.eject("right")
  79. end },
  80. { message = "Formatting file system...", action = function() shell.run("rename", "/root", "/disk") end },
  81. { message = "Creating boot recovery directory...", action = function() fs.copy("/disk/", "recovery") end },
  82. { action = function() shell.run("/disk/install-assist") end } -- No message for this step
  83. }
  84.  
  85. -- Simulate the installation process with updates
  86. local totalSteps = #steps
  87. for i, step in ipairs(steps) do
  88. local success, err = pcall(function()
  89. if step.message then
  90. drawLoadingBar(i, totalSteps, step.message)
  91. else
  92. drawLoadingBar(i, totalSteps)
  93. end
  94. step.action() -- Execute the installation step
  95. sleep(4) -- Increased sleep duration to slow down the process
  96. end)
  97.  
  98. if not success then
  99. showError(err)
  100. return
  101. end
  102. end
  103.  
  104. -- Final message indicating completion
  105. local _, height = getTerminalSize()
  106. term.setCursorPos(1, height - 2)
  107. term.write(string.rep(" ", term.getSize()))
  108. term.setCursorPos(math.floor((term.getSize() - #("Installation complete!")) / 2), height - 2)
  109. term.write("Installation complete!")
  110.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement