Chromium Code Reviews| Index: go/src/infra/tools/cr/lib/terminal/terminal.go |
| diff --git a/go/src/infra/tools/cr/lib/terminal/terminal.go b/go/src/infra/tools/cr/lib/terminal/terminal.go |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f65368bfb1561e0cddaacb5a0e6b581ba85c60ec |
| --- /dev/null |
| +++ b/go/src/infra/tools/cr/lib/terminal/terminal.go |
| @@ -0,0 +1,42 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +// Package terminal provides utilities for printing to and reading user input |
| +// from an interactive terminal. |
| +package terminal |
| + |
| +import ( |
| + "bufio" |
| + "fmt" |
| + "os" |
| +) |
| + |
| +var showDebug = false |
| + |
| +// 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
|
| +func SetDebug(show bool) { |
| + showDebug = show |
| +} |
| + |
| +// Print prints the given format string (and arguments) to standard out. |
| +func Print(format string, args ...interface{}) { |
|
seanmccullough1
2016/04/29 00:54:37
Just use fmt.Printf (or log.Printf)?
|
| + fmt.Printf(format, args) |
| +} |
| + |
| +// Debug is the same as Print, but only produces output if SetDebug(true) |
| +// has been called. |
| +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
|
| + if showDebug { |
| + fmt.Printf(format, args) |
| + } |
| +} |
| + |
| +// Prompt prints a string to standard out, then waits for a single line |
| +// of user input and returns it. |
| +func Prompt(prompt string) string { |
| + fmt.Print(prompt) |
| + reader := bufio.NewReader(os.Stdin) |
| + text, _ := reader.ReadString('\n') |
| + return text |
| +} |