ui.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # Copyright (C) 2021 Sven J. Grewe and other contributors
  2. #
  3. # This program is free software: you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation, either version 3 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  15. from flbry.variables import clr
  16. from flbry import variables
  17. import shutil
  18. terminal_width = shutil.get_terminal_size((80,40)).columns # Get terminal_width. Default to 40 if there is no info.
  19. empty_side = terminal_width//20 # Five percent on each verticle side.
  20. # Box colours (look at 'variables.clr' in the 'flbry' folder for more information):
  21. box_margin_clr = clr["bdma"] # Box margin colour
  22. box_inside_clr = clr["bdbu"] # Colour inside the box
  23. def midtext(txt = "",txtposition = "mid",box = "inside"): # Set the standard parameter for this function.
  24. box_left_side = " "*empty_side+box_margin_clr+" "+box_inside_clr+clr["bold"]
  25. box_right_side = box_margin_clr+" "+clr["norm"]
  26. add_l = " "*((terminal_width-(empty_side*2)-len(txt))//2) # Space between margin and text
  27. add_r = " "*(terminal_width-(empty_side*2)-len(txt)-len(add_l)) # Space between text and margin
  28. if box == "horizontal_side":
  29. complete = box_left_side+box_margin_clr+add_l+txt+add_r+box_right_side
  30. elif box == "inside":
  31. complete = box_left_side+add_l+txt+add_r+box_right_side
  32. elif box == None:
  33. complete = " "*((terminal_width-len(txt))//2)+txt
  34. else:
  35. complete = txt
  36. return complete # Complete line to print