Skip to content

Commit

Permalink
Shrink tty routines, maybe make some faster
Browse files Browse the repository at this point in the history
  • Loading branch information
ccoffing committed Jan 7, 2024
1 parent 23a7377 commit d6ce2fa
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
8 changes: 3 additions & 5 deletions elkscmd/tui/cons.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ static void display(void)
unsigned short __far *chattr = MK_FP(0xb800, 0);
char buf[16];

printf("\e[H");
fputs("\e[H", stdout);
for (r=0; r<LINES; r++) {
a = -1;
for (c=0; c<COLS; c++) {
Expand All @@ -55,11 +55,9 @@ static void display(void)
fputs(buf, stdout);
}
}
if (r == LINES - 1)
printf("\r");
else printf("\n");
putc(r == LINES - 1 ? '\r' : '\n', stdout);
}
printf("\e[1;0;0m");
fputs("\e[1;0;0m", stdout);
fflush(stdout);
}

Expand Down
28 changes: 23 additions & 5 deletions elkscmd/tui/tty-cp437.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ static char *attr_to_ansi(char *buf, unsigned int attr)
#if ELKS
static int elks_displayable(int c)
{
/* switch kept as documentation;
* bit tests below are smaller and faster
*/
#if 0
switch (c) {
case '\0':
case '\007':
Expand All @@ -71,6 +75,22 @@ static int elks_displayable(int c)
return 0;
}
return 1;
#else
/* Not displayable:
* \0 0x00 0001
* \007 0x07 0080
* \b 0x08 0100
* \t 0x09 0200
* \n 0x0a 0400
* \r 0x0d 2000
* \033 0x1d
*/
if (c == '\033')
return 0;
if (c & 0xFFF0)
return 1;
return ~0x2781 & (1U << c);
#endif
}
#endif

Expand Down Expand Up @@ -109,7 +129,7 @@ void tty_output_screen(int flush)
unsigned short *chattr = (unsigned short *)video_ram;
char buf[16];

printf("\e[?25l\e[H"); /* cursor off, home */
fputs("\e[?25l\e[H", stdout); /* cursor off, home */
for (r=0; r<LINES; r++) {
a = -1;
for (c=0; c<COLS; c++) {
Expand All @@ -121,11 +141,9 @@ void tty_output_screen(int flush)
if (cp437tostr(buf, b & 255))
fputs(buf, stdout);
}
if (r == LINES - 1)
printf("\r");
else printf("\n");
putc(r == LINES - 1 ? '\r' : '\n', stdout);
}
printf("\e[1;0;0m"); /* reset attrs, cursor left off */
fputs("\e[1;0;0m", stdout); /* reset attrs, cursor left off */
if (flush)
fflush(stdout);
}
4 changes: 1 addition & 3 deletions elkscmd/tui/tty.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@ int tty_iselksconsole(int fd)
char *p = ttyname(fd);

if (!p) return 0;
return !strcmp(p, "/dev/tty1") ||
!strcmp(p, "/dev/tty2") ||
!strcmp(p, "/dev/tty3");
return !strncmp(p, "/dev/tty", 8) && p[8] >= '1' && p[8] <= '3';
#else
return 0;
#endif
Expand Down

0 comments on commit d6ce2fa

Please sign in to comment.