mirror of
https://github.com/go-delve/delve.git
synced 2025-10-29 17:56:45 +08:00
terminal: Refactor handling of dumb terminals
This commit is contained in:
@ -14,13 +14,18 @@ import (
|
||||
"github.com/derekparker/delve/service"
|
||||
)
|
||||
|
||||
const historyFile string = ".dbg_history"
|
||||
const (
|
||||
historyFile string = ".dbg_history"
|
||||
TerminalBlueEscapeCode string = "\033[34m"
|
||||
TerminalWhiteEscapeCode string = "\033[37m"
|
||||
)
|
||||
|
||||
type Term struct {
|
||||
client service.Client
|
||||
prompt string
|
||||
line *liner.State
|
||||
conf *config.Config
|
||||
dumb bool
|
||||
}
|
||||
|
||||
func New(client service.Client, conf *config.Config) *Term {
|
||||
@ -29,6 +34,7 @@ func New(client service.Client, conf *config.Config) *Term {
|
||||
line: liner.NewLiner(),
|
||||
client: client,
|
||||
conf: conf,
|
||||
dumb: strings.ToLower(os.Getenv("TERM")) == "dumb",
|
||||
}
|
||||
}
|
||||
|
||||
@ -93,7 +99,7 @@ func (t *Term) Run() (error, int) {
|
||||
|
||||
cmdstr, args := parseCommand(cmdstr)
|
||||
cmd := cmds.Find(cmdstr)
|
||||
if err := cmd(t.client, args...); err != nil {
|
||||
if err := cmd(t, args...); err != nil {
|
||||
if _, ok := err.(ExitRequestError); ok {
|
||||
return t.handleExit()
|
||||
}
|
||||
@ -111,6 +117,13 @@ func (t *Term) Run() (error, int) {
|
||||
return nil, status
|
||||
}
|
||||
|
||||
func (t *Term) Println(prefix, str string) {
|
||||
if !t.dumb {
|
||||
prefix = fmt.Sprintf("%s%s%s", TerminalBlueEscapeCode, prefix, TerminalWhiteEscapeCode)
|
||||
}
|
||||
fmt.Printf("%s%s\n", prefix, str)
|
||||
}
|
||||
|
||||
func (t *Term) promptForInput() (string, error) {
|
||||
l, err := t.line.Prompt(t.prompt)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user