1 |
schoenebeck |
2515 |
/* |
2 |
|
|
* LSCP Shell |
3 |
|
|
* |
4 |
|
|
* Copyright (c) 2014 Christian Schoenebeck |
5 |
|
|
* |
6 |
|
|
* This program is part of LinuxSampler and released under the same terms. |
7 |
|
|
*/ |
8 |
|
|
|
9 |
|
|
#ifndef TERMINALCTRL_H |
10 |
|
|
#define TERMINALCTRL_H |
11 |
|
|
|
12 |
|
|
#include <vector> |
13 |
|
|
#include <string> |
14 |
|
|
|
15 |
|
|
class TerminalCtrl; |
16 |
|
|
|
17 |
|
|
/** |
18 |
|
|
* Represents a state of the command line terminal for being restored later on |
19 |
|
|
* at arbitrary time. |
20 |
|
|
*/ |
21 |
|
|
class TerminalSetting { |
22 |
|
|
public: |
23 |
|
|
TerminalSetting(); |
24 |
|
|
TerminalSetting(const TerminalSetting& ts); |
25 |
|
|
virtual ~TerminalSetting(); |
26 |
|
|
bool valid() const; |
27 |
|
|
protected: |
28 |
|
|
void* p; |
29 |
|
|
friend class TerminalCtrl; |
30 |
|
|
}; |
31 |
|
|
|
32 |
|
|
/** |
33 |
|
|
* OS dependent implementation for controlling keyboard input behavior and |
34 |
|
|
* retrieving terminal screen size (rows and columns). |
35 |
|
|
* |
36 |
|
|
* Current implementation assumes a POSIX compatible system. |
37 |
|
|
* |
38 |
|
|
* This is a lite-weight class to prevent a dependency to i.e. libncurses. |
39 |
|
|
*/ |
40 |
|
|
class TerminalCtrl { |
41 |
|
|
public: |
42 |
|
|
static std::vector<char> getChars(int max, int blockUntilMin, int burstDeciSeconds = 0); |
43 |
|
|
static std::vector<char> getCharsToDelimiter(char delimiter, bool includeDelimiter = false); |
44 |
|
|
static std::string getStringToDelimiter(char delimiter, bool includeDelimiter = false); |
45 |
|
|
static int echoInput(bool b); |
46 |
|
|
static int immediateInput(bool b); |
47 |
|
|
static int reset(); |
48 |
|
|
static int restore(const TerminalSetting& setting); |
49 |
|
|
static TerminalSetting now(); |
50 |
|
|
static int columns(); |
51 |
|
|
static int rows(); |
52 |
|
|
}; |
53 |
|
|
|
54 |
|
|
#endif // TERMINALCTRL_H |