Skip to content

Commit 4c6dfe3

Browse files
authored
Merge pull request #48 from martinRenou/reduce_cpu_consumption
Reduce CPU consumption in read_key
2 parents ec76e8d + 4372062 commit 4c6dfe3

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

cpp-terminal/terminal.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <iostream>
1919
#include <string>
2020
#include <vector>
21+
#include <thread>
2122

2223
#define CTRL_KEY(k) (char)(((unsigned char)(k) & 0x1f))
2324
#define ALT_KEY(k) (char)(((unsigned char)(k) + 0x80))
@@ -201,7 +202,10 @@ class Terminal: public BaseTerminal {
201202
int read_key() const
202203
{
203204
int key;
204-
while ((key = read_key0()) == 0) { }
205+
while ((key = read_key0()) == 0)
206+
{
207+
std::this_thread::sleep_for(std::chrono::milliseconds(10));
208+
}
205209
return key;
206210
}
207211

0 commit comments

Comments
 (0)