mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-27 13:34:28 +00:00
🔧 Use click.echo/click.prompt instead of print/input
This commit is contained in:
parent
0c16785d02
commit
2574651d6e
4 changed files with 36 additions and 13 deletions
17
poetry.lock
generated
17
poetry.lock
generated
|
@ -56,14 +56,21 @@ category = "dev"
|
|||
optional = false
|
||||
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
|
||||
|
||||
[[package]]
|
||||
name = "click"
|
||||
version = "7.1.2"
|
||||
description = "Composable command line interface toolkit"
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
|
||||
|
||||
[[package]]
|
||||
name = "colorama"
|
||||
version = "0.4.4"
|
||||
description = "Cross-platform colored terminal text."
|
||||
category = "dev"
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
|
||||
marker = "sys_platform == \"win32\""
|
||||
|
||||
[[package]]
|
||||
name = "docutils"
|
||||
|
@ -432,7 +439,7 @@ socks = ["PySocks (>=1.5.6,<1.5.7 || >1.5.7,<2.0)"]
|
|||
[metadata]
|
||||
lock-version = "1.0"
|
||||
python-versions = "^3.9"
|
||||
content-hash = "e5ce7e56ddb284da6206a9dab891023b5a8b057efd8b683e9b0c1dfb6d55131f"
|
||||
content-hash = "b205a562d986cf6f37d26656d253e542a637727073f7d16e83ceb10029762d7e"
|
||||
|
||||
[metadata.files]
|
||||
alabaster = [
|
||||
|
@ -459,6 +466,10 @@ chardet = [
|
|||
{file = "chardet-4.0.0-py2.py3-none-any.whl", hash = "sha256:f864054d66fd9118f2e67044ac8981a54775ec5b67aed0441892edb553d21da5"},
|
||||
{file = "chardet-4.0.0.tar.gz", hash = "sha256:0d6f53a15db4120f2b08c94f11e7d93d2c911ee118b6b30a04ec3ee8310179fa"},
|
||||
]
|
||||
click = [
|
||||
{file = "click-7.1.2-py2.py3-none-any.whl", hash = "sha256:dacca89f4bfadd5de3d7489b7c8a566eee0d3676333fbb50030263894c38c0dc"},
|
||||
{file = "click-7.1.2.tar.gz", hash = "sha256:d2b5255c7c6349bc1bd1e59e08cd12acbbd63ce649f2588755783aa94dfb6b1a"},
|
||||
]
|
||||
colorama = [
|
||||
{file = "colorama-0.4.4-py2.py3-none-any.whl", hash = "sha256:9f47eda37229f68eee03b24b9748937c7dc3868f906e8ba69fbcbdd3bc5dc3e2"},
|
||||
{file = "colorama-0.4.4.tar.gz", hash = "sha256:5941b2b48a20143d2267e95b1c2a7603ce057ee39fd88e7329b0c292aa16869b"},
|
||||
|
|
|
@ -9,6 +9,8 @@ license = "AGPL-3.0-or-later"
|
|||
python = "^3.9"
|
||||
royalnet = "^6.0.0a37"
|
||||
psutil = "^5.8.0"
|
||||
click = "^7.1.2"
|
||||
colorama = "^0.4.4"
|
||||
|
||||
[tool.poetry.dev-dependencies]
|
||||
pytest = "^6.1.1"
|
||||
|
|
|
@ -11,6 +11,7 @@ import royalnet.royaltyping as t
|
|||
import logging
|
||||
import asyncio
|
||||
import royalnet.engineer as engi
|
||||
import click
|
||||
|
||||
# Internal imports
|
||||
from . import magazine
|
||||
|
@ -22,7 +23,7 @@ log = logging.getLogger(__name__)
|
|||
# Code
|
||||
class ConsolePDA:
|
||||
"""
|
||||
.. todo:: Document the :class:`.ConsolePDA` class.
|
||||
A PDA which handles :mod:`royalnet` input and output using a terminal as source.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
|
@ -30,10 +31,13 @@ class ConsolePDA:
|
|||
|
||||
log.debug(f"Creating new magazine...")
|
||||
self.mag = magazine.ConsoleMagazine()
|
||||
"""
|
||||
The
|
||||
"""
|
||||
|
||||
self.dispenser: t.Optional[engi.Dispenser] = None
|
||||
"""
|
||||
The dispenser for this PDA.
|
||||
The :class:`royalnet.engineer.dispenser.Dispenser` of this PDA.
|
||||
"""
|
||||
|
||||
self.conversations: t.List[engi.Conversation] = []
|
||||
|
@ -42,9 +46,13 @@ class ConsolePDA:
|
|||
:class:`~royalnet.engineer.dispenser.Dispenser`.
|
||||
"""
|
||||
|
||||
async def run(self):
|
||||
async def run(self) -> t.NoReturn:
|
||||
"""
|
||||
Run the main loop of the :class:`.ConsolePDA`.
|
||||
"""
|
||||
|
||||
while True:
|
||||
message = input()
|
||||
message = click.prompt("", type=str, prompt_suffix=">>> ", show_default=False)
|
||||
log.debug(f"Received a new message: {message!r}")
|
||||
|
||||
log.debug(f"Creating ConsoleMessage from: {message!r}")
|
||||
|
@ -73,11 +81,12 @@ class ConsolePDA:
|
|||
|
||||
def register_partial(self, part: engi.PartialCommand, names: t.List[str]) -> engi.Command:
|
||||
"""
|
||||
Register a new :class:`PartialCommand` in the PDA, converting it to a :class:`Command` in the process.
|
||||
Register a new :class:`~royalnet.engineer.command.PartialCommand` in the PDA, converting it to a
|
||||
:class:`royalnet.engineer.Command` in the process.
|
||||
|
||||
:param part: The :class:`PartialCommand` to register.
|
||||
:param names: The :attr:`~royalnet.engineer.Command.names` to register the command as.
|
||||
:return: The resulting :class:`Command`.
|
||||
:param part: The :class:`~royalnet.engineer.command.PartialCommand` to register.
|
||||
:param names: The :attr:`~royalnet.engineer.command.Command.names` to register the command with.
|
||||
:return: The resulting :class:`~royalnet.engineer.command.Command`.
|
||||
"""
|
||||
log.debug(f"Completing partial: {part!r}")
|
||||
if part.syntax:
|
||||
|
@ -110,7 +119,7 @@ class ConsolePDA:
|
|||
log.debug(f"Putting bullet {bullet!r} in dispenser {self.dispenser!r}...")
|
||||
await self.dispenser.put(bullet)
|
||||
|
||||
log.debug("Awaiting another loop cycle")
|
||||
log.debug("Awaiting another event loop cycle...")
|
||||
await asyncio.sleep(0)
|
||||
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ import royalnet.royaltyping as t
|
|||
# External imports
|
||||
import logging
|
||||
import royalnet.engineer as engi
|
||||
import click
|
||||
|
||||
# Internal imports
|
||||
# from . import something
|
||||
|
@ -38,7 +39,7 @@ async def console_message(*,
|
|||
raise engi.exc.NotSupportedError("Console does not allow sending files.")
|
||||
|
||||
log.debug("Sending message...")
|
||||
print(text)
|
||||
click.echo(text)
|
||||
|
||||
log.debug("Creating bullet...")
|
||||
return mag.Message(_text=text)
|
||||
|
|
Loading…
Reference in a new issue