Compare commits

..

2 Commits

Author SHA1 Message Date
036cd1ea90 docs: update readme 2026-01-14 07:43:46 +01:00
16fe1178f4 feat: replace exit with ctrl+d 2026-01-14 07:43:40 +01:00
2 changed files with 6 additions and 13 deletions

View File

@@ -64,7 +64,7 @@ In **encode mode**:
In both modes:
- Type `exit` to quit the program
- Press `Ctrl+D` to quit the program
## Examples

View File

@@ -25,22 +25,15 @@ const map<char, string> morse_map = {
bool should_exit = false;
bool is_exit(const string &s) {
return s.length() == 4 && tolower(static_cast<unsigned char>(s[0])) == 'e' &&
tolower(static_cast<unsigned char>(s[1])) == 'x' &&
tolower(static_cast<unsigned char>(s[2])) == 'i' &&
tolower(static_cast<unsigned char>(s[3])) == 't';
}
string read_input(const string &prompt) {
cout << prompt;
string line;
if (!getline(cin, line) || line.empty())
return "";
if (is_exit(line)) {
if (!getline(cin, line)) {
should_exit = true;
return "";
}
if (line.empty())
return "";
return line;
}
@@ -119,7 +112,7 @@ public:
void decode_mode() {
MorseDecoder decoder;
cout << "Decode mode: Enter morse sequence to decode. Press 'e' to switch to "
"encode mode, 'exit' to exit.\n\n";
"encode mode.\n\n";
while (!should_exit) {
string input = read_input("Enter morse sequence: ");
@@ -171,7 +164,7 @@ void decode_mode() {
void encode_mode() {
MorseEncoder encoder;
cout << "Encode mode: Enter text to see Morse code patterns. Press 'd' to "
"switch to decode mode, 'exit' to exit.\n\n";
"switch to decode mode.\n\n";
while (!should_exit) {
string input = read_input("Enter text to encode: ");