Added \ escape code support in echo command!

This commit is contained in:
2024-05-28 20:43:30 +02:00
parent 7a2afbd653
commit 77d7c356e9
2 changed files with 42 additions and 10 deletions
+20 -9
View File
@@ -11,25 +11,36 @@ Note: the escape character will be denoted by ESC here
Syntax: Syntax:
All escape sequenced start with the escape character followed by an opening square bracket '[' All escape sequenced start with the escape character followed by an opening square bracket '['
The sequence can take any number of arguments in a semicolon separated list The sequence can take any number of arguments in a semicolon separated list
If a argument is skipped, it will be implicitly set to 0 If a argument is skipped, it will be implicitly set to 0 unless stated otherwise
The escape sequence must end with a uppercase or lowercase letter The escape sequence must end with a uppercase or lowercase letter
Available escape sequences: Available escape sequences:
- Cursor Controls - - Cursor Controls -
`ESC[#A` - Moves cursor # rows up `ESC[#A` - Moves cursor # rows up (default: 1)
`ESC[#B` - Moves cursor # rows down `ESC[#B` - Moves cursor # rows down (default: 1)
`ESC[#C` - Moves cursor # columns left `ESC[#C` - Moves cursor # columns left (default: 1)
`ESC[#D` - Moves cursor # columns right `ESC[#D` - Moves cursor # columns right (default: 1)
`ESC[#E` - Moves cursor to #th row `ESC[#E` - Moves cursor to #th row
`ESC[#F` - Moves cursor to #th column `ESC[#F` - Moves cursor to #th column
`ESC[#G` - Show (# = 1) or hide (# = 0) cursor `ESC[#G` - Show (# = 1) or hide (# = 0) cursor
`ESC[{row};{col}H` - Moves cursor to specified position (if not arguments given, moves to [0,0])a `ESC[{row};{col}H` - Moves cursor to specified position (if not arguments given, moves to [0,0])
- Erase functions - - Erase functions -
`ESC[I` - Reserved `ESC[I` - Reserved (Falls though to erase screen)
`ESC[J` - Erase screen `ESC[J` - Erase screen
`ESC[K` - Erase line (not implemented) `ESC[K` - Erase line (not implemented)
`ESC[L` - Erase column (not implemented) `ESC[L` - Erase column (not implemented)
- Text Style - - Text Style -
`ESC[#M` - Sets foreground color to # `ESC[#M` - Sets foreground color to # (default 8)
`ESC[#N` - Sets backgorund color to # `ESC[#N` - Sets backgorund color to # (default 8)
Color codes:
0 - Black
1 - Red
2 - Green
3 - Yellow
4 - Blue
5 - Magenta
6 - Cyan
7 - White
8 - Default
+22 -1
View File
@@ -22,6 +22,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#include <color.h>
#define PROMPT "#> " #define PROMPT "#> "
@@ -133,7 +134,27 @@ void main() {
continue; continue;
} }
} else if (strcmp(input, "echo") == 0) { } else if (strcmp(input, "echo") == 0) {
print(args); char* str = args;
char* printStr = args;
while (*args != '\0') {
if (*args == '\\') {
args++;
if (*args == 'n') *str++ = '\n';
else if (*args == 'b') *str++ = '\b';
else if (*args == 'e') *str++ = '\x1b';
else if (*args == '\\') *str++ = '\\';
else {
*str++ = '\\';
*str++ = *args;
}
args++;
} else {
*str++ = *args++;
}
}
*str = '\0';
print(printStr);
} else if (strcmp(input, "exit") == 0) { } else if (strcmp(input, "exit") == 0) {
break; break;
} else if (strcmp(input, "gfx") == 0) { } else if (strcmp(input, "gfx") == 0) {