console: admin.clearHistory() command

This commit is contained in:
Sorin Neacsu 2017-12-06 07:25:51 -08:00
parent 6e613cf3de
commit 271a97847e
2 changed files with 16 additions and 0 deletions

View file

@ -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 if obj := admin.Object(); obj != nil { // make sure the admin api is enabled over the interface
obj.Set("sleepBlocks", bridge.SleepBlocks) obj.Set("sleepBlocks", bridge.SleepBlocks)
obj.Set("sleep", bridge.Sleep) obj.Set("sleep", bridge.Sleep)
obj.Set("clearHistory", c.clearHistory)
} }
// Preload any JavaScript files before starting the console // Preload any JavaScript files before starting the console
for _, path := range preload { for _, path := range preload {
@ -216,6 +217,13 @@ func (c *Console) init(preload []string) error {
return nil return nil
} }
func (c *Console) clearHistory() {
c.history = nil
c.prompter.ClearHistory()
os.Remove(c.histPath)
fmt.Fprintf(c.printer, "history cleared\n")
}
// consoleOutput is an override for the console.log and console.error methods to // consoleOutput is an override for the console.log and console.error methods to
// stream the output into the configured output stream instead of stdout. // stream the output into the configured output stream instead of stdout.
func (c *Console) consoleOutput(call otto.FunctionCall) otto.Value { func (c *Console) consoleOutput(call otto.FunctionCall) otto.Value {

View file

@ -51,6 +51,9 @@ type UserPrompter interface {
// if and only if the prompt to append was a valid command. // if and only if the prompt to append was a valid command.
AppendHistory(command string) AppendHistory(command string)
// ClearHistory clears the entire history
ClearHistory()
// SetWordCompleter sets the completion function that the prompter will call to // SetWordCompleter sets the completion function that the prompter will call to
// fetch completion candidates when the user presses tab. // fetch completion candidates when the user presses tab.
SetWordCompleter(completer WordCompleter) SetWordCompleter(completer WordCompleter)
@ -158,6 +161,11 @@ func (p *terminalPrompter) AppendHistory(command string) {
p.State.AppendHistory(command) 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 // SetWordCompleter sets the completion function that the prompter will call to
// fetch completion candidates when the user presses tab. // fetch completion candidates when the user presses tab.
func (p *terminalPrompter) SetWordCompleter(completer WordCompleter) { func (p *terminalPrompter) SetWordCompleter(completer WordCompleter) {