sldisply.c
来自「ReactOS是一些高手根据Windows XP的内核编写出的类XP。内核实现机」· C语言 代码 · 共 2,241 行 · 第 1/4 页
C
2,241 行
case 'r':
stack[0] = x;
stack[1] = y;
break;
case '.':
case 'c':
ch = (unsigned char) stack[--i];
if (ch == '\n') ch++;
*b++ = ch;
break;
default:
*b++ = ch;
}
}
}
*b = 0;
return((unsigned int) (b - (unsigned char *) buf));
}
static void tt_printf(char *fmt, int x, int y)
{
char buf[256];
unsigned int n;
if (fmt == NULL) return;
n = tt_sprintf(buf, fmt, x, y);
tt_write(buf, n);
}
void SLtt_set_scroll_region (int r1, int r2)
{
Scroll_r1 = r1;
Scroll_r2 = r2;
tt_printf (Scroll_R_Str, Scroll_r1, Scroll_r2);
Cursor_Set = 0;
}
void SLtt_reset_scroll_region (void)
{
SLtt_set_scroll_region(0, SLtt_Screen_Rows - 1);
}
int SLtt_set_cursor_visibility (int show)
{
if ((Cursor_Visible_Str == NULL) || (Cursor_Invisible_Str == NULL))
return -1;
SLtt_write_string (show ? Cursor_Visible_Str : Cursor_Invisible_Str);
return 0;
}
/* the goto_rc function moves to row relative to scrolling region */
void SLtt_goto_rc(int r, int c)
{
char *s = NULL;
int n;
char buf[6];
#ifdef SLTT_TRANSP_ACS_PATCH
int check_alt_acs = 0;
#endif
if (c < 0)
{
c = -c - 1;
Cursor_Set = 0;
}
/* if (No_Move_In_Standout && Current_Fgbg) SLtt_normal_video (); */
r += Scroll_r1;
if ((Cursor_Set > 0) || ((Cursor_Set < 0) && !Automatic_Margins))
{
n = r - Cursor_r;
if ((n == -1) && (Cursor_Set > 0) && (Cursor_c == c)
&& (Curs_Up_Str != NULL))
{
s = Curs_Up_Str;
}
else if ((n >= 0) && (n <= 4))
{
if ((n == 0) && (Cursor_Set == 1)
&& ((c > 1) || (c == Cursor_c)))
{
if (Cursor_c == c) return;
if (Cursor_c == c + 1)
{
s = buf;
*s++ = '\b'; *s = 0;
s = buf;
#ifdef SLTT_TRANSP_ACS_PATCH
check_alt_acs = 1;
#endif
}
}
else if (c == 0)
{
s = buf;
if ((Cursor_Set != 1) || (Cursor_c != 0)) *s++ = '\r';
while (n--) *s++ = '\n';
#ifdef VMS
/* Need to add this after \n to start a new record. Sheesh. */
*s++ = '\r';
#endif
*s = 0;
s = buf;
#ifdef SLTT_TRANSP_ACS_PATCH
check_alt_acs = 1;
#endif
}
/* Will fail on VMS */
#ifndef VMS
else if (SLtt_Newline_Ok && (Cursor_Set == 1) &&
(Cursor_c >= c) && (c + 3 > Cursor_c))
{
s = buf;
while (n--) *s++ = '\n';
n = Cursor_c - c;
while (n--) *s++ = '\b';
*s = 0;
s = buf;
#ifdef SLTT_TRANSP_ACS_PATCH
check_alt_acs = 1;
#endif
}
#endif
}
}
#ifndef SLTT_TRANSP_ACS_PATCH
if (s != NULL) SLtt_write_string(s);
#else
if (s != NULL)
{
if (check_alt_acs && SLtt_ACS_Active)
{
SLtt_set_alt_char_set (0);
SLtt_write_string(s);
SLtt_set_alt_char_set (1);
}
else SLtt_write_string(s);
}
#endif
else tt_printf(Curs_Pos_Str, r, c);
Cursor_c = c; Cursor_r = r;
Cursor_Set = 1;
}
void SLtt_begin_insert (void)
{
SLtt_write_string(Ins_Mode_Str);
}
void SLtt_end_insert (void)
{
SLtt_write_string(Eins_Mode_Str);
}
void SLtt_delete_char (void)
{
SLtt_normal_video ();
SLtt_write_string(Del_Char_Str);
}
void SLtt_erase_line (void)
{
SLtt_write_string("\r");
Cursor_Set = 1; Cursor_c = 0;
SLtt_del_eol();
}
void SLtt_delete_nlines (int n)
{
int r1, curs;
char buf[132];
#ifdef SLTT_TRANSP_ACS_PATCH
int restore_acs = 0;
#endif
if (n <= 0) return;
SLtt_normal_video ();
if (Del_N_Lines_Str != NULL) tt_printf(Del_N_Lines_Str,n, 0);
else
/* get a new terminal */
{
r1 = Scroll_r1;
curs = Cursor_r;
SLtt_set_scroll_region(curs, Scroll_r2);
SLtt_goto_rc(Scroll_r2 - Scroll_r1, 0);
#ifdef SLTT_TRANSP_ACS_PATCH
if (SLtt_ACS_Active)
{
SLtt_set_alt_char_set (0);
restore_acs = 1;
}
#endif
SLMEMSET(buf, '\n', (unsigned int) n);
tt_write(buf, (unsigned int) n);
#ifdef SLTT_TRANSP_ACS_PATCH
if (restore_acs) SLtt_set_alt_char_set (1);
#endif
/* while (n--) tt_putchar('\n'); */
SLtt_set_scroll_region(r1, Scroll_r2);
SLtt_goto_rc(curs, 0);
}
}
void SLtt_cls (void)
{
SLtt_normal_video();
SLtt_reset_scroll_region ();
SLtt_write_string(Cls_Str);
}
void SLtt_reverse_index (int n)
{
if (!n) return;
SLtt_normal_video();
if (Add_N_Lines_Str != NULL) tt_printf(Add_N_Lines_Str,n, 0);
else
{
while(n--) SLtt_write_string(Rev_Scroll_Str);
}
}
int SLtt_Ignore_Beep = 1;
static char *Visible_Bell_Str;
void SLtt_beep (void)
{
if (SLtt_Ignore_Beep & 0x1) SLtt_putchar('\007');
if (SLtt_Ignore_Beep & 0x2)
{
if (Visible_Bell_Str != NULL) SLtt_write_string (Visible_Bell_Str);
#ifdef __linux__
else if (Linux_Console)
{
SLtt_write_string ("\033[?5h");
SLtt_flush_output ();
sl_usleep (50000);
SLtt_write_string ("\033[?5l");
}
#endif
}
SLtt_flush_output ();
}
void SLtt_del_eol (void)
{
if (Current_Fgbg != 0xFFFFFFFFU) SLtt_normal_video ();
SLtt_write_string(Del_Eol_Str);
}
typedef struct
{
char *name;
SLtt_Char_Type color;
}
Color_Def_Type;
#define MAX_COLOR_NAMES 17
static Color_Def_Type Color_Defs [MAX_COLOR_NAMES] =
{
{"black", SLSMG_COLOR_BLACK},
{"red", SLSMG_COLOR_RED},
{"green", SLSMG_COLOR_GREEN},
{"brown", SLSMG_COLOR_BROWN},
{"blue", SLSMG_COLOR_BLUE},
{"magenta", SLSMG_COLOR_MAGENTA},
{"cyan", SLSMG_COLOR_CYAN},
{"lightgray", SLSMG_COLOR_LGRAY},
{"gray", SLSMG_COLOR_GRAY},
{"brightred", SLSMG_COLOR_BRIGHT_RED},
{"brightgreen", SLSMG_COLOR_BRIGHT_GREEN},
{"yellow", SLSMG_COLOR_BRIGHT_BROWN},
{"brightblue", SLSMG_COLOR_BRIGHT_BLUE},
{"brightmagenta", SLSMG_COLOR_BRIGHT_CYAN},
{"brightcyan", SLSMG_COLOR_BRIGHT_MAGENTA},
{"white", SLSMG_COLOR_BRIGHT_WHITE},
{"default", 25}
};
void SLtt_set_mono (int obj, char *what, SLtt_Char_Type mask)
{
(void) what;
if ((obj < 0) || (obj >= JMAX_COLORS))
{
return;
}
Ansi_Color_Map[obj].mono = mask & ATTR_MASK;
}
static char *check_color_for_digit_form (char *color)
{
unsigned int i, ich;
char *s = color;
i = 0;
while ((ich = (int) *s) != 0)
{
if ((ich < '0') || (ich > '9'))
return color;
i = i * 10 + (ich - '0');
s++;
}
if (i < MAX_COLOR_NAMES)
color = Color_Defs[i].name;
return color;
}
static int get_default_colors (char **fgp, char **bgp)
{
static char fg_buf[16], bg_buf[16], *bg, *fg;
static int already_parsed;
char *p, *pmax;
if (already_parsed == -1)
return -1;
if (already_parsed)
{
*fgp = fg;
*bgp = bg;
return 0;
}
already_parsed = -1;
bg = getenv ("COLORFGBG");
if (bg == NULL)
{
bg = getenv ("DEFAULT_COLORS");
if (bg == NULL)
return -1;
}
p = fg_buf;
pmax = p + (sizeof (fg_buf) - 1);
while ((*bg != 0) && (*bg != ';'))
{
if (p < pmax) *p++ = *bg;
bg++;
}
*p = 0;
if (*bg) bg++;
p = bg_buf;
pmax = p + (sizeof (bg_buf) - 1);
/* Mark suggested allowing for extra spplication specific stuff following
* the background color. That is what the check for the semi-colon is for.
*/
while ((*bg != 0) && (*bg != ';'))
{
if (p < pmax) *p++ = *bg;
bg++;
}
*p = 0;
if (!strcmp (fg_buf, "default") || !strcmp(bg_buf, "default"))
{
*fgp = *bgp = fg = bg = "default";
}
else
{
*fgp = fg = check_color_for_digit_form (fg_buf);
*bgp = bg = check_color_for_digit_form (bg_buf);
}
already_parsed = 1;
return 0;
}
static unsigned char FgBg_Stats[JMAX_COLORS];
static int Color_0_Modified = 0;
void SLtt_set_color_object (int obj, SLtt_Char_Type attr)
{
char *cust_esc;
if ((obj < 0) || (obj >= JMAX_COLORS)) return;
cust_esc = Ansi_Color_Map[obj].custom_esc;
if (cust_esc != NULL)
{
SLFREE (cust_esc);
FgBg_Stats[(Ansi_Color_Map[obj].fgbg >> 8) & 0x7F] -= 1;
Ansi_Color_Map[obj].custom_esc = NULL;
}
Ansi_Color_Map[obj].fgbg = attr;
if (obj == 0) Color_0_Modified = 1;
}
SLtt_Char_Type SLtt_get_color_object (int obj)
{
if ((obj < 0) || (obj >= JMAX_COLORS)) return 0;
return Ansi_Color_Map[obj].fgbg;
}
void SLtt_add_color_attribute (int obj, SLtt_Char_Type attr)
{
if ((obj < 0) || (obj >= JMAX_COLORS)) return;
Ansi_Color_Map[obj].fgbg |= (attr & ATTR_MASK);
if (obj == 0) Color_0_Modified = 1;
}
static SLtt_Char_Type fb_to_fgbg (SLtt_Char_Type f, SLtt_Char_Type b)
{
SLtt_Char_Type attr = 0;
if ((f & 0xF0) == 0)
{
if (f & 0x8) attr = SLTT_BOLD_MASK;
f &= 0x7;
}
else f = 9;
if ((b & 0xF0) == 0)
{
if (b & 0x8) attr |= SLTT_BLINK_MASK;
b &= 0x7;
}
else b = 9;
return ((f << 8) | (b << 16) | attr);
}
static int make_color_fgbg (char *fg, char *bg, SLtt_Char_Type *fgbg)
{
SLtt_Char_Type f = 0xFFFFFFFFU, b = 0xFFFFFFFFU;
char *dfg, *dbg;
unsigned int i;
if ((fg != NULL) && (*fg == 0)) fg = NULL;
if ((bg != NULL) && (*bg == 0)) bg = NULL;
if ((fg == NULL) || (bg == NULL))
{
if (-1 == get_default_colors (&dfg, &dbg))
return -1;
if (fg == NULL) fg = dfg;
if (bg == NULL) bg = dbg;
}
for (i = 0; i < MAX_COLOR_NAMES; i++)
{
if (strcmp(fg, Color_Defs[i].name)) continue;
f = Color_Defs[i].color;
break;
}
for (i = 0; i < MAX_COLOR_NAMES; i++)
{
if (strcmp(bg, Color_Defs[i].name)) continue;
b = Color_Defs[i].color;
break;
}
if ((f == 0xFFFFFFFFU) || (b == 0xFFFFFFFFU))
return -1;
*fgbg = fb_to_fgbg (f, b);
return 0;
}
void SLtt_set_color (int obj, char *what, char *fg, char *bg)
{
SLtt_Char_Type fgbg;
(void) what;
if ((obj < 0) || (obj >= JMAX_COLORS))
return;
if (-1 != make_color_fgbg (fg, bg, &fgbg))
SLtt_set_color_object (obj, fgbg);
}
void SLtt_set_color_fgbg (int obj, SLtt_Char_Type f, SLtt_Char_Type b)
{
SLtt_set_color_object (obj, fb_to_fgbg (f, b));
}
void SLtt_set_color_esc (int obj, char *esc)
{
char *cust_esc;
SLtt_Char_Type fgbg = 0;
int i;
if ((obj < 0) || (obj >= JMAX_COLORS))
{
return;
}
cust_esc = Ansi_Color_Map[obj].custom_esc;
if (cust_esc != NULL)
{
SLFREE (cust_esc);
FgBg_Stats[(Ansi_Color_Map[obj].fgbg >> 8) & 0x7F] -= 1;
}
cust_esc = (char *) SLMALLOC (strlen(esc) + 1);
if (cust_esc != NULL) strcpy (cust_esc, esc);
Ansi_Color_Map[obj].custom_esc = cust_esc;
if (cust_esc == NULL) fgbg = 0;
else
{
/* The whole point of this is to generate a unique fgbg */
for (i = 0; i < JMAX_COLORS; i++)
{
if (FgBg_Stats[i] == 0) fgbg = i;
if (obj == i) continue;
if ((Ansi_Color_Map[i].custom_esc) == NULL) continue;
if (!strcmp (Ansi_Color_Map[i].custom_esc, cust_esc))
{
fgbg = (Ansi_Color_Map[i].fgbg >> 8) & 0x7F;
break;
}
}
FgBg_Stats[fgbg] += 1;
}
fgbg |= 0x80;
Ansi_Color_Map[obj].fgbg = (fgbg | (fgbg << 8)) << 8;
if (obj == 0) Color_0_Modified = 1;
}
void SLtt_set_alt_char_set (int i)
{
#ifndef SLTT_TRANSP_ACS_PATCH
static int last_i;
#else
#define last_i SLtt_ACS_Active
#endif
if (SLtt_Has_Alt_Charset == 0) return;
if (i == last_i) return;
SLtt_write_string (i ? Start_Alt_Chars_Str : End_Alt_Chars_Str );
/* if (i) Current_Fgbg |= SLTT_ALTC_MASK;
else Current_Fgbg &= ~SLTT_ALTC_MASK; */
last_i = i;
#ifdef SLTT_TRANSP_ACS_PATCH
#undef last_i
#endif
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?