-
Notifications
You must be signed in to change notification settings - Fork 20.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
console: admin.clearHistory() command #15614
Changes from 1 commit
271a978
dfb97ec
b1534d1
c79f7a4
1225817
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,13 @@ func (c *Console) init(preload []string) error { | |
return nil | ||
} | ||
|
||
func (c *Console) clearHistory() { | ||
c.history = nil | ||
c.prompter.ClearHistory() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. my original reasoning was that history is being persisted at the end of the session but I agree this is safer. |
||
os.Remove(c.histPath) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ... and do |
||
fmt.Fprintf(c.printer, "history cleared\n") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if this is needed.. @fjl ? |
||
} | ||
|
||
// 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 { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd suggest There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good suggestion, but since https://github.com/sorin/go-ethereum/blob/sorin-console-clear-history/vendor/github.com/peterh/liner/common.go#L148-L152 does not return an error I'd say ClearHistory() (which is basically a wrapper on top of it) stays like this. Also os.remove is not called inside this ClearHistory() - I did add an error return to Console.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) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest to let this return an error