| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Package terminal provides utilities for printing to and reading user input |
| 6 // from an interactive terminal. |
| 7 package terminal |
| 8 |
| 9 import ( |
| 10 "bufio" |
| 11 "fmt" |
| 12 "os" |
| 13 ) |
| 14 |
| 15 // ShowDebug controls whether or not calls to terminal.Debug produce output. |
| 16 var ShowDebug = false |
| 17 |
| 18 // Print prints the given format string (and arguments) to standard out. |
| 19 func Print(format string, args ...interface{}) { |
| 20 fmt.Printf(format, args) |
| 21 } |
| 22 |
| 23 // Debug is the same as Print, but only produces output if ShowDebug is true. |
| 24 func Debug(format string, args ...interface{}) { |
| 25 if ShowDebug { |
| 26 fmt.Printf(format, args) |
| 27 } |
| 28 } |
| 29 |
| 30 // Prompt prints a string to standard out, then waits for a single line |
| 31 // of user input and returns it. |
| 32 func Prompt(prompt string) string { |
| 33 fmt.Print(prompt) |
| 34 reader := bufio.NewReader(os.Stdin) |
| 35 text, _ := reader.ReadString('\n') |
| 36 return text |
| 37 } |
| OLD | NEW |