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