Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(125)

Side by Side Diff: go/src/infra/tools/cr/lib/terminal/terminal.go

Issue 1929153002: Add beginnings of new cr command (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Style and documentation Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698