summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go30
1 files changed, 17 insertions, 13 deletions
diff --git a/main.go b/main.go
index 695a8fc..715bc57 100644
--- a/main.go
+++ b/main.go
@@ -2,19 +2,18 @@ package main
import (
"flag"
- "fmt"
"io"
"log"
- "os"
"strings"
"github.com/chzyer/readline"
)
var (
- cmdMode = flag.String("c", "", "")
- helpMode = flag.Bool("h", false, "")
- quietMode = flag.Bool("q", false, "")
+ cmdMode = flag.String("c", "", "")
+ helpMode = flag.Bool("h", false, "")
+ quietMode = flag.Bool("q", false, "")
+ promptMode = flag.Bool("p", false, "")
)
func main() {
@@ -44,8 +43,11 @@ func main() {
state.Quiet = true
}
- runInteractivePrompt(state, flag.Args())
- // runTUI(state, flag.Args())
+ if *promptMode {
+ runInteractivePrompt(state, flag.Args())
+ } else {
+ runTUI(state, flag.Args())
+ }
}
func buildReadline(prompt string, conf *Config) (*readline.Instance, error) {
@@ -91,7 +93,7 @@ func buildInitialState() (*BrowserState, error) {
}
state.Identities = idents
- rl, err := buildReadline(Prompt, conf)
+ rl, err := buildReadline(prompt(), conf)
if err != nil {
log.Fatal(err)
}
@@ -105,12 +107,12 @@ func runInteractivePrompt(state *BrowserState, args []string) {
if len(args) > 0 {
if err := Go(state, args[0]); err != nil {
- writeError(err.Error())
+ state.Printer.PrintError(err.Error())
}
}
for {
- state.Readline.SetPrompt(Prompt)
+ state.Readline.SetPrompt(prompt())
line, err := state.Readline.Readline()
if err == io.EOF {
break
@@ -120,7 +122,7 @@ func runInteractivePrompt(state *BrowserState, args []string) {
}
if err := handleCmdLine(state, line); err != nil {
- writeError(err.Error())
+ state.Printer.PrintError(err.Error())
}
}
}
@@ -136,8 +138,10 @@ func handleCmdLine(state *BrowserState, line string) error {
return nil
}
-const Prompt = promptStyle + "X-1" + ansiClear + "> "
+func prompt() string {
+ return promptStyle.Render("X-1") + "> "
+}
func writeError(msg string) {
- fmt.Fprintf(os.Stdout, "\x1b[31m%s\x1b[0m\n", msg)
+ _ = PromptPrinter{}.PrintError(msg)
}