Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add readline support for interactive mode in go tool pprof
diff --git a/src/cmd/pprof/internal/plugin/plugin.go b/src/cmd/pprof/internal/plugin/plugin.go
index a22ec5f..4d545de 100644
--- a/src/cmd/pprof/internal/plugin/plugin.go
+++ b/src/cmd/pprof/internal/plugin/plugin.go
@@ -6,7 +6,6 @@
package plugin
import (
- "bufio"
"fmt"
"os"
"regexp"
@@ -14,6 +13,8 @@ import (
"time"
"cmd/pprof/internal/profile"
+
+ "github.com/chzyer/readline"
)
// A FlagSet creates and parses command-line flags.
@@ -166,16 +167,19 @@ type UI interface {
// prints messages to standard output,
// prints errors to standard error, and doesn't use auto-completion.
func StandardUI() UI {
- return &stdUI{r: bufio.NewReader(os.Stdin)}
+ r, err := readline.New("(pprof+r) ")
+ if err != nil {
+ panic(err)
+ }
+ return &stdUI{r: r}
}
type stdUI struct {
- r *bufio.Reader
+ r *readline.Instance
}
func (ui *stdUI) ReadLine() (string, error) {
- os.Stdout.WriteString("(pprof) ")
- return ui.r.ReadString('\n')
+ return ui.r.Readline()
}
func (ui *stdUI) Print(args ...interface{}) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.