Added helper functions for #81. So that we have a basic information about the terminal when outputting large lists/options.

This commit is contained in:
Anton Hvornum 2021-03-20 18:26:38 +01:00
parent b67257233f
commit e209767d13
No known key found for this signature in database
GPG Key ID: F1234C5BA67C59DF
1 changed files with 10 additions and 1 deletions

View File

@ -1,4 +1,4 @@
import getpass, pathlib
import getpass, pathlib, os, shutil
from .exceptions import *
from .profiles import Profile
from .locale_helpers import search_keyboard_layout
@ -9,6 +9,15 @@ from .networking import list_interfaces
## TODO: Some inconsistencies between the selection processes.
## Some return the keys from the options, some the values?
def get_terminal_height():
return shutil.get_terminal_size().lines
def get_terminal_width():
return shutil.get_terminal_size().columns
def get_longest_option(options):
return max([len(x) for x in options])
def get_password(prompt="Enter a password: "):
while (passwd := getpass.getpass(prompt)):
passwd_verification = getpass.getpass(prompt='And one more time for verification: ')