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

Unified 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: Fix windows arguments Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
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..f5baa685c5351780852066eefde6b3d11fa0ca44
--- /dev/null
+++ b/go/src/infra/tools/cr/lib/terminal/terminal.go
@@ -0,0 +1,36 @@
+// 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"
+)
+
+// ShowDebug controls whether or not calls to terminal.Debug produce output.
+var ShowDebug = false
+
+// Print prints the given format string (and arguments) to standard out.
+func Print(format string, args ...interface{}) {
+ fmt.Println(fmt.Sprintf(format, args...))
+}
+
+// Debug is the same as Print, but only produces output if ShowDebug is true.
+func Debug(format string, args ...interface{}) {
+ if ShowDebug {
+ fmt.Println(fmt.Sprintf(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, error) {
+ fmt.Print(prompt)
+ reader := bufio.NewReader(os.Stdin)
+ return reader.ReadString('\n')
+}
« no previous file with comments | « go/src/infra/tools/cr/lib/subcommand/subcommand_test.go ('k') | go/src/infra/tools/cr/lib/terminal/terminal.infra_testing » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698