diff options
author | Sorin Neacsu <sorin@users.noreply.github.com> | 2017-12-08 22:14:14 +0800 |
---|---|---|
committer | Felix Lange <fjl@users.noreply.github.com> | 2017-12-08 22:14:14 +0800 |
commit | 586198cceaf51435121b7e1166adf21910fee51a (patch) | |
tree | 92f7184113c18c904b19f15853b4f4a68161d1bf /console | |
parent | d95962cd5d3ea163f8e91d7a9ca2f6303799b2e2 (diff) | |
download | go-tangerine-586198cceaf51435121b7e1166adf21910fee51a.tar.gz go-tangerine-586198cceaf51435121b7e1166adf21910fee51a.tar.zst go-tangerine-586198cceaf51435121b7e1166adf21910fee51a.zip |
console: add admin.clearHistory command (#15614)
Diffstat (limited to 'console')
-rw-r--r-- | console/console.go | 11 | ||||
-rw-r--r-- | console/console_test.go | 1 | ||||
-rw-r--r-- | console/prompter.go | 8 |
3 files changed, 20 insertions, 0 deletions
diff --git a/console/console.go b/console/console.go index c42c9bfbb..1ecbfd0b0 100644 --- a/console/console.go +++ b/console/console.go @@ -192,6 +192,7 @@ func (c *Console) init(preload []string) error { if obj := admin.Object(); obj != nil { // make sure the admin api is enabled over the interface obj.Set("sleepBlocks", bridge.SleepBlocks) obj.Set("sleep", bridge.Sleep) + obj.Set("clearHistory", c.clearHistory) } // Preload any JavaScript files before starting the console for _, path := range preload { @@ -216,6 +217,16 @@ func (c *Console) init(preload []string) error { return nil } +func (c *Console) clearHistory() { + c.history = nil + c.prompter.ClearHistory() + if err := os.Remove(c.histPath); err != nil { + fmt.Fprintln(c.printer, "can't delete history file:", err) + } else { + fmt.Fprintln(c.printer, "history file deleted") + } +} + // consoleOutput is an override for the console.log and console.error methods to // stream the output into the configured output stream instead of stdout. func (c *Console) consoleOutput(call otto.FunctionCall) otto.Value { diff --git a/console/console_test.go b/console/console_test.go index d29680785..05aec2cc0 100644 --- a/console/console_test.go +++ b/console/console_test.go @@ -68,6 +68,7 @@ func (p *hookedPrompter) PromptConfirm(prompt string) (bool, error) { } func (p *hookedPrompter) SetHistory(history []string) {} func (p *hookedPrompter) AppendHistory(command string) {} +func (p *hookedPrompter) ClearHistory() {} func (p *hookedPrompter) SetWordCompleter(completer WordCompleter) {} // tester is a console test environment for the console tests to operate on. diff --git a/console/prompter.go b/console/prompter.go index 6acbfb0e2..ea03694d4 100644 --- a/console/prompter.go +++ b/console/prompter.go @@ -51,6 +51,9 @@ type UserPrompter interface { // if and only if the prompt to append was a valid command. AppendHistory(command string) + // ClearHistory clears the entire history + ClearHistory() + // SetWordCompleter sets the completion function that the prompter will call to // fetch completion candidates when the user presses tab. SetWordCompleter(completer WordCompleter) @@ -158,6 +161,11 @@ func (p *terminalPrompter) AppendHistory(command string) { p.State.AppendHistory(command) } +// ClearHistory clears the entire history +func (p *terminalPrompter) ClearHistory() { + p.State.ClearHistory() +} + // SetWordCompleter sets the completion function that the prompter will call to // fetch completion candidates when the user presses tab. func (p *terminalPrompter) SetWordCompleter(completer WordCompleter) { |