TUI refactor
- Clean up, improved startup logic, initial conversation load - Moved converation/message business logic (mostly) into `model/tui`
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
cmdutil "git.mlow.ca/mlow/lmcli/pkg/cmd/util"
|
||||
"git.mlow.ca/mlow/lmcli/pkg/lmcli"
|
||||
"git.mlow.ca/mlow/lmcli/pkg/tui"
|
||||
"git.mlow.ca/mlow/lmcli/pkg/tui/shared"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -19,17 +20,30 @@ func ChatCmd(ctx *lmcli.Context) *cobra.Command {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
shortname := ""
|
||||
if len(args) == 1 {
|
||||
shortname = args[0]
|
||||
|
||||
var opts []tui.LaunchOption
|
||||
|
||||
list, err := cmd.Flags().GetBool("list")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if shortname != ""{
|
||||
_, err := cmdutil.LookupConversationE(ctx, shortname)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
if !list && len(args) == 1 {
|
||||
shortname := args[0]
|
||||
if shortname != ""{
|
||||
conv, err := cmdutil.LookupConversationE(ctx, shortname)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts = append(opts, tui.WithInitialConversation(conv))
|
||||
}
|
||||
}
|
||||
err = tui.Launch(ctx, shortname)
|
||||
|
||||
if list {
|
||||
opts = append(opts, tui.WithInitialView(shared.StateConversations))
|
||||
}
|
||||
|
||||
err = tui.Launch(ctx, opts...)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error fetching LLM response: %v", err)
|
||||
}
|
||||
@@ -43,6 +57,10 @@ func ChatCmd(ctx *lmcli.Context) *cobra.Command {
|
||||
return ctx.Store.ConversationShortNameCompletions(toComplete), compMode
|
||||
},
|
||||
}
|
||||
|
||||
// -l, --list
|
||||
cmd.Flags().BoolP("list", "l", false, "View/manage conversations")
|
||||
|
||||
applyGenerationFlags(ctx, cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user