-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodelumer.sh
More file actions
189 lines (160 loc) · 6.79 KB
/
codelumer.sh
File metadata and controls
189 lines (160 loc) · 6.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/bin/bash
# ==============================================================================
# CODE-Lumer: Batch Code to Image Converter
# ==============================================================================
VERSION="1.0.0"
# --- Default Configuration ---
DEFAULT_WIDTH=1920
DEFAULT_FONT="Hack; Noto Color Emoji" # Fallback to Emoji font for icons
DEFAULT_FONT_SIZE=39
DEFAULT_THEME="Dracula" # Options: Dracula, Nord, Monokai Extended, etc.
DEFAULT_PAD_HORIZ=80
DEFAULT_PAD_VERT=100
DEFAULT_SHADOW_BLUR=30
DEFAULT_SHADOW_OFFSET_Y=10
DEFAULT_BG_COLOR="#282a36" # Matches Dracula background
# --- Variables ---
INPUT_PATH=""
OUTPUT_DIR="snapshots"
WIDTH="$DEFAULT_WIDTH"
FONT="$DEFAULT_FONT"
FONT_SIZE="$DEFAULT_FONT_SIZE"
THEME="$DEFAULT_THEME"
WINDOW_CONTROLS="true"
LINE_NUMBERS="true"
# --- Helper Functions ---
print_banner() {
echo -e "\033[1;36m"
echo " $$$$$$\ $$\ "
echo " $$ __$$\ $$ | "
echo " $$ / \__| $$$$$$\ $$$$$$$ | $$$$$$\ "
echo " $$ | $$ __$$\ $$ __$$ |$$ __$$\ "
echo " $$ | $$ / $$ |$$ / $$ |$$$$$$$$ | "
echo " $$ | $$\ $$ | $$ |$$ | $$ |$$ ____| "
echo " \$$$$$$ |\$$$$$$ |\$$$$$$$ |\$$$$$$$\ "
echo " \______/ \______/ \_______| \_______| "
echo " "
echo " "
echo " "
echo " $$\ "
echo " $$ | "
echo " $$ | $$\ $$\ $$$$$$\$$$$\ $$$$$$\ $$$$$$\ "
echo " $$ | $$ | $$ |$$ _$$ _$$\ $$ __$$\ $$ __$$\ "
echo " $$ | $$ | $$ |$$ / $$ / $$ |$$$$$$$$ |$$ | \__|"
echo " $$ | $$ | $$ |$$ | $$ | $$ |$$ ____|$$ | "
echo " $$$$$$$$\\$$$$$$ |$$ | $$ | $$ |\$$$$$$$\ $$ | "
echo " \________|\______/ \__| \__| \__| \_______|\__| "
echo " "
echo " "
echo " "
echo -e " v$VERSION | Code Lumer Screenshots\033[0m"
echo ""
}
show_help() {
print_banner
echo "Usage: $(basename "$0") [OPTIONS] <FILE_OR_DIRECTORY>"
echo ""
echo "Options:"
echo " -w, --width <px> Output image width (default: $DEFAULT_WIDTH)"
echo " -f, --font <name> Font family (default: '$DEFAULT_FONT')"
echo " -s, --size <pt> Font size (default: $DEFAULT_FONT_SIZE)"
echo " -t, --theme <name> Syntax theme (default: $DEFAULT_THEME)"
echo " -o, --output <dir> Output directory (default: ./snapshots)"
echo " --no-window Disable macOS-style window controls"
echo " --no-line-numbers Disable line numbers"
echo " --list-themes List available themes"
echo " -h, --help Show this help message"
echo ""
echo "Examples:"
echo " $(basename "$0") main.py"
echo " $(basename "$0") -w 2560 -t Nord ./src/"
echo ""
}
check_dependencies() {
if ! command -v silicon &> /dev/null; then
echo -e "\033[1;31m[Error] 'silicon' is not installed.\033[0m"
echo "Please install it via: 'brew install silicon' or 'cargo install silicon'"
exit 1
fi
}
list_themes() {
echo -e "\033[1;32mAvailable Themes:\033[0m"
silicon --list-themes
exit 0
}
generate_screenshot() {
local file="$1"
local filename=$(basename "$file")
local extension="${filename##*.}"
local output_file="${OUTPUT_DIR}/${filename%.*}.png"
# Skip non-text files or binary files loosely
if [[ "$extension" == "png" || "$extension" == "jpg" || "$extension" == "exe" ]]; then
return
fi
echo -e "Processing: \033[0;33m$file\033[0m -> $output_file"
local FONT_ARG="$FONT:$FONT_SIZE"
# Build the argument list
local args=(
"--font" "$FONT_ARG"
"--theme" "$THEME"
"--pad-horiz" "$DEFAULT_PAD_HORIZ"
"--pad-vert" "$DEFAULT_PAD_VERT"
"--shadow-blur-radius" "$DEFAULT_SHADOW_BLUR"
"--shadow-offset-y" "$DEFAULT_SHADOW_OFFSET_Y"
"--background" "$DEFAULT_BG_COLOR"
"--output" "$output_file"
)
# Line Numbers Logic
if [ "$LINE_NUMBERS" == "false" ]; then
args+=("--no-line-number")
fi
# Width Logic: Silicon doesn't stretch text, it pads background.
# To enforce a minimum width, we calculate padding dynamically?
# No, silicon handles background fill.
# Note: Silicon uses automatic width based on text usually,
# but we can assume the background color fills the view.
# Execute generation
silicon "${args[@]}" "$file"
}
# --- Main Logic ---
check_dependencies
# Argument Parsing
while [[ $# -gt 0 ]]; do
case "$1" in
-w|--width) WIDTH="$2"; shift 2 ;;
-f|--font) FONT="$2"; shift 2 ;;
-s|--size) FONT_SIZE="$2"; shift 2 ;;
-t|--theme) THEME="$2"; shift 2 ;;
-o|--output) OUTPUT_DIR="$2"; shift 2 ;;
--no-window) WINDOW_CONTROLS="false"; shift ;;
--no-line-numbers) LINE_NUMBERS="false"; shift ;;
--list-themes) list_themes ;;
-h|--help) show_help; exit 0 ;;
-*|--*) echo "Unknown option $1"; exit 1 ;;
*) INPUT_PATH="$1"; shift ;;
esac
done
if [ -z "$INPUT_PATH" ]; then
echo -e "\033[1;31m[Error] No input file or directory provided.\033[0m"
show_help
exit 1
fi
# Create output directory
mkdir -p "$OUTPUT_DIR"
print_banner
if [ -f "$INPUT_PATH" ]; then
# Single File Mode
generate_screenshot "$INPUT_PATH"
elif [ -d "$INPUT_PATH" ]; then
# Directory Mode (Read ALL files, excluding directories themselves)
echo -e "Scanning directory: \033[1;34m$INPUT_PATH\033[0m (Reading all files)"
# FIND: Find only files (-type f) up to 2 levels deep, excluding the output directory
find "$INPUT_PATH" -maxdepth 2 -type f -not -path "$OUTPUT_DIR/*" | while read -r file; do
generate_screenshot "$file"
done
else
echo "Error: Input path does not exist."
exit 1
fi
echo ""
echo -e "\033[1;32mDone! Screenshots saved in '$OUTPUT_DIR'\033[0m"