| 52 | from module.lib.rename_process import renameProcess |
| 53 | |
| 54 | class Cli: |
| 55 | def __init__(self, client, command): |
| 56 | self.client = client |
| 57 | self.command = command |
| 58 | |
| 59 | if not self.command: |
| 60 | renameProcess('pyLoadCli') |
| 61 | self.getch = Getch() |
| 62 | self.input = "" |
| 63 | self.inputline = 0 |
| 64 | self.lastLowestLine = 0 |
| 65 | self.menuline = 0 |
| 66 | |
| 67 | self.lock = Lock() |
| 68 | |
| 69 | #processor funcions, these will be changed dynamically depending on control flow |
| 70 | self.headerHandler = self #the download status |
| 71 | self.bodyHandler = self #the menu section |
| 72 | self.inputHandler = self |
| 73 | |
| 74 | os.system("clear") |
| 75 | println(1, blue("py") + yellow("Load") + white(_(" Command Line Interface"))) |
| 76 | println(2, "") |
| 77 | |
| 78 | self.thread = RefreshThread(self) |
| 79 | self.thread.start() |
| 80 | |
| 81 | self.start() |
| 82 | else: |
| 83 | self.processCommand() |
| 84 | |
| 85 | def reset(self): |
| 86 | """ reset to initial main menu """ |
| 87 | self.input = "" |
| 88 | self.headerHandler = self.bodyHandler = self.inputHandler = self |
| 89 | |
| 90 | def start(self): |
| 91 | """ main loop. handle input """ |
| 92 | while True: |
| 93 | #inp = raw_input() |
| 94 | inp = self.getch.impl() |
| 95 | if ord(inp) == 3: |
| 96 | os.system("clear") |
| 97 | sys.exit() # ctrl + c |
| 98 | elif ord(inp) == 13: #enter |
| 99 | try: |
| 100 | self.lock.acquire() |
| 101 | self.inputHandler.onEnter(self.input) |
| 102 | |
| 103 | except Exception, e: |
| 104 | println(2, red(e)) |
| 105 | finally: |
| 106 | self.lock.release() |
| 107 | |
| 108 | elif ord(inp) == 127: |
| 109 | self.input = self.input[:-1] #backspace |
| 110 | try: |
| 111 | self.lock.acquire() |