From b5ae8ab7ead1b9f4abd8de2b87ccb5b3a243e529 Mon Sep 17 00:00:00 2001 From: santaspeen Date: Sun, 20 Feb 2022 23:36:12 +0300 Subject: [PATCH] =?UTF-8?q?!!!!!!!=20=D0=9F=D0=A0=D0=9E=D0=A7=D0=98=D0=A2?= =?UTF-8?q?=D0=90=D0=99=20=D0=9C=D0=95=D0=9D=D0=AF=20!!!!!!!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 81 +++++++++++++++++++++++++++++++++++++++++++++++++--- README_RU.md | 81 +++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 154 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index ebabe20..8d0b3d2 100644 --- a/README.md +++ b/README.md @@ -2,19 +2,92 @@ #### Версия для русских: [здесь](./README_RU.md) -## Консольная оболочка для программ на питоне +## Command-line interface for programs on Python3 -### About +### How to run -1. +```python +from console import Console +cli = Console(prompt_in=">", prompt_out="]:") + +def cli_echo(x: str): + """ Help message here """ + + message = "Echo message: " + x + + return message + +cli.add("help", cli_echo) # Add commands + +cli.run() +``` -### Usage +### Usage output + +* Basic output ```python from console import Console cli = Console(prompt_in=">", prompt_out="]:") +cli.log("cli.og") +cli.write("cli.write") + +# Output +# ]: cli.og +# ]: cli.write +``` + +* With logging output usage + +```python +from console import Console +import logging + +cli = Console(prompt_in=">", prompt_out="]:") +logging.basicConfig(level=logging.NOTSET, format="%(asctime)s - %(name)-5s - %(levelname)-7s - %(message)s") + +# All calls below will be implemented via Console +cli.logger_hook() +logging.debug("Debug log") +logging.warning('Warning log') +logging.error("Error log") +logging.info("Info log") + +# Output +# ]: 2022-02-20 23:22:49,731 - root - DEBUG - Debug log +# ]: 2022-02-20 23:22:49,731 - root - WARNING - Warning log +# ]: 2022-02-20 23:22:49,731 - root - ERROR - Error log +# ]: 2022-02-20 23:22:49,731 - root - INFO - Info log +``` + +* with `print()` and `console.log` output usage + +```python +from console import Console + +cli = Console(prompt_in=">", prompt_out="]:") + +cli.builtins_hook() + +# Output below from the hook +# After builtins_hook() => cli = console + +print("print()") + +console.write("console.write") +console.log("console.log") + +console['[] log'] +console << "<< log" + +# Output +# ]: print() +# ]: console.write +# ]: console.log +# ]: [] log +# ]: << log ``` ## Links diff --git a/README_RU.md b/README_RU.md index ddf1f29..9be3ede 100644 --- a/README_RU.md +++ b/README_RU.md @@ -1,18 +1,91 @@ # CLI in Python -## Консольная оболочка для программ на питоне +## Консольная оболочка для программ на Python3 -### О проекте +### Как запускать -1. +```python +from console import Console +cli = Console(prompt_in=">", prompt_out="]:") + +def cli_echo(x: str): + """ Help message here """ + + message = "Echo message: " + x + + return message + +cli.add("help", cli_echo) # Add commands + +cli.run() +``` -### Использование +### Использование вывода + +* Базовое использование вывода ```python from console import Console cli = Console(prompt_in=">", prompt_out="]:") +cli.log("cli.og") +cli.write("cli.write") + +# Output +# ]: cli.og +# ]: cli.write +``` + +* Использование вывода с logging + +```python +from console import Console +import logging + +cli = Console(prompt_in=">", prompt_out="]:") +logging.basicConfig(level=logging.NOTSET, format="%(asctime)s - %(name)-5s - %(levelname)-7s - %(message)s") + +# All calls below will be implemented via Console +cli.logger_hook() +logging.debug("Debug log") +logging.warning('Warning log') +logging.error("Error log") +logging.info("Info log") + +# Output +# ]: 2022-02-20 23:22:49,731 - root - DEBUG - Debug log +# ]: 2022-02-20 23:22:49,731 - root - WARNING - Warning log +# ]: 2022-02-20 23:22:49,731 - root - ERROR - Error log +# ]: 2022-02-20 23:22:49,731 - root - INFO - Info log +``` + +* Использование вывода с`print()` и `console.log` + +```python +from console import Console + +cli = Console(prompt_in=">", prompt_out="]:") + +cli.builtins_hook() + +# Output below from the hook +# After builtins_hook() => cli = console + +print("print()") + +console.write("console.write") +console.log("console.log") + +console['[] log'] +console << "<< log" + +# Output +# ]: print() +# ]: console.write +# ]: console.log +# ]: [] log +# ]: << log ``` ## Ссылки