Moved to \033 as the most compatible esc representation
This commit is contained in:
@@ -36,24 +36,24 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* terminal control macros (constants) */
|
/* terminal control macros (constants) */
|
||||||
#define ERESET "\x1b[0m" /* reset the styling */
|
#define ERESET "\033[0m" /* reset the styling */
|
||||||
#define CLS "\x1b[2J" /* clear the entire screen */
|
#define CLS "\033[2J" /* clear the entire screen */
|
||||||
#define LINECLR "\x1b[2K" /* clear the current line */
|
#define LINECLR "\033[2K" /* clear the current line */
|
||||||
#define CURRESET "\x1b[0;0H" /* reset the visual cursor */
|
#define CURRESET "\033[0;0H" /* reset the visual cursor */
|
||||||
#ifdef NNE_NO_ALTBUF /* can be defined for legacy terminals */
|
#ifdef NNE_NO_ALTBUF /* can be defined for legacy terminals */
|
||||||
#define CURSHOW ""
|
#define CURSHOW ""
|
||||||
#define CURHIDE ""
|
#define CURHIDE ""
|
||||||
#define ALTBUFON ""
|
#define ALTBUFON ""
|
||||||
#define ALTBUFOFF CLS /* if no altbuf, then clear the screen */
|
#define ALTBUFOFF CLS /* if no altbuf, then clear the screen */
|
||||||
#else
|
#else
|
||||||
#define CURSHOW "\x1b[?25h" /* show the cursor */
|
#define CURSHOW "\033[?25h" /* show the cursor */
|
||||||
#define CURHIDE "\x1b[?25l" /* hide the cursor */
|
#define CURHIDE "\033[?25l" /* hide the cursor */
|
||||||
#define ALTBUFON "\x1b[?47h\x1b%G" /* turn on alternate screen + UTF-8 */
|
#define ALTBUFON "\033[?47h\033%G" /* turn on alternate screen + UTF-8 */
|
||||||
#define ALTBUFOFF "\x1b[?47l" /* turn off alternate screen */
|
#define ALTBUFOFF "\033[?47l" /* turn off alternate screen */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* terminal control macros (sprintf templates) */
|
/* terminal control macros (sprintf templates) */
|
||||||
#define CURSET "\x1b[%03u;%03uH" /* set the cursor position (line;col) */
|
#define CURSET "\033[%03u;%03uH" /* set the cursor position (line;col) */
|
||||||
|
|
||||||
/* some enums */
|
/* some enums */
|
||||||
enum nne_modes { NNE_NORMAL = 1, NNE_CMD }; /* operation modes */
|
enum nne_modes { NNE_NORMAL = 1, NNE_CMD }; /* operation modes */
|
||||||
@@ -97,46 +97,46 @@ static int nne_line_offset = 0; /* offset from the start to the screen */
|
|||||||
|
|
||||||
/* help screen */
|
/* help screen */
|
||||||
|
|
||||||
static char* nne_help_screen = "\x1b[s\
|
static char* nne_help_screen = "\033[s\
|
||||||
---------------------------- nne shortcut help ---------------------------\
|
---------------------------- nne shortcut help ---------------------------\
|
||||||
\x1b[1B\x1b[74D\
|
\033[1B\033[74D\
|
||||||
| |\
|
| |\
|
||||||
\x1b[1B\x1b[74D\
|
\033[1B\033[74D\
|
||||||
|Save Esc Esc s, Esc Esc w Line jump Esc Esc l [num] Return |\
|
|Save Esc Esc s, Esc Esc w Line jump Esc Esc l [num] Return |\
|
||||||
\x1b[1B\x1b[74D\
|
\033[1B\033[74D\
|
||||||
|Quit Esc Esc q Brace match Esc Esc 5 |\
|
|Quit Esc Esc q Brace match Esc Esc 5 |\
|
||||||
\x1b[1B\x1b[74D\
|
\033[1B\033[74D\
|
||||||
|Tab char Esc Esc Tab Find text Esc Esc / [text] Return|\
|
|Tab char Esc Esc Tab Find text Esc Esc / [text] Return|\
|
||||||
\x1b[1B\x1b[74D\
|
\033[1B\033[74D\
|
||||||
|Delete Del, Esc Esc Bksp Copy line Esc Esc y |\
|
|Delete Del, Esc Esc Bksp Copy line Esc Esc y |\
|
||||||
\x1b[1B\x1b[74D\
|
\033[1B\033[74D\
|
||||||
|Page Up PgUp, Esc Esc Up Copy lines Esc Esc Y [num] Return |\
|
|Page Up PgUp, Esc Esc Up Copy lines Esc Esc Y [num] Return |\
|
||||||
\x1b[1B\x1b[74D\
|
\033[1B\033[74D\
|
||||||
|Page Down PgDn, Esc Esc Down Cut line Esc Esc d |\
|
|Page Down PgDn, Esc Esc Down Cut line Esc Esc d |\
|
||||||
\x1b[1B\x1b[74D\
|
\033[1B\033[74D\
|
||||||
|Home Home, Esc Esc 0 Cut lines Esc Esc D [num] Return |\
|
|Home Home, Esc Esc 0 Cut lines Esc Esc D [num] Return |\
|
||||||
\x1b[1B\x1b[74D\
|
\033[1B\033[74D\
|
||||||
|End End, Esc Esc 4 Paste Esc Esc p, Esc Esc v |\
|
|End End, Esc Esc 4 Paste Esc Esc p, Esc Esc v |\
|
||||||
\x1b[1B\x1b[74D\
|
\033[1B\033[74D\
|
||||||
|Next word Esc Esc Right Discard/undo Esc Esc u |\
|
|Next word Esc Esc Right Discard/undo Esc Esc u |\
|
||||||
\x1b[1B\x1b[74D\
|
\033[1B\033[74D\
|
||||||
|Prev word Esc Esc Left Run shell Esc Esc e [cmd] Return |\
|
|Prev word Esc Esc Left Run shell Esc Esc e [cmd] Return |\
|
||||||
\x1b[1B\x1b[74D\
|
\033[1B\033[74D\
|
||||||
|File start Esc Esc 8 This help Esc Esc h |\
|
|File start Esc Esc 8 This help Esc Esc h |\
|
||||||
\x1b[1B\x1b[74D\
|
\033[1B\033[74D\
|
||||||
|File end Esc Esc 9 |\
|
|File end Esc Esc 9 |\
|
||||||
\x1b[1B\x1b[74D\
|
\033[1B\033[74D\
|
||||||
| |\
|
| |\
|
||||||
\x1b[1B\x1b[74D\
|
\033[1B\033[74D\
|
||||||
| Created by Luxferre in 2023 |\
|
| Created by Luxferre in 2023 |\
|
||||||
\x1b[1B\x1b[74D\
|
\033[1B\033[74D\
|
||||||
| Released into public domain |\
|
| Released into public domain |\
|
||||||
\x1b[1B\x1b[74D\
|
\033[1B\033[74D\
|
||||||
| |\
|
| |\
|
||||||
\x1b[1B\x1b[74D\
|
\033[1B\033[74D\
|
||||||
| Press Return to exit this screen |\
|
| Press Return to exit this screen |\
|
||||||
\x1b[1B\x1b[74D\
|
\033[1B\033[74D\
|
||||||
--------------------------------------------------------------------------\x1b[u";
|
--------------------------------------------------------------------------\033[u";
|
||||||
|
|
||||||
/* elementary routines */
|
/* elementary routines */
|
||||||
|
|
||||||
@@ -432,7 +432,7 @@ uint nne_prompt(char *prompt) {
|
|||||||
nne_cmdbuf[rd-1] = 0; /* zero out the character */
|
nne_cmdbuf[rd-1] = 0; /* zero out the character */
|
||||||
rd--; /* decrement the read counter */
|
rd--; /* decrement the read counter */
|
||||||
/* move cursor back and erase until the end of the line */
|
/* move cursor back and erase until the end of the line */
|
||||||
nnmsg(1, "\x1b[%uD\x1b[0K", c == '\t' ? NNE_TABWIDTH : 1);
|
nnmsg(1, "\033[%uD\033[0K", c == '\t' ? NNE_TABWIDTH : 1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case K_ESC: case K_MODCMD: endinput = 1; rd = 0; break; /* abort */
|
case K_ESC: case K_MODCMD: endinput = 1; rd = 0; break; /* abort */
|
||||||
@@ -539,16 +539,16 @@ void render() { /* main screen rendering function */
|
|||||||
|
|
||||||
/* platform-independent terminal size detection */
|
/* platform-independent terminal size detection */
|
||||||
static void nne_termsize() {
|
static void nne_termsize() {
|
||||||
if(write(1, "\x1b[s\x1b[999C\x1b[999B", 15) != 15) return;
|
if(write(1, "\033[s\033[999C\033[999B", 15) != 15) return;
|
||||||
if(write(1, "\x1b[6n", 4) != 4) return;
|
if(write(1, "\033[6n", 4) != 4) return;
|
||||||
char buf[32], i;
|
char buf[32], i;
|
||||||
for(i=0;i<31;i++) {
|
for(i=0;i<31;i++) {
|
||||||
if(read(0, &buf[i], 1) != 1) break;
|
if(read(0, &buf[i], 1) != 1) break;
|
||||||
if(buf[i] == 'R') break;
|
if(buf[i] == 'R') break;
|
||||||
}
|
}
|
||||||
if(write(1, "\x1b[u", 3) != 3) return; /* restore the cursor position */
|
if(write(1, "\033[u", 3) != 3) return; /* restore the cursor position */
|
||||||
buf[i] = 0;
|
buf[i] = 0;
|
||||||
if(buf[0] != '\x1b' || buf[1] != '[') return;
|
if(buf[0] != '\033' || buf[1] != '[') return;
|
||||||
if(sscanf(&buf[2], "%hu;%hu", &nne_termh, &nne_termw) != 2) return;
|
if(sscanf(&buf[2], "%hu;%hu", &nne_termh, &nne_termw) != 2) return;
|
||||||
nne_scrsize = (nne_termw * nne_termh) << 2; /* update the byte size */
|
nne_scrsize = (nne_termw * nne_termh) << 2; /* update the byte size */
|
||||||
nne_scrbuf = realloc(nne_scrbuf, nne_scrsize); /* reallocate accordingly */
|
nne_scrbuf = realloc(nne_scrbuf, nne_scrsize); /* reallocate accordingly */
|
||||||
@@ -851,7 +851,7 @@ int nne_action(int key) {
|
|||||||
|
|
||||||
int main(int argc, char* argv[]) { /* editor entry point */
|
int main(int argc, char* argv[]) { /* editor entry point */
|
||||||
/* use the alternative screen buffer and enable UTF-8 */
|
/* use the alternative screen buffer and enable UTF-8 */
|
||||||
nnputs(ALTBUFON CLS "\x1b[?7h");
|
nnputs(ALTBUFON CLS "\033[?7h");
|
||||||
/* prepare screen */
|
/* prepare screen */
|
||||||
tcgetattr(0, &tty_opts_backup);
|
tcgetattr(0, &tty_opts_backup);
|
||||||
atexit(&cleanup);
|
atexit(&cleanup);
|
||||||
|
|||||||
Reference in New Issue
Block a user