Beispiel #1
0
def display_info(heading, *lines, end_line='Press any key to continue.'):
    """Display a set of lines on screen"""
    screen.clear()
    screen.print(make_list(heading, lines))
    screen.move(0, -1)
    if end_line:
        screen.print(' ' + end_line)
    wait_for_key()
Beispiel #2
0
def simple_input(heading, prompt):
    """Simple single field string input"""
    h, g = 11, 3
    screen.clear()
    s = tx.overlay(tx.border(), logo(), tx.ln(tx.la(heading, 4), h),
                   tx.ln(tx.la('=' * 69), h + 1),
                   tx.ln(tx.la(prompt, 4), h + g))
    screen.print(s)
    screen.move(len(prompt) + 6, h + g)
    x = input()
    return x
Beispiel #3
0
def startup():
    """Display startup screen"""
    screen.clear()
    startup_screen = tx.overlay(tx.border(), logo(),
                                tx.ln(tx.la("Starting BMS."), -2))
    screen.print(startup_screen)
    screen.move(17, -4)
    time.sleep(1)
    screen.clear()
    screen.print(
        tx.overlay(tx.border(), logo(),
                   tx.ln(tx.la("Press any key to continue."), -2)))
    screen.move(29, -4)
    wait_for_key()
    screen.clear()
Beispiel #4
0
def list_handler(heading, options, *lines, go_back=False, end_line=None):
    """Asks user for a choice in a list of options"""
    lines = list(lines)
    if lines:
        lines.append('')
    choice = 0
    selected = False
    if go_back:
        options.append("Go Back")
    while not selected:
        screen.clear()
        screen.print(make_list(heading, lines + options, len(lines) + choice))
        screen.move(0, -1)
        if end_line:
            screen.print(' ' + end_line)
        key = ord(screen.read())
        key = find_key(key)
        if key == 'enter':
            selected = True
            if go_back and choice + 1 == len(options):
                return -1
            return choice
        elif key == 'esc':
            choice = -1
            selected = True
            return -1
        if key == 'up':
            choice -= 1
            if choice < 0:
                choice = len(options) - 1
        elif key == 'down':
            choice += 1
            if choice > len(options) - 1:
                choice = 0
        elif key == 'pdown':
            choice = len(options) - 1
        elif key == 'pup':
            choice = 0
    return -1
Beispiel #5
0
def input_form(heading, types, prompts, *lines):
    """Ask the user to fill in an input form.

    Types is a string consisting of the inputs to take.
    Three types are currently supported: string, number and password.
    
    For example, 'ssnpn' passed to types will ask for two strings, 
    one numeric value, one password and one more string in that order.

    Prompts is an array consisting of prompts for each corresponding input.
    """
    inputs = []
    lines = list(lines)
    if lines:
        lines.append('')
    for x in types:
        inputs.append((x, None))
    for i, x in enumerate(inputs):
        done = False
        ask_int = False
        ask_pass = False
        while not done:
            s = make_list(heading, lines + prompts)
            screen.clear()
            screen.print(s)
            if ask_int:
                screen.move(0, -1)
                screen.print(" Please enter a numeric value.")
            if ask_pass:
                screen.move(0, -1)
                screen.print(" Please enter a valid password.")
            screen.move(len(prompts[i]) + 6, 14 + len(lines) + i)
            if x[0] == 'p':
                import getpass
                inp = getpass.getpass(prompt='').strip()
                if ' ' in inp:
                    ask_pass = True
                    continue
            else:
                inp = input().strip()
            if x[0] == 'n':
                try:
                    inputs[i] = (x[0], float(inp))
                except ValueError:
                    if not inp:
                        inputs[i] = (x[0], 0)
                    else:
                        ask_int = True
                        continue
            else:
                inputs[i] = (x[0], inp)
            prompts[i] += ' ' + inp
            done = True
    return [x[1] for x in inputs]
Beispiel #6
0
import texty as t
import interface

if __name__ == "__main__":
    """Screen Test"""
    t.size(sc.width, sc.height)
    print("Screen clear test.\nWill attempt to clear screen in 3s.")
    time.sleep(3)
    sc.clear()
    print(sc.colorama.Fore.LIGHTGREEN_EX + "Screen cleared." +
          sc.colorama.Fore.RESET)
    time.sleep(1)
    sc.clear()
    print(
        "Border detection tests.\nWill attempt to find console size and print borders."
    )
    print("width: ", sc.width, "height: ", sc.height)
    time.sleep(2)
    sc.clear()
    print(t.overlay(t.border(), t.ca('\n' * 9 + "logo test."),
                    t.ca(interface.logo())),
          end='')
    sc.move()
    time.sleep(3)
    sc.clear()
    print(t.overlay(t.border(), t.border(20, 10), t.border(10, 20)), end='')
    sc.move()
    time.sleep(1)
    print("Basic Tests Complete.")
    sc.clear()  # clear on exit