Feat: collapse/expand thinking blocks with alt+t
This commit is contained in:
10
bot.go
10
bot.go
@@ -1087,7 +1087,15 @@ func chatToTextSlice(messages []models.RoleMsg, showSys bool) []string {
|
|||||||
|
|
||||||
func chatToText(messages []models.RoleMsg, showSys bool) string {
|
func chatToText(messages []models.RoleMsg, showSys bool) string {
|
||||||
s := chatToTextSlice(messages, showSys)
|
s := chatToTextSlice(messages, showSys)
|
||||||
return strings.Join(s, "\n")
|
text := strings.Join(s, "\n")
|
||||||
|
|
||||||
|
// Collapse thinking blocks if enabled
|
||||||
|
if thinkingCollapsed {
|
||||||
|
placeholder := "[yellow::i][thinking... (press Alt+T to expand)][-:-:-]"
|
||||||
|
text = thinkRE.ReplaceAllString(text, placeholder)
|
||||||
|
}
|
||||||
|
|
||||||
|
return text
|
||||||
}
|
}
|
||||||
|
|
||||||
func removeThinking(chatBody *models.ChatBody) {
|
func removeThinking(chatBody *models.ChatBody) {
|
||||||
|
|||||||
1
main.go
1
main.go
@@ -12,6 +12,7 @@ var (
|
|||||||
injectRole = true
|
injectRole = true
|
||||||
selectedIndex = int(-1)
|
selectedIndex = int(-1)
|
||||||
shellMode = false
|
shellMode = false
|
||||||
|
thinkingCollapsed = false
|
||||||
indexLineCompletion = "F12 to show keys help | llm turn: [%s:-:b]%v[-:-:-] (F6) | chat: [orange:-:b]%s[-:-:-] (F1) | toolUseAdviced: [%s:-:b]%v[-:-:-] (ctrl+k) | model: [orange:-:b]%s[-:-:-] (ctrl+l) | skip LLM resp: [%s:-:b]%v[-:-:-] (F10)\nAPI: [orange:-:b]%s[-:-:-] (ctrl+v) | recording: [%s:-:b]%v[-:-:-] (ctrl+r) | writing as: [orange:-:b]%s[-:-:-] (ctrl+q) | bot will write as [orange:-:b]%s[-:-:-] (ctrl+x) | role injection (alt+7) [%s:-:b]%v[-:-:-]"
|
indexLineCompletion = "F12 to show keys help | llm turn: [%s:-:b]%v[-:-:-] (F6) | chat: [orange:-:b]%s[-:-:-] (F1) | toolUseAdviced: [%s:-:b]%v[-:-:-] (ctrl+k) | model: [orange:-:b]%s[-:-:-] (ctrl+l) | skip LLM resp: [%s:-:b]%v[-:-:-] (F10)\nAPI: [orange:-:b]%s[-:-:-] (ctrl+v) | recording: [%s:-:b]%v[-:-:-] (ctrl+r) | writing as: [orange:-:b]%s[-:-:-] (ctrl+q) | bot will write as [orange:-:b]%s[-:-:-] (ctrl+x) | role injection (alt+7) [%s:-:b]%v[-:-:-]"
|
||||||
focusSwitcher = map[tview.Primitive]tview.Primitive{}
|
focusSwitcher = map[tview.Primitive]tview.Primitive{}
|
||||||
)
|
)
|
||||||
|
|||||||
15
tui.go
15
tui.go
@@ -96,6 +96,7 @@ var (
|
|||||||
[yellow]Alt+7[white]: toggle role injection (inject role in messages)
|
[yellow]Alt+7[white]: toggle role injection (inject role in messages)
|
||||||
[yellow]Alt+8[white]: show char img or last picked img
|
[yellow]Alt+8[white]: show char img or last picked img
|
||||||
[yellow]Alt+9[white]: warm up (load) selected llama.cpp model
|
[yellow]Alt+9[white]: warm up (load) selected llama.cpp model
|
||||||
|
[yellow]Alt+t[white]: toggle thinking blocks visibility (collapse/expand <think> blocks)
|
||||||
|
|
||||||
=== scrolling chat window (some keys similar to vim) ===
|
=== scrolling chat window (some keys similar to vim) ===
|
||||||
[yellow]arrows up/down and j/k[white]: scroll up and down
|
[yellow]arrows up/down and j/k[white]: scroll up and down
|
||||||
@@ -831,6 +832,20 @@ func init() {
|
|||||||
injectRole = !injectRole
|
injectRole = !injectRole
|
||||||
updateStatusLine()
|
updateStatusLine()
|
||||||
}
|
}
|
||||||
|
// Handle Alt+T to toggle thinking block visibility
|
||||||
|
if event.Key() == tcell.KeyRune && event.Rune() == 't' && event.Modifiers()&tcell.ModAlt != 0 {
|
||||||
|
thinkingCollapsed = !thinkingCollapsed
|
||||||
|
textView.SetText(chatToText(chatBody.Messages, cfg.ShowSys))
|
||||||
|
colorText()
|
||||||
|
status := "expanded"
|
||||||
|
if thinkingCollapsed {
|
||||||
|
status = "collapsed"
|
||||||
|
}
|
||||||
|
if err := notifyUser("thinking", fmt.Sprintf("Thinking blocks %s", status)); err != nil {
|
||||||
|
logger.Error("failed to send notification", "error", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
if event.Key() == tcell.KeyF1 {
|
if event.Key() == tcell.KeyF1 {
|
||||||
// chatList, err := loadHistoryChats()
|
// chatList, err := loadHistoryChats()
|
||||||
chatList, err := store.GetChatByChar(cfg.AssistantRole)
|
chatList, err := store.GetChatByChar(cfg.AssistantRole)
|
||||||
|
|||||||
Reference in New Issue
Block a user