-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreview.ps1
More file actions
136 lines (110 loc) · 4.03 KB
/
Copy pathpreview.ps1
File metadata and controls
136 lines (110 loc) · 4.03 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
<#
.SYNOPSIS
biscuit. e-ink screen preview — hot reload
.DESCRIPTION
Watches test_preview.cpp for changes, auto-builds, auto-opens BMP.
Just edit test_preview.cpp, save, and the preview appears.
.USAGE
.\preview.ps1 # watch mode — rebuilds on every save
.\preview.ps1 -Once # single build + open
.\preview.ps1 -Clean # delete all preview BMPs
#>
param(
[switch]$Once,
[switch]$Clean
)
$ErrorActionPreference = "Stop"
$env:PYTHONUTF8 = "1"
$projectRoot = $PSScriptRoot
if (-not (Test-Path "$projectRoot\platformio.ini")) {
$projectRoot = (Get-Location).Path
}
$previewFile = "$projectRoot\test\test_preview\test_preview.cpp"
$bmpPattern = "$projectRoot\test\preview_*.bmp"
$viewer = $null # will use default app
# ---- Clean mode ----
if ($Clean) {
Remove-Item $bmpPattern -Force -ErrorAction SilentlyContinue
Write-Host "Cleaned all preview BMPs." -ForegroundColor Green
exit 0
}
# ---- Build + Open ----
function Invoke-Preview {
$sw = [System.Diagnostics.Stopwatch]::StartNew()
Write-Host ""
Write-Host "Building preview..." -ForegroundColor Cyan
$buildOutput = & pio test -e native -f test_preview 2>&1
$exitCode = $LASTEXITCODE
$sw.Stop()
if ($exitCode -ne 0) {
Write-Host "BUILD FAILED ($($sw.ElapsedMilliseconds)ms)" -ForegroundColor Red
# Show only the first error
$errors = $buildOutput | Where-Object { $_ -match "error:" } | Select-Object -First 3
foreach ($e in $errors) {
Write-Host " $e" -ForegroundColor Yellow
}
return
}
# Count generated BMPs
$bmps = Get-ChildItem $bmpPattern -ErrorAction SilentlyContinue
$count = ($bmps | Measure-Object).Count
Write-Host "OK — $count preview(s) generated in $($sw.ElapsedMilliseconds)ms" -ForegroundColor Green
# List generated files
foreach ($bmp in $bmps) {
$size = [math]::Round($bmp.Length / 1024, 1)
Write-Host " $($bmp.Name) (${size}KB)" -ForegroundColor DarkGray
}
# Open the newest BMP (most likely the one being worked on)
if ($bmps) {
$newest = $bmps | Sort-Object LastWriteTime -Descending | Select-Object -First 1
Start-Process $newest.FullName
}
}
# ---- Single run mode ----
if ($Once) {
Invoke-Preview
exit 0
}
# ---- Watch mode ----
if (-not (Test-Path $previewFile)) {
Write-Host "ERROR: $previewFile not found" -ForegroundColor Red
Write-Host "Create test/test_preview/test_preview.cpp first." -ForegroundColor Yellow
exit 1
}
Write-Host @"
╔══════════════════════════════════════════════╗
║ biscuit. preview — hot reload active ║
║ ║
║ Edit: test\test_preview\test_preview.cpp ║
║ Save → auto-build → BMP opens ║
║ ║
║ Press Ctrl+C to stop ║
╚══════════════════════════════════════════════╝
"@ -ForegroundColor DarkCyan
# Initial build
Invoke-Preview
# Watch for changes
$lastWrite = (Get-Item $previewFile).LastWriteTime
$watchPaths = @(
$previewFile,
"$projectRoot\test\mocks\BitmapRenderer.h"
)
Write-Host "`nWatching for changes..." -ForegroundColor DarkGray
while ($true) {
Start-Sleep -Milliseconds 500
$changed = $false
foreach ($path in $watchPaths) {
if (Test-Path $path) {
$current = (Get-Item $path).LastWriteTime
if ($current -gt $lastWrite) {
$lastWrite = $current
$changed = $true
}
}
}
if ($changed) {
Write-Host "`n--- file changed at $(Get-Date -Format 'HH:mm:ss') ---" -ForegroundColor DarkYellow
Invoke-Preview
Write-Host "Watching for changes..." -ForegroundColor DarkGray
}
}