Skip to content

Commit

Permalink
feat: --show-last
Browse files Browse the repository at this point in the history
Signed-off-by: Marcello Sylvester Bauer <[email protected]>
  • Loading branch information
sylv-io committed Nov 11, 2023
1 parent 63d7d91 commit 17ac20d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ Continue from the last response or a given title or SHA1.

Lists all saved conversations.

#### Show last

`-S`, `--show-last`

Show the previous conversation.

#### Show

`-s`, `--show`
Expand Down
4 changes: 3 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ var help = map[string]string{
"title": "Saves the current conversation with the given title.",
"list": "Lists saved conversations.",
"delete": "Deletes a saved conversation with the given title or ID.",
"show": "Show a saved conversation with the given title or ID",
"show": "Show a saved conversation with the given title or ID.",
"show-last": "Show a the last saved conversation.",
}

// Model represents the LLM model used in the API call.
Expand Down Expand Up @@ -113,6 +114,7 @@ type Config struct {
ContinueLast bool
Continue string
Title string
ShowLast bool
Show string
List bool
Delete string
Expand Down
5 changes: 4 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ var (
if config.ShowHelp || (mods.Input == "" &&
config.Prefix == "" &&
config.Show == "" &&
!config.ShowLast &&
config.Delete == "" &&
!config.List) {
//nolint: wrapcheck
Expand All @@ -140,7 +141,7 @@ var (
}
}

if config.Show != "" {
if config.Show != "" || config.ShowLast {
return nil
}

Expand Down Expand Up @@ -168,6 +169,7 @@ func initFlags() {
flags.StringVarP(&config.Title, "title", "t", config.Title, stdoutStyles().FlagDesc.Render(help["title"]))
flags.StringVarP(&config.Delete, "delete", "d", config.Delete, stdoutStyles().FlagDesc.Render(help["delete"]))
flags.StringVarP(&config.Show, "show", "s", config.Show, stdoutStyles().FlagDesc.Render(help["show"]))
flags.BoolVarP(&config.ShowLast, "show-last", "S", false, stdoutStyles().FlagDesc.Render(help["show-last"]))
flags.BoolVarP(&config.Quiet, "quiet", "q", config.Quiet, stdoutStyles().FlagDesc.Render(help["quiet"]))
flags.BoolVarP(&config.ShowHelp, "help", "h", false, stdoutStyles().FlagDesc.Render(help["help"]))
flags.BoolVarP(&config.Version, "version", "v", false, stdoutStyles().FlagDesc.Render(help["version"]))
Expand Down Expand Up @@ -198,6 +200,7 @@ func initFlags() {
rootCmd.MarkFlagsMutuallyExclusive(
"settings",
"show",
"show-last",
"delete",
"list",
"continue",
Expand Down
6 changes: 3 additions & 3 deletions mods.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (m *Mods) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if msg.content != "" {
m.Input = msg.content
}
if msg.content == "" && m.Config.Prefix == "" && m.Config.Show == "" {
if msg.content == "" && m.Config.Prefix == "" && m.Config.Show == "" && !m.Config.ShowLast {
return m, m.quit
}
m.state = requestState
Expand Down Expand Up @@ -254,7 +254,7 @@ func (m *Mods) retry(content string, err modsError) tea.Msg {
}

func (m *Mods) startCompletionCmd(content string) tea.Cmd {
if m.Config.Show != "" {
if m.Config.Show != "" || m.Config.ShowLast {
return m.readFromCache()
}

Expand Down Expand Up @@ -512,7 +512,7 @@ func (m *Mods) findCacheOpsDetails() tea.Cmd {
}
}

if readID != "" || continueLast {
if readID != "" || continueLast || m.Config.ShowLast {
found, err := m.findReadID(readID)
if err != nil {
return modsError{
Expand Down

0 comments on commit 17ac20d

Please sign in to comment.