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

Side by Side 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: 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 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 #include <fcntl.h>
6 #include <stdio.h>
7 #include <unistd.h>
8
9 #include <iostream>
10
11 #include "examples/media_test/keystroke.h"
12
13 namespace examples {
14
15 bool eat_newline = false;
16 bool upped_already = false;
johngro 2016/03/21 22:10:46 This should either be hidden as private static mem
dalesat 2016/03/21 23:58:34 Done.
17
18 char Keystroke(void) {
19 const char *kUp = "\033[A";
20
21 fcntl(0, F_SETFL, fcntl(0, F_GETFL) | O_NONBLOCK);
johngro 2016/03/21 22:10:46 you can say STDIN_FILENO instead of 0 here. You w
dalesat 2016/03/21 23:58:34 Done.
22 char buf[1];
23 if (read(0, buf, 1) > 0) {
24 if (!upped_already) {
johngro 2016/03/21 22:10:46 so, this is terminal specific and is probably not
dalesat 2016/03/21 23:58:34 Acknowledged.
25 std::cerr << kUp << std::flush;
johngro 2016/03/21 22:10:46 Why cerr and not cout?
dalesat 2016/03/21 23:58:34 Force of habit. Fixed.
26 upped_already = true;
27 }
28
29 if (buf[0] == '\n') {
30 upped_already = false;
31 if (eat_newline) {
32 eat_newline = false;
33 } else {
34 return buf[0];
35 }
36 } else {
37 eat_newline = true;
38 return buf[0];
39 }
40 }
41 return 0;
42 }
43
44 } // namespace examples
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698