Enha: ctrl+g exit option
This commit is contained in:
@@ -14,6 +14,7 @@ ChunkLimit = 100000
|
|||||||
RAGBatchSize = 100
|
RAGBatchSize = 100
|
||||||
RAGWordLimit = 80
|
RAGWordLimit = 80
|
||||||
RAGWorkers = 5
|
RAGWorkers = 5
|
||||||
|
RAGDir = "ragimport"
|
||||||
# extra tts
|
# extra tts
|
||||||
TTS_ENABLED = false
|
TTS_ENABLED = false
|
||||||
TTS_URL = "http://localhost:8880/v1/audio/speech"
|
TTS_URL = "http://localhost:8880/v1/audio/speech"
|
||||||
|
|||||||
35
tables.go
35
tables.go
@@ -171,7 +171,7 @@ func makeChatTable(chatMap map[string]models.Chat) *tview.Table {
|
|||||||
|
|
||||||
// nolint:unused
|
// nolint:unused
|
||||||
func makeRAGTable(fileList []string) *tview.Flex {
|
func makeRAGTable(fileList []string) *tview.Flex {
|
||||||
actions := []string{"load", "delete"}
|
actions := []string{"load", "delete", "exit"}
|
||||||
rows, cols := len(fileList), len(actions)+1
|
rows, cols := len(fileList), len(actions)+1
|
||||||
fileTable := tview.NewTable().
|
fileTable := tview.NewTable().
|
||||||
SetBorders(true)
|
SetBorders(true)
|
||||||
@@ -227,7 +227,7 @@ func makeRAGTable(fileList []string) *tview.Flex {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
fileTable.Select(0, 0).SetFixed(1, 1).SetDoneFunc(func(key tcell.Key) {
|
fileTable.Select(0, 0).SetFixed(1, 1).SetDoneFunc(func(key tcell.Key) {
|
||||||
if key == tcell.KeyEsc || key == tcell.KeyF1 {
|
if key == tcell.KeyEsc || key == tcell.KeyF1 || key == tcell.Key('x') || key == tcell.KeyCtrlX {
|
||||||
pages.RemovePage(RAGPage)
|
pages.RemovePage(RAGPage)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -265,6 +265,7 @@ func makeRAGTable(fileList []string) *tview.Flex {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
default:
|
default:
|
||||||
|
pages.RemovePage(RAGPage)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -555,7 +556,6 @@ func makeFilePicker() *tview.Flex {
|
|||||||
if startDir == "" {
|
if startDir == "" {
|
||||||
startDir = "."
|
startDir = "."
|
||||||
}
|
}
|
||||||
|
|
||||||
// If startDir is ".", resolve it to the actual current working directory
|
// If startDir is ".", resolve it to the actual current working directory
|
||||||
if startDir == "." {
|
if startDir == "." {
|
||||||
wd, err := os.Getwd()
|
wd, err := os.Getwd()
|
||||||
@@ -563,29 +563,22 @@ func makeFilePicker() *tview.Flex {
|
|||||||
startDir = wd
|
startDir = wd
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Track navigation history
|
// Track navigation history
|
||||||
dirStack := []string{startDir}
|
dirStack := []string{startDir}
|
||||||
currentStackPos := 0
|
currentStackPos := 0
|
||||||
|
|
||||||
// Track selected file
|
// Track selected file
|
||||||
var selectedFile string
|
var selectedFile string
|
||||||
|
|
||||||
// Track currently displayed directory (changes as user navigates)
|
// Track currently displayed directory (changes as user navigates)
|
||||||
currentDisplayDir := startDir
|
currentDisplayDir := startDir
|
||||||
|
|
||||||
// Helper function to check if a file has an allowed extension from config
|
// Helper function to check if a file has an allowed extension from config
|
||||||
hasAllowedExtension := func(filename string) bool {
|
hasAllowedExtension := func(filename string) bool {
|
||||||
// If no allowed extensions are specified in config, allow all files
|
// If no allowed extensions are specified in config, allow all files
|
||||||
if cfg.FilePickerExts == "" {
|
if cfg.FilePickerExts == "" {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Split the allowed extensions from the config string
|
// Split the allowed extensions from the config string
|
||||||
allowedExts := strings.Split(cfg.FilePickerExts, ",")
|
allowedExts := strings.Split(cfg.FilePickerExts, ",")
|
||||||
|
|
||||||
lowerFilename := strings.ToLower(strings.TrimSpace(filename))
|
lowerFilename := strings.ToLower(strings.TrimSpace(filename))
|
||||||
|
|
||||||
for _, ext := range allowedExts {
|
for _, ext := range allowedExts {
|
||||||
ext = strings.TrimSpace(ext) // Remove any whitespace around the extension
|
ext = strings.TrimSpace(ext) // Remove any whitespace around the extension
|
||||||
if ext != "" && strings.HasSuffix(lowerFilename, "."+ext) {
|
if ext != "" && strings.HasSuffix(lowerFilename, "."+ext) {
|
||||||
@@ -594,7 +587,6 @@ func makeFilePicker() *tview.Flex {
|
|||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper function to check if a file is an image
|
// Helper function to check if a file is an image
|
||||||
isImageFile := func(filename string) bool {
|
isImageFile := func(filename string) bool {
|
||||||
imageExtensions := []string{".png", ".jpg", ".jpeg", ".gif", ".webp", ".bmp", ".tiff", ".svg"}
|
imageExtensions := []string{".png", ".jpg", ".jpeg", ".gif", ".webp", ".bmp", ".tiff", ".svg"}
|
||||||
@@ -606,34 +598,27 @@ func makeFilePicker() *tview.Flex {
|
|||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create UI elements
|
// Create UI elements
|
||||||
listView := tview.NewList()
|
listView := tview.NewList()
|
||||||
listView.SetBorder(true).SetTitle("Files & Directories").SetTitleAlign(tview.AlignLeft)
|
listView.SetBorder(true).SetTitle("Files & Directories").SetTitleAlign(tview.AlignLeft)
|
||||||
|
|
||||||
// Status view for selected file information
|
// Status view for selected file information
|
||||||
statusView := tview.NewTextView()
|
statusView := tview.NewTextView()
|
||||||
statusView.SetBorder(true).SetTitle("Selected File").SetTitleAlign(tview.AlignLeft)
|
statusView.SetBorder(true).SetTitle("Selected File").SetTitleAlign(tview.AlignLeft)
|
||||||
statusView.SetTextColor(tcell.ColorYellow)
|
statusView.SetTextColor(tcell.ColorYellow)
|
||||||
|
|
||||||
// Layout - only include list view and status view
|
// Layout - only include list view and status view
|
||||||
flex := tview.NewFlex().SetDirection(tview.FlexRow)
|
flex := tview.NewFlex().SetDirection(tview.FlexRow)
|
||||||
flex.AddItem(listView, 0, 3, true)
|
flex.AddItem(listView, 0, 3, true)
|
||||||
flex.AddItem(statusView, 3, 0, false)
|
flex.AddItem(statusView, 3, 0, false)
|
||||||
|
|
||||||
// Refresh the file list
|
// Refresh the file list
|
||||||
var refreshList func(string)
|
var refreshList func(string)
|
||||||
refreshList = func(dir string) {
|
refreshList = func(dir string) {
|
||||||
listView.Clear()
|
listView.Clear()
|
||||||
|
|
||||||
// Update the current display directory
|
// Update the current display directory
|
||||||
currentDisplayDir = dir // Update the current display directory
|
currentDisplayDir = dir // Update the current display directory
|
||||||
|
|
||||||
// Add exit option at the top
|
// Add exit option at the top
|
||||||
listView.AddItem("Exit file picker [gray](Close without selecting)[-]", "", 'x', func() {
|
listView.AddItem("Exit file picker [gray](Close without selecting)[-]", "", 'x', func() {
|
||||||
pages.RemovePage(filePickerPage)
|
pages.RemovePage(filePickerPage)
|
||||||
})
|
})
|
||||||
|
|
||||||
// Add parent directory (..) if not at root
|
// Add parent directory (..) if not at root
|
||||||
if dir != "/" {
|
if dir != "/" {
|
||||||
parentDir := path.Dir(dir)
|
parentDir := path.Dir(dir)
|
||||||
@@ -649,23 +634,19 @@ func makeFilePicker() *tview.Flex {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read directory contents
|
// Read directory contents
|
||||||
files, err := os.ReadDir(dir)
|
files, err := os.ReadDir(dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
statusView.SetText("Error reading directory: " + err.Error())
|
statusView.SetText("Error reading directory: " + err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add directories and files to the list
|
// Add directories and files to the list
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
name := file.Name()
|
name := file.Name()
|
||||||
|
|
||||||
// Skip hidden files and directories (those starting with a dot)
|
// Skip hidden files and directories (those starting with a dot)
|
||||||
if strings.HasPrefix(name, ".") {
|
if strings.HasPrefix(name, ".") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if file.IsDir() {
|
if file.IsDir() {
|
||||||
// Capture the directory name for the closure to avoid loop variable issues
|
// Capture the directory name for the closure to avoid loop variable issues
|
||||||
dirName := name
|
dirName := name
|
||||||
@@ -685,7 +666,6 @@ func makeFilePicker() *tview.Flex {
|
|||||||
listView.AddItem(fileName+" [gray](File)[-]", "", 0, func() {
|
listView.AddItem(fileName+" [gray](File)[-]", "", 0, func() {
|
||||||
selectedFile = fullFilePath
|
selectedFile = fullFilePath
|
||||||
statusView.SetText("Selected: " + selectedFile)
|
statusView.SetText("Selected: " + selectedFile)
|
||||||
|
|
||||||
// Check if the file is an image
|
// Check if the file is an image
|
||||||
if isImageFile(fileName) {
|
if isImageFile(fileName) {
|
||||||
// For image files, offer to attach to the next LLM message
|
// For image files, offer to attach to the next LLM message
|
||||||
@@ -698,13 +678,10 @@ func makeFilePicker() *tview.Flex {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
statusView.SetText("Current: " + dir)
|
statusView.SetText("Current: " + dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize the file list
|
// Initialize the file list
|
||||||
refreshList(startDir)
|
refreshList(startDir)
|
||||||
|
|
||||||
// Set up keyboard navigation
|
// Set up keyboard navigation
|
||||||
flex.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
|
flex.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
|
||||||
switch event.Key() {
|
switch event.Key() {
|
||||||
@@ -728,22 +705,18 @@ func makeFilePicker() *tview.Flex {
|
|||||||
// Since we can't directly get the item text, we'll keep track of items differently
|
// Since we can't directly get the item text, we'll keep track of items differently
|
||||||
// Let's improve the approach by tracking the currently selected item
|
// Let's improve the approach by tracking the currently selected item
|
||||||
itemText, _ := listView.GetItemText(itemIndex)
|
itemText, _ := listView.GetItemText(itemIndex)
|
||||||
|
|
||||||
logger.Info("choosing dir", "itemText", itemText)
|
logger.Info("choosing dir", "itemText", itemText)
|
||||||
|
|
||||||
// Check for the exit option first (should be the first item)
|
// Check for the exit option first (should be the first item)
|
||||||
if strings.HasPrefix(itemText, "Exit file picker") {
|
if strings.HasPrefix(itemText, "Exit file picker") {
|
||||||
pages.RemovePage(filePickerPage)
|
pages.RemovePage(filePickerPage)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract the actual filename/directory name by removing the type info in brackets
|
// Extract the actual filename/directory name by removing the type info in brackets
|
||||||
// Format is "name [gray](type)[-]"
|
// Format is "name [gray](type)[-]"
|
||||||
actualItemName := itemText
|
actualItemName := itemText
|
||||||
if bracketPos := strings.Index(itemText, " ["); bracketPos != -1 {
|
if bracketPos := strings.Index(itemText, " ["); bracketPos != -1 {
|
||||||
actualItemName = itemText[:bracketPos]
|
actualItemName = itemText[:bracketPos]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if it's a directory (ends with /)
|
// Check if it's a directory (ends with /)
|
||||||
if strings.HasSuffix(actualItemName, "/") {
|
if strings.HasSuffix(actualItemName, "/") {
|
||||||
// This is a directory, we need to get the full path
|
// This is a directory, we need to get the full path
|
||||||
@@ -763,7 +736,6 @@ func makeFilePicker() *tview.Flex {
|
|||||||
dirName := strings.TrimSuffix(actualItemName, "/")
|
dirName := strings.TrimSuffix(actualItemName, "/")
|
||||||
targetDir = path.Join(currentDisplayDir, dirName)
|
targetDir = path.Join(currentDisplayDir, dirName)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Navigate to the selected directory
|
// Navigate to the selected directory
|
||||||
logger.Info("going to the dir", "dir", targetDir)
|
logger.Info("going to the dir", "dir", targetDir)
|
||||||
refreshList(targetDir)
|
refreshList(targetDir)
|
||||||
@@ -803,6 +775,5 @@ func makeFilePicker() *tview.Flex {
|
|||||||
}
|
}
|
||||||
return event
|
return event
|
||||||
})
|
})
|
||||||
|
|
||||||
return flex
|
return flex
|
||||||
}
|
}
|
||||||
|
|||||||
20
tui.go
20
tui.go
@@ -74,8 +74,10 @@ var (
|
|||||||
[yellow]Ctrl+k[white]: switch tool use (recommend tool use to llm after user msg)
|
[yellow]Ctrl+k[white]: switch tool use (recommend tool use to llm after user msg)
|
||||||
[yellow]Ctrl+j[white]: if chat agent is char.png will show the image; then any key to return
|
[yellow]Ctrl+j[white]: if chat agent is char.png will show the image; then any key to return
|
||||||
[yellow]Ctrl+a[white]: interrupt tts (needs tts server)
|
[yellow]Ctrl+a[white]: interrupt tts (needs tts server)
|
||||||
|
[yellow]Ctrl+g[white]: open RAG file manager (load files for context retrieval)
|
||||||
[yellow]Ctrl+q[white]: cycle through mentioned chars in chat, to pick persona to send next msg as
|
[yellow]Ctrl+q[white]: cycle through mentioned chars in chat, to pick persona to send next msg as
|
||||||
[yellow]Ctrl+x[white]: cycle through mentioned chars in chat, to pick persona to send next msg as (for llm)
|
[yellow]Ctrl+x[white]: cycle through mentioned chars in chat, to pick persona to send next msg as (for llm)
|
||||||
|
RAG Window: [yellow]x[white]: close window | [yellow]Enter[white]: select action
|
||||||
|
|
||||||
%s
|
%s
|
||||||
|
|
||||||
@@ -684,26 +686,8 @@ func init() {
|
|||||||
}
|
}
|
||||||
table := makeCodeBlockTable(cb)
|
table := makeCodeBlockTable(cb)
|
||||||
pages.AddPage(codeBlockPage, table, true, true)
|
pages.AddPage(codeBlockPage, table, true, true)
|
||||||
// updateStatusLine()
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
// if event.Key() == tcell.KeyF10 {
|
|
||||||
// // list rag loaded in db
|
|
||||||
// loadedFiles, err := ragger.ListLoaded()
|
|
||||||
// if err != nil {
|
|
||||||
// logger.Error("failed to list regfiles in db", "error", err)
|
|
||||||
// return nil
|
|
||||||
// }
|
|
||||||
// if len(loadedFiles) == 0 {
|
|
||||||
// if err := notifyUser("loaded RAG", "no files in db"); err != nil {
|
|
||||||
// logger.Error("failed to send notification", "error", err)
|
|
||||||
// }
|
|
||||||
// return nil
|
|
||||||
// }
|
|
||||||
// dbRAGTable := makeLoadedRAGTable(loadedFiles)
|
|
||||||
// pages.AddPage(RAGPage, dbRAGTable, true, true)
|
|
||||||
// return nil
|
|
||||||
// }
|
|
||||||
if event.Key() == tcell.KeyF10 {
|
if event.Key() == tcell.KeyF10 {
|
||||||
cfg.SkipLLMResp = !cfg.SkipLLMResp
|
cfg.SkipLLMResp = !cfg.SkipLLMResp
|
||||||
updateStatusLine()
|
updateStatusLine()
|
||||||
|
|||||||
Reference in New Issue
Block a user