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

Unified Diff: runtime/bin/stdin_linux.cc

Issue 19627004: Add echo and line modes to Stdin. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add missing files. Created 7 years, 5 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: runtime/bin/stdin_linux.cc
diff --git a/runtime/bin/stdin_linux.cc b/runtime/bin/stdin_linux.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e9a3a0f843aa0f295f9df0c24e976c4fa481157a
--- /dev/null
+++ b/runtime/bin/stdin_linux.cc
@@ -0,0 +1,52 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+#include "platform/globals.h"
+#if defined(TARGET_OS_LINUX)
+
+#include <termios.h> // NOLINT
+
+#include "bin/stdin.h"
+
+
+namespace dart {
+namespace bin {
+
+int Stdin::ReadByte() {
+ int c = getchar();
+ if (c == EOF) {
+ c = -1;
+ }
+ return c;
+}
+
+
+void Stdin::setEchoMode(bool enabled) {
+ struct termios term;
+ tcgetattr(fileno(stdin), &term);
+ if (enabled) {
+ term.c_lflag |= ECHO;
+ } else {
+ term.c_lflag &= ~(ECHO|ECHONL);
Søren Gjesse 2013/07/24 12:18:49 Why is ECHONL not turned on above - is it turned o
Anders Johnsen 2013/07/24 12:57:49 Done.
+ }
+ tcsetattr(fileno(stdin), TCSANOW, &term);
+}
+
+
+void Stdin::setLineMode(bool enabled) {
+ struct termios term;
+ tcgetattr(fileno(stdin), &term);
+ if (enabled) {
+ term.c_lflag |= ICANON;
+ } else {
+ term.c_lflag &= ~(ICANON);
+ }
+ tcsetattr(fileno(stdin), TCSANOW, &term);
+}
+
+} // namespace bin
+} // namespace dart
+
+#endif // defined(TARGET_OS_LINUX)
+
« runtime/bin/stdin.h ('K') | « runtime/bin/stdin.cc ('k') | runtime/bin/stdio_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698