A set of helpers to implement a text user interface (TUI) in a terminal.
- Colored command line outputs based on colorama
- Message classification in fatal, error, warning, normal, quiet, ...
- Get information like terminal dimensions from underlying terminal window
This is a minimal terminal application example which inherits from LineTerminal
.
from pyTooling.TerminalUI import LineTerminal
class Application(LineTerminal):
def __init__(self):
super().__init__(verbose=True, debug=True, quiet=False)
def run(self):
self.WriteNormal("This is a simple application.")
self.WriteWarning("This is a warning message.")
self.WriteError("This is an error message.")
# entry point
if __name__ == "__main__":
Application.versionCheck((3, 6, 0))
app = Application()
app.run()
app.exit()
This example hands over the terminal instance to a submodule, which implements
ILineTerminal
, so the submodule can also use the terminal's writing methods.
from pathlib import Path
from pyTooling.TerminalUI import LineTerminal, ILineTerminal
class SubModule(ILineTerminal):
def __init__(self, configFile: Path, terminal):
super().__init__(terminal)
if not configFile.exists():
self.WriteError(f"Config file '{configFile}' not found.")
class Application(LineTerminal):
def __init__(self):
super().__init__(verbose=True, debug=True, quiet=False)
mod = SubModule(Path("config.yml"), self)
def run(self):
pass
# entry point
if __name__ == "__main__":
app = Application()
app.run()
- Patrick Lehmann (Maintainer)
- and more...
This Python package (source code) licensed under Apache License 2.0.
The accompanying documentation is licensed under Creative Commons - Attribution 4.0 (CC-BY 4.0).
SPDX-License-Identifier: Apache-2.0