fated 0.2.1__tar.gz
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.
- fated-0.2.1/LICENSE +21 -0
- fated-0.2.1/MANIFEST.in +3 -0
- fated-0.2.1/PKG-INFO +129 -0
- fated-0.2.1/README.md +108 -0
- fated-0.2.1/fate/__init__.py +77 -0
- fated-0.2.1/fate/__init__.py.bak +77 -0
- fated-0.2.1/fate/__pycache__/__init__.cpython-311.pyc +0 -0
- fated-0.2.1/fate/__pycache__/animation.cpython-311.pyc +0 -0
- fated-0.2.1/fate/__pycache__/effects.cpython-311.pyc +0 -0
- fated-0.2.1/fate/__pycache__/styles.cpython-311.pyc +0 -0
- fated-0.2.1/fate/__pycache__/utils.cpython-311.pyc +0 -0
- fated-0.2.1/fate/animation.py +209 -0
- fated-0.2.1/fate/effects.py +242 -0
- fated-0.2.1/fate/shortcuts.py +101 -0
- fated-0.2.1/fate/styles.py +149 -0
- fated-0.2.1/fate/utils.py +135 -0
- fated-0.2.1/fated.egg-info/PKG-INFO +129 -0
- fated-0.2.1/fated.egg-info/SOURCES.txt +22 -0
- fated-0.2.1/fated.egg-info/dependency_links.txt +1 -0
- fated-0.2.1/fated.egg-info/requires.txt +3 -0
- fated-0.2.1/fated.egg-info/top_level.txt +1 -0
- fated-0.2.1/pyproject.toml +30 -0
- fated-0.2.1/setup.cfg +4 -0
- fated-0.2.1/setup.py +5 -0
fated-0.2.1/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2025 Fred
|
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.
|
fated-0.2.1/MANIFEST.in
ADDED
fated-0.2.1/PKG-INFO
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: fated
|
3
|
+
Version: 0.2.1
|
4
|
+
Summary: A Python library for adding visual effects to terminal text output
|
5
|
+
Author-email: Fred <fredised@users.noreply.github.com>
|
6
|
+
Project-URL: Homepage, https://github.com/fredised/fated
|
7
|
+
Project-URL: Bug Tracker, https://github.com/fredised/fated/issues
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
10
|
+
Classifier: Operating System :: OS Independent
|
11
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
12
|
+
Classifier: Topic :: Text Processing :: General
|
13
|
+
Classifier: Intended Audience :: Developers
|
14
|
+
Requires-Python: >=3.7
|
15
|
+
Description-Content-Type: text/markdown
|
16
|
+
License-File: LICENSE
|
17
|
+
Requires-Dist: build>=1.1.1
|
18
|
+
Requires-Dist: setuptools>=68.0.0
|
19
|
+
Requires-Dist: twine>=4.0.2
|
20
|
+
Dynamic: license-file
|
21
|
+
|
22
|
+
# Fated - Text Effects Library for Python
|
23
|
+
|
24
|
+
Fated is a Python library that adds visual effects to text output including typewriter animation and other text styling options. It provides a simple API for creating rich, animated terminal text with no external dependencies.
|
25
|
+
|
26
|
+
## Features
|
27
|
+
|
28
|
+
- **Text Animation Effects**: Typewriter, blink, fade-in, wave, glitch, shake, matrix, and more
|
29
|
+
- **Text Styling**: Colors, background colors, bold, italic, underline, and other text styles
|
30
|
+
- **Chainable Effects**: Combine multiple effects together seamlessly
|
31
|
+
- **Simple API**: Intuitive interface that works with standard print function
|
32
|
+
- **Alternative Syntax**: Use the + operator with shortcut objects for even cleaner code
|
33
|
+
- **No Dependencies**: Uses only Python standard library modules
|
34
|
+
|
35
|
+
## Installation
|
36
|
+
|
37
|
+
Install directly from PyPI using pip:
|
38
|
+
|
39
|
+
```bash
|
40
|
+
pip install fated
|
41
|
+
```
|
42
|
+
|
43
|
+
Alternative installation methods:
|
44
|
+
|
45
|
+
1. Clone the repository and include the `fate` folder in your project:
|
46
|
+
|
47
|
+
```bash
|
48
|
+
git clone https://github.com/fredised/fated.git
|
49
|
+
```
|
50
|
+
|
51
|
+
2. Or simply copy the `fate` directory to your project.
|
52
|
+
|
53
|
+
## Usage
|
54
|
+
|
55
|
+
### Traditional Syntax
|
56
|
+
|
57
|
+
```python
|
58
|
+
from fate import typewriter, color, style
|
59
|
+
|
60
|
+
# Simple typewriter effect
|
61
|
+
print(typewriter("Hello, World!"))
|
62
|
+
|
63
|
+
# Colored text
|
64
|
+
print(color.red("This text is red"))
|
65
|
+
print(color.blue("This text is blue"))
|
66
|
+
|
67
|
+
# Text styling
|
68
|
+
print(style.bold("Bold text"))
|
69
|
+
print(style.italic("Italic text"))
|
70
|
+
|
71
|
+
# Chain multiple effects
|
72
|
+
print(style.bold(color.green(typewriter("Bold green typewriter text"))))
|
73
|
+
|
74
|
+
# Predefined combinations
|
75
|
+
from fate import error, warning, success, info
|
76
|
+
print(error("Error message"))
|
77
|
+
print(success("Success message"))
|
78
|
+
```
|
79
|
+
|
80
|
+
### Shortcut Syntax (New!)
|
81
|
+
|
82
|
+
```python
|
83
|
+
from fate.shortcuts import fateTypeWriter, fateRed, fateBold
|
84
|
+
|
85
|
+
# Use the + operator
|
86
|
+
print(fateTypeWriter + "Hello, World!")
|
87
|
+
|
88
|
+
# Colored text
|
89
|
+
print(fateRed + "This text is red")
|
90
|
+
|
91
|
+
# Text styling
|
92
|
+
print(fateBold + "Bold text")
|
93
|
+
|
94
|
+
# Custom parameters
|
95
|
+
print(fateTypeWriter(speed=20) + "Fast typing!")
|
96
|
+
|
97
|
+
# Predefined combinations
|
98
|
+
from fate.shortcuts import fateError, fateSuccess
|
99
|
+
print(fateError + "Error message")
|
100
|
+
print(fateSuccess + "Success message")
|
101
|
+
```
|
102
|
+
|
103
|
+
## Examples
|
104
|
+
|
105
|
+
The repository includes example files:
|
106
|
+
|
107
|
+
- `examples.py` - Demonstrates the traditional syntax
|
108
|
+
- `shortcut_example.py` - Demonstrates the new shortcut syntax
|
109
|
+
|
110
|
+
Run the examples to see the library in action:
|
111
|
+
|
112
|
+
```bash
|
113
|
+
python examples.py
|
114
|
+
python shortcut_example.py
|
115
|
+
```
|
116
|
+
|
117
|
+
## Available Effects
|
118
|
+
|
119
|
+
- `typewriter` - Types text character by character
|
120
|
+
- `blink` - Makes text blink
|
121
|
+
- `fade_in` - Gradually reveals text
|
122
|
+
- `wave` - Creates a wave-like animation
|
123
|
+
- `glitch` - Creates a glitchy, distorted effect
|
124
|
+
- `shake` - Shakes the text
|
125
|
+
- `rainbow` - Cycles through rainbow colors
|
126
|
+
- `typing_with_errors` - Realistic typing with random errors
|
127
|
+
- `matrix_effect` - Matrix-like falling character effect
|
128
|
+
- `slide_in` - Slides text in from left or right
|
129
|
+
- `reveal_masked` - Reveals masked text character by character
|
fated-0.2.1/README.md
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
# Fated - Text Effects Library for Python
|
2
|
+
|
3
|
+
Fated is a Python library that adds visual effects to text output including typewriter animation and other text styling options. It provides a simple API for creating rich, animated terminal text with no external dependencies.
|
4
|
+
|
5
|
+
## Features
|
6
|
+
|
7
|
+
- **Text Animation Effects**: Typewriter, blink, fade-in, wave, glitch, shake, matrix, and more
|
8
|
+
- **Text Styling**: Colors, background colors, bold, italic, underline, and other text styles
|
9
|
+
- **Chainable Effects**: Combine multiple effects together seamlessly
|
10
|
+
- **Simple API**: Intuitive interface that works with standard print function
|
11
|
+
- **Alternative Syntax**: Use the + operator with shortcut objects for even cleaner code
|
12
|
+
- **No Dependencies**: Uses only Python standard library modules
|
13
|
+
|
14
|
+
## Installation
|
15
|
+
|
16
|
+
Install directly from PyPI using pip:
|
17
|
+
|
18
|
+
```bash
|
19
|
+
pip install fated
|
20
|
+
```
|
21
|
+
|
22
|
+
Alternative installation methods:
|
23
|
+
|
24
|
+
1. Clone the repository and include the `fate` folder in your project:
|
25
|
+
|
26
|
+
```bash
|
27
|
+
git clone https://github.com/fredised/fated.git
|
28
|
+
```
|
29
|
+
|
30
|
+
2. Or simply copy the `fate` directory to your project.
|
31
|
+
|
32
|
+
## Usage
|
33
|
+
|
34
|
+
### Traditional Syntax
|
35
|
+
|
36
|
+
```python
|
37
|
+
from fate import typewriter, color, style
|
38
|
+
|
39
|
+
# Simple typewriter effect
|
40
|
+
print(typewriter("Hello, World!"))
|
41
|
+
|
42
|
+
# Colored text
|
43
|
+
print(color.red("This text is red"))
|
44
|
+
print(color.blue("This text is blue"))
|
45
|
+
|
46
|
+
# Text styling
|
47
|
+
print(style.bold("Bold text"))
|
48
|
+
print(style.italic("Italic text"))
|
49
|
+
|
50
|
+
# Chain multiple effects
|
51
|
+
print(style.bold(color.green(typewriter("Bold green typewriter text"))))
|
52
|
+
|
53
|
+
# Predefined combinations
|
54
|
+
from fate import error, warning, success, info
|
55
|
+
print(error("Error message"))
|
56
|
+
print(success("Success message"))
|
57
|
+
```
|
58
|
+
|
59
|
+
### Shortcut Syntax (New!)
|
60
|
+
|
61
|
+
```python
|
62
|
+
from fate.shortcuts import fateTypeWriter, fateRed, fateBold
|
63
|
+
|
64
|
+
# Use the + operator
|
65
|
+
print(fateTypeWriter + "Hello, World!")
|
66
|
+
|
67
|
+
# Colored text
|
68
|
+
print(fateRed + "This text is red")
|
69
|
+
|
70
|
+
# Text styling
|
71
|
+
print(fateBold + "Bold text")
|
72
|
+
|
73
|
+
# Custom parameters
|
74
|
+
print(fateTypeWriter(speed=20) + "Fast typing!")
|
75
|
+
|
76
|
+
# Predefined combinations
|
77
|
+
from fate.shortcuts import fateError, fateSuccess
|
78
|
+
print(fateError + "Error message")
|
79
|
+
print(fateSuccess + "Success message")
|
80
|
+
```
|
81
|
+
|
82
|
+
## Examples
|
83
|
+
|
84
|
+
The repository includes example files:
|
85
|
+
|
86
|
+
- `examples.py` - Demonstrates the traditional syntax
|
87
|
+
- `shortcut_example.py` - Demonstrates the new shortcut syntax
|
88
|
+
|
89
|
+
Run the examples to see the library in action:
|
90
|
+
|
91
|
+
```bash
|
92
|
+
python examples.py
|
93
|
+
python shortcut_example.py
|
94
|
+
```
|
95
|
+
|
96
|
+
## Available Effects
|
97
|
+
|
98
|
+
- `typewriter` - Types text character by character
|
99
|
+
- `blink` - Makes text blink
|
100
|
+
- `fade_in` - Gradually reveals text
|
101
|
+
- `wave` - Creates a wave-like animation
|
102
|
+
- `glitch` - Creates a glitchy, distorted effect
|
103
|
+
- `shake` - Shakes the text
|
104
|
+
- `rainbow` - Cycles through rainbow colors
|
105
|
+
- `typing_with_errors` - Realistic typing with random errors
|
106
|
+
- `matrix_effect` - Matrix-like falling character effect
|
107
|
+
- `slide_in` - Slides text in from left or right
|
108
|
+
- `reveal_masked` - Reveals masked text character by character
|
@@ -0,0 +1,77 @@
|
|
1
|
+
"""
|
2
|
+
fate - A Python library for adding visual effects to text output
|
3
|
+
|
4
|
+
This library provides various text effects including typewriter animation,
|
5
|
+
colorization, styling, and more for enhancing terminal output.
|
6
|
+
|
7
|
+
Basic usage:
|
8
|
+
from fate import typewriter, color, style
|
9
|
+
|
10
|
+
# Simple typewriter effect
|
11
|
+
print(typewriter("Hello, World!"))
|
12
|
+
|
13
|
+
# Chained effects
|
14
|
+
print(color.red(typewriter("Error message", speed=5)))
|
15
|
+
|
16
|
+
# Mix and match
|
17
|
+
print(style.bold(color.blue(typewriter("Important notification"))))
|
18
|
+
|
19
|
+
Alternative shortcut syntax:
|
20
|
+
from fate.shortcuts import fateTypeWriter, fateRed, fateBold
|
21
|
+
|
22
|
+
# Using the + operator
|
23
|
+
print(fateTypeWriter + "Hello, World!")
|
24
|
+
|
25
|
+
# Combining shortcuts
|
26
|
+
print(fateBold + fateRed + "Important error message")
|
27
|
+
|
28
|
+
# With custom parameters
|
29
|
+
print(fateTypeWriter(speed=20) + "Fast typing!")
|
30
|
+
"""
|
31
|
+
|
32
|
+
__version__ = "0.2.1"
|
33
|
+
|
34
|
+
from fate.effects import (
|
35
|
+
typewriter,
|
36
|
+
blink,
|
37
|
+
fade_in,
|
38
|
+
wave,
|
39
|
+
glitch,
|
40
|
+
shake,
|
41
|
+
rainbow
|
42
|
+
)
|
43
|
+
|
44
|
+
from fate.styles import (
|
45
|
+
color,
|
46
|
+
style,
|
47
|
+
bg_color
|
48
|
+
)
|
49
|
+
|
50
|
+
# Predefined effect combinations
|
51
|
+
error = lambda text: style.bold(color.red(text))
|
52
|
+
warning = lambda text: style.bold(color.yellow(text))
|
53
|
+
success = lambda text: style.bold(color.green(text))
|
54
|
+
info = lambda text: style.bold(color.blue(text))
|
55
|
+
|
56
|
+
# Advanced animations
|
57
|
+
from fate.animation import (
|
58
|
+
typing_with_errors,
|
59
|
+
matrix_effect,
|
60
|
+
slide_in,
|
61
|
+
reveal_masked
|
62
|
+
)
|
63
|
+
|
64
|
+
# Make FateString available for type hints and advanced usage
|
65
|
+
from fate.utils import FateString
|
66
|
+
|
67
|
+
# Import shortcuts
|
68
|
+
# The shortcuts are not imported by default to avoid namespace pollution,
|
69
|
+
# but they can be imported explicitly from fate.shortcuts
|
70
|
+
|
71
|
+
__all__ = [
|
72
|
+
'typewriter', 'blink', 'fade_in', 'wave', 'glitch', 'shake', 'rainbow',
|
73
|
+
'color', 'style', 'bg_color',
|
74
|
+
'error', 'warning', 'success', 'info',
|
75
|
+
'typing_with_errors', 'matrix_effect', 'slide_in', 'reveal_masked',
|
76
|
+
'FateString'
|
77
|
+
]
|
@@ -0,0 +1,77 @@
|
|
1
|
+
"""
|
2
|
+
fate - A Python library for adding visual effects to text output
|
3
|
+
|
4
|
+
This library provides various text effects including typewriter animation,
|
5
|
+
colorization, styling, and more for enhancing terminal output.
|
6
|
+
|
7
|
+
Basic usage:
|
8
|
+
from fate import typewriter, color, style
|
9
|
+
|
10
|
+
# Simple typewriter effect
|
11
|
+
print(typewriter("Hello, World!"))
|
12
|
+
|
13
|
+
# Chained effects
|
14
|
+
print(color.red(typewriter("Error message", speed=5)))
|
15
|
+
|
16
|
+
# Mix and match
|
17
|
+
print(style.bold(color.blue(typewriter("Important notification"))))
|
18
|
+
|
19
|
+
Alternative shortcut syntax:
|
20
|
+
from fate.shortcuts import fateTypeWriter, fateRed, fateBold
|
21
|
+
|
22
|
+
# Using the + operator
|
23
|
+
print(fateTypeWriter + "Hello, World!")
|
24
|
+
|
25
|
+
# Combining shortcuts
|
26
|
+
print(fateBold + fateRed + "Important error message")
|
27
|
+
|
28
|
+
# With custom parameters
|
29
|
+
print(fateTypeWriter(speed=20) + "Fast typing!")
|
30
|
+
"""
|
31
|
+
|
32
|
+
__version__ = "0.2.0"
|
33
|
+
|
34
|
+
from fate.effects import (
|
35
|
+
typewriter,
|
36
|
+
blink,
|
37
|
+
fade_in,
|
38
|
+
wave,
|
39
|
+
glitch,
|
40
|
+
shake,
|
41
|
+
rainbow
|
42
|
+
)
|
43
|
+
|
44
|
+
from fate.styles import (
|
45
|
+
color,
|
46
|
+
style,
|
47
|
+
bg_color
|
48
|
+
)
|
49
|
+
|
50
|
+
# Predefined effect combinations
|
51
|
+
error = lambda text: style.bold(color.red(text))
|
52
|
+
warning = lambda text: style.bold(color.yellow(text))
|
53
|
+
success = lambda text: style.bold(color.green(text))
|
54
|
+
info = lambda text: style.bold(color.blue(text))
|
55
|
+
|
56
|
+
# Advanced animations
|
57
|
+
from fate.animation import (
|
58
|
+
typing_with_errors,
|
59
|
+
matrix_effect,
|
60
|
+
slide_in,
|
61
|
+
reveal_masked
|
62
|
+
)
|
63
|
+
|
64
|
+
# Make FateString available for type hints and advanced usage
|
65
|
+
from fate.utils import FateString
|
66
|
+
|
67
|
+
# Import shortcuts
|
68
|
+
# The shortcuts are not imported by default to avoid namespace pollution,
|
69
|
+
# but they can be imported explicitly from fate.shortcuts
|
70
|
+
|
71
|
+
__all__ = [
|
72
|
+
'typewriter', 'blink', 'fade_in', 'wave', 'glitch', 'shake', 'rainbow',
|
73
|
+
'color', 'style', 'bg_color',
|
74
|
+
'error', 'warning', 'success', 'info',
|
75
|
+
'typing_with_errors', 'matrix_effect', 'slide_in', 'reveal_masked',
|
76
|
+
'FateString'
|
77
|
+
]
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,209 @@
|
|
1
|
+
"""
|
2
|
+
Advanced animation utilities for the fate library.
|
3
|
+
"""
|
4
|
+
|
5
|
+
import sys
|
6
|
+
import time
|
7
|
+
import random
|
8
|
+
from typing import List, Callable, Optional, Union
|
9
|
+
|
10
|
+
from fate.utils import create_effect
|
11
|
+
|
12
|
+
@create_effect
|
13
|
+
def typing_with_errors(text: str, error_rate: float = 0.1, backspace_delay: float = 0.1,
|
14
|
+
typing_speed: int = 10) -> str:
|
15
|
+
"""
|
16
|
+
Realistic typing animation that includes random errors and backspacing.
|
17
|
+
|
18
|
+
Args:
|
19
|
+
text: Text to be displayed
|
20
|
+
error_rate: Probability of making a typo (0-1)
|
21
|
+
backspace_delay: Delay between backspace operations
|
22
|
+
typing_speed: Characters per second
|
23
|
+
|
24
|
+
Returns:
|
25
|
+
The text after animation
|
26
|
+
"""
|
27
|
+
delay = 1.0 / typing_speed
|
28
|
+
|
29
|
+
# Possible typo characters (neighbors on QWERTY keyboard)
|
30
|
+
keyboard_map = {
|
31
|
+
'a': 'qwsz', 'b': 'vghn', 'c': 'xdfv', 'd': 'serfcx', 'e': 'wsdr',
|
32
|
+
'f': 'drtgvc', 'g': 'ftyhbv', 'h': 'gyujnb', 'i': 'ujko', 'j': 'huikmn',
|
33
|
+
'k': 'jiolm', 'l': 'kop;', 'm': 'njk,', 'n': 'bhjm', 'o': 'iklp',
|
34
|
+
'p': 'ol;[', 'q': 'wa', 'r': 'edft', 's': 'awedxz', 't': 'rfgy',
|
35
|
+
'u': 'yhji', 'v': 'cfgb', 'w': 'qase', 'x': 'zsdc', 'y': 'tghu',
|
36
|
+
'z': 'asx'
|
37
|
+
}
|
38
|
+
|
39
|
+
current = ""
|
40
|
+
errors = 0
|
41
|
+
|
42
|
+
try:
|
43
|
+
for i, char in enumerate(text):
|
44
|
+
# Randomly decide whether to make a typo
|
45
|
+
if random.random() < error_rate and char.lower() in keyboard_map:
|
46
|
+
# Choose a typo character from nearby keys
|
47
|
+
typo_char = random.choice(keyboard_map.get(char.lower(), char))
|
48
|
+
if char.isupper():
|
49
|
+
typo_char = typo_char.upper()
|
50
|
+
|
51
|
+
current += typo_char
|
52
|
+
sys.stdout.write('\r' + current)
|
53
|
+
sys.stdout.flush()
|
54
|
+
time.sleep(delay)
|
55
|
+
|
56
|
+
# Backspace the typo
|
57
|
+
current = current[:-1]
|
58
|
+
sys.stdout.write('\r' + current + ' ')
|
59
|
+
sys.stdout.flush()
|
60
|
+
time.sleep(backspace_delay)
|
61
|
+
|
62
|
+
# Continue with the correct character
|
63
|
+
current += char
|
64
|
+
else:
|
65
|
+
current += char
|
66
|
+
|
67
|
+
sys.stdout.write('\r' + current)
|
68
|
+
sys.stdout.flush()
|
69
|
+
time.sleep(delay)
|
70
|
+
|
71
|
+
sys.stdout.write('\n')
|
72
|
+
return text
|
73
|
+
except KeyboardInterrupt:
|
74
|
+
sys.stdout.write('\r' + text + '\n')
|
75
|
+
return text
|
76
|
+
|
77
|
+
|
78
|
+
@create_effect
|
79
|
+
def matrix_effect(text: str, speed: int = 5, char_set: Optional[str] = None) -> str:
|
80
|
+
"""
|
81
|
+
Creates a matrix-like effect where characters fall into place.
|
82
|
+
|
83
|
+
Args:
|
84
|
+
text: Text to display
|
85
|
+
speed: Animation speed
|
86
|
+
char_set: Optional set of characters to use for the effect
|
87
|
+
|
88
|
+
Returns:
|
89
|
+
The text after animation
|
90
|
+
"""
|
91
|
+
if char_set is None:
|
92
|
+
char_set = "01"
|
93
|
+
|
94
|
+
delay = 1.0 / speed
|
95
|
+
width = len(text)
|
96
|
+
|
97
|
+
# Create random initial positions for each character
|
98
|
+
positions = [random.randint(0, 5) for _ in range(width)]
|
99
|
+
max_height = max(positions) + 1
|
100
|
+
|
101
|
+
try:
|
102
|
+
# Animate characters falling into place
|
103
|
+
for step in range(max_height + len(text)):
|
104
|
+
result = ""
|
105
|
+
|
106
|
+
for i in range(width):
|
107
|
+
char_pos = step - positions[i]
|
108
|
+
|
109
|
+
if char_pos < 0:
|
110
|
+
# Character hasn't started falling yet
|
111
|
+
result += " "
|
112
|
+
elif char_pos < 5:
|
113
|
+
# Character is falling, show a random matrix character
|
114
|
+
result += random.choice(char_set)
|
115
|
+
else:
|
116
|
+
# Character has reached its position, show the actual character
|
117
|
+
result += text[i]
|
118
|
+
|
119
|
+
sys.stdout.write('\r' + result)
|
120
|
+
sys.stdout.flush()
|
121
|
+
time.sleep(delay)
|
122
|
+
|
123
|
+
sys.stdout.write('\n')
|
124
|
+
return text
|
125
|
+
except KeyboardInterrupt:
|
126
|
+
sys.stdout.write('\r' + text + '\n')
|
127
|
+
return text
|
128
|
+
|
129
|
+
|
130
|
+
@create_effect
|
131
|
+
def slide_in(text: str, direction: str = "left", speed: int = 10) -> str:
|
132
|
+
"""
|
133
|
+
Slides text into view from a specified direction.
|
134
|
+
|
135
|
+
Args:
|
136
|
+
text: Text to display
|
137
|
+
direction: Direction to slide from ("left", "right")
|
138
|
+
speed: Animation speed
|
139
|
+
|
140
|
+
Returns:
|
141
|
+
The text after animation
|
142
|
+
"""
|
143
|
+
delay = 1.0 / speed
|
144
|
+
width = len(text)
|
145
|
+
|
146
|
+
try:
|
147
|
+
if direction.lower() == "left":
|
148
|
+
# Slide in from left
|
149
|
+
for i in range(width + 1):
|
150
|
+
result = text[:i]
|
151
|
+
sys.stdout.write('\r' + result)
|
152
|
+
sys.stdout.flush()
|
153
|
+
time.sleep(delay)
|
154
|
+
else:
|
155
|
+
# Slide in from right
|
156
|
+
for i in range(width + 1):
|
157
|
+
result = " " * (width - i) + text[:i]
|
158
|
+
sys.stdout.write('\r' + result)
|
159
|
+
sys.stdout.flush()
|
160
|
+
time.sleep(delay)
|
161
|
+
|
162
|
+
sys.stdout.write('\n')
|
163
|
+
return text
|
164
|
+
except KeyboardInterrupt:
|
165
|
+
sys.stdout.write('\r' + text + '\n')
|
166
|
+
return text
|
167
|
+
|
168
|
+
|
169
|
+
@create_effect
|
170
|
+
def reveal_masked(text: str, mask_char: str = "*", speed: int = 5) -> str:
|
171
|
+
"""
|
172
|
+
Reveals text by replacing mask characters one by one.
|
173
|
+
|
174
|
+
Args:
|
175
|
+
text: Text to reveal
|
176
|
+
mask_char: Character used for masking
|
177
|
+
speed: Characters per second to reveal
|
178
|
+
|
179
|
+
Returns:
|
180
|
+
The text after animation
|
181
|
+
"""
|
182
|
+
delay = 1.0 / speed
|
183
|
+
width = len(text)
|
184
|
+
|
185
|
+
try:
|
186
|
+
# Start with all characters masked
|
187
|
+
current = mask_char * width
|
188
|
+
revealed = [False] * width
|
189
|
+
|
190
|
+
# Reveal characters one by one in random order
|
191
|
+
indices = list(range(width))
|
192
|
+
random.shuffle(indices)
|
193
|
+
|
194
|
+
for idx in indices:
|
195
|
+
# Update the current text
|
196
|
+
current_list = list(current)
|
197
|
+
current_list[idx] = text[idx]
|
198
|
+
current = ''.join(current_list)
|
199
|
+
|
200
|
+
# Display
|
201
|
+
sys.stdout.write('\r' + current)
|
202
|
+
sys.stdout.flush()
|
203
|
+
time.sleep(delay)
|
204
|
+
|
205
|
+
sys.stdout.write('\n')
|
206
|
+
return text
|
207
|
+
except KeyboardInterrupt:
|
208
|
+
sys.stdout.write('\r' + text + '\n')
|
209
|
+
return text
|