unsigned long ticks;
static void toggle_mode(Terminal *term, int mode, int query, int state){    unsigned long ticks;    if (query)	switch (mode) {	  case 1:		       /* DECCKM: application cursor keys */	    term->app_cursor_keys = state;	    break;	  case 2:		       /* DECANM: VT52 mode */	    term->vt52_mode = !state;	    if (term->vt52_mode) {		term->blink_is_real = FALSE;		term->vt52_bold = FALSE;	    } else {		term->blink_is_real = term->cfg.blinktext;	    }	    break;	  case 3:		       /* DECCOLM: 80/132 columns */	    deselect(term);	    if (!term->cfg.no_remote_resize)		request_resize(term->frontend, state ? 132 : 80, term->rows);	    term->reset_132 = state;	    term->alt_t = term->marg_t = 0;	    term->alt_b = term->marg_b = term->rows - 1;	    move(term, 0, 0, 0);	    erase_lots(term, FALSE, TRUE, TRUE);	    break;	  case 5:		       /* DECSCNM: reverse video */	    /*	     * Toggle reverse video. If we receive an OFF within the	     * visual bell timeout period after an ON, we trigger an	     * effective visual bell, so that ESC[?5hESC[?5l will	     * always be an actually _visible_ visual bell.	     */	    ticks = GETTICKCOUNT();	    /* turn off a previous vbell to avoid inconsistencies */	    if (ticks - term->vbell_startpoint >= VBELL_TIMEOUT)		term->in_vbell = FALSE;	    if (term->rvideo && !state &&    /* we're turning it off... */		(ticks - term->rvbell_startpoint) < VBELL_TIMEOUT) {/*...soon*/		/* If there's no vbell timeout already, or this one lasts		 * longer, replace vbell_timeout with ours. */		if (!term->in_vbell ||		    (term->rvbell_startpoint - term->vbell_startpoint <		     VBELL_TIMEOUT))		    term->vbell_startpoint = term->rvbell_startpoint;		term->in_vbell = TRUE; /* may clear rvideo but set in_vbell */	    } else if (!term->rvideo && state) {		/* This is an ON, so we notice the time and save it. */		term->rvbell_startpoint = ticks;	    }	    term->rvideo = state;	    term->seen_disp_event = TRUE;	    if (state)		term_update(term);	    break;	  case 6:		       /* DECOM: DEC origin mode */	    term->dec_om = state;	    break;	  case 7:		       /* DECAWM: auto wrap */	    term->wrap = state;	    break;	  case 8:		       /* DECARM: auto key repeat */	    term->repeat_off = !state;	    break;	  case 10:		       /* DECEDM: set local edit mode */	    term->term_editing = state;	    if (term->ldisc)	       /* cause ldisc to notice changes */		ldisc_send(term->ldisc, NULL, 0, 0);	    break;	  case 25:		       /* DECTCEM: enable/disable cursor */	    compatibility2(OTHER, VT220);	    term->cursor_on = state;	    term->seen_disp_event = TRUE;	    break;	  case 47:		       /* alternate screen */	    compatibility(OTHER);	    deselect(term);	    swap_screen(term, term->cfg.no_alt_screen ? 0 : state, FALSE, FALSE);	    term->disptop = 0;	    break;	  case 1000:		       /* xterm mouse 1 */	    term->xterm_mouse = state ? 1 : 0;	    set_raw_mouse_mode(term->frontend, state);	    break;	  case 1002:		       /* xterm mouse 2 */	    term->xterm_mouse = state ? 2 : 0;	    set_raw_mouse_mode(term->frontend, state);	    break;	  case 1047:                   /* alternate screen */	    compatibility(OTHER);	    deselect(term);	    swap_screen(term, term->cfg.no_alt_screen ? 0 : state, TRUE, TRUE);	    term->disptop = 0;	    break;	  case 1048:                   /* save/restore cursor */	    if (!term->cfg.no_alt_screen)                save_cursor(term, state);	    if (!state) term->seen_disp_event = TRUE;	    break;	  case 1049:                   /* cursor & alternate screen */	    if (state && !term->cfg.no_alt_screen)		save_cursor(term, state);	    if (!state) term->seen_disp_event = TRUE;	    compatibility(OTHER);	    deselect(term);	    swap_screen(term, term->cfg.no_alt_screen ? 0 : state, TRUE, FALSE);	    if (!state && !term->cfg.no_alt_screen)		save_cursor(term, state);	    term->disptop = 0;	    break;    } else	switch (mode) {	  case 4:		       /* IRM: set insert mode */	    compatibility(VT102);	    term->insert = state;	    break;	  case 12:		       /* SRM: set echo mode */	    term->term_echoing = !state;	    if (term->ldisc)	       /* cause ldisc to notice changes */		ldisc_send(term->ldisc, NULL, 0, 0);	    break;	  case 20:		       /* LNM: Return sends ... */	    term->cr_lf_return = state;	    break;	  case 34:		       /* WYULCURM: Make cursor BIG */	    compatibility2(OTHER, VT220);	    term->big_cursor = !state;	}}