aboutsummaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2019-03-09 12:31:20 +0000
committerRon Yorston <rmy@pobox.com>2019-03-09 12:56:44 +0000
commit399b1dd641c16113c3340933a9b1ab1793a13d8a (patch)
treed4cb44df1df4b966fa8dd329e004b99328f31f31 /win32
parent486582a7307cf845ee52fcb6f9ede2d92c69ed86 (diff)
downloadbusybox-w32-399b1dd641c16113c3340933a9b1ab1793a13d8a.tar.gz
busybox-w32-399b1dd641c16113c3340933a9b1ab1793a13d8a.tar.bz2
busybox-w32-399b1dd641c16113c3340933a9b1ab1793a13d8a.zip
winansi: support escape sequence to set window title
To set the window title from the command line: echo -en '\e]0;Hello World\007' The same sequence can be used in the shell's prompt (PS1).
Diffstat (limited to 'win32')
-rw-r--r--win32/winansi.c44
1 files changed, 32 insertions, 12 deletions
diff --git a/win32/winansi.c b/win32/winansi.c
index 08d37335b..018b05c76 100644
--- a/win32/winansi.c
+++ b/win32/winansi.c
@@ -465,6 +465,28 @@ static BOOL winansi_OemToCharBuff(LPCSTR s, LPSTR d, DWORD len)
465# define OemToCharBuff winansi_OemToCharBuff 465# define OemToCharBuff winansi_OemToCharBuff
466#endif 466#endif
467 467
468static char *check_escapes(char *pos)
469{
470 char *str = pos+1;
471
472 switch (pos[1]) {
473 case '[':
474 str = (char *)set_attr(pos+2);
475 break;
476 case ']':
477 if ((pos[2] == '0' || pos[2] == '2') && pos[3] == ';' &&
478 (str=strchr(pos, '\007')) && str - pos < 260) {
479 *str = '\0';
480 CharToOem(pos+4, pos+4);
481 SetConsoleTitle(pos+4);
482 ++str;
483 }
484 break;
485 }
486
487 return str;
488}
489
468static int ansi_emulate(const char *s, FILE *stream) 490static int ansi_emulate(const char *s, FILE *stream)
469{ 491{
470 int rv = 0; 492 int rv = 0;
@@ -502,7 +524,7 @@ static int ansi_emulate(const char *s, FILE *stream)
502 pos = str = mem; 524 pos = str = mem;
503 525
504 while (*pos) { 526 while (*pos) {
505 pos = strstr(str, "\033["); 527 pos = strchr(str, '\033');
506 if (pos && !skip_ansi_emulation()) { 528 if (pos && !skip_ansi_emulation()) {
507 size_t len = pos - str; 529 size_t len = pos - str;
508 530
@@ -514,15 +536,16 @@ static int ansi_emulate(const char *s, FILE *stream)
514 rv += len; 536 rv += len;
515 } 537 }
516 538
517 str = pos + 2;
518 rv += 2;
519
520 if (fflush(stream) == EOF) 539 if (fflush(stream) == EOF)
521 return EOF; 540 return EOF;
522 541
523 pos = (char *)set_attr(str); 542 str = check_escapes(pos);
524 rv += pos - str; 543 rv += pos - str;
525 str = pos; 544 pos = str;
545
546 if (fflush(stream) == EOF)
547 return EOF;
548
526 } else { 549 } else {
527 rv += strlen(str); 550 rv += strlen(str);
528 CharToOem(str, str); 551 CharToOem(str, str);
@@ -750,7 +773,7 @@ static int ansi_emulate_write(int fd, const void *buf, size_t count)
750 773
751 /* we've checked the data doesn't contain any NULs */ 774 /* we've checked the data doesn't contain any NULs */
752 while (*pos) { 775 while (*pos) {
753 pos = strstr(str, "\033["); 776 pos = strchr(str, '\033');
754 if (pos && !skip_ansi_emulation()) { 777 if (pos && !skip_ansi_emulation()) {
755 len = pos - str; 778 len = pos - str;
756 779
@@ -762,12 +785,9 @@ static int ansi_emulate_write(int fd, const void *buf, size_t count)
762 rv += out_len; 785 rv += out_len;
763 } 786 }
764 787
765 str = pos + 2; 788 str = check_escapes(pos);
766 rv += 2;
767
768 pos = (char *)set_attr(str);
769 rv += pos - str; 789 rv += pos - str;
770 str = pos; 790 pos = str;
771 } else { 791 } else {
772 len = strlen(str); 792 len = strlen(str);
773 CharToOem(str, str); 793 CharToOem(str, str);