Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 | |
| OLD | NEW |