Exemple #1
0
static void
vidc_putchar(int c)
{
#ifdef TERM_EMU
    vidc_term_emu(c);
#else
    vidc_rawputchar(c);
#endif
}
Exemple #2
0
static void
vidc_rawputchar(int c)
{
    int		i;

    if (c == '\t')
	/* lame tab expansion */
	for (i = 0; i < 8; i++)
	    vidc_rawputchar(' ');
    else {
#ifndef TERM_EMU
        vidc_biosputchar(c);
#else
	/* Emulate AH=0eh (teletype output) */
	switch(c) {
	case '\a':
	    vidc_biosputchar(c);
	    return;
	case '\r':
	    curx = 0;
	    curs_move(&curx, &cury, curx, cury);
	    return;
	case '\n':
	    cury++;
	    if (cury > 24) {
		scroll_up(1, fg_c, bg_c);
		cury--;
	    } else {
		curs_move(&curx, &cury, curx, cury);
	    }
	    return;
	case '\b':
	    if (curx > 0) {
		curx--;
		curs_move(&curx, &cury, curx, cury);
		/* write_char(' ', fg_c, bg_c); XXX destructive(!) */
		return;
	    }
	    return;
	default:
	    write_char(c, fg_c, bg_c);
	    curx++;
	    if (curx > 79) {
		curx = 0;
		cury++;
	    }
	    if (cury > 24) {
		curx = 0;
		scroll_up(1, fg_c, bg_c);
		cury--;
	    }
	}
	curs_move(&curx, &cury, curx, cury);
#endif
    }
}
Exemple #3
0
/* Gracefully exit ESC-sequence processing in case of misunderstanding */
void
bail_out(int c)
{
    char buf[16], *ch;
    int i;

    if (esc) {
	vidc_rawputchar('\033');
	if (esc != '\033')
	    vidc_rawputchar(esc);
	for (i = 0; i <= argc; ++i) {
	    sprintf(buf, "%d", args[i]);
	    ch = buf;
	    while (*ch)
		vidc_rawputchar(*ch++);
	}
    }
    vidc_rawputchar(c);
    end_term();
}
Exemple #4
0
/* Gracefully exit ESC-sequence processing in case of misunderstanding */
void
bail_out(int c)
{
	char buf[6],*ch;

	if(esc) vidc_rawputchar('\033');
	if(br) vidc_rawputchar('[');
	if(argc>-1) {
		sprintf(buf,"%d",args[0]);
		ch=buf;
		while(*ch) vidc_rawputchar(*ch++);
		
		if(argc>0) {
			vidc_rawputchar(';');
			sprintf(buf,"%d",args[1]);
			ch=buf;
			while(*ch) vidc_rawputchar(*ch++);
		}
	}
	vidc_rawputchar(c);
	end_term();
}
Exemple #5
0
/* Emulate basic capabilities of cons25 terminal */
void
vidc_term_emu(int c)
{
    static int ansi_col[] = {
	0, 4, 2, 6, 1, 5, 3, 7,
    };
    int t;
    int i;

    switch (esc) {
    case 0:
	switch (c) {
	case '\033':
	    esc = c;
	    break;
	default:
	    vidc_rawputchar(c);
	    break;
	}
	break;

    case '\033':
	switch (c) {
	case '[':
	    esc = c;
	    args[0] = 0;
	    argc = -1;
	    break;
	default:
	    bail_out(c);
	    break;
	}
	break;

    case '[':
	switch (c) {
	case ';':
	    if (argc < 0)	/* XXX */
		argc = 0;
	    else if (argc + 1 >= MAXARGS)
		bail_out(c);
	    else
		args[++argc] = 0;
	    break;
	case 'H':
	    if (argc < 0)
		HO();
	    else if (argc == 1)
		CM();
	    else
		bail_out(c);
	    break;
	case 'J':
	    if (argc < 0)
		CD();
	    else
		bail_out(c);
	    break;
	case 'm':
	    if (argc < 0) {
		fg_c = DEFAULT_FGCOLOR;
		bg_c = DEFAULT_BGCOLOR;
	    }
	    for (i = 0; i <= argc; ++i) {
		switch (args[i]) {
		case 0:		/* back to normal */
		    fg_c = DEFAULT_FGCOLOR;
		    bg_c = DEFAULT_BGCOLOR;
		    break;
		case 1:		/* bold */
		    fg_c |= 0x8;
		    break;
		case 4:		/* underline */
		case 5:		/* blink */
		    bg_c |= 0x8;
		    break;
		case 7:		/* reverse */
		    t = fg_c;
		    fg_c = bg_c;
		    bg_c = t;
		    break;
		case 30: case 31: case 32: case 33:
		case 34: case 35: case 36: case 37:
		    fg_c = ansi_col[args[i] - 30];
		    break;
		case 39:	/* normal */
		    fg_c = DEFAULT_FGCOLOR;
		    break;
		case 40: case 41: case 42: case 43:
		case 44: case 45: case 46: case 47:
		    bg_c = ansi_col[args[i] - 40];
		    break;
		case 49:	/* normal */
		    bg_c = DEFAULT_BGCOLOR;
		    break;
		}
	    }
	    end_term();
	    break;
	default:
	    if (isdigit(c))
		get_arg(c);
	    else
		bail_out(c);
	    break;
	}
	break;

    default:
	bail_out(c);
	break;
    }
}
Exemple #6
0
/* Emulate basic capabilities of cons25 terminal */
void
vidc_term_emu(int c)
{

    if(!esc) {
	if(c=='\033') {
	    esc=1;
	} else {
	    vidc_rawputchar(c);
	}
	return;
    }

    /* Do ESC sequences processing */
    switch(c) {
    case '\033':
	/* ESC in ESC sequence - error */
	bail_out(c);
	break;
    case '[':
	/* Check if it's first char after ESC */
        if(argc<0) {
            br=1;
        } else {
	    bail_out(c);
        }
	break;
    case 'H':
	/* Emulate \E[H (cursor home) and 
	 * \E%d;%dH (cursor absolute move) */
	if(br) {
	    switch(argc) {
	    case -1:
		HO();
		break;
	    case 1:
		if(fg) args[0]+=pow10(dig)*3;
		if(bg) args[0]+=pow10(dig)*4;
		CM();
		break;
	    default:
		bail_out(c);
	    }
	} else bail_out(c);
	break;
    case 'J':
	/* Emulate \EJ (clear to end of screen) */
	if(br && argc<0) {
	    CD();
	} else bail_out(c);
	break;
    case ';':
	/* perhaps args separator */
	if(br && (argc>-1)) {
	    argc++;
	} else bail_out(c);
	break;
    case 'm':
	/* Change char attributes */
	if(br) {
	    switch(argc) {
	    case -1:
		ME();
		break;
	    case 0:
		if(fg) AF();
		else AB();
		break;
	    default:
		bail_out(c);
	    }
	} else bail_out(c);
	break;
    default:
	if(isdigit(c)) {
	    /* Carefully collect numeric arguments */
	    /* XXX this is ugly. */
	    if(br) {
	        if(argc==-1) {
	     	    argc=0;
		    args[argc]=0;
		    dig=0;
		    /* in case we're in error... */
		    if(c=='3') {
			fg=1;
			return;
		    }
		    if(c=='4') {
			bg=1;
			return;
		    }
	     	    args[argc]=(int)(c-'0');
		    dig=1;
	     	    args[argc+1]=0;
	    	} else {
		    args[argc]=args[argc]*10+(int)(c-'0');
		    if(argc==0) dig++;
	    	}
	    } else bail_out(c);
	} else bail_out(c);
	break;
    }
}