feat: inline conversion with status updates, cwebp support, v0.1.4

- Conversion now happens inline on the file list — status column updates
  from idle → converting... → done/error in place (no separate screen)
- Fixed value-receiver bug in convertNext() that prevented 'converting'
  status from being displayed
- Added cwebp fallback for PNG/JPEG → WebP (ffmpeg webp encoder often
  missing on macOS)
- Format selector arrows hidden during conversion/results states
- Simplified to 2 states: stateFileList + stateResults
- Added tests for conversion state machine and view rendering
This commit is contained in:
noah
2026-03-09 23:45:54 +01:00
parent ed25ffa533
commit 6254c0431e
6 changed files with 271 additions and 120 deletions
+28
View File
@@ -0,0 +1,28 @@
package converter
import (
"os"
"path/filepath"
"testing"
)
func TestConvertImage(t *testing.T) {
// Find a test PNG file
testFile := filepath.Join("..", "..", "..", "public", "logo.png")
if _, err := os.Stat(testFile); err != nil {
t.Skipf("test file not found: %s", testFile)
}
outDir := t.TempDir()
result := Convert(testFile, "webp", outDir)
if result.Err != nil {
t.Fatalf("conversion failed: %v", result.Err)
}
info, err := os.Stat(result.OutputPath)
if err != nil {
t.Fatalf("output file not found: %v", err)
}
t.Logf("Converted %s -> %s (%d bytes)", testFile, result.OutputPath, info.Size())
}
+12
View File
@@ -7,6 +7,7 @@ import (
"image/jpeg"
"image/png"
"os"
"os/exec"
"strings"
"golang.org/x/image/bmp"
@@ -88,6 +89,17 @@ func tryDecodeImage(f *os.File, path string) (image.Image, error) {
}
func convertImageViaFFmpeg(inputPath, outputPath, format string) error {
// For WebP: prefer cwebp (from libwebp-tools) which is widely available
if format == "webp" {
if cwebpPath, err := exec.LookPath("cwebp"); err == nil {
cmd := exec.Command(cwebpPath, "-q", "90", inputPath, "-o", outputPath)
if out, err := cmd.CombinedOutput(); err != nil {
return fmt.Errorf("cwebp error: %w\n%s", err, string(out))
}
return nil
}
}
args := []string{"-y", "-i", inputPath}
switch format {