Chromium Code Reviews| 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 var showDebug = false | |
| 16 | |
| 17 // SetDebug sets the internal state to start/stop printing lines sent to Debug. | |
|
seanmccullough1
2016/04/29 00:54:37
Just make var ShowDebug exported and get rid of th
agable
2016/05/05 23:59:43
Done. See reply below for whether or not this pack
| |
| 18 func SetDebug(show bool) { | |
| 19 showDebug = show | |
| 20 } | |
| 21 | |
| 22 // Print prints the given format string (and arguments) to standard out. | |
| 23 func Print(format string, args ...interface{}) { | |
|
seanmccullough1
2016/04/29 00:54:37
Just use fmt.Printf (or log.Printf)?
| |
| 24 fmt.Printf(format, args) | |
| 25 } | |
| 26 | |
| 27 // Debug is the same as Print, but only produces output if SetDebug(true) | |
| 28 // has been called. | |
| 29 func Debug(format string, args ...interface{}) { | |
|
seanmccullough1
2016/04/29 00:54:37
I'd just use the standard logging packages for now
agable
2016/05/05 23:59:43
Command line tools without verbosity levels make m
| |
| 30 if showDebug { | |
| 31 fmt.Printf(format, args) | |
| 32 } | |
| 33 } | |
| 34 | |
| 35 // Prompt prints a string to standard out, then waits for a single line | |
| 36 // of user input and returns it. | |
| 37 func Prompt(prompt string) string { | |
| 38 fmt.Print(prompt) | |
| 39 reader := bufio.NewReader(os.Stdin) | |
| 40 text, _ := reader.ReadString('\n') | |
| 41 return text | |
| 42 } | |
| OLD | NEW |