summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrail Finder <wohilas@gmail.com>2025-11-20 23:25:50 +0300
committerGrail Finder <wohilas@gmail.com>2025-11-20 23:25:50 +0300
commite8413ce613a71b6ec0b62b928a1179738655b49b (patch)
treef9bccb94b894c44599ccd8fab8d2eb717422f702
parent6e73513aacf1e499fccb32ee0b09d90c22341214 (diff)
Enha: extentions for filepicker
-rw-r--r--config.example.toml1
-rw-r--r--config/config.go2
-rw-r--r--tables.go54
3 files changed, 42 insertions, 15 deletions
diff --git a/config.example.toml b/config.example.toml
index a6d3290..98a7c71 100644
--- a/config.example.toml
+++ b/config.example.toml
@@ -28,6 +28,7 @@ STT_LANG = "en" # Language for speech recognition (for WHISPER_BINARY mode)
STT_SR = 16000 # Sample rate for audio recording
DBPATH = "gflt.db"
FilePickerDir = "." # Directory where file picker should start
+FilePickerExts = "png,jpg,jpeg,gif,webp" # Comma-separated list of allowed file extensions for file picker
#
FetchModelNameAPI = "http://localhost:8080/v1/models"
# external search tool
diff --git a/config/config.go b/config/config.go
index ff74089..499c84f 100644
--- a/config/config.go
+++ b/config/config.go
@@ -65,6 +65,7 @@ type Config struct {
STT_LANG string `toml:"STT_LANG"`
DBPATH string `toml:"DBPATH"`
FilePickerDir string `toml:"FilePickerDir"`
+ FilePickerExts string `toml:"FilePickerExts"`
}
func LoadConfigOrDefault(fn string) *Config {
@@ -101,6 +102,7 @@ func LoadConfigOrDefault(fn string) *Config {
config.FetchModelNameAPI = "http://localhost:8080/v1/models"
config.STT_SR = 16000
config.FilePickerDir = "." // Default to current directory
+ config.FilePickerExts = "png,jpg,jpeg,gif,webp" // Default allowed extensions
}
config.CurrentAPI = config.ChatAPI
config.APIMap = map[string]string{
diff --git a/tables.go b/tables.go
index 8fa80ed..3e58e72 100644
--- a/tables.go
+++ b/tables.go
@@ -563,6 +563,27 @@ func makeFilePicker() *tview.Flex {
// Track currently displayed directory (changes as user navigates)
currentDisplayDir := startDir
+ // Helper function to check if a file has an allowed extension from config
+ hasAllowedExtension := func(filename string) bool {
+ // If no allowed extensions are specified in config, allow all files
+ if cfg.FilePickerExts == "" {
+ return true
+ }
+
+ // Split the allowed extensions from the config string
+ allowedExts := strings.Split(cfg.FilePickerExts, ",")
+
+ lowerFilename := strings.ToLower(strings.TrimSpace(filename))
+
+ for _, ext := range allowedExts {
+ ext = strings.TrimSpace(ext) // Remove any whitespace around the extension
+ if ext != "" && strings.HasSuffix(lowerFilename, "."+ext) {
+ return true
+ }
+ }
+ return false
+ }
+
// Helper function to check if a file is an image
isImageFile := func(filename string) bool {
imageExtensions := []string{".png", ".jpg", ".jpeg", ".gif", ".webp", ".bmp", ".tiff", ".svg"}
@@ -690,22 +711,25 @@ func makeFilePicker() *tview.Flex {
statusView.SetText("Current: " + newDir)
})
} else {
- // Capture the file name for the closure to avoid loop variable issues
- fileName := name
- fullFilePath := path.Join(dir, fileName)
- listView.AddItem(fileName, "(File)", 0, func() {
- selectedFile = fullFilePath
- statusView.SetText("Selected: " + selectedFile)
-
- // Check if the file is an image
- if isImageFile(fileName) {
- // For image files, offer to attach to the next LLM message
- statusView.SetText("Selected image: " + selectedFile + " (Press Load to attach)")
- } else {
- // For non-image files, display as before
+ // Only show files that have allowed extensions (from config)
+ if hasAllowedExtension(name) {
+ // Capture the file name for the closure to avoid loop variable issues
+ fileName := name
+ fullFilePath := path.Join(dir, fileName)
+ listView.AddItem(fileName, "(File)", 0, func() {
+ selectedFile = fullFilePath
statusView.SetText("Selected: " + selectedFile)
- }
- })
+
+ // Check if the file is an image
+ if isImageFile(fileName) {
+ // For image files, offer to attach to the next LLM message
+ statusView.SetText("Selected image: " + selectedFile + " (Press Load to attach)")
+ } else {
+ // For non-image files, display as before
+ statusView.SetText("Selected: " + selectedFile)
+ }
+ })
+ }
}
}