Skip to content

Commit f3f068c

Browse files
authored
Merge pull request #255 from flagarde/master
add <cctype> like functions to key
2 parents 7d96019 + 3a3b580 commit f3f068c

File tree

10 files changed

+383
-175
lines changed

10 files changed

+383
-175
lines changed

README.md

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,20 +94,39 @@ We have created serval examples to show possible use cases of CPP-Terminal and t
9494
| Linux | All supported | x86_64 | 4.7<=GCC<= 12 3.5<=Clang<=15 intel-oneapi | 11,14,17,20 |
9595
| Linux (dockcross) | All supported | arm64 armv5 armv5-musl armv5-uclibc armv6 armv7a, mips, mipsel-lts, s390x, ppc64le, xtensa-uclibc, x86, x64, x64-clang, x64-tinycc | 4.7<=GCC<= 12 3.5<=Clang<=15 | 11,14,17,20 |
9696
97-
> Windows versions prior Windows 10 are missing the Win32 API functionality for entering the "raw mode" and therefore won't work. They are also lacking ANSI support. See #173 for adding support to prior windows versions for MSVC / Win32.
97+
> Windows versions prior Windows 10 are missing the Win32 API functionality for entering the "raw mode" and therefore
98+
> won't work. They are also lacking ANSI support. See #173 for adding support to prior windows versions for MSVC / Win32.
9899
99100
## How to use
100101
101-
Adding CPP-Terminal to your own project is really easy. We have collected various ways with easy how-to's [in our documentation](https://github.com/jupyter-xeus/cpp-terminal/wiki/Adding-CPP-Terminal-to-your-ptoject).
102+
Adding CPP-Terminal to your own project is really easy. We have collected various ways with easy
103+
how-to's [in our documentation](https://github.com/jupyter-xeus/cpp-terminal/wiki/Adding-CPP-Terminal-to-your-ptoject).
102104
103-
## Documentation
105+
## Documentation [![docs](https://github.com/jupyter-xeus/cpp-terminal/actions/workflows/docs.yml/badge.svg)](https://github.com/jupyter-xeus/cpp-terminal/actions/workflows/docs.yml) ##
104106
105-
CPP-Terminal's documentation can be found [here](https://github.com/jupyter-xeus/cpp-terminal/wiki).
107+
<h1 align="center">
108+
<a href="https://jupyter-xeus.github.io/cpp-terminal/">
109+
110+
```markdown
111+
🌍 Online
112+
```
113+
114+
</a>
115+
<a href="https://jupyter-xeus.github.io/cpp-terminal/cpp-terminal_Manual.pdf">
116+
117+
```markdown
118+
📖 PDF
119+
```
120+
121+
</a>
122+
</h1>
106123

107124
## Contributing
108125

109-
Contributing to CPP-Terminal is highly appreciated and can be done in more ways than code. Extending it's functionality, reporting or fixing bugs and extending the documentations are just a few of them.
126+
Contributing to CPP-Terminal is highly appreciated and can be done in more ways than code. Extending it's functionality,
127+
reporting or fixing bugs and extending the documentations are just a few of them.
110128

111129
## License
112130

