github.com/kevinklinger/open_terraform@v1.3.6/noninternal/command/console_interactive.go (about) 1 //go:build !solaris 2 // +build !solaris 3 4 // The readline library we use doesn't currently support solaris so 5 // we just build tag it off. 6 7 package command 8 9 import ( 10 "fmt" 11 "io" 12 "os" 13 14 "github.com/kevinklinger/open_terraform/noninternal/repl" 15 16 "github.com/chzyer/readline" 17 "github.com/mitchellh/cli" 18 ) 19 20 func (c *ConsoleCommand) modeInteractive(session *repl.Session, ui cli.Ui) int { 21 // Configure input 22 l, err := readline.NewEx(&readline.Config{ 23 Prompt: "> ", 24 InterruptPrompt: "^C", 25 EOFPrompt: "exit", 26 HistorySearchFold: true, 27 Stdin: os.Stdin, 28 Stdout: os.Stdout, 29 Stderr: os.Stderr, 30 }) 31 if err != nil { 32 c.Ui.Error(fmt.Sprintf( 33 "Error initializing console: %s", 34 err)) 35 return 1 36 } 37 defer l.Close() 38 39 for { 40 // Read a line 41 line, err := l.Readline() 42 if err == readline.ErrInterrupt { 43 if len(line) == 0 { 44 break 45 } else { 46 continue 47 } 48 } else if err == io.EOF { 49 break 50 } 51 52 out, exit, diags := session.Handle(line) 53 if diags.HasErrors() { 54 c.showDiagnostics(diags) 55 } 56 if exit { 57 break 58 } 59 60 ui.Output(out) 61 } 62 63 return 0 64 }