rastas 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- rastas/__init__.py +6 -0
- rastas/cli.py +66 -0
- rastas/say.py +128 -0
- rastas-0.1.0.dist-info/METADATA +114 -0
- rastas-0.1.0.dist-info/RECORD +8 -0
- rastas-0.1.0.dist-info/WHEEL +4 -0
- rastas-0.1.0.dist-info/entry_points.txt +2 -0
- rastas-0.1.0.dist-info/licenses/LICENSE +21 -0
rastas/__init__.py
ADDED
rastas/cli.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"""Command-line interface for rastas."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import sys
|
|
7
|
+
from typing import Optional, Sequence
|
|
8
|
+
|
|
9
|
+
from rastas import __version__
|
|
10
|
+
from rastas.say import MOODS, say
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
14
|
+
"""Create the CLI argument parser."""
|
|
15
|
+
parser = argparse.ArgumentParser(
|
|
16
|
+
prog="rastas",
|
|
17
|
+
description="Let an ASCII thrush (rastas) speak your message in the terminal.",
|
|
18
|
+
)
|
|
19
|
+
parser.add_argument(
|
|
20
|
+
"message",
|
|
21
|
+
nargs="*",
|
|
22
|
+
help="Message for the thrush to say. Reads stdin if piped, or picks a random quote.",
|
|
23
|
+
)
|
|
24
|
+
parser.add_argument(
|
|
25
|
+
"-m",
|
|
26
|
+
"--mood",
|
|
27
|
+
choices=sorted(MOODS),
|
|
28
|
+
default="default",
|
|
29
|
+
help="Bird mood (default: %(default)s).",
|
|
30
|
+
)
|
|
31
|
+
parser.add_argument(
|
|
32
|
+
"-w",
|
|
33
|
+
"--width",
|
|
34
|
+
type=int,
|
|
35
|
+
default=40,
|
|
36
|
+
help="Maximum speech bubble text width (default: %(default)s).",
|
|
37
|
+
)
|
|
38
|
+
parser.add_argument(
|
|
39
|
+
"--version",
|
|
40
|
+
action="version",
|
|
41
|
+
version=f"%(prog)s {__version__}",
|
|
42
|
+
)
|
|
43
|
+
return parser
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def main(argv: Optional[Sequence[str]] = None) -> int:
|
|
47
|
+
"""Run the rastas command-line interface."""
|
|
48
|
+
parser = build_parser()
|
|
49
|
+
args = parser.parse_args(argv)
|
|
50
|
+
|
|
51
|
+
if args.width < 1:
|
|
52
|
+
parser.error("--width must be at least 1")
|
|
53
|
+
|
|
54
|
+
if args.message:
|
|
55
|
+
text: Optional[str] = " ".join(args.message)
|
|
56
|
+
elif argv is None and not sys.stdin.isatty():
|
|
57
|
+
text = sys.stdin.read()
|
|
58
|
+
else:
|
|
59
|
+
text = None
|
|
60
|
+
|
|
61
|
+
print(say(text, mood=args.mood, width=args.width))
|
|
62
|
+
return 0
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
if __name__ == "__main__":
|
|
66
|
+
raise SystemExit(main())
|
rastas/say.py
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"""Speech-bubble ASCII thrush (rastas) renderer."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import random
|
|
6
|
+
import textwrap
|
|
7
|
+
from typing import Optional, Sequence
|
|
8
|
+
|
|
9
|
+
QUOTES: tuple[str, ...] = (
|
|
10
|
+
"Early thrush catches the bug.",
|
|
11
|
+
"Simple code flies furthest.",
|
|
12
|
+
"No dependencies, no worries.",
|
|
13
|
+
"Even a small song brightens the morning.",
|
|
14
|
+
"Keep calm and ship small packages.",
|
|
15
|
+
"A tidy nest makes a happy developer.",
|
|
16
|
+
"Readability counts, chirped the thrush.",
|
|
17
|
+
"Test early, sing often.",
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
MOODS: dict[str, str] = {
|
|
21
|
+
"default": r"""
|
|
22
|
+
\
|
|
23
|
+
\ __
|
|
24
|
+
( o)>
|
|
25
|
+
//\
|
|
26
|
+
V_/_
|
|
27
|
+
""",
|
|
28
|
+
"happy": r"""
|
|
29
|
+
\
|
|
30
|
+
\ __
|
|
31
|
+
( ^)>
|
|
32
|
+
//\
|
|
33
|
+
V_/_
|
|
34
|
+
""",
|
|
35
|
+
"sleepy": r"""
|
|
36
|
+
\
|
|
37
|
+
\ __
|
|
38
|
+
( -)> zZ
|
|
39
|
+
//\
|
|
40
|
+
V_/_
|
|
41
|
+
""",
|
|
42
|
+
"singing": r"""
|
|
43
|
+
\
|
|
44
|
+
\ __ ~
|
|
45
|
+
( o)> ~
|
|
46
|
+
//\
|
|
47
|
+
V_/_
|
|
48
|
+
""",
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def random_quote(rng: Optional[random.Random] = None) -> str:
|
|
53
|
+
"""Return a random short quote."""
|
|
54
|
+
chooser = rng if rng is not None else random
|
|
55
|
+
return chooser.choice(QUOTES)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def _wrap_lines(message: str, width: int) -> list[str]:
|
|
59
|
+
"""Wrap message lines to the given maximum width."""
|
|
60
|
+
if width < 1:
|
|
61
|
+
raise ValueError("width must be at least 1")
|
|
62
|
+
|
|
63
|
+
lines: list[str] = []
|
|
64
|
+
for raw_line in message.splitlines() or [""]:
|
|
65
|
+
if not raw_line.strip():
|
|
66
|
+
lines.append("")
|
|
67
|
+
continue
|
|
68
|
+
wrapped = textwrap.wrap(
|
|
69
|
+
raw_line,
|
|
70
|
+
width=width,
|
|
71
|
+
break_long_words=True,
|
|
72
|
+
break_on_hyphens=True,
|
|
73
|
+
)
|
|
74
|
+
lines.extend(wrapped or [""])
|
|
75
|
+
return lines or [""]
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _format_bubble(lines: Sequence[str]) -> str:
|
|
79
|
+
"""Wrap text lines in a simple ASCII speech bubble."""
|
|
80
|
+
max_len = max((len(line) for line in lines), default=0)
|
|
81
|
+
top = " " + "_" * (max_len + 2)
|
|
82
|
+
bottom = " " + "-" * (max_len + 2)
|
|
83
|
+
|
|
84
|
+
if len(lines) == 1:
|
|
85
|
+
middle = [f"< {lines[0].ljust(max_len)} >"]
|
|
86
|
+
else:
|
|
87
|
+
middle = []
|
|
88
|
+
last_index = len(lines) - 1
|
|
89
|
+
for idx, line in enumerate(lines):
|
|
90
|
+
padded = line.ljust(max_len)
|
|
91
|
+
if idx == 0:
|
|
92
|
+
middle.append(f"/ {padded} \\")
|
|
93
|
+
elif idx == last_index:
|
|
94
|
+
middle.append(f"\\ {padded} /")
|
|
95
|
+
else:
|
|
96
|
+
middle.append(f"| {padded} |")
|
|
97
|
+
|
|
98
|
+
return "\n".join([top, *middle, bottom])
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def say(
|
|
102
|
+
message: Optional[str] = None,
|
|
103
|
+
*,
|
|
104
|
+
mood: str = "default",
|
|
105
|
+
width: int = 40,
|
|
106
|
+
) -> str:
|
|
107
|
+
"""Render an ASCII thrush speaking a message in a speech bubble.
|
|
108
|
+
|
|
109
|
+
Args:
|
|
110
|
+
message: Text to display. If None or empty, a random quote is chosen.
|
|
111
|
+
mood: Bird expression. One of ``default``, ``happy``, ``sleepy``, ``singing``.
|
|
112
|
+
width: Maximum text width inside the speech bubble.
|
|
113
|
+
|
|
114
|
+
Returns:
|
|
115
|
+
Multi-line string containing the speech bubble and ASCII bird.
|
|
116
|
+
"""
|
|
117
|
+
if mood not in MOODS:
|
|
118
|
+
valid = ", ".join(sorted(MOODS))
|
|
119
|
+
raise ValueError(f"Unknown mood {mood!r}. Choose from: {valid}")
|
|
120
|
+
|
|
121
|
+
text = message.strip() if message is not None else ""
|
|
122
|
+
if not text:
|
|
123
|
+
text = random_quote()
|
|
124
|
+
|
|
125
|
+
lines = _wrap_lines(text, width=width)
|
|
126
|
+
bubble = _format_bubble(lines)
|
|
127
|
+
bird = MOODS[mood].strip("\n")
|
|
128
|
+
return f"{bubble}\n{bird}"
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: rastas
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A tiny, zero-dependency ASCII thrush (rastas) that speaks your messages in the terminal.
|
|
5
|
+
Project-URL: Homepage, https://github.com/markorastas/Rastas
|
|
6
|
+
Project-URL: Repository, https://github.com/markorastas/Rastas
|
|
7
|
+
Project-URL: Issues, https://github.com/markorastas/Rastas/issues
|
|
8
|
+
Author: Marko Rastas
|
|
9
|
+
License: MIT License
|
|
10
|
+
|
|
11
|
+
Copyright (c) 2026 Marko Rastas
|
|
12
|
+
|
|
13
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
14
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
15
|
+
in the Software without restriction, including without limitation the rights
|
|
16
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
17
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
18
|
+
furnished to do so, subject to the following conditions:
|
|
19
|
+
|
|
20
|
+
The above copyright notice and this permission notice shall be included in all
|
|
21
|
+
copies or substantial portions of the Software.
|
|
22
|
+
|
|
23
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
24
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
25
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
26
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
27
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
28
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
29
|
+
SOFTWARE.
|
|
30
|
+
License-File: LICENSE
|
|
31
|
+
Keywords: ascii,bird,cli,cowsay,fun,rastas,thrush
|
|
32
|
+
Classifier: Development Status :: 3 - Alpha
|
|
33
|
+
Classifier: Environment :: Console
|
|
34
|
+
Classifier: Intended Audience :: Developers
|
|
35
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
36
|
+
Classifier: Operating System :: OS Independent
|
|
37
|
+
Classifier: Programming Language :: Python :: 3
|
|
38
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
39
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
40
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
41
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
42
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
43
|
+
Classifier: Topic :: Games/Entertainment
|
|
44
|
+
Classifier: Topic :: Terminals
|
|
45
|
+
Requires-Python: >=3.9
|
|
46
|
+
Description-Content-Type: text/markdown
|
|
47
|
+
|
|
48
|
+
# rastas
|
|
49
|
+
|
|
50
|
+
A tiny, zero-dependency Python package and CLI that puts an ASCII thrush (*rastas* in Finnish) in your terminal to speak your messages or share a short quote.
|
|
51
|
+
|
|
52
|
+
> **Note:** This is a small personal hobby package and is not actively maintained. It uses only the Python standard library so it should keep working as-is for years.
|
|
53
|
+
|
|
54
|
+
## Installation
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
pip install rastas
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Requires Python 3.9 or newer.
|
|
61
|
+
|
|
62
|
+
## Command-line usage
|
|
63
|
+
|
|
64
|
+
Say a custom message:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
rastas "Hello from the terminal!"
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Output:
|
|
71
|
+
|
|
72
|
+
```text
|
|
73
|
+
__________________________
|
|
74
|
+
< Hello from the terminal! >
|
|
75
|
+
--------------------------
|
|
76
|
+
\
|
|
77
|
+
\ __
|
|
78
|
+
( o)>
|
|
79
|
+
//\
|
|
80
|
+
V_/_
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Pick a random quote (no arguments):
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
rastas
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Change the bird's mood (`default`, `happy`, `sleepy`, `singing`) or bubble width:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
rastas --mood singing "Good morning!"
|
|
93
|
+
rastas --mood sleepy --width 25 "Time for a short break."
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Pipe text from standard input:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
echo "Piped message" | rastas --mood happy
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Python API
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
import rastas
|
|
106
|
+
|
|
107
|
+
print(rastas.say("Hello from Python!"))
|
|
108
|
+
print(rastas.say("Feeling great", mood="happy", width=30))
|
|
109
|
+
print(rastas.random_quote())
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## License
|
|
113
|
+
|
|
114
|
+
MIT License — see [LICENSE](LICENSE) for details.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
rastas/__init__.py,sha256=vHb1smFkUFtD_S0JSs8Pw7YxDqRHO3b5qsX6jXfmc4I,223
|
|
2
|
+
rastas/cli.py,sha256=K_2U2icRIeQRmPayjSRbPDsu5ZGhYyA4tTnA1kUhy4k,1661
|
|
3
|
+
rastas/say.py,sha256=IIClNDduYIzxcZ_N1BADlLgt3GBXUFekuuxTNMq1tJY,3353
|
|
4
|
+
rastas-0.1.0.dist-info/METADATA,sha256=Vf8ZYSIB8mX2m187NtUbneuhq9ah5DZGIwedYlCueNw,3595
|
|
5
|
+
rastas-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
6
|
+
rastas-0.1.0.dist-info/entry_points.txt,sha256=8Nc8NHPIX4VR0fil2dmLfQv7A67Jo5WT_cJsaxyB9KQ,43
|
|
7
|
+
rastas-0.1.0.dist-info/licenses/LICENSE,sha256=OQfUZZTKzzFvLvz4d_bY7YSh7eWC_AhHc2DJfgZf_Uk,1069
|
|
8
|
+
rastas-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Marko Rastas
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|