示例#1
0
文件: pimesh.py 项目: FLHerne/PIMesh
        networkfile = open(filename, 'r+')
        # Note that this does not (and should not) create a new file
        network = Network.from_file(networkfile)
        print("Loaded PIMesh network from file")
    except FileNotFoundError:
        networkfile = open(filename, 'w')
        network = Network()
        print("Created empty network (file not found)")

    ui = UI(network)

    try:
        ui.run()
    except KeyboardInterrupt:
        print("Caught leopard interrupt")

    networkfile.seek(0)
    try:
        network.to_file(networkfile)
        networkfile.truncate()
        print("Saved session changes to file.")
    except:
        print("Saving to file failed!")
    networkfile.close()

except IndexError:
    print("Please specify filename as first argument.")

print("PIMesh quitting...")

示例#2
0
quitting = False
while not quitting:
    UI.cols, UI.lines = shutil.get_terminal_size()
    os.system("clear")
    if current_mode == Mode.list:               # Elif chains are ugly - FIXME
        used_lines = print_entity_list()
    elif current_mode == Mode.links:
        used_lines = print_links(current_name)
    elif current_mode == Mode.help:
        used_lines = print_help()
    else:
        UI.status = "Error: Unknown current_mode!"

    used_lines += 3
    print("\n" * (UI.lines - used_lines))            # Pad vertically so that the command prompt is at the bottom of the terminal
    UI.status_line = " " + UI.status + (" " * (UI.cols - len(UI.status) - 1))
    termcolor.cprint(UI.status_line, attrs=['reverse'])
    command, arguments = split_input(input("> "))
    process_command(command, arguments)


os.system("clear")
try:
    network.to_file(open(filename, 'w'))
    print("Saved session changes to file. \nPIMesh quitting...")
except:
    print("Saving to file failed!")

print("\x1B[23t")		#restore window title