Skip to content

Commit b5ae8ab

Browse files
committed
!!!!!!! ПРОЧИТАЙ МЕНЯ !!!!!!!
1 parent 363a23d commit b5ae8ab

File tree

2 files changed

+154
-8
lines changed

2 files changed

+154
-8
lines changed

README.md

+77-4
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,92 @@
22

33
#### Версия для русских: [здесь](./README_RU.md)
44

5-
## Консольная оболочка для программ на питоне
5+
## Command-line interface for programs on Python3
66

7-
### About
7+
### How to run
88

9-
1.
9+
```python
10+
from console import Console
11+
cli = Console(prompt_in=">", prompt_out="]:")
12+
13+
def cli_echo(x: str):
14+
""" Help message here """
15+
16+
message = "Echo message: " + x
17+
18+
return message
19+
20+
cli.add("help", cli_echo) # Add commands
21+
22+
cli.run()
23+
```
1024

11-
### Usage
25+
### Usage output
26+
27+
* Basic output
1228

1329
```python
1430
from console import Console
1531

1632
cli = Console(prompt_in=">", prompt_out="]:")
1733

34+
cli.log("cli.og")
35+
cli.write("cli.write")
36+
37+
# Output
38+
# ]: cli.og
39+
# ]: cli.write
40+
```
41+
42+
* With logging output usage
43+
44+
```python
45+
from console import Console
46+
import logging
47+
48+
cli = Console(prompt_in=">", prompt_out="]:")
49+
logging.basicConfig(level=logging.NOTSET, format="%(asctime)s - %(name)-5s - %(levelname)-7s - %(message)s")
50+
51+
# All calls below will be implemented via Console
52+
cli.logger_hook()
53+
logging.debug("Debug log")
54+
logging.warning('Warning log')
55+
logging.error("Error log")
56+
logging.info("Info log")
57+
58+
# Output
59+
# ]: 2022-02-20 23:22:49,731 - root - DEBUG - Debug log
60+
# ]: 2022-02-20 23:22:49,731 - root - WARNING - Warning log
61+
# ]: 2022-02-20 23:22:49,731 - root - ERROR - Error log
62+
# ]: 2022-02-20 23:22:49,731 - root - INFO - Info log
63+
```
64+
65+
* with `print()` and `console.log` output usage
66+
67+
```python
68+
from console import Console
69+
70+
cli = Console(prompt_in=">", prompt_out="]:")
71+
72+
cli.builtins_hook()
73+
74+
# Output below from the hook
75+
# After builtins_hook() => cli = console
76+
77+
print("print()")
78+
79+
console.write("console.write")
80+
console.log("console.log")
81+
82+
console['[] log']
83+
console << "<< log"
84+
85+
# Output
86+
# ]: print()
87+
# ]: console.write
88+
# ]: console.log
89+
# ]: [] log
90+
# ]: << log
1891
```
1992

2093
## Links

README_RU.md

+77-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,91 @@
11
# CLI in Python
22

3-
## Консольная оболочка для программ на питоне
3+
## Консольная оболочка для программ на Python3
44

5-
### О проекте
5+
### Как запускать
66

7-
1.
7+
```python
8+
from console import Console
9+
cli = Console(prompt_in=">", prompt_out="]:")
10+
11+
def cli_echo(x: str):
12+
""" Help message here """
13+
14+
message = "Echo message: " + x
15+
16+
return message
17+
18+
cli.add("help", cli_echo) # Add commands
19+
20+
cli.run()
21+
```
822

9-
### Использование
23+
### Использование вывода
24+
25+
* Базовое использование вывода
1026

1127
```python
1228
from console import Console
1329

1430
cli = Console(prompt_in=">", prompt_out="]:")
1531

32+
cli.log("cli.og")
33+
cli.write("cli.write")
34+
35+
# Output
36+
# ]: cli.og
37+
# ]: cli.write
38+
```
39+
40+
* Использование вывода с logging
41+
42+
```python
43+
from console import Console
44+
import logging
45+
46+
cli = Console(prompt_in=">", prompt_out="]:")
47+
logging.basicConfig(level=logging.NOTSET, format="%(asctime)s - %(name)-5s - %(levelname)-7s - %(message)s")
48+
49+
# All calls below will be implemented via Console
50+
cli.logger_hook()
51+
logging.debug("Debug log")
52+
logging.warning('Warning log')
53+
logging.error("Error log")
54+
logging.info("Info log")
55+
56+
# Output
57+
# ]: 2022-02-20 23:22:49,731 - root - DEBUG - Debug log
58+
# ]: 2022-02-20 23:22:49,731 - root - WARNING - Warning log
59+
# ]: 2022-02-20 23:22:49,731 - root - ERROR - Error log
60+
# ]: 2022-02-20 23:22:49,731 - root - INFO - Info log
61+
```
62+
63+
* Использование вывода с`print()` и `console.log`
64+
65+
```python
66+
from console import Console
67+
68+
cli = Console(prompt_in=">", prompt_out="]:")
69+
70+
cli.builtins_hook()
71+
72+
# Output below from the hook
73+
# After builtins_hook() => cli = console
74+
75+
print("print()")
76+
77+
console.write("console.write")
78+
console.log("console.log")
79+
80+
console['[] log']
81+
console << "<< log"
82+
83+
# Output
84+
# ]: print()
85+
# ]: console.write
86+
# ]: console.log
87+
# ]: [] log
88+
# ]: << log
1689
```
1790

1891
## Ссылки

0 commit comments

Comments
 (0)