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

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: Created 4 years, 8 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..7ef0eb041b42e464a30fc4ef55c20ca6f4bd2b69
--- /dev/null
+++ b/go/src/infra/tools/cr/lib/terminal/terminal.go
@@ -0,0 +1,40 @@
+// 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
+
+func ToggleDebug() {
+ showDebug = !showDebug
+}
+
+func SetDebug(show bool) {
+ showDebug = show
+}
+
+func Print(format string, args ...interface{}) {
+ fmt.Printf(format, args)
+}
+
+func Debug(format string, args ...interface{}) {
+ if showDebug {
+ fmt.Printf(format, args)
+ }
+}
+
+func Prompt(prompt string) string {
+ fmt.Print(prompt)
+ reader := bufio.NewReader(os.Stdin)
+ text, _ := reader.ReadString('\n')
+ return text
+}

Powered by Google App Engine
This is Rietveld 408576698