Skip to content

Commit e8f8583

Browse files
authored
feat: add converFrame to convert the ascii output from https://www.ascii-animator.com/ (#5)
1 parent cff356c commit e8f8583

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+26208
-4
lines changed

README.md

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,93 @@ except KeyboardInterrupt:
7575
lazy.stop()
7676
```
7777

78+
## 🎬 Adding Custom Animations
79+
80+
LazyB supports ASCII animations that play while keeping your status active. You can add your own custom animations to the system.
81+
82+
### Animation File Structure
83+
84+
Animations are stored in the `animations` directory, with each animation in its own subdirectory. Each frame should be saved as a separate `.txt` file with a numbered sequence.
85+
86+
**Supported naming formats:**
87+
- `frame_1.txt`, `frame_2.txt`, `frame_3.txt`, ... (frame_NUMBER.txt)
88+
- `001_description.txt`, `002_description.txt`, `003_description.txt`, ... (NUMBER_description.txt)
89+
90+
**Example structure:**
91+
```
92+
animations/
93+
├── my_cool_animation/
94+
│ ├── frame_1.txt
95+
│ ├── frame_2.txt
96+
│ └── frame_3.txt
97+
└── another_animation/
98+
├── 001_start.txt
99+
├── 002_middle.txt
100+
└── 003_end.txt
101+
```
102+
103+
### Creating Animations from Videos
104+
105+
If you want to convert a video into ASCII animation, follow these steps:
106+
107+
#### Step 1: Convert Video to ASCII Frames
108+
109+
1. **Clone the ASCII Animator tool:**
110+
```bash
111+
git clone https://github.com/bradysheridan/ascii-animator.git
112+
cd ascii-animator
113+
```
114+
115+
2. **Upload your video file** to the ASCII Animator and process it through their system.
116+
117+
3. **Export the output** - you should get a `frames.js` file containing an array of ASCII frames.
118+
119+
#### Step 2: Convert Frames to TXT Files
120+
121+
1. **Place the `frames.js` file** in your LazyB `animations` directory.
122+
123+
2. **Run the conversion script** (requires Node.js):
124+
```bash
125+
# Install Node.js if not already installed
126+
# Visit https://nodejs.org/ or use package manager
127+
128+
cd animations
129+
node convertFramesToTxt.js
130+
```
131+
132+
3. **Follow the prompts** to name your animation directory (avoid spaces and special characters).
133+
134+
4. **The script will create** a new directory with all frames converted to individual `.txt` files.
135+
136+
#### Step 3: Test Your Animation
137+
138+
1. **Run LazyB** and your new animation should appear in the selection menu:
139+
```bash
140+
lazy-b
141+
```
142+
143+
2. **Use arrow keys** to navigate and select your animation.
144+
145+
### Animation Guidelines
146+
147+
- **File naming**: Frames must be numbered sequentially starting from 1
148+
- **File format**: Plain text (`.txt`) files with UTF-8 encoding
149+
- **Frame size**: Recommended maximum 80 characters wide for terminal compatibility
150+
- **Frame rate**: Default is 0.2 seconds per frame (5 FPS), configurable
151+
- **Directory naming**: Use underscores instead of spaces, avoid special characters
152+
153+
### Troubleshooting
154+
155+
- **Animation not showing up?** Check that frame files follow the naming convention
156+
- **Frames out of order?** Ensure sequential numbering without gaps
157+
- **Display issues?** Verify files are UTF-8 encoded and frames aren't too wide
158+
78159
## Features
79160

80161
- Prevents "away" or "inactive" status in messaging applications
81-
- Customizable interval between key presses (default: 1 second)
162+
- **🎬 ASCII Animation Support**: Display entertaining animations while keeping your status active
163+
- Interactive animation selection menu with live preview
164+
- Customizable interval between key presses (default: 3 minutes)
82165
- Simple command-line interface
83166
- Cross-platform: Works on macOS, Windows, and Linux
84167
- Background mode on macOS (no dock icon)
@@ -121,10 +204,15 @@ Pushing a tag will automatically trigger the release workflow, which will:
121204

122205
## Requirements
123206

207+
### Runtime Requirements
124208
- Python 3.8 or higher
125209
- PyAutoGUI
126210
- PyObjC-Core (for macOS dock icon hiding, optional)
127211

212+
### Animation Development Requirements (Optional)
213+
- Node.js (for running the frame conversion script)
214+
- Access to [ASCII Animator](https://github.com/bradysheridan/ascii-animator) for video-to-ASCII conversion
215+
128216
## License
129217

130218
MIT

animations/convertFramesToTxt.js

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import fs from 'fs';
2+
import path from 'path';
3+
import { fileURLToPath } from 'url';
4+
import readline from 'readline';
5+
6+
// Get __dirname equivalent in ES modules
7+
const __filename = fileURLToPath(import.meta.url);
8+
const __dirname = path.dirname(__filename);
9+
10+
// Import frames from frames.js
11+
import { frames } from './frames.js';
12+
13+
// Create readline interface for user input
14+
const rl = readline.createInterface({
15+
input: process.stdin,
16+
output: process.stdout
17+
});
18+
19+
// Function to validate directory name
20+
function validateDirectoryName(name) {
21+
// Check for invalid characters (spaces, special characters that might cause issues)
22+
const invalidChars = /[<>:"/\\|?*\s]/;
23+
if (invalidChars.test(name)) {
24+
return false;
25+
}
26+
// Check if name is not empty
27+
if (!name.trim()) {
28+
return false;
29+
}
30+
return true;
31+
}
32+
33+
// Function to prompt user for directory name
34+
function promptForDirectoryName() {
35+
return new Promise((resolve) => {
36+
rl.question('請輸入動畫資料夾名稱 (不能包含空格或特殊字元): ', (answer) => {
37+
const trimmedAnswer = answer.trim();
38+
if (validateDirectoryName(trimmedAnswer)) {
39+
resolve(trimmedAnswer);
40+
} else {
41+
console.log('❌ 無效的資料夾名稱!請避免使用空格和特殊字元 (<>:"/\\|?*)');
42+
promptForDirectoryName().then(resolve);
43+
}
44+
});
45+
});
46+
}
47+
48+
// Main execution
49+
async function main() {
50+
try {
51+
console.log('🎬 Frame to TXT 轉換工具');
52+
console.log(`📊 共找到 ${frames.length} 個影格`);
53+
54+
const directoryName = await promptForDirectoryName();
55+
const outputDir = path.join(__dirname, directoryName);
56+
57+
// Ensure the output directory exists
58+
if (!fs.existsSync(outputDir)) {
59+
fs.mkdirSync(outputDir);
60+
console.log(`📁 已建立資料夾: ${directoryName}`);
61+
} else {
62+
console.log(`📁 使用現有資料夾: ${directoryName}`);
63+
}
64+
65+
// Convert each frame to a .txt file
66+
console.log('🔄 開始轉換 Frames...');
67+
frames.forEach((frame, index) => {
68+
const fileName = `frame_${index + 1}.txt`;
69+
const filePath = path.join(outputDir, fileName);
70+
71+
fs.writeFileSync(filePath, frame, 'utf8');
72+
console.log(`✅ 已儲存: ${fileName}`);
73+
});
74+
75+
console.log(`🎉 所有 Frames 已成功轉換為 .txt 檔案!`);
76+
console.log(`📍 檔案位置: ${outputDir}`);
77+
78+
} catch (error) {
79+
console.error('❌ 轉換過程中發生錯誤:', error.message);
80+
} finally {
81+
rl.close();
82+
}
83+
}
84+
85+
main();

0 commit comments

Comments
 (0)