ViniCastilho

Untitled

Oct 17th, 2022
1,312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.68 KB | None | 0 0
  1. local site = (...);
  2. site.bg = 0xF;
  3. site.fg = 0x0;
  4.  
  5. local EMPTY_STRING = '';
  6.  
  7. local format = _G.string.format;
  8. local char = _G.string.char;
  9.  
  10. local WHITESPACE = char(32);
  11.  
  12. local STYLE_HEADER = {
  13.     backgroundColor = 0x0;
  14.     foregroundColor = 0x7;
  15. };
  16.  
  17. function site:header(text, style)
  18.     local r = #text / 2;
  19.     local m = r % 1;
  20.     if (m == 0) then
  21.         local padding = WHITESPACE:rep(r);
  22.         site:text(format("%s%s%s", padding, text, padding), style);
  23.     else
  24.         local padding = WHITESPACE(r-m);
  25.         site:text(format("%s%s%s ", padding, text, padding), style);
  26.     end
  27. end
  28.  
  29. function site:draw()
  30.     site:header("HELLO WORLD!", STYLE_HEADER);
  31. end
Advertisement
Add Comment
Please, Sign In to add comment