Skip to content

Commit 8e14395

Browse files
committed
feat(console): add shared history
1 parent 553c870 commit 8e14395

5 files changed

Lines changed: 30 additions & 10 deletions

File tree

runner/console/completion_data.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -179,19 +179,9 @@ func providerCommandSuggestions() []prompt.Suggest {
179179
{Text: "clear", Description: "clear the console"},
180180
{Text: "exit", Description: "exit the console"},
181181
}
182-
if canReturnToPreviousConsole() {
183-
suggestions = append(suggestions, prompt.Suggest{
184-
Text: "back",
185-
Description: "return to the previous console",
186-
})
187-
}
188182
return suggestions
189183
}
190184

191-
func canReturnToPreviousConsole() bool {
192-
return len(consoleStack) > 0
193-
}
194-
195185
func showTopicSuggestions() []prompt.Suggest {
196186
return showTopicSuggestionsData
197187
}

runner/console/executor.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"os"
77
"os/signal"
88
"sort"
9+
"strings"
910
"time"
1011

1112
"github.com/404tk/cloudtoolkit/runner/payloads"
@@ -17,9 +18,11 @@ import (
1718
)
1819

1920
func Executor(s string) {
21+
s = strings.TrimSpace(s)
2022
if s == "" {
2123
return
2224
}
25+
rememberConsoleCommand(s)
2326
cmd, args := utils.ParseCmd(s)
2427

2528
// Only payload `run` needs a cancellable context with timeout + SIGINT wiring.

runner/console/history.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package console
2+
3+
import (
4+
"strings"
5+
6+
"github.com/404tk/go-prompt"
7+
)
8+
9+
var sharedConsoleHistory []string
10+
11+
func rememberConsoleCommand(cmd string) {
12+
cmd = strings.TrimSpace(cmd)
13+
if cmd == "" {
14+
return
15+
}
16+
sharedConsoleHistory = append(sharedConsoleHistory, cmd)
17+
}
18+
19+
func sharedConsoleHistorySnapshot() []string {
20+
return append([]string(nil), sharedConsoleHistory...)
21+
}
22+
23+
func sharedConsoleHistoryOption() prompt.Option {
24+
return prompt.OptionHistory(sharedConsoleHistorySnapshot())
25+
}

runner/console/sessions.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ func internation(uuid string) {
126126
actionCompleter,
127127
prompt.OptionPrefix(fmt.Sprintf("ctk > %s > ", provider)),
128128
prompt.OptionInputTextColor(prompt.White),
129+
sharedConsoleHistoryOption(),
129130
)
130131
currentConsole = p
131132
p.Run()

runner/console/use.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ func loadModule(m string) error {
4242
actionCompleter,
4343
prompt.OptionPrefix(fmt.Sprintf("ctk > %s > ", m)),
4444
prompt.OptionInputTextColor(prompt.White),
45+
sharedConsoleHistoryOption(),
4546
)
4647
currentConsole = p
4748
p.Run()

0 commit comments

Comments
 (0)