113-
CPP-Terminal is licensed under the terms of [the MIT License](https://github.com/jupyter-xeus/cpp-terminal/blob/master/LICENSE) by Ondřej Čertík.
131+
CPP-Terminal is licensed under the terms
132+
of [the MIT License](https://github.com/jupyter-xeus/cpp-terminal/blob/master/LICENSE) by Ondřej Čertík.

cpp-terminal/event.cpp

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ void Term::Event::parse()
3434
if(m_str.size() == 1)
3535
{
3636
m_Type = Type::Key;
37-
m_Key = static_cast<Term::Key::Value>(m_str[0]);
37+
m_Key = Key(static_cast<Term::Key::Value>(m_str[0]));
3838
/* Backspace return 127 CTRL+backspace return 8 */
39-
if(m_Key == Term::Key::Value::DEL) m_Key = Term::Key::Value::BACKSPACE;
39+
if(m_Key == Term::Key::Value::DEL) m_Key = Key(Term::Key::Value::BACKSPACE);
4040
m_str.clear();
4141
}
4242
else if(m_str.size() == 2 && m_str[0] == '\033')
4343
{
44-
m_Key = static_cast<Term::Key::Value>(Term::Key::Value::ALT + static_cast<Term::Key::Value>(m_str[1]));
44+
m_Key = Key(static_cast<Term::Key::Value>(Term::Key::Value::ALT + static_cast<Term::Key::Value>(m_str[1])));
4545
m_Type = Type::Key;
4646
m_str.clear();
4747
}
@@ -50,8 +50,7 @@ void Term::Event::parse()
5050
std::size_t found = m_str.find(';', 2);
5151
if(found != std::string::npos)
5252
{
53-
m_Type = Type::Cursor;
54-
53+
m_Type = Type::Cursor;
5554
m_Cursor = Cursor(std::stoi(m_str.substr(2, found - 2)), std::stoi(m_str.substr(found + 1, m_str.size() - (found + 2))));
5655
}
5756
}
@@ -75,13 +74,13 @@ void Term::Event::parse()
7574
* Cursor Left | ESC D
7675
* -------------+--------------------
7776
*/
78-
if(m_str == "\033OA" || m_str == "\033[A" || m_str == "\033A") m_Key = Term::Key::Value::ARROW_UP;
77+
if(m_str == "\033OA" || m_str == "\033[A" || m_str == "\033A") m_Key = Key(Term::Key::Value::ARROW_UP);
7978
else if(m_str == "\033OB" || m_str == "\033[B" || m_str == "\033B")
80-
m_Key = Term::Key::Value::ARROW_DOWN;
79+
m_Key = Key(Term::Key::Value::ARROW_DOWN);
8180
else if(m_str == "\033OC" || m_str == "\033[C" || m_str == "\033C")
82-
m_Key = Term::Key::Value::ARROW_RIGHT;
81+
m_Key = Key(Term::Key::Value::ARROW_RIGHT);
8382
else if(m_str == "\033OD" || m_str == "\033[D" || m_str == "\033D")
84-
m_Key = Term::Key::Value::ARROW_LEFT;
83+
m_Key = Key(Term::Key::Value::ARROW_LEFT);
8584
/*
8685
* Key Normal Application
8786
* ---------+----------+-------------
@@ -90,9 +89,9 @@ void Term::Event::parse()
9089
* ---------+----------+-------------
9190
*/
9291
else if(m_str == "\033OH" || m_str == "\033[H")
93-
m_Key = Term::Key::Value::HOME;
92+
m_Key = Key(Term::Key::Value::HOME);
9493
else if(m_str == "\033OF" || m_str == "\033[F")
95-
m_Key = Term::Key::Value::END;
94+
m_Key = Key(Term::Key::Value::END);
9695
/*
9796
* Key Escape Sequence
9897
* ---------+-----------------
@@ -115,29 +114,29 @@ void Term::Event::parse()
115114
* ---------+-----------------
116115
*/
117116
else if(m_str == "\033OP" || m_str == "\033[11~")
118-
m_Key = Term::Key::Value::F1;
117+
m_Key = Key(Term::Key::Value::F1);
119118
else if(m_str == "\033OQ" || m_str == "\033[12~")
120-
m_Key = Term::Key::Value::F2;
119+
m_Key = Key(Term::Key::Value::F2);
121120
else if(m_str == "\033OR" || m_str == "\033[13~")
122-
m_Key = Term::Key::Value::F3;
121+
m_Key = Key(Term::Key::Value::F3);
123122
else if(m_str == "\033OS" || m_str == "\033[14~")
124-
m_Key = Term::Key::Value::F4;
123+
m_Key = Key(Term::Key::Value::F4);
125124
else if(m_str == "\033[15~")
126-
m_Key = Term::Key::Value::F5;
125+
m_Key = Key(Term::Key::Value::F5);
127126
else if(m_str == "\033[17~")
128-
m_Key = Term::Key::Value::F6;
127+
m_Key = Key(Term::Key::Value::F6);
129128
else if(m_str == "\033[18~")
130-
m_Key = Term::Key::Value::F7;
129+
m_Key = Key(Term::Key::Value::F7);
131130
else if(m_str == "\033[19~")
132-
m_Key = Term::Key::Value::F8;
131+
m_Key = Key(Term::Key::Value::F8);
133132
else if(m_str == "\033[20~")
134-
m_Key = Term::Key::Value::F9;
133+
m_Key = Key(Term::Key::Value::F9);
135134
else if(m_str == "\033[21~")
136-
m_Key = Term::Key::Value::F10;
135+
m_Key = Key(Term::Key::Value::F10);
137136
else if(m_str == "\033[23~")
138-
m_Key = Term::Key::Value::F11;
137+
m_Key = Key(Term::Key::Value::F11);
139138
else if(m_str == "\033[24~")
140-
m_Key = Term::Key::Value::F12;
139+
m_Key = Key(Term::Key::Value::F12);
141140
/*
142141
* Key Normal Application
143142
* ---------+----------+-------------
@@ -150,17 +149,17 @@ void Term::Event::parse()
150149
* ---------+----------+-------------
151150
*/
152151
else if(m_str == "\033[2~")
153-
m_Key = Term::Key::Value::INSERT;
152+
m_Key = Key(Term::Key::Value::INSERT);
154153
else if(m_str == "\033[3~")
155-
m_Key = Term::Key::Value::DEL;
154+
m_Key = Key(Term::Key::Value::DEL);
156155
else if(m_str == "\033[1~")
157-
m_Key = Term::Key::Value::HOME;
156+
m_Key = Key(Term::Key::Value::HOME);
158157
else if(m_str == "\033[4~")
159-
m_Key = Term::Key::Value::END;
158+
m_Key = Key(Term::Key::Value::END);
160159
else if(m_str == "\033[5~")
161-
m_Key = Term::Key::Value::PAGE_UP;
160+
m_Key = Key(Term::Key::Value::PAGE_UP);
162161
else if(m_str == "\033[6~")
163-
m_Key = Term::Key::Value::PAGE_DOWN;
162+
m_Key = Key(Term::Key::Value::PAGE_DOWN);
164163
/*
165164
* Key Escape Sequence
166165
* ---------+-----------------
@@ -175,21 +174,23 @@ void Term::Event::parse()
175174
* ---------+-----------------
176175
*/
177176
else if(m_str == "\033[25~")
178-
m_Key = Term::Key::Value::F13;
177+
m_Key = Key(Term::Key::Value::F13);
179178
else if(m_str == "\033[26~")
180-
m_Key = Term::Key::Value::F14;
179+
m_Key = Key(Term::Key::Value::F14);
181180
else if(m_str == "\033[28~")
182-
m_Key = Term::Key::Value::F15;
181+
m_Key = Key(Term::Key::Value::F15);
183182
else if(m_str == "\033[29~")
184-
m_Key = Term::Key::Value::F16;
183+
m_Key = Key(Term::Key::Value::F16);
185184
else if(m_str == "\033[31~")
186-
m_Key = Term::Key::Value::F17;
185+
m_Key = Key(Term::Key::Value::F17);
187186
else if(m_str == "\033[32~")
188-
m_Key = Term::Key::Value::F18;
187+
m_Key = Key(Term::Key::Value::F18);
189188
else if(m_str == "\033[33~")
190-
m_Key = Term::Key::Value::F19;
189+
m_Key = Key(Term::Key::Value::F19);
191190
else if(m_str == "\033[34~")
192-
m_Key = Term::Key::Value::F20;
191+
m_Key = Key(Term::Key::Value::F20);
192+
else if(m_str == "\033[G")
193+
m_Key = Key(Term::Key::Value::NUMERIC_5);
193194
if(!m_Key.empty())
194195
{
195196
m_Type = Type::Key;

cpp-terminal/key.cpp

Lines changed: 105 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,29 @@ Term::Key::Key(const Term::Key::Value& value) : m_value(value) {}
44

55
Term::Key::operator Term::Key::Value() { return m_value; }
66

7-
bool Term::Key::is_ASCII()
7+
bool Term::Key::isASCII()
88
{
9-
if(m_value >= 0 && m_value <= 127) return true;
9+
if(m_value >= NUL && m_value <= DEL) return true;
1010
else
1111
return false;
1212
}
1313

14-
bool Term::Key::is_extended_ASCII()
14+
bool Term::Key::isExtendedASCII()
1515
{
16-
if(m_value >= 0 && m_value <= 255) return true;
16+
if(m_value >= NUL && m_value <= 255) return true;
1717
else
1818
return false;
1919
}
2020

21-
bool Term::Key::is_CTRL()
21+
bool Term::Key::isCTRL()
2222
{
2323
// Need to suppress the TAB etc...
24-
if(m_value > 0 && m_value <= 31 && m_value != Key::BACKSPACE && m_value != Key::TAB && m_value != ESC && /* the two mapped to ENTER */ m_value != ENTER) return true;
24+
if(iscntrl() && m_value != Key::BACKSPACE && m_value != Key::TAB && m_value != ESC && m_value != ENTER && m_value != DEL) return true;
2525
else
2626
return false;
2727
}
2828

29-
bool Term::Key::is_ALT()
29+
bool Term::Key::isALT()
3030
{
3131
if(m_value >= Key::ALT && Key::ALT < (Key::ALT << 1)) return true;
3232
else
@@ -39,3 +39,101 @@ bool Term::Key::empty()
3939
else
4040
return false;
4141
}
42+
43+
bool Term::Key::iscntrl()
44+
{
45+
if((m_value >= NUL && m_value <= CTRL_UNDERSCORE) || m_value == DEL) return true;
46+
else
47+
return false;
48+
}
49+
50+
bool Term::Key::isblank()
51+
{
52+
if(m_value == TAB || m_value == SPACE) return true;
53+
else
54+
return false;
55+
}
56+
57+
bool Term::Key::isspace()
58+
{
59+
if(isblank() || (m_value >= CTRL_J && m_value <= ENTER)) return true;
60+
else
61+
return false;
62+
}
63+
64+
bool Term::Key::isupper()
65+
{
66+
if(m_value >= A && m_value <= Z) return true;
67+
else
68+
return false;
69+
}
70+
71+
bool Term::Key::islower()
72+
{
73+
if(m_value >= a && m_value <= z) return true;
74+
else
75+
return false;
76+
}
77+
78+
bool Term::Key::isalpha()
79+
{
80+
if(isupper() || islower()) return true;
81+
else
82+
return false;
83+
}
84+
85+
bool Term::Key::isdigit()
86+
{
87+
if(m_value >= ZERO && m_value <= NINE) return true;
88+
else
89+
return false;
90+
}
91+
92+
bool Term::Key::isxdigit()
93+
{
94+
if(isdigit() || (m_value >= A && m_value <= F) || (m_value >= a && m_value <= f)) return true;
95+
else
96+
return false;
97+
}
98+
99+
bool Term::Key::isalnum()
100+
{
101+
if(isdigit() || isalpha()) return true;
102+
else
103+
return false;
104+
}
105+
106+
bool Term::Key::ispunct()
107+
{
108+
if((m_value >= EXCLAMATION_MARK && m_value <= SLASH) || (m_value >= COLON && m_value <= AROBASE) || (m_value >= OPEN_BRACKET && m_value <= GRAVE_ACCENT) || (m_value >= OPEN_BRACE && m_value <= TILDE)) return true;
109+
else
110+
return false;
111+
}
112+
113+
bool Term::Key::isgraph()
114+
{
115+
if(isalnum() || ispunct()) return true;
116+
else
117+
return false;
118+
}
119+
120+
bool Term::Key::isprint()
121+
{
122+
if(isgraph() || m_value == SPACE) return true;
123+
else
124+
return false;
125+
}
126+
127+
char Term::Key::tolower()
128+
{
129+
if(isalpha() && isupper()) return static_cast<char>(m_value + 32);
130+
else
131+
return static_cast<char>(m_value);
132+
}
133+
134+
char Term::Key::toupper()
135+
{
136+
if(isalpha() && islower()) return static_cast<char>(m_value - 32);
137+
else
138+
return static_cast<char>(m_value);
139+
}

0 commit comments

Comments
 (0)