par-term 0.4.0

Cross-platform GPU-accelerated terminal emulator with inline graphics support (Sixel, iTerm2, Kitty)
Documentation
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
# Makefile for par-term
# Cross-platform terminal emulator frontend

.PHONY: help build run run-release run-error run-warn run-info run-debug run-trace release test check clean fmt lint checkall install doc coverage test-fonts benchmark-shaping test-text-shaping bundle run-bundle

# Default target
.DEFAULT_GOAL := help

# Help target - display available commands
help:
	@echo "par-term - Cross-platform Terminal Emulator"
	@echo ""
	@echo "Available targets:"
	@echo "  make build       - Build the project in debug mode"
	@echo "  make release     - Build the project in release mode"
	@echo "  make run         - Run the application (release mode)"
	@echo "  make run-debug   - Run with debug logging"
	@echo ""
	@echo "Run with logging:"
	@echo "  make run-error   - Run with error level logs"
	@echo "  make run-warn    - Run with warning level logs"
	@echo "  make run-info    - Run with info level logs"
	@echo "  make run-perf    - Run with performance logging to /tmp/par-term-perf.log"
	@echo "  make run-debug   - Run with DEBUG_LEVEL=3 (logs to /tmp/par_term_debug.log)"
	@echo "  make run-trace   - Run with DEBUG_LEVEL=4 (most verbose)"
	@echo ""
	@echo "Text Shaping Testing:"
	@echo "  make test-fonts        - Run comprehensive text shaping test suite"
	@echo "  make benchmark-shaping - Run text shaping performance benchmark"
	@echo "  make test-text-shaping - Run both font tests and benchmark"
	@echo ""
	@echo "Graphics Testing:"
	@echo "  make test-graphics     - Test graphics with debug logging"
	@echo "  make test-animations   - Test Kitty animations"
	@echo "  make tail-log          - Monitor debug log in real-time"
	@echo "  make watch-graphics    - Monitor graphics-related logs only"
	@echo "  make show-graphics-logs - Show recent graphics logs"
	@echo "  make clean-logs        - Clean debug logs"
	@echo ""
	@echo "Testing & Quality:"
	@echo "  make test        - Run all tests"
	@echo "  make check       - Check code without building"
	@echo "  make fmt         - Format code using rustfmt"
	@echo "  make lint        - Run clippy linter"
	@echo "  make checkall    - Format, lint, and test"
	@echo "  make all         - Format, lint, test, and build"
	@echo ""
	@echo "macOS Bundle:"
	@echo "  make bundle      - Create macOS .app bundle (release mode)"
	@echo "  make run-bundle  - Run as macOS .app (shows dock icon)"
	@echo ""
	@echo "Other:"
	@echo "  make clean       - Clean build artifacts"
	@echo "  make install     - Install the binary"
	@echo "  make doc         - Generate and open documentation"
	@echo "  make coverage    - Generate test coverage report"
	@echo ""

# Build in debug mode
build:
	@echo "Building par-term (debug mode)..."
	cargo build

# Build in release mode
release:
	@echo "Building par-term (release mode)..."
	cargo build --release
	@echo "Release binary: target/release/par-term"

# Run the application (always use release mode for performance)
run:
	@echo "Running par-term (release mode)..."
	cargo run --release

# Run the application in release mode
run-release:
	@echo "Running par-term (release mode)..."
	cargo run --release

# Run with error level logging
run-error:
	@echo "Running par-term (error level logs)..."
	RUST_LOG=error cargo run

# Run with warning level logging
run-warn:
	@echo "Running par-term (warn level logs)..."
	RUST_LOG=warn cargo run

# Run with info level logging (default)
run-info:
	@echo "Running par-term (info level logs)..."
	RUST_LOG=info cargo run

