Enha: better colors

This commit is contained in:
Grail Finder
2025-12-03 14:48:41 +03:00
parent 87f67b374d
commit b9cef57b71

View File

@@ -32,13 +32,10 @@ func makePropsTable(props map[string]float32) *tview.Table {
table := tview.NewTable(). table := tview.NewTable().
SetBorders(true). SetBorders(true).
SetSelectable(true, false). SetSelectable(true, false).
SetSelectedStyle(tcell.StyleDefault.Background(tcell.ColorDarkCyan).Foreground(tcell.ColorWhite)) // Allow row selection but not column selection SetSelectedStyle(tcell.StyleDefault.Background(tcell.ColorGray).Foreground(tcell.ColorWhite)) // Allow row selection but not column selection
table.SetTitle("Properties Configuration (Press 'x' to exit)"). table.SetTitle("Properties Configuration (Press 'x' to exit)").
SetTitleAlign(tview.AlignLeft) SetTitleAlign(tview.AlignLeft)
row := 0 row := 0
// Add a header or note row // Add a header or note row
headerCell := tview.NewTableCell("Props for llamacpp completion call"). headerCell := tview.NewTableCell("Props for llamacpp completion call").
SetTextColor(tcell.ColorYellow). SetTextColor(tcell.ColorYellow).
@@ -46,14 +43,12 @@ func makePropsTable(props map[string]float32) *tview.Table {
SetSelectable(false) SetSelectable(false)
table.SetCell(row, 0, headerCell) table.SetCell(row, 0, headerCell)
table.SetCell(row, 1, table.SetCell(row, 1,
tview.NewTableCell(""). tview.NewTableCell("press 'x' to exit").
SetTextColor(tcell.ColorYellow). SetTextColor(tcell.ColorYellow).
SetSelectable(false)) SetSelectable(false))
row++ row++
// Store cell data for later use in selection functions // Store cell data for later use in selection functions
cellData := make(map[string]*CellData) cellData := make(map[string]*CellData)
// Helper function to add a checkbox-like row // Helper function to add a checkbox-like row
addCheckboxRow := func(label string, initialValue bool, onChange func(bool)) { addCheckboxRow := func(label string, initialValue bool, onChange func(bool)) {
table.SetCell(row, 0, table.SetCell(row, 0,
@@ -61,17 +56,14 @@ func makePropsTable(props map[string]float32) *tview.Table {
SetTextColor(tcell.ColorWhite). SetTextColor(tcell.ColorWhite).
SetAlign(tview.AlignLeft). SetAlign(tview.AlignLeft).
SetSelectable(false)) SetSelectable(false))
valueText := "No" valueText := "No"
if initialValue { if initialValue {
valueText = "Yes" valueText = "Yes"
} }
valueCell := tview.NewTableCell(valueText). valueCell := tview.NewTableCell(valueText).
SetTextColor(tcell.ColorYellow). SetTextColor(tcell.ColorYellow).
SetAlign(tview.AlignCenter) SetAlign(tview.AlignCenter)
table.SetCell(row, 1, valueCell) table.SetCell(row, 1, valueCell)
// Store cell data // Store cell data
cellID := fmt.Sprintf("checkbox_%d", row) cellID := fmt.Sprintf("checkbox_%d", row)
cellData[cellID] = &CellData{ cellData[cellID] = &CellData{
@@ -80,7 +72,6 @@ func makePropsTable(props map[string]float32) *tview.Table {
} }
row++ row++
} }
// Helper function to add a dropdown-like row, that opens a list popup // Helper function to add a dropdown-like row, that opens a list popup
addListPopupRow := func(label string, options []string, initialValue string, onChange func(string)) { addListPopupRow := func(label string, options []string, initialValue string, onChange func(string)) {
table.SetCell(row, 0, table.SetCell(row, 0,
@@ -88,12 +79,10 @@ func makePropsTable(props map[string]float32) *tview.Table {
SetTextColor(tcell.ColorWhite). SetTextColor(tcell.ColorWhite).
SetAlign(tview.AlignLeft). SetAlign(tview.AlignLeft).
SetSelectable(false)) SetSelectable(false))
valueCell := tview.NewTableCell(initialValue). valueCell := tview.NewTableCell(initialValue).
SetTextColor(tcell.ColorYellow). SetTextColor(tcell.ColorYellow).
SetAlign(tview.AlignCenter) SetAlign(tview.AlignCenter)
table.SetCell(row, 1, valueCell) table.SetCell(row, 1, valueCell)
// Store cell data // Store cell data
cellID := fmt.Sprintf("listpopup_%d", row) cellID := fmt.Sprintf("listpopup_%d", row)
cellData[cellID] = &CellData{ cellData[cellID] = &CellData{
@@ -103,7 +92,6 @@ func makePropsTable(props map[string]float32) *tview.Table {
} }
row++ row++
} }
// Helper function to add an input field row // Helper function to add an input field row
addInputRow := func(label string, initialValue string, onChange func(string)) { addInputRow := func(label string, initialValue string, onChange func(string)) {
table.SetCell(row, 0, table.SetCell(row, 0,
@@ -111,12 +99,10 @@ func makePropsTable(props map[string]float32) *tview.Table {
SetTextColor(tcell.ColorWhite). SetTextColor(tcell.ColorWhite).
SetAlign(tview.AlignLeft). SetAlign(tview.AlignLeft).
SetSelectable(false)) SetSelectable(false))
valueCell := tview.NewTableCell(initialValue). valueCell := tview.NewTableCell(initialValue).
SetTextColor(tcell.ColorYellow). SetTextColor(tcell.ColorYellow).
SetAlign(tview.AlignCenter) SetAlign(tview.AlignCenter)
table.SetCell(row, 1, valueCell) table.SetCell(row, 1, valueCell)
// Store cell data // Store cell data
cellID := fmt.Sprintf("input_%d", row) cellID := fmt.Sprintf("input_%d", row)
cellData[cellID] = &CellData{ cellData[cellID] = &CellData{
@@ -125,58 +111,48 @@ func makePropsTable(props map[string]float32) *tview.Table {
} }
row++ row++
} }
// Add checkboxes // Add checkboxes
addCheckboxRow("Insert \U000F0E88 (/completion only)", cfg.ThinkUse, func(checked bool) { addCheckboxRow("Insert <think> tag (/completion only)", cfg.ThinkUse, func(checked bool) {
cfg.ThinkUse = checked cfg.ThinkUse = checked
}) })
addCheckboxRow("RAG use", cfg.RAGEnabled, func(checked bool) { addCheckboxRow("RAG use", cfg.RAGEnabled, func(checked bool) {
cfg.RAGEnabled = checked cfg.RAGEnabled = checked
}) })
addCheckboxRow("Inject role", injectRole, func(checked bool) { addCheckboxRow("Inject role", injectRole, func(checked bool) {
injectRole = checked injectRole = checked
}) })
// Add dropdowns // Add dropdowns
logLevels := []string{"Debug", "Info", "Warn"} logLevels := []string{"Debug", "Info", "Warn"}
addListPopupRow("Set log level", logLevels, GetLogLevel(), func(option string) { addListPopupRow("Set log level", logLevels, GetLogLevel(), func(option string) {
setLogLevel(option) setLogLevel(option)
}) })
// Prepare API links dropdown - insert current API at the beginning // Prepare API links dropdown - insert current API at the beginning
apiLinks := slices.Insert(cfg.ApiLinks, 0, cfg.CurrentAPI) apiLinks := slices.Insert(cfg.ApiLinks, 0, cfg.CurrentAPI)
addListPopupRow("Select an api", apiLinks, cfg.CurrentAPI, func(option string) { addListPopupRow("Select an api", apiLinks, cfg.CurrentAPI, func(option string) {
cfg.CurrentAPI = option cfg.CurrentAPI = option
}) })
// Prepare model list dropdown // Prepare model list dropdown
modelList := []string{chatBody.Model, "deepseek-chat", "deepseek-reasoner"} modelList := []string{chatBody.Model, "deepseek-chat", "deepseek-reasoner"}
modelList = append(modelList, ORFreeModels...) modelList = append(modelList, ORFreeModels...)
addListPopupRow("Select a model", modelList, chatBody.Model, func(option string) { addListPopupRow("Select a model", modelList, chatBody.Model, func(option string) {
chatBody.Model = option chatBody.Model = option
}) })
// Role selection dropdown // Role selection dropdown
addListPopupRow("Write next message as", listRolesWithUser(), cfg.WriteNextMsgAs, func(option string) { addListPopupRow("Write next message as", listRolesWithUser(), cfg.WriteNextMsgAs, func(option string) {
cfg.WriteNextMsgAs = option cfg.WriteNextMsgAs = option
}) })
// Add input fields // Add input fields
addInputRow("New char to write msg as", "", func(text string) { addInputRow("New char to write msg as", "", func(text string) {
if text != "" { if text != "" {
cfg.WriteNextMsgAs = text cfg.WriteNextMsgAs = text
} }
}) })
addInputRow("Username", cfg.UserRole, func(text string) { addInputRow("Username", cfg.UserRole, func(text string) {
if text != "" { if text != "" {
renameUser(cfg.UserRole, text) renameUser(cfg.UserRole, text)
cfg.UserRole = text cfg.UserRole = text
} }
}) })
// Add property fields (the float32 values) // Add property fields (the float32 values)
for propName, value := range props { for propName, value := range props {
propName := propName // capture loop variable for closure propName := propName // capture loop variable for closure
@@ -187,7 +163,6 @@ func makePropsTable(props map[string]float32) *tview.Table {
} }
}) })
} }
// Set selection function to handle dropdown-like behavior // Set selection function to handle dropdown-like behavior
table.SetSelectedFunc(func(selectedRow, selectedCol int) { table.SetSelectedFunc(func(selectedRow, selectedCol int) {
// Only handle selection on the value column (column 1) // Only handle selection on the value column (column 1)
@@ -198,11 +173,9 @@ func makePropsTable(props map[string]float32) *tview.Table {
} }
return return
} }
// Get the cell and its corresponding data // Get the cell and its corresponding data
cell := table.GetCell(selectedRow, selectedCol) cell := table.GetCell(selectedRow, selectedCol)
cellID := fmt.Sprintf("checkbox_%d", selectedRow) cellID := fmt.Sprintf("checkbox_%d", selectedRow)
// Check if it's a checkbox // Check if it's a checkbox
if cellData[cellID] != nil && cellData[cellID].Type == CellTypeCheckbox { if cellData[cellID] != nil && cellData[cellID].Type == CellTypeCheckbox {
data := cellData[cellID] data := cellData[cellID]
@@ -218,7 +191,6 @@ func makePropsTable(props map[string]float32) *tview.Table {
} }
return return
} }
// Check for dropdown // Check for dropdown
dropdownCellID := fmt.Sprintf("dropdown_%d", selectedRow) dropdownCellID := fmt.Sprintf("dropdown_%d", selectedRow)
if cellData[dropdownCellID] != nil && cellData[dropdownCellID].Type == CellTypeDropdown { if cellData[dropdownCellID] != nil && cellData[dropdownCellID].Type == CellTypeDropdown {
@@ -233,24 +205,22 @@ func makePropsTable(props map[string]float32) *tview.Table {
break break
} }
} }
// Move to next option (cycle back to 0 if at end) // Move to next option (cycle back to 0 if at end)
nextIndex := (currentIndex + 1) % len(data.Options) nextIndex := (currentIndex + 1) % len(data.Options)
newValue := data.Options[nextIndex] newValue := data.Options[nextIndex]
onChange(newValue) onChange(newValue)
cell.SetText(newValue) cell.SetText(newValue)
} }
return return
} }
// Check for listpopup // Check for listpopup
listPopupCellID := fmt.Sprintf("listpopup_%d", selectedRow) listPopupCellID := fmt.Sprintf("listpopup_%d", selectedRow)
if cellData[listPopupCellID] != nil && cellData[listPopupCellID].Type == CellTypeListPopup { if cellData[listPopupCellID] != nil && cellData[listPopupCellID].Type == CellTypeListPopup {
data := cellData[listPopupCellID] data := cellData[listPopupCellID]
if onChange, ok := data.OnChange.(func(string)); ok && data.Options != nil { if onChange, ok := data.OnChange.(func(string)); ok && data.Options != nil {
// Create a list primitive // Create a list primitive
apiList := tview.NewList().ShowSecondaryText(false) apiList := tview.NewList().ShowSecondaryText(false).
SetSelectedBackgroundColor(tcell.ColorGray)
apiList.SetTitle("Select an API").SetBorder(true) apiList.SetTitle("Select an API").SetBorder(true)
for i, api := range data.Options { for i, api := range data.Options {
if api == cell.Text { if api == cell.Text {
@@ -258,13 +228,11 @@ func makePropsTable(props map[string]float32) *tview.Table {
} }
apiList.AddItem(api, "", 0, nil) apiList.AddItem(api, "", 0, nil)
} }
apiList.SetSelectedFunc(func(index int, mainText string, secondaryText string, shortcut rune) { apiList.SetSelectedFunc(func(index int, mainText string, secondaryText string, shortcut rune) {
onChange(mainText) onChange(mainText)
cell.SetText(mainText) cell.SetText(mainText)
pages.RemovePage("apiListPopup") pages.RemovePage("apiListPopup")
}) })
apiList.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey { apiList.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
if event.Key() == tcell.KeyEscape { if event.Key() == tcell.KeyEscape {
pages.RemovePage("apiListPopup") pages.RemovePage("apiListPopup")
@@ -272,7 +240,6 @@ func makePropsTable(props map[string]float32) *tview.Table {
} }
return event return event
}) })
modal := func(p tview.Primitive, width, height int) tview.Primitive { modal := func(p tview.Primitive, width, height int) tview.Primitive {
return tview.NewFlex(). return tview.NewFlex().
AddItem(nil, 0, 1, false). AddItem(nil, 0, 1, false).
@@ -282,14 +249,12 @@ func makePropsTable(props map[string]float32) *tview.Table {
AddItem(nil, 0, 1, false), width, 1, true). AddItem(nil, 0, 1, false), width, 1, true).
AddItem(nil, 0, 1, false) AddItem(nil, 0, 1, false)
} }
// Add modal page and make it visible // Add modal page and make it visible
pages.AddPage("apiListPopup", modal(apiList, 80, 20), true, true) pages.AddPage("apiListPopup", modal(apiList, 80, 20), true, true)
app.SetFocus(apiList) app.SetFocus(apiList)
} }
return return
} }
// Handle input fields by creating an input modal on selection // Handle input fields by creating an input modal on selection
inputCellID := fmt.Sprintf("input_%d", selectedRow) inputCellID := fmt.Sprintf("input_%d", selectedRow)
if cellData[inputCellID] != nil && cellData[inputCellID].Type == CellTypeInput { if cellData[inputCellID] != nil && cellData[inputCellID].Type == CellTypeInput {
@@ -308,7 +273,6 @@ func makePropsTable(props map[string]float32) *tview.Table {
} }
pages.RemovePage("editModal") pages.RemovePage("editModal")
}) })
// Create a simple modal with the input field // Create a simple modal with the input field
modalFlex := tview.NewFlex(). modalFlex := tview.NewFlex().
SetDirection(tview.FlexRow). SetDirection(tview.FlexRow).
@@ -319,14 +283,12 @@ func makePropsTable(props map[string]float32) *tview.Table {
AddItem(tview.NewBox(), 0, 1, false), // Spacer AddItem(tview.NewBox(), 0, 1, false), // Spacer
0, 1, true). 0, 1, true).
AddItem(tview.NewBox(), 0, 1, false) // Spacer AddItem(tview.NewBox(), 0, 1, false) // Spacer
// Add modal page and make it visible // Add modal page and make it visible
pages.AddPage("editModal", modalFlex, true, true) pages.AddPage("editModal", modalFlex, true, true)
} }
return return
} }
}) })
// Set input capture to handle 'x' key for exiting // Set input capture to handle 'x' key for exiting
table.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey { table.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
if event.Key() == tcell.KeyRune && event.Rune() == 'x' { if event.Key() == tcell.KeyRune && event.Rune() == 'x' {
@@ -335,7 +297,6 @@ func makePropsTable(props map[string]float32) *tview.Table {
} }
return event return event
}) })
return table return table
} }