Add limit to number of conversations shown by default by lmcli ls
This commit is contained in:
parent
1184f9aaae
commit
b3913d0027
@ -17,6 +17,11 @@ var (
|
|||||||
systemPromptFile string
|
systemPromptFile string
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Limit to number of conversations shown with `ls`, without --all
|
||||||
|
LS_LIMIT int = 25
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
inputCmds := []*cobra.Command{newCmd, promptCmd, replyCmd, retryCmd, continueCmd, editCmd}
|
inputCmds := []*cobra.Command{newCmd, promptCmd, replyCmd, retryCmd, continueCmd, editCmd}
|
||||||
for _, cmd := range inputCmds {
|
for _, cmd := range inputCmds {
|
||||||
@ -27,6 +32,7 @@ func init() {
|
|||||||
cmd.MarkFlagsMutuallyExclusive("system-prompt", "system-prompt-file")
|
cmd.MarkFlagsMutuallyExclusive("system-prompt", "system-prompt-file")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lsCmd.Flags().Bool("all", false, fmt.Sprintf("Show all conversations, by default only the last %d are shown", LS_LIMIT))
|
||||||
renameCmd.Flags().Bool("generate", false, "Generate a conversation title")
|
renameCmd.Flags().Bool("generate", false, "Generate a conversation title")
|
||||||
|
|
||||||
rootCmd.AddCommand(
|
rootCmd.AddCommand(
|
||||||
@ -203,6 +209,8 @@ var lsCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
categorized := map[string][]ConversationLine{}
|
categorized := map[string][]ConversationLine{}
|
||||||
|
|
||||||
|
all, _ := cmd.Flags().GetBool("all")
|
||||||
|
|
||||||
for _, conversation := range conversations {
|
for _, conversation := range conversations {
|
||||||
lastMessage, err := store.LastMessage(&conversation)
|
lastMessage, err := store.LastMessage(&conversation)
|
||||||
if lastMessage == nil || err != nil {
|
if lastMessage == nil || err != nil {
|
||||||
@ -232,17 +240,27 @@ var lsCmd = &cobra.Command{
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var conversationsPrinted int
|
||||||
|
outer:
|
||||||
for _, category := range categories {
|
for _, category := range categories {
|
||||||
conversations, ok := categorized[category]
|
conversations, ok := categorized[category.name]
|
||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
slices.SortFunc(conversations, func(a, b ConversationLine) int {
|
slices.SortFunc(conversations, func(a, b ConversationLine) int {
|
||||||
return int(a.timeSinceReply - b.timeSinceReply)
|
return int(a.timeSinceReply - b.timeSinceReply)
|
||||||
})
|
})
|
||||||
fmt.Printf("%s:\n", category)
|
|
||||||
|
fmt.Printf("%s:\n", category.name)
|
||||||
for _, conv := range conversations {
|
for _, conv := range conversations {
|
||||||
|
if conversationsPrinted >= LS_LIMIT && !all {
|
||||||
|
fmt.Printf("%d remaining message(s), use --all to view.\n", len(conversations)-conversationsPrinted)
|
||||||
|
break outer
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Printf(" %s\n", conv.formatted)
|
fmt.Printf(" %s\n", conv.formatted)
|
||||||
|
conversationsPrinted++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user