# Run with performance logging to file
run-perf:
	@echo "Running par-term with performance logging..."
	@echo "Logs will be written to: /tmp/par-term-perf.log"
	@echo ""
	@echo "๐Ÿ’ก In another terminal, run:"
	@echo "   tail -f /tmp/par-term-perf.log | grep PERF"
	@echo ""
	RUST_LOG=info cargo run --release 2>&1 | tee /tmp/par-term-perf.log

# Run with debug level logging (uses custom DEBUG_LEVEL for file logging)
run-debug:
	@echo "Running par-term with DEBUG_LEVEL=3..."
	@echo "Debug log: /tmp/par_term_debug.log"
	@echo ""
	@echo "๐Ÿ’ก In another terminal, run: make tail-log"
	@echo ""
	RUST_LOG=debug DEBUG_LEVEL=3 cargo run

# Run with trace level logging (most verbose, uses custom DEBUG_LEVEL)
run-trace:
	@echo "Running par-term with DEBUG_LEVEL=4 (trace)..."
	@echo "Debug log: /tmp/par_term_debug.log"
	@echo ""
	@echo "๐Ÿ’ก In another terminal, run: make tail-log"
	@echo ""
	RUST_LOG=trace DEBUG_LEVEL=4 cargo run

# Run all tests
test:
	@echo "Running tests..."
	cargo test

# Run tests with output
test-verbose:
	@echo "Running tests (verbose)..."
	cargo test -- --nocapture

# Run specific test
test-one:
	@echo "Running specific test..."
	@echo "Usage: make test-one TEST=test_name"
	cargo test $(TEST)

# Check code without building
check:
	@echo "Checking code..."
	cargo check

# Check all targets
check-all:
	@echo "Checking all targets..."
	cargo check --all-targets

# Format code
fmt:
	@echo "Formatting code..."
	cargo fmt

# Check formatting without modifying files
fmt-check:
	@echo "Checking code formatting..."
	cargo fmt -- --check

# Run clippy linter
lint:
	@echo "Running clippy..."
	cargo clippy -- -D warnings

# Run clippy on all targets
lint-all:
	@echo "Running clippy on all targets..."
	cargo clippy --all-targets -- -D warnings

# Run all quality checks (format, lint, test)
checkall: fmt lint test
	@echo "All quality checks passed!"

# Clean build artifacts
clean:
	@echo "Cleaning build artifacts..."
	cargo clean

# Install the binary
install:
	@echo "Installing par-term..."
	cargo install --path .

# Generate documentation
doc:
	@echo "Generating documentation..."
	cargo doc --no-deps

# Generate and open documentation
doc-open:
	@echo "Generating and opening documentation..."
	cargo doc --no-deps --open

# Run all checks (format, lint, test)
all: fmt lint test build
	@echo "All checks passed!"

# Pre-commit checks
pre-commit: fmt-check lint test
	@echo "Pre-commit checks passed!"

# CI checks (what CI would run)
ci: fmt-check lint-all test check-all
	@echo "CI checks passed!"

# Update dependencies
update:
	@echo "Updating dependencies..."
	cargo update

# Generate test coverage (requires tarpaulin)
coverage:
	@echo "Generating test coverage..."
	@command -v cargo-tarpaulin >/dev/null 2>&1 || { echo "cargo-tarpaulin not installed. Install with: cargo install cargo-tarpaulin"; exit 1; }
	cargo tarpaulin --out Html --output-dir coverage

# Benchmark (when benchmarks are added)
bench:
	@echo "Running benchmarks..."
	cargo bench

# Watch for changes and rebuild
watch:
	@echo "Watching for changes..."
	@command -v cargo-watch >/dev/null 2>&1 || { echo "cargo-watch not installed. Install with: cargo install cargo-watch"; exit 1; }
	cargo watch -x check -x test

# Watch and run
watch-run:
	@echo "Watching and running..."
	@command -v cargo-watch >/dev/null 2>&1 || { echo "cargo-watch not installed. Install with: cargo install cargo-watch"; exit 1; }
	cargo watch -x run

