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

Unified Diff: examples/media_test/keystroke.cc

Issue 1809703003: Motown: Add examples/media_test, a command line media player app. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Tweaks based on feedback. Created 4 years, 9 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: examples/media_test/keystroke.cc
diff --git a/examples/media_test/keystroke.cc b/examples/media_test/keystroke.cc
new file mode 100644
index 0000000000000000000000000000000000000000..9e1206340b1f7ec23db0a5bb5b3925e7d7a5e4c1
--- /dev/null
+++ b/examples/media_test/keystroke.cc
@@ -0,0 +1,52 @@
+// Copyright 2015 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.
+
+#include <fcntl.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include <iostream>
+
+#include "examples/media_test/keystroke.h"
+
+namespace mojo {
+namespace media {
+namespace examples {
+
+namespace {
+
+bool eat_newline = false;
+bool upped_already = false;
+
+} // namespace
+
+char Keystroke(void) {
+ const char *kUp = "\033[A";
+
+ fcntl(STDIN_FILENO, F_SETFL, fcntl(0, F_GETFL) | O_NONBLOCK);
+ char buf[1];
+ if (read(STDIN_FILENO, buf, 1) > 0) {
+ if (!upped_already) {
+ std::cout << kUp << std::flush;
+ upped_already = true;
+ }
+
+ if (buf[0] == '\n') {
+ upped_already = false;
+ if (eat_newline) {
+ eat_newline = false;
+ } else {
+ return buf[0];
+ }
+ } else {
+ eat_newline = true;
+ return buf[0];
+ }
+ }
+ return 0;
+}
+
+} // namespace examples
+} // namespace media
+} // namespace mojo

Powered by Google App Engine
This is Rietveld 408576698