|
19 | 19 |
|
20 | 20 | A set of helpers to implement a text user interface (TUI) in a terminal. |
21 | 21 |
|
| 22 | +## Features |
| 23 | +* Colored command line outputs based on colorama |
| 24 | +* Message classification in fatal, error, warning, normal, quiet, ... |
| 25 | +* Get information like terminal dimensions from underlying terminal window |
| 26 | + |
| 27 | + |
| 28 | +## Simple Terminal Application |
| 29 | + |
| 30 | +This is a minimal terminal application example which inherits from `LineTerminal`. |
| 31 | + |
| 32 | +```python |
| 33 | +from pyTerminalUI import LineTerminal |
| 34 | + |
| 35 | +class Application(LineTerminal): |
| 36 | + def __init__(self): |
| 37 | + super().__init__(verbose=True, debug=True, quiet=False) |
| 38 | + |
| 39 | + def run(self): |
| 40 | + self.WriteNormal("This is a simple application.") |
| 41 | + self.WriteWarning("This is a warning message.") |
| 42 | + self.WriteError("This is an error message.") |
| 43 | + |
| 44 | +# entry point |
| 45 | +if __name__ == "__main__": |
| 46 | + Application.versionCheck((3,6,0)) |
| 47 | + app = Application() |
| 48 | + app.run() |
| 49 | + app.exit() |
| 50 | +``` |
| 51 | + |
| 52 | +## Complex Terminal Application |
| 53 | + |
| 54 | +This example hands over the terminal instance to a submodule, which implements |
| 55 | +`ILineTerminal`, so the submodule can also use the terminal's writing methods. |
| 56 | + |
| 57 | +```python |
| 58 | +from pathlib import Path |
| 59 | +from pyTerminalUI import LineTerminal, ILineTerminal |
| 60 | + |
| 61 | +class SubModule(ILineTerminal): |
| 62 | + def __init__(self, configFile, terminal): |
| 63 | + super().__init__(terminal) |
| 64 | + |
| 65 | + if not configFile.exists(): |
| 66 | + self.WriteError("Config file '{0!s}' not found.".format(configFile)) |
| 67 | + |
| 68 | + |
| 69 | +class Application(LineTerminal): |
| 70 | + def __init__(self): |
| 71 | + super().__init__(verbose=True, debug=True, quiet=False) |
| 72 | + |
| 73 | + mod = SubModule(Path("config.yml"), self) |
| 74 | + |
| 75 | + def run(self): |
| 76 | + pass |
| 77 | + |
| 78 | +# entry point |
| 79 | +if __name__ == "__main__": |
| 80 | + app = Application() |
| 81 | + app.run() |
| 82 | +``` |
| 83 | + |
22 | 84 |
|
23 | 85 | ## Contributors |
24 | 86 |
|
|
0 commit comments