/*
 *      Driver file for Cifer 2841 (ansi)
 *      - Use with UMIST.def
 */


cf41_setup()
{
        ictab[033] = ectab[033] = SPECIAL;
}

cf41_move(srow, scol)
register int srow, scol;
/* ESC [ row ; col H */
{
        ttyout('\033');
        ttyout('[');
        dedpnum(ttyout, srow+1, 10);
        ttyout(';');
        dedpnum(ttyout, scol+1, 10);
        ttyout('H');
}

int cf41_special(typein,c)
int typein;
register char c;
/* returns the character type corresponding
 * to VT100 keypad escape sequences
 */
{
        register char ch;

        if (c != '\033') editerror("character %o given to cf41_special", c);
        else
        {
                if (typein)
                {
                        ch = ttyin();
                        switch(ch)
                        {
                        case '\033' : return(ENTERedit);
                        case '[' :
                                ch = ttyin();
                                switch(ch)
                                {
                                case 'A' : return(UP);
                                case 'B' : return(DOWN);
                                case 'C' : return(RIGHT);
                                case 'D' : return(LEFT);
                                }
                        }
                complain();
                }
        return(IGN);
        }
}

struct TERMINAL cf41_ter =
 {  /* nrows, ncols - size of the screen */
    TER_ROWS, TER_COLS,

    /* up, left, c_MODIFY, c_CONTROL, c_BLOB - single characters */
    { 0, '\010', 0, 0200|'^', 0200|' ' },
        /* onechar */

    /* rollup, pushdown, pushup, pulldown, pullup STRINGS */
    /* and hardscroll boolean */
    /* you MUST have rollup */
    { "\n", 0, 0, 0, 0, false },
        /* scrseq */

    /* scrollup, scrolldown PROCEDURES */
    /* scr1_ is pushup, pulldown */
    /* scr2_ is pushdown, pullup */
    /* scr3_ is both */
    /* scr0_ is neither (and in that case hardscroll is false) */
    scr0_up, scr0_down,

    /* splitdown, splitup, joindown, joinup STRINGS */
    { 0, 0, 0, 0 },
        /* splitseq */

    /* split_row, join_row PROCEDURES */
    split0, join0,

    /* clearscreen, *clearhead, *cleartail STRINGS */
    /* I assume ^L for clear screen, but it isn't important */
    { "\033[2J\033[H", "\033[1K", "\033[K" },
        /* clrseq */

    /* clr_screen, clr_head, clr_tail PROCEDURES */
    /* I assume hardware support for clear screen at least */
    clrs1, clrh1, clrt1,

    /* inspace, makespace, rubout, erase STRINGS */
    /* inspace puts a space and moves the cursor right,
     * makespace doesn't move it. Likewise rubout moves the
     * cursor left, erase doesn't move it
     */
    { 0, 0, 0, 0 },
        /* charseq */

    /* ins_char, del_char PROCEDURES */
    /* insc1 uses inspace, insc2 makespace */
    /* delc1 uses rubout, delc2 erase */
    /* insc0, delc0 use neither */
    insc0, delc0,

    /* bright, normal STRINGS */
    { "\033[1;7m", "\033[m" },
        /* vidseq */

    /* in_two, out_two PROCEDURES */
    no_char, no_char,

    /* move PROCEDURE and nmove integer */
    cf41_move, 8,

    /* setup, special, pad PROCEDURES */
    cf41_setup, cf41_special, no_int

 };
