Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions examples/keys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,17 @@ int main() {
std::cout << rawterm::set_header(header) << std::flush;

while (true) {
auto k = rawterm::process_keypress();
if (k.has_value()) {
if (k.value() == rawterm::Key('q')) {
break;
} else {
auto key_value = k.value();
std::string mods = "[";
while (!(key_value.mod.empty()))
mods += " " + rawterm::to_string(key_value.getMod());
mods += " ]";

std::cout << "Key{ code: " << key_value.code << ", mods: " << mods
<< ", raw: " << key_value.raw << "}\r\n";
}
auto k = rawterm::wait_for_input();
if (k == rawterm::Key('q')) {
break;
} else {
std::string mods = "[";
while (!(k.mod.empty()))
mods += " " + rawterm::to_string(k.getMod());
mods += " ]";

std::cout << "Key{ code: " << k.code << ", mods: " << mods << ", raw: " << k.raw
<< "}\r\n";
}
}

Expand Down
4 changes: 4 additions & 0 deletions rawterm/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ namespace rawterm {

} // namespace detail

void Key::addMod(rawterm::Mod m) {
mod.push_back(m);
}

rawterm::Mod Key::getMod() {
if (mod.empty()) {
return rawterm::Mod::None;
Expand Down
1 change: 1 addition & 0 deletions rawterm/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ namespace rawterm {
Key(char c, Mod m) : code(c), mod(std::deque<Mod> {m}) {}
Key(char c, Mod m, std::string r) : code(c), mod(std::deque<Mod> {m}), raw(r) {}

void addMod(rawterm::Mod);
[[nodiscard]] rawterm::Mod getMod();
[[nodiscard]] bool isCharInput();
[[nodiscard]] bool isValid();
Expand Down
Loading