Skip to content
This repository has been archived by the owner on Mar 20, 2023. It is now read-only.

Commit

Permalink
refactor prompt, show current context
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikulas committed Jul 3, 2018
1 parent 6422558 commit 16097da
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion main/builtin-namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func pickNamespace() error {
variables[key] = ns
printIndexedLine(key, ns)
}
return prompt("# namespace")
return prompt()
})
}

Expand Down
19 changes: 16 additions & 3 deletions main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,21 @@ var (
verbose bool
)

func prompt(text string) (string, error) {
fmt.Print(color.New(color.Bold).Sprintf(text + " "))
func prompt() (string, error) {
color.New(color.Bold).Print("# ")

if context != "" {
color.New(color.FgBlack, color.Italic).Print(context)
fmt.Print(" ")
}

if namespace != "" {
color.New(color.Bold).Print(namespace)
} else {
color.New(color.Bold).Print("namespace")
}
fmt.Print(" ")

line, err := input.ReadString('\n')
if err != nil {
return "", err
Expand All @@ -38,7 +51,7 @@ func printIndexedLine(index, line string) {
}

func repl() error {
command, err := prompt("# " + namespace)
command, err := prompt()
if err != nil {
return err
}
Expand Down

0 comments on commit 16097da

Please sign in to comment.