8000 minix/commands/elvis/curses.c at R3.1.0 · ledinhminh/minix · GitHub
[go: up one dir, main page]

Skip to content

Latest commit

 

History

History
executable file
·
930 lines (838 loc) · 19 KB

curses.c

File metadata and controls

executable file
·
930 lines (838 loc) · 19 KB
CQ = tgetstr("cQ", &capbuf);
if (has_CQ)
{
CX = tgetstr("cX", &capbuf);
if (!CX) CX = CQ;
CV = tgetstr("cV", &capbuf);
if (!CV) CV = CQ;
CI = tgetstr("cI", &capbuf);
if (!CI) CI = CQ;
CR = tgetstr("cR", &capbuf);
if (!CR) CR = CQ;
}
# ifndef CRUNCH
else
{
CQ = CV = "";
pair(&CQ, &CV, "ve", "vs");
CX = CI = CR = CQ;
}
# endif /* !CRUNCH */
#endif /* !NO_CURSORSHAPE */
#ifndef NO_COLOR
strcpy(SOcolor, SO);
strcpy(SEcolor, SE);
strcpy(AScolor, AS);
strcpy(AEcolor, AE);
strcpy(MDcolor, MD);
strcpy(MEcolor, ME);
strcpy(UScolor, US);
strcpy(UEcolor, UE);
# ifndef NO_POPUP
strcpy(POPUPcolor, SO);
# endif
# ifndef NO_VISIBLE
strcpy(VISIBLEcolor, MV);
# endif
#endif
}
/* This function gets the window size. It uses the TIOCGWINSZ ioctl call if
* your system has it, or tgetnum("li") and tgetnum("co") if it doesn't.
* This function is called once during initialization, and thereafter it is
* called whenever the SIGWINCH signal is sent to this process.
*/
int getsize(signo)
int signo;
{
int lines;
int cols;
#ifdef TIOCGWINSZ
struct winsize size;
#endif
#ifdef SIGWINCH
/* reset the signal vector */
signal(SIGWINCH, getsize);
#endif
/* get the window size, one way or another. */
lines = cols = 0;
#ifdef TIOCGWINSZ
if (ioctl(2, TIOCGWINSZ, &size) >= 0)
{
lines = size.ws_row;
cols = size.ws_col;
}
#endif
#if AMIGA
/* Amiga gets window size by asking the console.device */
if (!strcmp(TERMTYPE, termtype))
{
auto long len;
auto char buf[30];
Write(Output(), "\2330 q", 4); /* Ask the console.device */
len = Read(Input(), buf, 29);
buf[len] = '\000';
sscanf(&buf[5], "%d;%d", &lines, &cols);
}
#endif
if ((lines == 0 || cols == 0) && signo == 0)
{
LINES = tgetnum("li");
COLS = tgetnum("co");
}
#if MSDOS
# ifdef RAINBOW
if (!strcmp(termtype, "rainbow"))
{
/* Determine whether Rainbow is in 80-column or 132-column mode */
cols = *(unsigned char far *)0xee000f57L;
}
else
# endif
{
lines = v_rows();
cols = v_cols();
}
#endif
if (lines >= 2)
{
LINES = lines;
}
if (cols >= 30)
{
COLS = cols;
}
/* Make sure we got values that we can live with */
if (LINES < 2 || COLS < 30)
{
write(2, "Screen too small\n", (unsigned)17);
#if OSK
write(2, "\l", 1);
#endif
endwin();
exit(2);
}
#if AMIGA
if (*o_lines != LINES || *o_columns != COLS)
{
*o_lines = LINES;
*o_columns = COLS;
}
#endif
return 0;
}
/* This is a function version of addch() -- it is used by tputs() */
int faddch(ch)
int ch;
{
addch(ch);
return 0;
}
/* This function quickly adds a string to the output queue. It does *NOT*
* convert \n into <CR><LF>.
*/
void qaddstr(str)
char *str;
{
REG char *s_, *d_;
#if MSDOS
if (o_pcbios[0])
{
while (*str)
qaddch(*str++);
return;
}
#endif
for (s_=(str), d_=stdscr; *d_++ = *s_++; )
{
}
stdscr = d_ - 1;
}
/* Output the ESC sequence needed to go into any video mode, if supported */
void attrset(a)
int a;
{
do_aend();
if (a == A_BOLD)
{
do_MD();
aend = ME;
}
else if (a == A_UNDERLINE)
{
do_US();
aend = UE;
}
else if (a == A_ALTCHARSET)
{
do_AS();
aend = AE;
}
else
{
aend = "";
}
}
/* Insert a single character into the display */
void insch(ch)
int ch;
{
if (has_IM)
do_IM();
do_IC();
qaddch(ch);
if (has_EI)
do_EI();
}
void wrefresh()
{
if (stdscr != kbuf)
{
VOIDBIOS(;,ttywrite(kbuf, (unsigned)(stdscr - kbuf)));
stdscr = kbuf;
}
}
void wqrefresh()
{
if (stdscr - kbuf > 2000)
{
VOIDBIOS(stdscr = kbuf,
{
ttywrite(kbuf, (unsigned)(stdscr - kbuf));
stdscr = kbuf;
});
}
}
#ifndef NO_COLOR
/* This function is called during termination. It resets color modes */
int ansiquit()
{
/* if ANSI color terminal, then reset the colors */
if (!strcmp(UP, "\033[A"))
{
tputs("\033[37;40m\033[m", 1, faddch);
clrtoeol();
return 1;
}
return 0;
}
/* This sets the color strings that work for ANSI terminals. If the TERMCAP
* doesn't look like an ANSI terminal, then it returns FALSE. If the colors
* aren't understood, it also returns FALSE. If all goes well, it returns TRUE
*/
int ansicolor(cmode, attrbyte)
int cmode; /* mode to set, e.g. A_NORMAL */
int attrbyte; /* IBM PC attribute byte */
{
char temp[16]; /* hold the new mode string */
/* if not ANSI-ish, then fail */
if (strcmp(UP, "\033[A") && strcmp(UP, "\033OA"))
{
msg("Don't know how to set colors for this terminal");
return 0;
}
/* construct the color string */
sprintf(temp, "\033[m\033[3%c;4%c%s%sm",
"04261537"[attrbyte & 0x07],
"04261537"[(attrbyte >> 4) & 0x07],
(attrbyte & 0x08) ? ";1" : "",
(attrbyte & 0x80) ? ";5" : "");
/* stick it in the right place */
switch (cmode)
{
case A_NORMAL:
if (!strcmp(MEcolor, normalcolor))
strcpy(MEcolor, temp);
if (!strcmp(UEcolor, normalcolor))
strcpy(UEcolor, temp);
if (!strcmp(AEcolor, normalcolor))
strcpy(AEcolor, temp);
if (!strcmp(SEcolor, normalcolor))
strcpy(SEcolor, temp);
strcpy(normalcolor, temp);
tputs(normalcolor, 1, faddch);
break;
case A_BOLD:
strcpy(MDcolor, temp);
strcpy(MEcolor, normalcolor);
break;
case A_UNDERLINE:
strcpy(UScolor, temp);
strcpy(UEcolor, normalcolor);
break;
case A_ALTCHARSET:
strcpy(AScolor, temp);
strcpy(AEcolor, normalcolor);
break;
case A_STANDOUT:
strcpy(SOcolor, temp);
strcpy(SEcolor, normalcolor);
break;
#ifndef NO_POPUP
case A_POPUP:
strcpy(POPUPcolor, temp);
break;
#endif
#ifndef NO_VISIBLE
case A_VISIBLE:
strcpy(VISIBLEcolor, temp);
break;
#endif
}
return 1;
}
/* This function outputs the ESC sequence needed to switch the screen back
* to "normal" mode. On color terminals which haven't had their color set
* yet, this is one of the termcap strings; for color terminals that really
* have had colors defined, we just the "normal color" escape sequence.
*/
endcolor()
{
if (aend == ME)
tputs(MEcolor, 1, faddch);
else if (aend == UE)
tputs(UEcolor, 1, faddch);
else if (aend == AE)
tputs(AEcolor, 1, faddch);
else if (aend == SE)
tputs(SEcolor, 1, faddch);
aend = "";
return 0;
}
#endif /* !NO_COLOR */
0