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

Side by Side Diff: examples/media_test/keystroke.cc

Issue 1822333002: Motown: wholesale clang-format (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: dalesat 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
« no previous file with comments | « no previous file | examples/media_test/media_test.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <fcntl.h> 5 #include <fcntl.h>
6 #include <stdio.h> 6 #include <stdio.h>
7 #include <unistd.h> 7 #include <unistd.h>
8 8
9 #include <iostream> 9 #include <iostream>
10 10
11 #include "examples/media_test/keystroke.h" 11 #include "examples/media_test/keystroke.h"
12 12
13 namespace mojo { 13 namespace mojo {
14 namespace media { 14 namespace media {
15 namespace examples { 15 namespace examples {
16 16
17 namespace { 17 namespace {
18 18
19 bool eat_newline = false; 19 bool eat_newline = false;
20 bool upped_already = false; 20 bool upped_already = false;
21 21
22 } // namespace 22 } // namespace
23 23
24 char Keystroke(void) { 24 char Keystroke(void) {
25 const char *kUp = "\033[A"; 25 const char* kUp = "\033[A";
26 26
27 fcntl(STDIN_FILENO, F_SETFL, fcntl(0, F_GETFL) | O_NONBLOCK); 27 fcntl(STDIN_FILENO, F_SETFL, fcntl(0, F_GETFL) | O_NONBLOCK);
28 char buf[1]; 28 char buf[1];
29 if (read(STDIN_FILENO, buf, 1) > 0) { 29 if (read(STDIN_FILENO, buf, 1) > 0) {
30 if (!upped_already) { 30 if (!upped_already) {
31 std::cout << kUp << std::flush; 31 std::cout << kUp << std::flush;
32 upped_already = true; 32 upped_already = true;
33 } 33 }
34 34
35 if (buf[0] == '\n') { 35 if (buf[0] == '\n') {
36 upped_already = false; 36 upped_already = false;
37 if (eat_newline) { 37 if (eat_newline) {
38 eat_newline = false; 38 eat_newline = false;
39 } else { 39 } else {
40 return buf[0]; 40 return buf[0];
41 } 41 }
42 } else { 42 } else {
43 eat_newline = true; 43 eat_newline = true;
44 return buf[0]; 44 return buf[0];
45 } 45 }
46 } 46 }
47 return 0; 47 return 0;
48 } 48 }
49 49
50 } // namespace examples 50 } // namespace examples
51 } // namespace media 51 } // namespace media
52 } // namespace mojo 52 } // namespace mojo
OLDNEW
« no previous file with comments | « no previous file | examples/media_test/media_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698