Advertisement
joshgreatuk

term_utils.lua

Feb 11th, 2025
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.81 KB | None | 0 0
  1. _M = {
  2.     ["version"] = 1.0
  3. }
  4.  
  5. ---@param text string
  6. ---@param term_y number
  7. ---@param text_colour string
  8. ---@param back_colour string
  9. ---@return nil
  10. function Write_In_Centre_Colour(text, term_y, text_colour, back_colour)
  11.     ---@type number, number
  12.     local term_x, term_y = term.getSize()
  13.     ---@type number
  14.     local text_length = string.len(text)
  15.     ---@type number
  16.     local write_x = (term_x / 2) - (text_length / 2)
  17.     term.setCursorPos(write_x, term_y)
  18.  
  19.     ---@type string
  20.     local last_text_colour = term.getTextColour()
  21.     ---@type string
  22.     local last_back_colour = term.getBackgroundColour()
  23.  
  24.     term.setTextColour(text_colour)
  25.     term.setBackgroundColour(back_colour)
  26.  
  27.     write(text)
  28.  
  29.     term.setTextColour(last_text_colour)
  30.     term.setBackgroundColour(last_back_colour)
  31. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement