0
# Command Line Interface
1
2
Full-featured command line interface with extensive options for font selection, text formatting, color output, and font management. The CLI provides complete access to PyFiglet functionality from the terminal.
3
4
## Capabilities
5
6
### Command Entry Point
7
8
Main function that implements the complete command-line interface.
9
10
```python { .api }
11
def main():
12
"""
13
Command-line interface entry point.
14
15
Returns:
16
int: Exit code (0 for success, 1 for error)
17
18
Processes command-line arguments and executes the requested operation:
19
- Text rendering with various options
20
- Font management operations
21
- Color output support
22
- Help and information display
23
"""
24
```
25
26
## Usage Patterns
27
28
### Basic Text Rendering
29
30
```bash
31
# Simple text conversion
32
pyfiglet "Hello World"
33
34
# Using a specific font
35
pyfiglet -f big "Hello World"
36
37
# Multiple words as separate arguments
38
pyfiglet Hello World
39
40
# Text from stdin (interactive mode)
41
echo "Hello" | pyfiglet
42
```
43
44
### Font Options
45
46
```bash
47
# List all available fonts
48
pyfiglet -l
49
50
# Get information about a specific font
51
pyfiglet -f standard -i
52
53
# Use different fonts
54
pyfiglet -f slant "Slanted Text"
55
pyfiglet -f big "Big Text"
56
pyfiglet -f shadow "Shadow Text"
57
```
58
59
### Text Formatting Options
60
61
```bash
62
# Set output width
63
pyfiglet -w 120 "Wide Output"
64
65
# Text direction
66
pyfiglet -D left-to-right "LTR Text"
67
pyfiglet -D right-to-left "RTL Text"
68
69
# Justification
70
pyfiglet -j left "Left Aligned"
71
pyfiglet -j center "Centered"
72
pyfiglet -j right "Right Aligned"
73
```
74
75
### Text Transformations
76
77
```bash
78
# Reverse (mirror horizontally)
79
pyfiglet -r "Reversed"
80
81
# Flip (mirror vertically)
82
pyfiglet -F "Flipped"
83
84
# Both transformations
85
pyfiglet -r -F "Reversed and Flipped"
86
87
# Normalize surrounding newlines
88
pyfiglet -n "Normalized"
89
90
# Strip surrounding newlines
91
pyfiglet -s "Stripped"
92
```
93
94
### Color Output
95
96
```bash
97
# Foreground color only
98
pyfiglet -c red: "Red Text"
99
100
# Background color only
101
pyfiglet -c :blue "Blue Background"
102
103
# Both foreground and background
104
pyfiglet -c red:blue "Red on Blue"
105
106
# RGB colors
107
pyfiglet -c "255;100;50:0;0;255" "RGB Colors"
108
109
# List available colors
110
pyfiglet -c list
111
```
112
113
### Font Management
114
115
```bash
116
# Install new fonts from file
117
pyfiglet -L path/to/font.flf
118
119
# Install fonts from ZIP archive
120
pyfiglet -L font-collection.zip
121
122
# Get font information
123
pyfiglet -f big -i
124
```
125
126
## Command Line Options
127
128
### Text Input Options
129
- **`text...`**: Text to convert (multiple arguments joined with spaces)
130
131
### Font Options
132
- **`-f FONT, --font FONT`**: Font to render with (default: standard)
133
- **`-l, --list_fonts`**: Show installed fonts list
134
- **`-i, --info_font`**: Show font information (use with -f)
135
- **`-L FILE, --load FILE`**: Load and install specified font file
136
137
### Layout Options
138
- **`-w COLS, --width COLS`**: Set terminal width for wrapping/justification (default: 80)
139
- **`-D DIRECTION, --direction DIRECTION`**: Set text direction (auto, left-to-right, right-to-left)
140
- **`-j SIDE, --justify SIDE`**: Set justification (auto, left, center, right)
141
142
### Transformation Options
143
- **`-r, --reverse`**: Show mirror image of output text
144
- **`-F, --flip`**: Flip rendered output text over
145
- **`-n, --normalize-surrounding-newlines`**: Output has one empty line before and after
146
- **`-s, --strip-surrounding-newlines`**: Remove empty leading and trailing lines
147
148
### Color Options
149
- **`-c COLORS, --color COLORS`**: Print with colors in foreground:background format
150
151
### Information Options
152
- **`--version`**: Show version number and exit
153
- **`-h, --help`**: Show help message and exit
154
155
## Examples
156
157
### Simple Usage
158
```bash
159
# Basic text
160
pyfiglet "PyFiglet"
161
162
# With custom font and width
163
pyfiglet -f slant -w 100 "Custom Style"
164
```
165
166
### Complex Formatting
167
```bash
168
# Centered, colored text with transformations
169
pyfiglet -f big -j center -c "green:black" -w 120 "Fancy Title"
170
171
# Right-aligned, reversed text
172
pyfiglet -f shadow -j right -r "Mirrored"
173
```
174
175
### Font Discovery
176
```bash
177
# List fonts and try a few
178
pyfiglet -l | head -5
179
pyfiglet -f banner "Banner Font"
180
pyfiglet -f bubble "Bubble Font"
181
```
182
183
### Color Examples
184
```bash
185
# Different color combinations
186
pyfiglet -c "red:" "Red Text"
187
pyfiglet -c ":yellow" "Yellow Background"
188
pyfiglet -c "white:blue" "White on Blue"
189
pyfiglet -c "255;0;128:0;255;128" "Pink on Green (RGB)"
190
```
191
192
### Font Information
193
```bash
194
# Get details about fonts
195
pyfiglet -f standard -i
196
pyfiglet -f big -i
197
```
198
199
### Installation and Management
200
```bash
201
# Install new fonts
202
pyfiglet -L ~/Downloads/new-font.flf
203
pyfiglet -L ~/Downloads/font-pack.zip
204
205
# Test newly installed font
206
pyfiglet -f new-font "Testing New Font"
207
```
208
209
## Exit Codes
210
211
- **0**: Success
212
- **1**: Error (font not found, invalid arguments, etc.)
213
214
## Input Handling
215
216
- **Arguments**: Text provided as command-line arguments
217
- **Interactive**: If no text arguments provided, shows help
218
- **Encoding**: Supports UTF-8 text input
219
- **Stdin**: Can accept piped input in interactive shells
220
221
## Output Format
222
223
- **Stdout**: ASCII art output with optional ANSI color codes
224
- **Stderr**: Error messages and informational output
225
- **Binary mode**: Switches stdout to binary mode for proper color handling
226
227
## Platform Compatibility
228
229
- **Unix/Linux**: Full feature support including colors
230
- **Windows**: Full support with modern terminals, basic support with legacy Command Prompt
231
- **Color support**: Automatically detected based on terminal capabilities