yorukot / superfile

Pretty fancy and modern terminal file manager
https://superfile.netlify.app
MIT License
7.33k stars 157 forks source link

Crash when preview images #377

Closed sparkwenc closed 2 months ago

sparkwenc commented 2 months ago

Describe the bug A clear and concise description of what the bug is.

To Reproduce Move the focus to image files, then spf crashes with following errors

Caught panic:

runtime error: slice bounds out of range [1:0]

Restoring terminal...

goroutine 1 [running]:
runtime/debug.Stack()
    runtime/debug/stack.go:24 +0x64
runtime/debug.PrintStack()
    runtime/debug/stack.go:16 +0x1c
github.com/charmbracelet/bubbletea.(*Program).Run.func1()
    github.com/charmbracelet/bubbletea@v0.26.6/tea.go:479 +0x88
panic({0x102f50d00?, 0x14000124030?})
    runtime/panic.go:770 +0x124
github.com/yorukot/superfile/src/pkg/file_preview.hexToColor({0x0?, 0x18?})
    github.com/yorukot/superfile/src/pkg/file_preview/image_preview.go:81 +0x70
github.com/yorukot/superfile/src/pkg/file_preview.ImagePreview({0x1400039e300?, 0x1c?}, 0x2f, 0x18, {0x0, 0x0})
    github.com/yorukot/superfile/src/pkg/file_preview/image_preview.go:75 +0xf0
github.com/yorukot/superfile/src/internal.model.filePreviewPanelRender({{{0x14000180d88, 0x1, 0x1}, 0x31, 0x0, 0x2, {0x1, 0x2f}}, {{0x14000684c40, 0xa, ...}, ...}, ...})
    github.com/yorukot/superfile/src/internal/model_render.go:559 +0x584
github.com/yorukot/superfile/src/internal.model.View({{{0x14000180d88, 0x1, 0x1}, 0x31, 0x0, 0x2, {0x1, 0x2f}}, {{0x14000684c40, 0xa, ...}, ...}, ...})
    github.com/yorukot/superfile/src/internal/model.go:207 +0x120
github.com/charmbracelet/bubbletea.(*Program).eventLoop(0x14000233200, {0x102f93cf0?, 0x140001de008?}, 0x140000302a0)
    github.com/charmbracelet/bubbletea@v0.26.6/tea.go:414 +0x5c8
github.com/charmbracelet/bubbletea.(*Program).Run(0x14000233200)
    github.com/charmbracelet/bubbletea@v0.26.6/tea.go:550 +0x7ec
github.com/yorukot/superfile/src/cmd.Run.func3(0x14000394040?)
    github.com/yorukot/superfile/src/cmd/main.go:68 +0x138
github.com/urfave/cli/v2.(*Command).Run(0x140001c46e0, 0x14000394040, {0x14000020090, 0x1, 0x1})
    github.com/urfave/cli/v2@v2.27.3/command.go:276 +0x71c
github.com/urfave/cli/v2.(*App).RunContext(0x14000194000, {0x102f947d8, 0x1035b8d20}, {0x14000020090, 0x1, 0x1})
    github.com/urfave/cli/v2@v2.27.3/app.go:333 +0x51c
github.com/urfave/cli/v2.(*App).Run(...)
    github.com/urfave/cli/v2@v2.27.3/app.go:307
github.com/yorukot/superfile/src/cmd.Run({0x1034a0fc8?})
    github.com/yorukot/superfile/src/cmd/main.go:77 +0x270
main.main()
    github.com/yorukot/superfile/main.go:15 +0x24

System information (please complete the following information):

yorukot commented 2 months ago

Thanks for your report! Can you send me that image so I can test it?

sparkwenc commented 2 months ago

Indeed, every image here. It seems not a problem on your end, should I reinstall it?

sparkwenc commented 2 months ago

Here is one example

111

sparkwenc commented 2 months ago

Ok, I found the incompatibility here:

Actually, I changed the theme file, with the default theme Catpuccin, everything is fine.

Now I customized it by commenting all its settings about background color as follows

# ========= Background (bg) =========
#full_screen_bg = "#1e1e2e"
#file_panel_bg = "#1e1e2e"
#sidebar_bg = "#1e1e2e"
#footer_bg = "#1e1e2e"
#modal_bg = "#1e1e2e"

Now get back to image preview spf will crash.

sparkwenc commented 2 months ago

OK! I get that the transparency should be set in config.toml rather than customize the theme file by removing the background color setting. So my own problem is resolved.

But removing the background color setting resulting in crashing when previewing image may still be a minor bug

yorukot commented 2 months ago

Got it, thanks for you debug!