diff options
| -rw-r--r-- | key.cpp | 46 | ||||
| -rw-r--r-- | tmux101_print.cpp | 20 |
2 files changed, 66 insertions, 0 deletions
@@ -0,0 +1,46 @@ +#include <iostream> +#include <termios.h> +#include <unistd.h> +#include <escape.ansi> + +char getch() { + struct termios oldt, newt; + char ch; + tcgetattr(STDIN_FILENO, &oldt); // Get the current terminal settings + newt = oldt; // Copy the settings + newt.c_lflag &= ~(ICANON | ECHO); // Disable canonical mode and echo + tcsetattr(STDIN_FILENO, TCSANOW, &newt); // Set the new settings + ch = getchar(); // Read a character + tcsetattr(STDIN_FILENO, TCSANOW, &oldt); // Restore the old settings + return ch; +} + +int main() { + std::cout << "Press " << red << "any key" << def << " to see its ASCII keycode. | Press " << red << "ESC" << def << " to exit." << std::endl; + + while (true) { + char ch = getch(); // Get a character from the user + + // Check for ESC key to exit + if (ch == 27) { // ASCII code for ESC + std::cout << "ESC = 27\n" << red << "Quitting ..\n" << def; + break; + } + + if (ch == 32) { + std::cout << "SPACEBAR = " << static_cast<int>(ch) << std::endl; + } else if (ch == 9) { + std::cout << "TAB = " << static_cast<int>(ch) << std::endl; + } else if (ch == 127) { + std::cout << "BACKSPACE = " << static_cast<int>(ch) << std::endl; + } else if (ch == 10) { + std::cout << "ENTER = " << static_cast<int>(ch) << std::endl; + } else { + // Output pressed key + std::cout << ch << " = " << static_cast<int>(ch) << std::endl; + } + } + + return 0; +} + diff --git a/tmux101_print.cpp b/tmux101_print.cpp new file mode 100644 index 0000000..14dc0ac --- /dev/null +++ b/tmux101_print.cpp @@ -0,0 +1,20 @@ +#include <iostream> +#include <escape.ansi> + +int main() { + std::cout + << "[ "<<red<<"TMUX 101 - Terminal MUltipleXer 101 "<<def<<"]\n" + + << "[ "<<red<<"Basics "<<def<<"]\n" + << "> ^b -> Enter command mode ("<<yellow<<"ESC in VIM talk"<<def<<")\n" + << "[ "<<red<<"Sessions "<<def<<"]\n" + << "> ^b^c -> Open a new sesh\n" + << "> ^b^& -> Exit focused sesh (Same as 'exit' command)\n" + << "[ "<<red<<"Layout control "<<def<<"]\n" + << "> ^b^n -> Goes to next window\n" + << "> ^b^p -> Goes to previous window\n" + << "> ^b^% -> Horizontal split\n" + << "> ^b^' / ^b^("<<yellow<<"S"<<def<<"') -> Vertical split \n" + << "> ^b("<<yellow<<"*ArrowKey"<<def<<") -> Switch between panes\n" + ; return 0; +} |