Skip to content

Commit

Permalink
Banner final retouching.
Browse files Browse the repository at this point in the history
* Make `banner` public attribute
* Use builtin print() to avoid race condition with input()
* Add README section regarding banner
  • Loading branch information
fwkz committed Jul 18, 2019
1 parent af49c96 commit 9fb249e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
39 changes: 39 additions & 0 deletions README.md
Expand Up @@ -36,6 +36,7 @@ and they were completely right, the better way is called _Riposte_.
* [Printing](#printing)
* [History](#history)
* [Prompt](#Prompt)
* [Banner](#Banner)
* [Project status](#project-status)
* [Contributing](#contributing)
* [Versioning](#versioning)
Expand Down Expand Up @@ -464,6 +465,44 @@ foo:bar > unset
foo >
```
### Banner
```python
# banner.py
from riposte import Riposte
BANNER = """ _ _ _ _ _ _ _ _ _
| | | | | | | | | | | | | | | |
| |_| | ___| | | ___ | | | | ___ _ __| | __| | |
| _ |/ _ \ | |/ _ \ | |/\| |/ _ \| '__| |/ _` | |
| | | | __/ | | (_) | \ /\ / (_) | | | | (_| |_|
\_| |_/\___|_|_|\___/ \/ \/ \___/|_| |_|\__,_(_)
Welcome User Hello World v1.2.3
"""
repl = Riposte(banner=BANNER)
@repl.command("hello")
def hello():
repl.print("Hello World!")
repl.run()
```
```bash
$ python banner.py
_ _ _ _ _ _ _ _ _
| | | | | | | | | | | | | | | |
| |_| | ___| | | ___ | | | | ___ _ __| | __| | |
| _ |/ _ \ | |/ _ \ | |/\| |/ _ \| '__| |/ _` | |
| | | | __/ | | (_) | \ /\ / (_) | | | | (_| |_|
\_| |_/\___|_|_|\___/ \/ \/ \___/|_| |_|\__,_(_)
Welcome User Hello World v1.2.3
riposte:~ $
```
## Project status
_Riposte_ is under development. It might be considered to be in beta phase.
There might be some breaking changes in the future although a lot of concepts
Expand Down
10 changes: 6 additions & 4 deletions riposte/riposte.py
Expand Up @@ -22,8 +22,9 @@ def __init__(
history_file: Path = Path.home() / ".riposte",
history_length: int = 100,
):
self.banner = banner

self._prompt = prompt
self._banner = banner
self._commands: Dict[str, Command] = {}

self._printer_thread = PrinterThread()
Expand Down Expand Up @@ -164,9 +165,10 @@ def _process(self) -> None:
def run(self) -> None:
self._printer_thread.start()

if self._banner:
self.print(self._banner)

if self.banner:
# builtin print() to avoid race condition with input()
print(self.banner)

while True:
try:
self._process()
Expand Down

0 comments on commit 9fb249e

Please sign in to comment.