# Audit dependencies for security vulnerabilities
audit:
	@echo "Auditing dependencies..."
	@command -v cargo-audit >/dev/null 2>&1 || { echo "cargo-audit not installed. Install with: cargo install cargo-audit"; exit 1; }
	cargo audit

# Show package info
info:
	@echo "Package information:"
	@cargo metadata --no-deps --format-version 1 | grep -E '"name"|"version"|"authors"|"description"'

# Create release build and package
package: release
	@echo "Creating release package..."
	@mkdir -p dist
	@cp target/release/par-term dist/
	@cp README.md LICENSE-MIT dist/
	@echo "Package created in dist/"

# macOS app bundle
bundle: release
ifeq ($(shell uname),Darwin)
	@echo "Creating macOS app bundle..."
	$(eval VERSION := $(shell grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)"/\1/'))
	@mkdir -p target/release/bundle/par-term.app/Contents/MacOS
	@mkdir -p target/release/bundle/par-term.app/Contents/Resources
	@cp target/release/par-term target/release/bundle/par-term.app/Contents/MacOS/
	@cp assets/par-term.icns target/release/bundle/par-term.app/Contents/Resources/
	@echo '<?xml version="1.0" encoding="UTF-8"?>' > target/release/bundle/par-term.app/Contents/Info.plist
	@echo '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">' >> target/release/bundle/par-term.app/Contents/Info.plist
	@echo '<plist version="1.0">' >> target/release/bundle/par-term.app/Contents/Info.plist
	@echo '<dict>' >> target/release/bundle/par-term.app/Contents/Info.plist
	@echo '    <key>CFBundleName</key>' >> target/release/bundle/par-term.app/Contents/Info.plist
	@echo '    <string>par-term</string>' >> target/release/bundle/par-term.app/Contents/Info.plist
	@echo '    <key>CFBundleDisplayName</key>' >> target/release/bundle/par-term.app/Contents/Info.plist
	@echo '    <string>par-term</string>' >> target/release/bundle/par-term.app/Contents/Info.plist
	@echo '    <key>CFBundleIdentifier</key>' >> target/release/bundle/par-term.app/Contents/Info.plist
	@echo '    <string>com.paulrobello.par-term</string>' >> target/release/bundle/par-term.app/Contents/Info.plist
	@echo '    <key>CFBundleVersion</key>' >> target/release/bundle/par-term.app/Contents/Info.plist
	@echo '    <string>$(VERSION)</string>' >> target/release/bundle/par-term.app/Contents/Info.plist
	@echo '    <key>CFBundleShortVersionString</key>' >> target/release/bundle/par-term.app/Contents/Info.plist
	@echo '    <string>$(VERSION)</string>' >> target/release/bundle/par-term.app/Contents/Info.plist
	@echo '    <key>CFBundleExecutable</key>' >> target/release/bundle/par-term.app/Contents/Info.plist
	@echo '    <string>par-term</string>' >> target/release/bundle/par-term.app/Contents/Info.plist
	@echo '    <key>CFBundleIconFile</key>' >> target/release/bundle/par-term.app/Contents/Info.plist
	@echo '    <string>par-term</string>' >> target/release/bundle/par-term.app/Contents/Info.plist
	@echo '    <key>CFBundlePackageType</key>' >> target/release/bundle/par-term.app/Contents/Info.plist
	@echo '    <string>APPL</string>' >> target/release/bundle/par-term.app/Contents/Info.plist
	@echo '    <key>NSHighResolutionCapable</key>' >> target/release/bundle/par-term.app/Contents/Info.plist
	@echo '    <true/>' >> target/release/bundle/par-term.app/Contents/Info.plist
	@echo '    <key>LSMinimumSystemVersion</key>' >> target/release/bundle/par-term.app/Contents/Info.plist
	@echo '    <string>10.13</string>' >> target/release/bundle/par-term.app/Contents/Info.plist
	@echo '</dict>' >> target/release/bundle/par-term.app/Contents/Info.plist
	@echo '</plist>' >> target/release/bundle/par-term.app/Contents/Info.plist
	@echo "Bundle created at: target/release/bundle/par-term.app (version $(VERSION))"
else
	@echo "App bundle creation is only supported on macOS"
endif

# Run macOS app bundle (shows proper dock icon)
run-bundle: bundle
ifeq ($(shell uname),Darwin)
	@echo "Running par-term.app..."
	@open target/release/bundle/par-term.app
else
	@echo "App bundle is only supported on macOS"
	@echo "Running regular binary instead..."
	cargo run --release
endif

# Generate config file example
config-example:
	@echo "# par-term configuration example" > config.yaml.example
	@echo "cols: 80" >> config.yaml.example
	@echo "rows: 24" >> config.yaml.example
	@echo "font_size: 14.0" >> config.yaml.example
	@echo "font_family: \"JetBrains Mono\"" >> config.yaml.example
	@echo "scrollback_size: 10000" >> config.yaml.example
	@echo "window_title: \"par-term\"" >> config.yaml.example
	@echo "theme: \"dark-background\"" >> config.yaml.example
	@echo "auto_copy_selection: false" >> config.yaml.example
	@echo "middle_click_paste: true" >> config.yaml.example
	@echo "screenshot_format: \"png\"" >> config.yaml.example
	@echo "Example config written to config.yaml.example"

# === Text Shaping Testing Targets ===

# Run comprehensive text shaping test suite
test-fonts:
	@echo "๐Ÿ”ค Running comprehensive font and text shaping tests..."
	@echo ""
	@echo "This test suite covers:"
	@echo "  โœ“ Emoji with skin tones"
	@echo "  โœ“ Flag emoji (Regional Indicators)"
	@echo "  โœ“ ZWJ sequences"
	@echo "  โœ“ Complex scripts (Arabic, Devanagari, Thai)"
	@echo "  โœ“ BiDi text (LTR + RTL)"
	@echo "  โœ“ Combining diacritics"
	@echo "  โœ“ Programming ligatures"
	@echo "  โœ“ Wide character rendering"
	@echo ""
	@./scripts/test_fonts.sh

# Run text shaping performance benchmark
benchmark-shaping:
	@echo "โšก Running text shaping performance benchmark..."
	@echo ""
	@echo "This will benchmark:"
	@echo "  - ASCII baseline"
	@echo "  - CJK characters"
	@echo "  - Simple and complex emoji"
	@echo "  - Complex scripts (Arabic, Devanagari, Thai)"
	@echo "  - Mixed content stress test"
	@echo ""
	@echo "๐Ÿ’ก Run this twice to compare:"
	@echo "   1. With enable_text_shaping: true (default)"
	@echo "   2. With enable_text_shaping: false"
	@echo ""
	@./scripts/benchmark_text_shaping.sh

# Run both font tests and benchmark
test-text-shaping: test-fonts benchmark-shaping
	@echo ""
	@echo "โœ… Text shaping tests and benchmarks complete!"

# === Graphics Testing Targets ===

# Monitor the debug log
tail-log:
	@if [ ! -f /tmp/par_term_debug.log ]; then \
		echo "โŒ Debug log not found."; \
		echo ""; \
		echo "Start par-term with: make run-debug"; \
		exit 1; \
	fi
	@echo "๐Ÿ“ Monitoring /tmp/par_term_debug.log..."
	@echo "Press Ctrl+C to stop"
	@echo ""
	tail -f /tmp/par_term_debug.log

# Watch log with graphics filtering
watch-graphics:
	@if [ ! -f /tmp/par_term_debug.log ]; then \
		echo "โŒ Debug log not found."; \
		echo ""; \
		echo "Start par-term with: make run-debug"; \
		exit 1; \
	fi
	@echo "๐Ÿ“ Monitoring /tmp/par_term_debug.log (graphics only)..."
	@echo "Press Ctrl+C to stop"
	@echo ""
	tail -f /tmp/par_term_debug.log | grep -i --line-buffered "graphics\|terminal\|animation\|sixel\|kitty"

# Test graphics with debug logging
test-graphics:
	@echo "๐ŸŽจ Graphics Testing Mode"
	@echo ""
	@echo "Starting par-term with DEBUG_LEVEL=4..."
	@echo ""
	@echo "๐Ÿ“ Debug log: /tmp/par_term_debug.log"
	@echo ""
	@echo "๐Ÿ’ก In another terminal, run:"
	@echo "   make tail-log         (all logs)"
	@echo "   make watch-graphics   (graphics only)"
	@echo ""
	@echo "๐Ÿงช In par-term, run test:"
	@echo "   bash /tmp/test_par_term_graphics.sh"
	@echo ""
	DEBUG_LEVEL=4 cargo run

# Clean debug logs
clean-logs:
	@echo "Cleaning debug logs..."
	@rm -f /tmp/par_term_debug.log
	@echo "โœ… Debug logs cleaned"

# Show recent graphics-related logs
show-graphics-logs:
	@if [ ! -f /tmp/par_term_debug.log ]; then \
		echo "โŒ Debug log not found."; \
		echo ""; \
		echo "Start par-term with: make run-debug"; \
		exit 1; \
	fi
	@echo "Recent graphics-related logs:"
	@echo ""
	@grep -i "graphics\|terminal\|animation\|sixel" /tmp/par_term_debug.log | tail -30

# Test animations specifically
test-animations:
	@echo "๐ŸŽฌ Animation Testing Mode"
	@echo ""
	@echo "Starting par-term with DEBUG_LEVEL=4..."
	@echo ""
	@echo "๐Ÿ“ Debug log: /tmp/par_term_debug.log"
	@echo ""
	@echo "๐Ÿ’ก In another terminal, run: make watch-graphics"
	@echo ""
	@echo "๐Ÿงช In par-term, run:"
	@echo "   uv run python ../par-term-emu-core-rust/scripts/test_kitty_animation.py"
	@echo ""
	DEBUG_LEVEL=4 cargo run

# === Profiling Targets ===

# Profile with flamegraph (CPU profiling)
profile:
	@echo "๐Ÿ”ฅ Profiling with flamegraph..."
	@command -v cargo-flamegraph >/dev/null 2>&1 || { echo "โŒ cargo-flamegraph not installed."; echo "Install with: cargo install flamegraph"; exit 1; }
	@echo ""
	@echo "This will:"
	@echo "  1. Build in release mode with debug symbols"
	@echo "  2. Run par-term and collect CPU samples"
	@echo "  3. Generate flamegraph.svg when you quit"
	@echo ""
	@echo "๐Ÿ’ก Use the terminal normally, then quit to generate the flamegraph"
	@echo ""
	cargo flamegraph --release --output flamegraph.svg

# Profile with perf (Linux only)
profile-perf:
	@echo "๐Ÿ“Š Profiling with perf..."
	@command -v perf >/dev/null 2>&1 || { echo "โŒ perf not installed (Linux only)"; exit 1; }
	@echo "Recording 30 seconds of perf data..."
	@echo "Use the terminal normally during this time"
	cargo build --release
	perf record -F 99 -g --call-graph=dwarf -- target/release/par-term
	@echo ""
	@echo "Generating report..."
	perf report

# Profile with Instruments (macOS only)
profile-instruments:
	@echo "๐ŸŽฏ Profiling with Instruments (macOS)..."
	@command -v instruments >/dev/null 2>&1 || { echo "โŒ Instruments not found (macOS only)"; exit 1; }
	cargo build --release
	@echo "Starting Instruments Time Profiler..."
	@echo "Use the terminal normally, then stop recording in Instruments"
	instruments -t "Time Profiler" target/release/par-term