Beispiel #1
0
Datei: util.c Projekt: kjk/qemacs
void keytostr(char *buf, int buf_size, int key)
{
    int i;
    char buf1[32];
    
    for (i = 0; i < (int)(sizeof(keycodes)/sizeof(keycodes[0])); i++) {
        if (keycodes[i] == key) {
            pstrcpy(buf, buf_size, keystr[i]);
            return;
        }
    }
    if (key >= KEY_META(0) && key <= KEY_META(0xff)) {
        keytostr(buf1, sizeof(buf1), key & 0xff);
        snprintf(buf, buf_size, "M-%s", buf1);
    } else if (key >= KEY_CTRL('a') && key <= KEY_CTRL('z')) {
        snprintf(buf, buf_size, "C-%c", key + 'a' - 1);
    } else if (key >= KEY_F1 && key <= KEY_F20) {
        snprintf(buf, buf_size, "f%d", key - KEY_F1 + 1);
    } else if (key > 32 && key < 127 && buf_size >= 2) {
        buf[0] = key;
        buf[1] = '\0';
    } else {
        char *q;
        q = utf8_encode(buf1, key);
        *q = '\0';
        pstrcpy(buf, buf_size, buf1);
    }
}
Beispiel #2
0
int strtokey(const char **pp)
{
    const char *p;
    int key;

    /* XXX: handle all cases */
    p = *pp;
    if (p[0] == 'C' && p[1] == '-') {
        /* control */
        p += 2;
        key = strtokey1(p);
        if (key >= 'a' && key <= 'z')
            key = KEY_CTRL(key);
    } else if (p[0] == 'M' && p[1] == '-') { 
        p += 2;
        key = strtokey1(p);
        if ((key >= 'a' && key <= 'z') ||
            key == KEY_BACKSPACE)
            key = KEY_META(key);
    } else {
        key = strtokey1(p);
    }
    while (*p != ' ' && *p != '\0')
        p++;
    *pp = p;
    return key;
}
Beispiel #3
0
/*
	the reverse of Ansi_Color()
*/
int Color_Ansi(User *usr, int value) {
int i;

/*
	if (value == 5)
		return KEY_CTRL('F');
*/
	if (!value)
		return KEY_CTRL('N');

	for(i = 0; i < NUM_COLORS; i++) {
		if (color_table[usr->colors[i]].value == value)
			return color_table[usr->colors[i]].key;
	}
	return KEY_CTRL('G');
}
Beispiel #4
0
/* Page through a buffer string
 *	buf	Buffer to page through
 */
void rosh_more_buf(char *buf, int buflen, int rows, int cols, char *scrbuf)
{
    char *bufp, *bufeol, *bufeol2;	/* Pointer to current and next
					   end-of-line position in buffer */
    int bufpos, bufcnt;		/* current position, count characters */
    int inc;
    int i, numln;		/* Index, Number of lines */
    int elpl;		/* Extra lines per line read */

    (void)cols;

    bufpos = 0;
    bufp = buf + bufpos;
    bufeol = bufp;
    numln = rows - 1;
    ROSH_DEBUG("--(%d)\n", buflen);
    while (bufpos < buflen) {
	for (i = 0; i < numln; i++) {
	    bufeol2 = strchr(bufeol, '\n');
	    if (bufeol2 == NULL) {
		bufeol = buf + buflen;
		i = numln;
	    } else {
		elpl = ((bufeol2 - bufeol - 1) / cols);
		if (elpl < 0)
		    elpl = 0;
		i += elpl;
		ROSH_DEBUG2("  %d/%d  ", elpl, i+1);
		/* If this will not push too much, use it */
		/* but if it's the first line, use it */
		/* //HERE: We should probably snip the line off */
		if ((i < numln) || (i == elpl))
		    bufeol = bufeol2 + 1;
	    }
	}
	ROSH_DEBUG2("\n");
	bufcnt = bufeol - bufp;
	printf("--(%d/%d @%d)\n", bufcnt, buflen, bufpos);
	memcpy(scrbuf, bufp, bufcnt);
	scrbuf[bufcnt] = 0;
	printf("%s", scrbuf);
	bufp = bufeol;
	bufpos += bufcnt;
	if (bufpos == buflen)
	    break;
	inc = rosh_getkey();
	numln = 1;
	switch (inc) {
	case KEY_CTRL('c'):
	case 'q':
	case 'Q':
	    bufpos = buflen;
	    break;
	case ' ':
	    numln = rows - 1;
	}
    }
}				/* rosh_more_buf */
Beispiel #5
0
void QEQtView::closeEvent(QCloseEvent *event)
{
    qWarning() << Q_FUNC_INFO;
    QEEvent ev;

    // cancel pending operation
    ev.key_event.type = QE_KEY_EVENT;
    ev.key_event.key = KEY_CTRL('g');
    qe_handle_event(&ev);

    // simulate C-x C-c
    ev.key_event.type = QE_KEY_EVENT;
    ev.key_event.key = KEY_CTRL('x');
    qe_handle_event(&ev);

    ev.key_event.type = QE_KEY_EVENT;
    ev.key_event.key = KEY_CTRL('c');
    qe_handle_event(&ev);

    event->accept();
}
Beispiel #6
0
int color_by_name(char *name) {
int i;

	for(i = 0; i < NUM_COLORS; i++) {
		if (i == HOTKEY)
			continue;

		if (!cstricmp(name, color_table[i].name))
			return color_table[i].key;
	}
/*
	if (!cstricmp(name, "blink") || !cstricmp(name, "flash"))
		return KEY_CTRL('F');
*/
	if (!cstricmp(name, "hotkey"))
		return KEY_CTRL('K');

	if (!cstricmp(name, "beep"))
		return KEY_CTRL('A');

	if (!cstricmp(name, "normal"))
		return KEY_CTRL('N');

	if (!cstricmp(name, "default"))
		return KEY_CTRL('D');

	if (!cstricmp(name, "cr"))
		return KEY_CTRL('X');

	if (!cstricmp(name, "lt"))
		return '<';

	if (!cstricmp(name, "gt"))
		return '>';

	return 0;
}
Beispiel #7
0
//HERE: minor pagination issue; sometimes prints 1 less than rows
void rosh_more_buf(char *buf, int buflen, int rows, int cols)
{
    char *bufp, *bufeol, *bufeol2;	/* Pointer to current and next
					   end-of-line position in buffer */
    int bufpos, bufcnt;		/* current position, count characters */
    char scrbuf[ROSH_SBUF_SZ];
    int inc;
    int i, numln;		/* Index, Number of lines */

    (void)cols;

    bufpos = 0;
    bufp = buf + bufpos;
    bufeol = bufp;
    numln = rows - 1;
    ROSH_DEBUG("--(%d)\n", buflen);
    while (bufpos < buflen) {
	for (i = 0; i < numln; i++) {
	    bufeol2 = strchr(bufeol, '\n');
	    if (bufeol2 == NULL) {
		bufeol = buf + buflen;
		i = numln;
	    } else {
		i += ((bufeol2 - bufeol) / cols);
		bufeol = bufeol2 + 1;
	    }
	}
	bufcnt = bufeol - bufp;
	printf("--(%d/%d @%d)\n", bufcnt, buflen, bufpos);
	memcpy(scrbuf, bufp, bufcnt);
	scrbuf[bufcnt] = 0;
	printf("%s", scrbuf);
	bufp = bufeol;
	bufpos += bufcnt;
	if (bufpos == buflen)
	    break;
	inc = rosh_getkey();
	numln = 1;
	switch (inc) {
	case KEY_CTRL('c'):
	case 'q':
	case 'Q':
	    bufpos = buflen;
	    break;
	case ' ':
	    numln = rows - 1;
	}
    }
}				/* rosh_more_buf */
Beispiel #8
0
void clear_screen(User *usr) {
char cls[2];

	if (usr == NULL)
		return;

	if (usr->runtime_flags & RTF_BUFFER_TEXT)
		return;

	if (!(usr->flags & (USR_ANSI|USR_BOLD)))
		return;

	cls[0] = KEY_CTRL('L');
	cls[1] = 0;

	Put(usr, cls);
}
Beispiel #9
0
Datei: util.c Projekt: kjk/qemacs
int strtokey(const char **pp)
{
    const char *p;
    int key;

    p = *pp;
    if (p[0] == 'M' && p[1] == '-') {
        p += 2;
        key = KEY_META(strtokey1(&p));
    } else
    if (p[0] == 'C' && p[1] == '-' && p[0] == 'M' && p[1] == '-') {
        p += 4;
        key = KEY_META(KEY_CTRL(strtokey1(&p)));
    } else {
        key = strtokey1(&p);
    }
    *pp = p;
    return key;
}
Beispiel #10
0
Datei: util.c Projekt: kjk/qemacs
/* CG: this code is still quite inelegant */
static int strtokey1(const char **pp)
{
    const char *p, *p1, *q;
    int i, key;

    /* should return KEY_NONE at end and KEY_UNKNOWN if unrecognized */
    p = *pp;

    /* scan for separator */
    for (p1 = p; *p1 && *p1 != ' '; p1++)
        continue;

    for (i = 0; i < sizeof(keycodes)/sizeof(keycodes[0]); i++) {
        if (strstart(p, keystr[i], &q) && q == p1) {
            key = keycodes[i];
            *pp = p1;
            return key;
        }
    }
#if 0
    if (p[0] == 'f' && p[1] >= '1' && p[1] <= '9') {
        i = p[1] - '0';
        p += 2;
        if (p1 == isdigit((unsigned char)*p))
            i = i * 10 + *p++ - '0';
        key = KEY_F1 + i - 1;
        *pp = p1;
        return key;
    }
#endif
    if (p[0] == 'C' && p[1] == '-' && p1 == p + 3) {
        /* control */
        key = KEY_CTRL(p[2]);
    } else {
        key = utf8_decode(&p);
    }
    *pp = p1;

    return key;
}
Beispiel #11
0
/*
	try to determine the length of the next word
	this is used by the word wrapper in Out()
	do NOT try to use this function for anything else, because it is
	way crappy
	scans at most only 15 characters ahead
*/
int word_len(char *str) {
int len;

	len = 0;
	while(*str) {
		switch(*str) {
			case '<':
				str += skip_long_color_code(str)-1;
				break;

			case KEY_CTRL('X'):
			case '\r':
				return -10000;		/* fool him */

			case ' ':
			case '\n':
			case '\t':
				return len;

			default:
				if (cstrchr(Wrap_Charset1, *str) != NULL) {
					len++;
					return len;
				}
				if (cstrchr(Wrap_Charset2, *str) != NULL)
					return len;

/* count as printable character (this is NOT always the case, however) */
				if (*str >= ' ' && *str <= '~') {
					len++;
					if (len >= 15)
						return len;
				}
		}
		if (*str)
			str++;
	}
	return len;
}
Beispiel #12
0
static const char *edit_cmdline(const char *input, int top)
{
    static char cmdline[MAX_CMDLINE_LEN];
    int key, len, prev_len, cursor;
    int redraw = 1;		/* We enter with the menu already drawn */

    strlcpy(cmdline, input, MAX_CMDLINE_LEN);
    cmdline[MAX_CMDLINE_LEN - 1] = '\0';

    len = cursor = strlen(cmdline);
    prev_len = 0;

    for (;;) {
	if (redraw > 1) {
	    /* Clear and redraw whole screen */
	    /* Enable ASCII on G0 and DEC VT on G1; do it in this order
	       to avoid confusing the Linux console */
	    clear_screen();
	    draw_menu(-1, top, 1);
	    prev_len = 0;
	}

	if (redraw > 0) {
	    /* Redraw the command line */
	    printf("\033[?25l\033[%d;1H\1#9> \2#10%s",
		   CMDLINE_ROW, pad_line(cmdline, 0, max(len, prev_len)));
	    printf("\2#10\033[%d;3H%s\033[?25h",
		   CMDLINE_ROW, pad_line(cmdline, 0, cursor));
	    prev_len = len;
	    redraw = 0;
	}

	key = mygetkey(0);

	switch (key) {
	case KEY_CTRL('L'):
	    redraw = 2;
	    break;

	case KEY_ENTER:
	case KEY_CTRL('J'):
	    return cmdline;

	case KEY_ESC:
	case KEY_CTRL('C'):
	    return NULL;

	case KEY_BACKSPACE:
	case KEY_DEL:
	    if (cursor) {
		memmove(cmdline + cursor - 1, cmdline + cursor,
			len - cursor + 1);
		len--;
		cursor--;
		redraw = 1;
	    }
	    break;

	case KEY_CTRL('D'):
	case KEY_DELETE:
	    if (cursor < len) {
		memmove(cmdline + cursor, cmdline + cursor + 1, len - cursor);
		len--;
		redraw = 1;
	    }
	    break;

	case KEY_CTRL('U'):
	    if (len) {
		len = cursor = 0;
		cmdline[len] = '\0';
		redraw = 1;
	    }
	    break;

	case KEY_CTRL('W'):
	    if (cursor) {
		int prevcursor = cursor;

		while (cursor && my_isspace(cmdline[cursor - 1]))
		    cursor--;

		while (cursor && !my_isspace(cmdline[cursor - 1]))
		    cursor--;

		memmove(cmdline + cursor, cmdline + prevcursor,
			len - prevcursor + 1);
		len -= (prevcursor - cursor);
		redraw = 1;
	    }
	    break;

	case KEY_LEFT:
	case KEY_CTRL('B'):
	    if (cursor) {
		cursor--;
		redraw = 1;
	    }
	    break;

	case KEY_RIGHT:
	case KEY_CTRL('F'):
	    if (cursor < len) {
		putchar(cmdline[cursor++]);
	    }
	    break;

	case KEY_CTRL('K'):
	    if (cursor < len) {
		cmdline[len = cursor] = '\0';
		redraw = 1;
	    }
	    break;

	case KEY_HOME:
	case KEY_CTRL('A'):
	    if (cursor) {
		cursor = 0;
		redraw = 1;
	    }
	    break;

	case KEY_END:
	case KEY_CTRL('E'):
	    if (cursor != len) {
		cursor = len;
		redraw = 1;
	    }
	    break;

	case KEY_F1:
	case KEY_F2:
	case KEY_F3:
	case KEY_F4:
	case KEY_F5:
	case KEY_F6:
	case KEY_F7:
	case KEY_F8:
	case KEY_F9:
	case KEY_F10:
	case KEY_F11:
	case KEY_F12:
	    show_fkey(key);
	    redraw = 1;
	    break;

	default:
	    if (key >= ' ' && key <= 0xFF && len < MAX_CMDLINE_LEN - 1) {
		if (cursor == len) {
		    cmdline[len] = key;
		    cmdline[++len] = '\0';
		    cursor++;
		    putchar(key);
		    prev_len++;
		} else {
		    memmove(cmdline + cursor + 1, cmdline + cursor,
			    len - cursor + 1);
		    cmdline[cursor++] = key;
		    len++;
		    redraw = 1;
		}
	    }
	    break;
	}
    }
}
Beispiel #13
0
int Ansi_Color(User *usr, int c) {
	if (usr == NULL)
		return 0;

	switch(c) {
		case KEY_CTRL('Z'):
			c = BLACK;
			break;

		case KEY_CTRL('R'):
			c = RED;
			break;

		case KEY_CTRL('G'):
			c = GREEN;
			break;

		case KEY_CTRL('Y'):
			c = YELLOW;
			break;

		case KEY_CTRL('B'):
			c = BLUE;
			break;

		case KEY_CTRL('P'):
		case KEY_CTRL('M'):
			c = MAGENTA;
			break;

		case KEY_CTRL('C'):
			c = CYAN;
			break;

		case KEY_CTRL('W'):
			c = WHITE;
			break;

		case KEY_CTRL('K'):
			c = HOTKEY;
			break;

		case KEY_CTRL('D'):
			return 33;

/*
		case KEY_CTRL('F'):
			return 5;
*/
		case KEY_CTRL('N'):
			return 0;

		default:
			c = 0;
	}
	return color_table[usr->colors[c]].value;
}
Beispiel #14
0
#include "state_room.h"

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <ctype.h>


#define HACK_CHANCE	((rand() % 20) < 4)


ColorTable color_table[NUM_COLORS] = {
	{ "Black",		30,	KEY_CTRL('Z')	},
	{ "Red",		31,	KEY_CTRL('R')	},
	{ "Green",		32,	KEY_CTRL('G')	},
	{ "Yellow",		33,	KEY_CTRL('Y')	},
	{ "Blue",		34,	KEY_CTRL('B')	},
	{ "Magenta",	35,	KEY_CTRL('M')	},
	{ "Cyan",		36,	KEY_CTRL('C')	},
	{ "White",		37,	KEY_CTRL('W')	},
	{ "Hotkeys",	33, KEY_CTRL('K')	}
};

char *Default_Symbols = DEFAULT_SYMBOLS;


int Out(User *usr, char *str) {
	if (usr == NULL || str == NULL || !*str)
Beispiel #15
0
static void bufed_mode_close(EditState *s)
{
    BufedState *bs = s->mode_data;

    free_strings(&bs->items);

    list_mode.mode_close(s);
}

/* specific bufed commands */
static CmdDef bufed_commands[] = {
    CMD1( KEY_RET, KEY_RIGHT,
          "bufed-select", bufed_select, 0)
    /* bufed-abort should restore previous buffer in right-window */
    CMD1( KEY_CTRL('g'), KEY_NONE,
          "bufed-abort", do_delete_window, 0)
    CMD0( ' ', KEY_CTRL('t'),
          "bufed-toggle-selection", list_toggle_selection)
    /* BS should go back to previous item and unmark it */
    //CMD1( 'u', KEY_NONE, "bufed-unmark", bufed_mark, ' ')
    CMD0( '~', KEY_NONE,
          "bufed-clear-modified", bufed_clear_modified)
    CMD0( '%', KEY_NONE,
          "bufed-toggle-read-only", bufed_toggle_read_only)
    CMD1( 'a', KEY_NONE,
          "bufed-toggle-all-visible", bufed_refresh, 1)
    CMD1( 'n', KEY_NONE,
          "next-line", do_up_down, 1)
    CMD1( 'p', KEY_NONE,
          "previous-line", do_up_down, -1)
Beispiel #16
0
static const char *run_menu(void)
{
    int key;
    int done = 0;
    volatile int entry = cm->curentry;
    int prev_entry = -1;
    volatile int top = cm->curtop;
    int prev_top = -1;
    int clear = 1, to_clear;
    const char *cmdline = NULL;
    volatile clock_t key_timeout, timeout_left, this_timeout;
    const struct menu_entry *me;
    bool hotkey = false;

    /* Note: for both key_timeout and timeout == 0 means no limit */
    timeout_left = key_timeout = cm->timeout;

    /* If we're in shiftkey mode, exit immediately unless a shift key
       is pressed */
    if (shiftkey && !shift_is_held()) {
	return cm->menu_entries[cm->defentry]->cmdline;
    } else {
	shiftkey = 0;
    }

    /* Do this before hiddenmenu handling, so we show the background */
    prepare_screen_for_menu();

    /* Handle hiddenmenu */
    if (hiddenmenu) {
	cmdline = do_hidden_menu();
	if (cmdline)
	    return cmdline;

	/* Otherwise display the menu now; the timeout has already been
	   cancelled, since the user pressed a key. */
	hiddenmenu = 0;
	key_timeout = 0;
    }

    /* Handle both local and global timeout */
    if (setjmp(timeout_jump)) {
	entry = cm->defentry;

	if (top < 0 || top < entry - MENU_ROWS + 1)
	    top = max(0, entry - MENU_ROWS + 1);
	else if (top > entry || top > max(0, cm->nentries - MENU_ROWS))
	    top = min(entry, max(0, cm->nentries - MENU_ROWS));

	draw_menu(cm->ontimeout ? -1 : entry, top, 1);
	cmdline =
	    cm->ontimeout ? cm->ontimeout : cm->menu_entries[entry]->cmdline;
	done = 1;
    }

    while (!done) {
	if (entry <= 0) {
	    entry = 0;
	    while (entry < cm->nentries && is_disabled(cm->menu_entries[entry]))
		entry++;
	}
	if (entry >= cm->nentries - 1) {
	    entry = cm->nentries - 1;
	    while (entry > 0 && is_disabled(cm->menu_entries[entry]))
		entry--;
	}

	me = cm->menu_entries[entry];

	if (top < 0 || top < entry - MENU_ROWS + 1)
	    top = max(0, entry - MENU_ROWS + 1);
	else if (top > entry || top > max(0, cm->nentries - MENU_ROWS))
	    top = min(entry, max(0, cm->nentries - MENU_ROWS));

	/* Start with a clear screen */
	if (clear) {
	    /* Clear and redraw whole screen */
	    /* Enable ASCII on G0 and DEC VT on G1; do it in this order
	       to avoid confusing the Linux console */
	    if (clear >= 2)
		prepare_screen_for_menu();
	    clear_screen();
	    clear = 0;
	    prev_entry = prev_top = -1;
	}

	if (top != prev_top) {
	    draw_menu(entry, top, 1);
	    display_help(me->helptext);
	} else if (entry != prev_entry) {
	    draw_row(prev_entry - top + 4 + VSHIFT, entry, top, 0, 0);
	    draw_row(entry - top + 4 + VSHIFT, entry, top, 0, 0);
	    display_help(me->helptext);
	}

	prev_entry = entry;
	prev_top = top;
	cm->curentry = entry;
	cm->curtop = top;

	/* Cursor movement cancels timeout */
	if (entry != cm->defentry)
	    key_timeout = 0;

	if (key_timeout) {
	    int tol = timeout_left / CLK_TCK;
	    print_timeout_message(tol, TIMEOUT_ROW, cm->messages[MSG_AUTOBOOT]);
	    to_clear = 1;
	} else {
	    to_clear = 0;
	}

	if (hotkey && me->immediate) {
	    /* If the hotkey was flagged immediate, simulate pressing ENTER */
	    key = KEY_ENTER;
	} else {
	    this_timeout = min(min(key_timeout, timeout_left),
			       (clock_t) CLK_TCK);
	    key = mygetkey(this_timeout);

	    if (key != KEY_NONE) {
		timeout_left = key_timeout;
		if (to_clear)
		    printf("\033[%d;1H\1#0\033[K", TIMEOUT_ROW);
	    }
	}

	hotkey = false;

	switch (key) {
	case KEY_NONE:		/* Timeout */
	    /* This is somewhat hacky, but this at least lets the user
	       know what's going on, and still deals with "phantom inputs"
	       e.g. on serial ports.

	       Warning: a timeout will boot the default entry without any
	       password! */
	    if (key_timeout) {
		if (timeout_left <= this_timeout)
		    longjmp(timeout_jump, 1);

		timeout_left -= this_timeout;
	    }
	    break;

	case KEY_CTRL('L'):
	    clear = 1;
	    break;

	case KEY_ENTER:
	case KEY_CTRL('J'):
	    key_timeout = 0;	/* Cancels timeout */
	    if (me->passwd) {
		clear = 1;
		done = ask_passwd(me->passwd);
	    } else {
		done = 1;
	    }
	    cmdline = NULL;
	    if (done) {
		switch (me->action) {
		case MA_CMD:
		    cmdline = me->cmdline;
		    break;
		case MA_SUBMENU:
		case MA_GOTO:
		case MA_EXIT:
		    done = 0;
		    clear = 2;
		    cm = me->submenu;
		    entry = cm->curentry;
		    top = cm->curtop;
		    break;
		case MA_QUIT:
		    /* Quit menu system */
		    done = 1;
		    clear = 1;
		    draw_row(entry - top + 4 + VSHIFT, -1, top, 0, 0);
		    break;
		case MA_HELP:
		    key = show_message_file(me->cmdline, me->background);
		    /* If the exit was an F-key, display that help screen */
		    show_fkey(key);
		    done = 0;
		    clear = 1;
		    break;
		default:
		    done = 0;
		    break;
		}
	    }
	    if (done && !me->passwd) {
		/* Only save a new default if we don't have a password... */
		if (me->save && me->label) {
		    syslinux_setadv(ADV_MENUSAVE, strlen(me->label), me->label);
		    syslinux_adv_write();
		}
	    }
	    break;

	case KEY_UP:
	case KEY_CTRL('P'):
	    while (entry > 0) {
		entry--;
		if (entry < top)
		    top -= MENU_ROWS;
		if (!is_disabled(cm->menu_entries[entry]))
		    break;
	    }
	    break;

	case KEY_DOWN:
	case KEY_CTRL('N'):
	    while (entry < cm->nentries - 1) {
		entry++;
		if (entry >= top + MENU_ROWS)
		    top += MENU_ROWS;
		if (!is_disabled(cm->menu_entries[entry]))
		    break;
	    }
	    break;

	case KEY_PGUP:
	case KEY_LEFT:
	case KEY_CTRL('B'):
	case '<':
	    entry -= MENU_ROWS;
	    top -= MENU_ROWS;
	    while (entry > 0 && is_disabled(cm->menu_entries[entry])) {
		entry--;
		if (entry < top)
		    top -= MENU_ROWS;
	    }
	    break;

	case KEY_PGDN:
	case KEY_RIGHT:
	case KEY_CTRL('F'):
	case '>':
	case ' ':
	    entry += MENU_ROWS;
	    top += MENU_ROWS;
	    while (entry < cm->nentries - 1
		   && is_disabled(cm->menu_entries[entry])) {
		entry++;
		if (entry >= top + MENU_ROWS)
		    top += MENU_ROWS;
	    }
	    break;

	case '-':
	    while (entry > 0) {
		entry--;
		top--;
		if (!is_disabled(cm->menu_entries[entry]))
		    break;
	    }
	    break;

	case '+':
	    while (entry < cm->nentries - 1) {
		entry++;
		top++;
		if (!is_disabled(cm->menu_entries[entry]))
		    break;
	    }
	    break;

	case KEY_CTRL('A'):
	case KEY_HOME:
	    top = entry = 0;
	    break;

	case KEY_CTRL('E'):
	case KEY_END:
	    entry = cm->nentries - 1;
	    top = max(0, cm->nentries - MENU_ROWS);
	    break;

	case KEY_F1:
	case KEY_F2:
	case KEY_F3:
	case KEY_F4:
	case KEY_F5:
	case KEY_F6:
	case KEY_F7:
	case KEY_F8:
	case KEY_F9:
	case KEY_F10:
	case KEY_F11:
	case KEY_F12:
	    show_fkey(key);
	    clear = 1;
	    break;

	case KEY_TAB:
	    if (cm->allowedit && me->action == MA_CMD) {
		int ok = 1;

		key_timeout = 0;	/* Cancels timeout */
		draw_row(entry - top + 4 + VSHIFT, -1, top, 0, 0);

		if (cm->menu_master_passwd) {
		    ok = ask_passwd(NULL);
		    clear_screen();
		    draw_menu(-1, top, 0);
		} else {
		    /* Erase [Tab] message and help text */
		    printf("\033[%d;1H\1#0\033[K", TABMSG_ROW);
		    display_help(NULL);
		}

		if (ok) {
		    cmdline = edit_cmdline(me->cmdline, top);
		    done = !!cmdline;
		    clear = 1;	/* In case we hit [Esc] and done is null */
		} else {
		    draw_row(entry - top + 4 + VSHIFT, entry, top, 0, 0);
		}
	    }
	    break;
	case KEY_CTRL('C'):	/* Ctrl-C */
	case KEY_ESC:		/* Esc */
	    if (cm->parent) {
		cm = cm->parent;
		clear = 2;
		entry = cm->curentry;
		top = cm->curtop;
	    } else if (cm->allowedit) {
		done = 1;
		clear = 1;
		key_timeout = 0;

		draw_row(entry - top + 4 + VSHIFT, -1, top, 0, 0);

		if (cm->menu_master_passwd)
		    done = ask_passwd(NULL);
	    }
	    break;
	default:
	    if (key > 0 && key < 0xFF) {
		key &= ~0x20;	/* Upper case */
		if (cm->menu_hotkeys[key]) {
		    key_timeout = 0;
		    entry = cm->menu_hotkeys[key]->entry;
		    /* Should we commit at this point? */
		    hotkey = true;
		}
	    }
	    break;
	}
    }

    printf("\033[?25h");	/* Show cursor */

    /* Return the label name so localboot and ipappend work */
    return cmdline;
}
Beispiel #17
0
    }
    return -1;
}

unsigned short keycodes[] = {
    KEY_LEFT,
    KEY_RIGHT,
    KEY_UP,
    KEY_DOWN,
    KEY_CTRL_LEFT,
    KEY_CTRL_RIGHT,
    KEY_CTRL_UP,
    KEY_CTRL_DOWN,
    KEY_CTRL_HOME,
    KEY_CTRL_END,
    KEY_CTRL('_'),
    KEY_CTRL(' '),
    KEY_CTRL('\\'),
    KEY_BACKSPACE,
    KEY_INSERT,
    KEY_DELETE, 
    KEY_PAGEUP,
    KEY_PAGEDOWN,
    KEY_HOME,
    KEY_END,
    ' ',
    KEY_RET,
    KEY_ESC,
    KEY_TAB,
    KEY_SHIFT_TAB,
    KEY_DEFAULT,
Beispiel #18
0
/**
 * An event handler for pressing a key
 *
 * @param key the key code
 */
void EditorWindow::OnKeyPressed(int key)
{
	if (key == KEY_ESC) {

		if (splitPane->OneComponentMode() == SPLITPANE_COMPONENT_NONE) {

			// Close the find dialog

			splitPane->SetOneComponentMode(SPLITPANE_COMPONENT_FIRST);
			editor->SetHighlightPattern(NULL);
		}
	}

	else if (key == KEY_CTRL('f')) {

		if (splitPane->OneComponentMode() == SPLITPANE_COMPONENT_NONE) {

			// Focus the find dialog

			patternEditor->Focus();
			patternEditor->SelectAll();
		}
		else {

			// Open the find dialog

			splitPane->SetOneComponentMode(SPLITPANE_COMPONENT_NONE);
			editor->SetHighlightPattern(patternEditor->Document()->Line(0));
			patternEditor->Focus();
		}
	}

	else if (key == KEY_CTRL('d')) {

		if (editor->HighlightPattern() != NULL) {
			editor->FindNext(false, false);
		}
	}

	else if (key == KEY_CTRL('g')) {

		if (editor->HighlightPattern() != NULL) {
			editor->FindNext(true, false);
		}
	}

	else if (key == KEY_CTRL('s')) {

		if (editor->Document()->FileName() == NULL) {
			// XXX
			ReturnExt r = editor->Document()->Save();
			Dialogs::Error(this, r.Message());
		}
		else {
			ReturnExt r = editor->Document()->Save();
			if (!r) Dialogs::Error(this, r.Message());
		}
	}

	else {

		Window::OnKeyPressed(key);
	}
}
Beispiel #19
0
/*
	- it takes the cursor position into account for <hline> and <center> tags
	- when max_lines > -1, can display a limited number of lines
	  (used in --More-- prompt reading)
	- returns position in the string where it stopped
	- if dev is NULL, it produces no output, but does run the function and update the cursor pos
	- force_auto_color_off is used for hline tags, that really don't like auto-coloring

	- is_symbol says if it's a symbol that needs auto-coloring
	- dont_auto_color is for controlling exceptions to the rule of auto-coloring
*/
int Out_text(StringIO *dev, User *usr, char *str, int *cpos, int *lines, int max_lines, int force_auto_color_off) {
char buf[MAX_COLORBUF], c;
int pos, n, dont_auto_color, color, is_symbol;

	if (usr == NULL || usr->display == NULL || str == NULL || cpos == NULL || lines == NULL)
		return 0;

	if (max_lines > -1 && *lines >= max_lines)
		return 0;

	dont_auto_color = force_auto_color_off;

	pos = 0;
	while(*str) {
		is_symbol = 0;
		pos++;
		c = *str;

		if ((usr->flags & USR_HACKERZ) && HACK_CHANCE)
			c = hackerz_mode(c);

/* user-defined auto-coloring symbols */

		if ((usr->flags & (USR_ANSI|USR_DONT_AUTO_COLOR)) == USR_ANSI) {
			char *symbol_str;

			symbol_str = (usr->symbols == NULL) ? Default_Symbols : usr->symbols;
			if (cstrchr(symbol_str, c) != NULL) {
				is_symbol = 1;
/*
	auto-coloring a single dot is ugly, but multiple ones is fun
*/
				if (c == '.' && str[1] != '.' && (pos > 0 && str[-1] != '.'))
					dont_auto_color = AUTO_COLOR_FORCED;
			}
		}
/*
	word-wrap in display function
	Charset1 contains characters that break the line
*/
		if (cstrchr(Wrap_Charset1, c) != NULL) {
			if (*cpos + word_len(str+1) >= usr->display->term_width) {
				if (c != ' ') {
					if (is_symbol && !dont_auto_color) {
						auto_color(usr, buf, MAX_COLORBUF);
						put_StringIO(dev, buf);
					}
					write_StringIO(dev, str, 1);

					if (is_symbol && !dont_auto_color) {
						restore_colorbuf(usr, usr->color, buf, MAX_COLORBUF);
						put_StringIO(dev, buf);
					}
				}
				if (str[1] == ' ') {
					str++;
					pos++;
				}
				put_StringIO(dev, "\r\n");
				*cpos = 0;
				(*lines)++;
				if (max_lines > -1 && *lines >= max_lines)
					return pos;

				dont_auto_color = force_auto_color_off;

				if (*str)
					str++;
				continue;
			}
		} else {
/*
	pretty word-wrap: Charset2 contains characters that wrap along with the line
	mind that the < character is also used for long color codes
*/
			if (c != '<' && cstrchr(Wrap_Charset2, c) != NULL) {
				if (*cpos + word_len(str+1) >= usr->display->term_width) {
					write_StringIO(dev, "\r\n", 2);
					*cpos = 0;
					(*lines)++;
					if (max_lines > -1 && *lines >= max_lines)
						return pos-1;

					dont_auto_color = force_auto_color_off;
				}
			}
		}
		switch(c) {
			case '\b':
				write_StringIO(dev, "\b", 1);
				if (*cpos)
					(*cpos)--;

				dont_auto_color = force_auto_color_off;
				break;

			case '\n':
				write_StringIO(dev, "\r\n", 2);
				*cpos = 0;

				(*lines)++;
				if (max_lines > -1 && *lines >= max_lines)
					return pos;

				dont_auto_color = force_auto_color_off;
				break;

			case KEY_CTRL('Q'):								/* don't auto-color this string */
				dont_auto_color = AUTO_COLOR_FORCED;
				break;

			case KEY_CTRL('X'):
				write_StringIO(dev, "\r", 1);
				*cpos = 0;

				dont_auto_color = force_auto_color_off;
				break;

			case KEY_CTRL('A'):
				if (usr->flags & USR_BEEP)
					write_StringIO(dev, "\a", 1);

				dont_auto_color = force_auto_color_off;
				break;

			case KEY_CTRL('L'):				/* clear screen */
				if (usr->flags & (USR_ANSI|USR_BOLD))
					write_StringIO(dev, "\x1b[1;1H\x1b[2J", 10);
				break;

			case KEY_CTRL('Z'):
			case KEY_CTRL('R'):
			case KEY_CTRL('G'):
			case KEY_CTRL('Y'):
			case KEY_CTRL('B'):
			case KEY_CTRL('M'):
			case KEY_CTRL('C'):
			case KEY_CTRL('W'):
/*			case KEY_CTRL('F'):		*/
				if (usr->flags & USR_ANSI) {
					usr->color = c;
					color = Ansi_Color(usr, c);
					if (usr->flags & USR_BOLD)
						bufprintf(buf, sizeof(buf), "\x1b[1;%dm", color);
					else
						bufprintf(buf, sizeof(buf), "\x1b[%dm", color);
					put_StringIO(dev, buf);
					dont_auto_color = AUTO_COLOR_FORCED;
				}
				break;

			case KEY_CTRL('K'):
				str++;
				if (!*str)
					break;

				print_hotkey(usr, *str, buf, sizeof(buf), cpos);
				put_StringIO(dev, buf);

				dont_auto_color = force_auto_color_off;
				break;

			case KEY_CTRL('N'):
				if (usr->flags & USR_ANSI) {
					bufprintf(buf, sizeof(buf), "\x1b[0;%dm", color_table[usr->colors[BACKGROUND]].value+10);
					put_StringIO(dev, buf);
				} else
					if (usr->flags & USR_BOLD)
						put_StringIO(dev, "\x1b[0m");

				if (usr->flags & USR_BOLD)
					put_StringIO(dev, "\x1b[1m");

				dont_auto_color = force_auto_color_off;
				break;

			case KEY_CTRL('D'):
				if (usr->flags & (USR_ANSI | USR_BOLD))
					put_StringIO(dev, "\x1b[0m");

				dont_auto_color = force_auto_color_off;
				break;

/* long codes are specified as '<yellow>', '<beep>', etc. */

			case '<':
				n = long_color_code(dev, usr, str, cpos, lines, max_lines, dont_auto_color);
				if (n > 0)
					dont_auto_color = AUTO_COLOR_FORCED;
				str += n;
				pos += n;
				break;

			default:
				if (is_symbol && !dont_auto_color) {
					auto_color(usr, buf, MAX_COLORBUF);
					put_StringIO(dev, buf);
				}
				write_StringIO(dev, &c, 1);
				(*cpos)++;

				if (is_symbol && !dont_auto_color) {
					restore_colorbuf(usr, usr->color, buf, MAX_COLORBUF);
					put_StringIO(dev, buf);
				}
				if (!is_symbol)
					dont_auto_color = force_auto_color_off;
		}
		if (*str)
			str++;
	}
/*	Flush(usr);		the buffering code and mainloop() will flush for us */
	return pos;
}
Beispiel #20
0
Datei: util.c Projekt: kjk/qemacs
                return val;
            else
                break;
        } else {
            if (len == (s1 - s) && !memcmp(s, str, len))
                return val;
            s = s1 + 1;
        }
        val++;
    }
    return -1;
}

unsigned short keycodes[] = {
    KEY_SPC, KEY_DEL, KEY_RET, KEY_ESC, KEY_TAB, KEY_SHIFT_TAB,
    KEY_CTRL(' '), KEY_DEL, KEY_CTRL('\\'),
    KEY_CTRL(']'), KEY_CTRL('^'), KEY_CTRL('_'),
    KEY_LEFT, KEY_RIGHT, KEY_UP, KEY_DOWN,
    KEY_HOME, KEY_END, KEY_PAGEUP, KEY_PAGEDOWN,
    KEY_CTRL_LEFT, KEY_CTRL_RIGHT, KEY_CTRL_UP, KEY_CTRL_DOWN,
    KEY_CTRL_HOME, KEY_CTRL_END, KEY_CTRL_PAGEUP, KEY_CTRL_PAGEDOWN,
    KEY_PAGEUP, KEY_PAGEDOWN, KEY_CTRL_PAGEUP, KEY_CTRL_PAGEDOWN,
    KEY_INSERT, KEY_DELETE, KEY_DEFAULT,
    KEY_F1, KEY_F2, KEY_F3, KEY_F4, KEY_F5,
    KEY_F6, KEY_F7, KEY_F8, KEY_F9, KEY_F10,
    KEY_F11, KEY_F12, KEY_F13, KEY_F14, KEY_F15,
    KEY_F16, KEY_F17, KEY_F18, KEY_F19, KEY_F20,
};

const char *keystr[] = {
    "SPC", "DEL", "RET", "ESC", "TAB", "S-TAB",
Beispiel #21
0
static int ask_passwd(const char *menu_entry)
{
    char user_passwd[WIDTH], *p;
    int done;
    int key;
    int x;
    int rv;

    printf("\033[%d;%dH\2#11\016l", PASSWD_ROW, PASSWD_MARGIN + 1);
    for (x = 2; x <= WIDTH - 2 * PASSWD_MARGIN - 1; x++)
	putchar('q');

    printf("k\033[%d;%dHx", PASSWD_ROW + 1, PASSWD_MARGIN + 1);
    for (x = 2; x <= WIDTH - 2 * PASSWD_MARGIN - 1; x++)
	putchar(' ');

    printf("x\033[%d;%dHm", PASSWD_ROW + 2, PASSWD_MARGIN + 1);
    for (x = 2; x <= WIDTH - 2 * PASSWD_MARGIN - 1; x++)
	putchar('q');

    printf("j\017\033[%d;%dH\2#12 %s \033[%d;%dH\2#13",
	   PASSWD_ROW, (WIDTH - (strlen(cm->messages[MSG_PASSPROMPT]) + 2)) / 2,
	   cm->messages[MSG_PASSPROMPT], PASSWD_ROW + 1, PASSWD_MARGIN + 3);

    drain_keyboard();

    /* Actually allow user to type a password, then compare to the SHA1 */
    done = 0;
    p = user_passwd;

    while (!done) {
	key = mygetkey(0);

	switch (key) {
	case KEY_ENTER:
	case KEY_CTRL('J'):
	    done = 1;
	    break;

	case KEY_ESC:
	case KEY_CTRL('C'):
	    p = user_passwd;	/* No password entered */
	    done = 1;
	    break;

	case KEY_BACKSPACE:
	case KEY_DEL:
	case KEY_DELETE:
	    if (p > user_passwd) {
		printf("\b \b");
		p--;
	    }
	    break;

	case KEY_CTRL('U'):
	    while (p > user_passwd) {
		printf("\b \b");
		p--;
	    }
	    break;

	default:
	    if (key >= ' ' && key <= 0xFF &&
		(p - user_passwd) < WIDTH - 2 * PASSWD_MARGIN - 5) {
		*p++ = key;
		putchar('*');
	    }
	    break;
	}
    }

    if (p == user_passwd)
	return 0;		/* No password entered */

    *p = '\0';

    rv = (cm->menu_master_passwd &&
	  passwd_compare(cm->menu_master_passwd, user_passwd))
	|| (menu_entry && passwd_compare(menu_entry, user_passwd));

    /* Clean up */
    memset(user_passwd, 0, WIDTH);
    drain_keyboard();

    return rv;
}
Beispiel #22
0
            } else {
                latex_cmd_run((void *)&latex_funcs[i], buf);
            }
            break;
        }
    }
    if(latex_funcs[i].name == 0)
        put_status(e, "%s: No match", buf);
    free(bname);
}

/* specific LaTeX commands */
static CmdDef latex_commands[] = {
    CMD0('\"', KEY_NONE, "tex-insert-quote", do_tex_insert_quote)
    /* this should actually be KEY_CTRLC(KEY_CTRL('c')), ie C-c C-c */
    CMD( KEY_CTRL('c'), KEY_NONE, "TeX-command-master\0s{Command: (default LaTeX) }[latex]|latex|", do_latex)
    CMD_DEF_END,
};

static int latex_init(void)
{
    /* LaTeX mode is almost like the text mode, so we copy and patch it */
    memcpy(&latex_mode, &text_mode, sizeof(ModeDef));
    latex_mode.name = "LaTeX";
    latex_mode.mode_probe = latex_mode_probe;
    latex_mode.mode_init = latex_mode_init;

    qe_register_mode(&latex_mode);
    qe_register_cmd_table(latex_commands, "LaTeX");
	register_completion("latex", latex_completion);
Beispiel #23
0
/*
	long color codes look like '<yellow>', '<white>', '<hotkey>', etc.

	parsing the long color code is a slow function...
	but it makes programming with color coded strings a lot easier task

	it's more or less sorted in order of most frequent appearance to make
	it less slow

	cpos is the cursor position, which is used in <hline> and <center> tags
	for <hline>, the function recurses with Out_text()

	if dev is NULL, it produces no output
*/
int long_color_code(StringIO *dev, User *usr, char *code, int *cpos, int *lines, int max_lines, int dont_auto_color) {
int i, c, color;
char colorbuf[MAX_COLORBUF], buf[PRINT_BUF], *p;

	if (usr == NULL || code == NULL || !*code || cpos == NULL || lines == NULL)
		return 0;

	for(i = 0; i < NUM_COLORS; i++) {
		if (i == HOTKEY)
			continue;

		bufprintf(colorbuf, sizeof(colorbuf), "<%s>", color_table[i].name);

		if (!cstrnicmp(code, colorbuf, strlen(colorbuf))) {
			if (!(usr->flags & USR_ANSI))
				return strlen(colorbuf)-1;

			c = usr->color = color_table[i].key;

			color = Ansi_Color(usr, c);
			if (usr->flags & USR_BOLD)
				bufprintf(buf, sizeof(buf), "\x1b[1;%dm", color);
			else
				bufprintf(buf, sizeof(buf), "\x1b[%dm", color);
			put_StringIO(dev, buf);
			return strlen(colorbuf)-1;
		}
	}
/*
	Blinking is really irritating...

	if (!cstrnicmp(code, "<flash>", 7) || !cstrnicmp(code, "<blink>", 7)) {
		if (!(usr->flags & USR_ANSI))
			return 6;

		usr->color = KEY_CTRL('F');
		color = Ansi_Color(usr, KEY_CTRL('F'));
		if (usr->flags & USR_BOLD)
			bufprintf(buf, sizeof(buf), "\x1b[1;%dm", color);
		else
			bufprintf(buf, sizeof(buf), "\x1b[%dm", color);
		put_StringIO(dev, buf);
		return 6;
	}
*/
	if (!cstrnicmp(code, "<hotkey>", 8)) {
		c = code[8];
		if (!c)
			return 7;

		print_hotkey(usr, c, buf, sizeof(buf), cpos);
		put_StringIO(dev, buf);
		return 8;
	}
	if (!cstrnicmp(code, "<key>", 5)) {
		c = code[5];
		if (!c)
			return 4;
/*
	Don't do this; the <key> code is used in the Help files to keep this from happening

		if (usr->flags & USR_UPPERCASE_HOTKEYS)
			c = ctoupper(c);
*/
		if (usr->flags & USR_ANSI) {
			if (usr->flags & USR_BOLD)
				bufprintf(buf, sizeof(buf), "\x1b[1;%dm%c\x1b[1;%dm", color_table[usr->colors[HOTKEY]].value, c, Ansi_Color(usr, usr->color));
			else
				bufprintf(buf, sizeof(buf), "\x1b[%dm%c\x1b[%dm", color_table[usr->colors[HOTKEY]].value, c, Ansi_Color(usr, usr->color));

			(*cpos)++;
		} else {
			bufprintf(buf, sizeof(buf), "<%c>", c);
			*cpos += 3;
		}
		put_StringIO(dev, buf);
		return 5;
	}
	if (!cstrnicmp(code, "<beep>", 6)) {
		if (usr->flags & USR_BEEP)
			write_StringIO(dev, "\a", 1);
		return 5;
	}
	if (!cstrnicmp(code, "<normal>", 8)) {
		if (usr->flags & USR_ANSI) {
			bufprintf(buf, sizeof(buf), "\x1b[0;%dm", color_table[usr->colors[BACKGROUND]].value+10);
			put_StringIO(dev, buf);
		} else
			if (usr->flags & USR_BOLD)
				put_StringIO(dev, "\x1b[0m");

		if (usr->flags & USR_BOLD)
			put_StringIO(dev, "\x1b[1m");
		return 7;
	}
	if (!cstrnicmp(code, "<default>", 9)) {
		if (usr->flags & (USR_ANSI | USR_BOLD))
			put_StringIO(dev, "\x1b[0m");
		return 8;
	}
	if (!cstrnicmp(code, "<lt>", 4)) {
		if ((usr->flags & USR_ANSI) && !(usr->flags & USR_DONT_AUTO_COLOR) && !dont_auto_color) {
			auto_color(usr, colorbuf, MAX_COLORBUF);
			put_StringIO(dev, colorbuf);
		}
		write_StringIO(dev, "<", 1);
		(*cpos)++;

		if ((usr->flags & USR_ANSI) && !(usr->flags & USR_DONT_AUTO_COLOR) && !dont_auto_color) {
			restore_colorbuf(usr, usr->color, colorbuf, MAX_COLORBUF);
			put_StringIO(dev, colorbuf);
		}
		return 3;
	}
	if (!cstrnicmp(code, "<gt>", 4)) {
		if ((usr->flags & USR_ANSI) && !(usr->flags & USR_DONT_AUTO_COLOR) && !dont_auto_color) {
			auto_color(usr, colorbuf, MAX_COLORBUF);
			put_StringIO(dev, colorbuf);
		}
		write_StringIO(dev, ">", 1);
		(*cpos)++;

		if ((usr->flags & USR_ANSI) && !(usr->flags & USR_DONT_AUTO_COLOR) && !dont_auto_color) {
			restore_colorbuf(usr, usr->color, colorbuf, MAX_COLORBUF);
			put_StringIO(dev, colorbuf);
		}
		return 3;
	}

/*
	there are two special codes for use in help files and stuff...
	<hline> and <center>

	especially the code for hline is cryptic, but the idea is that
	it fills the line to the width of the terminal
*/
	if (!cstrnicmp(code, "<hline>", 7)) {
		int l;

		code += 7;
		if (!*code)
			return 6;

		c = ((usr->display->term_width-1) > PRINT_BUF) ? PRINT_BUF : (usr->display->term_width-1);
		cstrncpy(buf, code, c);
/*
	it stinks, but you have to remove all chars that can reset the cursor pos
*/
		p = buf;
		while(*p) {
			if (*p == KEY_CTRL('X') || *p == '\b')
				memmove(p, p+1, strlen(p+1)+1);
			else {
				if (*p == '\n') {		/* don't go over newlines */
					*p = 0;
					break;
				}
				p++;
			}
		}
		l = strlen(buf);
		i = color_strlen(buf);

		while(*cpos + i < usr->display->term_width-1)
			Out_text(dev, usr, buf, cpos, lines, max_lines, AUTO_COLOR_FORCED);	/* recurse */

		if (*cpos + i >= usr->display->term_width-1) {			/* 'partial put' of the remainder */
			buf[color_index(buf, c - *cpos)] = 0;
			Out_text(dev, usr, buf, cpos, lines, max_lines, AUTO_COLOR_FORCED);
		}
		return 6+l;
	}
	if (!cstrnicmp(code, "<center>", 8)) {
		code += 8;
		if (!*code)
			return 7;

		c = strlen(code);
		c = (c > PRINT_BUF) ? PRINT_BUF : c;
		cstrncpy(buf, code, c);
		buf[c-1] = 0;

		if ((p = cstrchr(buf, '\n')) != NULL)		/* don't go over newlines */
			*p = 0;

		i = (usr->display->term_width-1)/2 - color_strlen(buf)/2 - *cpos;
		while(i > 0) {
			write_StringIO(dev, " ", 1);
			(*cpos)++;
			i--;
		}
		return 7;
	}
	if ((usr->flags & USR_ANSI) && !(usr->flags & USR_DONT_AUTO_COLOR) && !dont_auto_color) {
		auto_color(usr, colorbuf, MAX_COLORBUF);
		put_StringIO(dev, colorbuf);
	}
	write_StringIO(dev, "<", 1);
	(*cpos)++;

	if ((usr->flags & USR_ANSI) && !(usr->flags & USR_DONT_AUTO_COLOR) && !dont_auto_color) {
		restore_colorbuf(usr, usr->color, colorbuf, MAX_COLORBUF);
		put_StringIO(dev, colorbuf);
	}
	return 0;
}
Beispiel #24
0
void QEQtView::keyPressEvent (QKeyEvent *event)
{
    qDebug() << Q_FUNC_INFO << QKeySequence(event->key()).toString();

    QEKeyEvent ev;
    ev.type = QE_KEY_EVENT;
    ev.key = KEY_NONE;

    bool ctrl = event->modifiers() & Qt::ControlModifier;
    bool shift = event->modifiers() & Qt::ShiftModifier;
    bool meta = event->modifiers() & Qt::AltModifier;

    switch (event->key()) {
    // in the same order as qe.h
    case Qt::Key_Tab:
        ev.key = shift ? KEY_SHIFT_TAB : KEY_TAB;
        break;
    case Qt::Key_Return:
        ev.key = KEY_RET;
        break;
    case Qt::Key_Escape:
        ev.key = KEY_ESC;
        break;
    case Qt::Key_Space:
        ev.key = KEY_SPC;
        break;
    //case Qt::Key_????:
        //ev.key = KEY_DEL;
        //break;
    case Qt::Key_Backspace:
        ev.key = meta ? KEY_META(KEY_DEL) : KEY_DEL;
        break;
    case Qt::Key_Up:
        ev.key = ctrl ? KEY_CTRL_UP : KEY_UP;
        break;
    case Qt::Key_Down:
        ev.key = ctrl ? KEY_CTRL_DOWN : KEY_DOWN;
        break;
    case Qt::Key_Right:
        ev.key = ctrl ? KEY_CTRL_RIGHT: KEY_RIGHT;
        break;
    case Qt::Key_Left:
        ev.key = ctrl ? KEY_CTRL_LEFT : KEY_LEFT;
        break;
    case Qt::Key_End:
        ev.key = ctrl ? KEY_CTRL_END : KEY_END;
        break;
   case Qt::Key_Home:
        ev.key = ctrl ? KEY_CTRL_HOME : KEY_HOME;
        break;
   case Qt::Key_PageUp:
        ev.key = ctrl ? KEY_CTRL_PAGEUP : KEY_PAGEUP;
        break;
   case Qt::Key_PageDown:
        ev.key = ctrl ? KEY_CTRL_PAGEDOWN : KEY_PAGEDOWN;
        break;
   case Qt::Key_Insert:
        ev.key = KEY_INSERT;
        break;
   case Qt::Key_Delete:
        ev.key = KEY_DELETE;
        break;
   case Qt::Key_F1:
        ev.key = KEY_F1;
        break;
   case Qt::Key_F2:
        ev.key = KEY_F2;
        break;
   case Qt::Key_F3:
        ev.key = KEY_F3;
        break;
   case Qt::Key_F4:
        ev.key = KEY_F4;
        break;
   case Qt::Key_F5:
        ev.key = KEY_F5;
        break;
   case Qt::Key_F6:
        ev.key = KEY_F6;
        break;
   case Qt::Key_F7:
        ev.key = KEY_F7;
        break;
   case Qt::Key_F8:
        ev.key = KEY_F8;
        break;
   case Qt::Key_F9:
        ev.key = KEY_F9;
        break;
   case Qt::Key_F10:
        ev.key = KEY_F10;
        break;
   case Qt::Key_F11:
        ev.key = KEY_F11;
        break;
   case Qt::Key_F12:
        ev.key = KEY_F12;
        break;
   case Qt::Key_F13:
        ev.key = KEY_F13;
        break;
   case Qt::Key_F14:
        ev.key = KEY_F14;
        break;
   case Qt::Key_F15:
        ev.key = KEY_F15;
        break;
   case Qt::Key_F16:
        ev.key = KEY_F16;
        break;
   case Qt::Key_F17:
        ev.key = KEY_F17;
        break;
   case Qt::Key_F18:
        ev.key = KEY_F18;
        break;
   case Qt::Key_F19:
        ev.key = KEY_F19;
        break;
   case Qt::Key_F20:
        ev.key = KEY_F20;
        break;
    case Qt::Key_Control:
    case Qt::Key_Meta:
    case Qt::Key_Alt:
    case Qt::Key_AltGr:
    default:
        if (event->text().isEmpty()) {
            qDebug() << Q_FUNC_INFO << "empty key" << event->nativeScanCode();
            return;
        }

        int key = event->text().at(0).toLatin1();
        if (ctrl) {
            ev.key = KEY_CTRL(key);
        }
        else if (meta) {
            ev.key = KEY_META(' ') + key - ' ';
        }
        else {
            ev.key = key;
        }
        qDebug() << Q_FUNC_INFO << " other key" << event->nativeScanCode();
    }

    write(_ctx->events_wr, &ev, sizeof(QEEvent));
}
Beispiel #25
0
/*
	convert key code to long color code
	some key codes do not have a long equivalent

	flags can be USR_SHORT_DL_COLORS, which means that the color codes should be
	represented in short format
*/
int short_color_to_long(char c, char *buf, int max_len, int flags) {
int i;

	if (buf == NULL || max_len <= 0)
		return -1;

	buf[0] = 0;
	switch(c) {
		case KEY_CTRL('Q'):				/* don't auto-color this string */
			break;

		case KEY_CTRL('X'):
			break;

		case KEY_CTRL('A'):
			cstrcpy(buf, "<beep>", max_len);
			break;

		case KEY_CTRL('L'):				/* clear screen */
			break;

		case KEY_CTRL('Z'):
		case KEY_CTRL('R'):
		case KEY_CTRL('G'):
		case KEY_CTRL('Y'):
		case KEY_CTRL('B'):
		case KEY_CTRL('M'):
		case KEY_CTRL('C'):
		case KEY_CTRL('W'):
			for(i = 0; i < NUM_COLORS; i++) {
				if (color_table[i].key == c) {
					if (flags & USR_SHORT_DL_COLORS) {
/*
	black is Ctrl-Z, but actually has to entered as Ctrl-K
	see also edit_color() in edit.c

	(this is confusing, but black is blacK, while the K is for hotkeys)
*/
						if (c == KEY_CTRL('Z'))
							c = KEY_CTRL('K');

						bufprintf(buf, max_len, "^%c", c + 'A' - 1);
					} else {
						bufprintf(buf, max_len, "<%s>", color_table[i].name);
						cstrlwr(buf);
					}
					break;
				}
			}
			break;

		case KEY_CTRL('K'):
			cstrcpy(buf, "<hotkey>", max_len);
			break;

		case KEY_CTRL('N'):
			cstrcpy(buf, "<normal>", max_len);
			break;

		case KEY_CTRL('D'):
			cstrcpy(buf, "<default>", max_len);
			break;

		default:
			if (c >= ' ' && c <= '~' && max_len >= 2) {
				buf[0] = c;
				buf[1] = 0;
			}
	}
	return 0;
}
Beispiel #26
0
    for (e = qs->first_window; e != NULL; e = e->next_window) {
        if (e->b == b) {
            e->offset = error_offset;
        }
    }

    /* CG: Should remove popups, sidepanes, helppanes... */

    /* go to the error */
    do_load(s, filename);
    do_goto_line(s, line_num);
}

/* specific shell commands */
static CmdDef shell_commands[] = {
    CMD0( KEY_CTRL('o'), KEY_NONE, "shell-toggle-input", do_shell_toggle_input)
    CMD1( '\r', KEY_NONE, "shell-return", shell_write_char, '\r')
    /* CG: should send s->kbs */
    CMD1( 127, KEY_NONE, "shell-backward-delete-char", shell_write_char, 127)
    CMD1( KEY_CTRL('c'), KEY_NONE, "shell-intr", shell_write_char, 3)
    CMD1( KEY_CTRL('d'), KEY_DELETE, "shell-delete-char", shell_write_char, 4)
    CMD1( KEY_CTRL('i'), KEY_NONE, "shell-tabulate", shell_write_char, 9)
    CMD1( KEY_CTRL('k'), KEY_NONE, "shell-kill-line", shell_write_char, 11)
    CMD1( KEY_CTRL('y'), KEY_NONE, "shell-yank", shell_write_char, 25)
    CMD_DEF_END,
};

/* compilation commands */
static CmdDef compile_commands[] = {
    CMD_( KEY_CTRLXRET('\r'), KEY_NONE, "shell", do_shell, "i")
    CMD_( KEY_CTRLX(KEY_CTRL('e')), KEY_NONE, "compile", do_compile,
Beispiel #27
0
void state_help_menu(User *usr, char c) {
char filename[MAX_PATHLEN];

	if (usr == NULL)
		return;

	Enter(state_help_menu);

	switch(c) {
		case INIT_PROMPT:
			break;

		case INIT_STATE:
			usr->runtime_flags |= RTF_BUSY;

			buffer_text(usr);

			Put(usr, "<magenta>\n"
				"<hotkey>Introduction                 Editing recipient <hotkey>lists\n"
				"e<hotkey>Xpress messages             Editing with <hotkey>colors\n"
				"<hotkey>Friends and enemies          <hotkey>Navigating the --More-- prompt\n"
			);
			Put(usr,
				"Reading and posting <hotkey>messages\n"
				"The <hotkey>room system\n"
				"Customizing your <hotkey>profile     <hotkey>Other commands\n"
			);
			read_menu(usr);
			Return;

		case ' ':
		case KEY_RETURN:
		case KEY_CTRL('C'):
		case KEY_CTRL('D'):
		case KEY_BS:
			Put(usr, "\n");
			RET(usr);
			Return;

		case KEY_CTRL('L'):
			Put(usr, "\n");
			CURRENT_STATE(usr);
			Return;

		case '`':
			CALL(usr, STATE_BOSS);
			Return;

		case 'i':
		case 'I':
			Put(usr, "Introduction\n");
			HELP_TEXT("intro");

		case 'x':
		case 'X':
			Put(usr, "eXpress Messages\n");
			HELP_TEXT("xmsg");

		case 'f':
		case 'F':
			Put(usr, "Friends and Enemies\n");
			HELP_TEXT("friends");

		case 'm':
		case 'M':
			Put(usr, "Reading and posting messages\n");
			HELP_TEXT("msgs");

		case 'r':
		case 'R':
			Put(usr, "The room system\n");
			HELP_TEXT("rooms");

		case 'p':
		case 'P':
			Put(usr, "Customizing your profile\n");
			HELP_TEXT("profile");

		case 'l':
		case 'L':
			Put(usr, "Editing recipient lists\n");
			HELP_TEXT("recipients");

		case 'c':
		case 'C':
			Put(usr, "Editing with colors\n");
			HELP_TEXT("colors");

		case 'n':
		case 'N':
			Put(usr, "Navigating the --More-- prompt\n");
			HELP_TEXT("more");

		case 'o':
		case 'O':
			Put(usr, "Other commands\n");
			HELP_TEXT("other");
	}
	Print(usr, "<yellow>\n[Help] %c <white>", (usr->runtime_flags & RTF_SYSOP) ? '#' : '>');
	Return;
}
Beispiel #28
0
void shell_key(void *opaque, int key)
{
    ShellState *s = opaque;
    char buf[10];
    const char *p;
    int len;

    if (key == KEY_CTRL('o')) {
        qe_ungrab_keys();
        unget_key(key);
        return;
    }
    p = buf;
    len = -1;
    switch (key) {
    case KEY_UP:        p = s->kcuu1; break;
    case KEY_DOWN:      p = s->kcud1; break;
    case KEY_RIGHT:     p = s->kcuf1; break;
    case KEY_LEFT:      p = s->kcub1; break;
    //case KEY_CTRL_UP:
    //case KEY_CTRL_DOWN:
    //case KEY_CTRL_RIGHT:
    //case KEY_CTRL_LEFT:
    //case KEY_CTRL_END:
    //case KEY_CTRL_HOME:
    //case KEY_CTRL_PAGEUP:
    //case KEY_CTRL_PAGEDOWN:
    case KEY_SHIFT_TAB: p = s->kcbt; break;
    case KEY_HOME:      p = s->khome; break;
    case KEY_INSERT:    p = s->kich1; break;
    case KEY_DELETE:    p = s->kdch1; break;
    case KEY_END:       p = s->kend; break;
    case KEY_PAGEUP:    p = s->kpp; break;
    case KEY_PAGEDOWN:  p = s->knp; break;
    case KEY_F1:        p = s->kf1; break;
    case KEY_F2:        p = s->kf2; break;
    case KEY_F3:        p = s->kf3; break;
    case KEY_F4:        p = s->kf4; break;
    case KEY_F5:        p = s->kf5; break;
    case KEY_F6:        p = s->kf6; break;
    case KEY_F7:        p = s->kf7; break;
    case KEY_F8:        p = s->kf8; break;
    case KEY_F9:        p = s->kf9; break;
    case KEY_F10:       p = s->kf10; break;
    case KEY_F11:       p = s->kf11; break;
    case KEY_F12:       p = s->kf12; break;
    case KEY_F13:       p = s->kf13; break;
    case KEY_F14:       p = s->kf14; break;
    case KEY_F15:       p = s->kf15; break;
    case KEY_F16:       p = s->kf16; break;
    case KEY_F17:       p = s->kf17; break;
    case KEY_F18:       p = s->kf18; break;
    case KEY_F19:       p = s->kf19; break;
    case KEY_F20:       p = s->kf20; break;
    default:
        if (key < 256) {
            buf[0] = key;
            len = 1;
        } else
        if (key >= KEY_META(0) && key <= KEY_META(255)) {
            buf[0] = '\033';
            buf[1] = key;
            len = 2;
        } else {
            p = NULL;
        }
        break;
    } 
    if (p)
        tty_write(s, p, len);
}
Beispiel #29
0
}

static void bufed_mode_close(EditState *s)
{
    BufedState *bs = s->mode_data;

    free_strings(&bs->items);

    list_mode.mode_close(s);
}

/* specific bufed commands */
static CmdDef bufed_commands[] = {
    CMD1( KEY_RET, KEY_RIGHT, "bufed-select", bufed_select, 0)
    /* bufed-abort should restore previous buffer in right-window */
    CMD1( KEY_CTRL('g'), KEY_NONE, "bufed-abort", do_delete_window, 0)
    CMD0( ' ', KEY_CTRL('t'), "bufed-toggle_selection", list_toggle_selection)
    /* BS should go back to previous item and unmark it */
    //CMD1( 'u', KEY_NONE, "bufed-unmark", bufed_mark, ' ')
    CMD0( '~', KEY_NONE, "bufed-clear-modified", bufed_clear_modified)
    CMD0( '%', KEY_NONE, "bufed-toggle-read-only", bufed_toggle_read_only)
    CMD1( 'a', KEY_NONE, "bufed-toggle-all-visible", bufed_refresh, 1)
    CMD1( 'n', KEY_NONE, "next-line", do_up_down, 1 )
    CMD1( 'p', KEY_NONE, "previous-line", do_up_down, -1 )
    CMD1( 'r', 'g', "bufed-refresh", bufed_refresh, 0)
    CMD0( 'k', KEY_F8, "bufed-kill-buffer", bufed_kill_buffer)
    CMD_DEF_END,
};

static CmdDef bufed_global_commands[] = {
    CMD0( KEY_CTRLX(KEY_CTRL('b')), KEY_NONE, "list-buffers", do_list_buffers)
Beispiel #30
0
void pconsole(void) {
int key, typed = 0;
char kar;
Conn *c, *c_next;

	if (AllConns == NULL)
		command_mode();										/* start in command mode */
	else {
		printf("\n"
			"Press <Ctlr-A> for command mode\n"
			"> ");
		fflush(stdout);
		terminal_mode(TERMINAL_RAW);
	}
	while(read(fileno(stdin), &kar, 1) > 0) {
		key = kar & 0xff;
		if (key == 1) {										/* Ctrl-A => command mode */
			printf("<Ctrl-A>\n");
			command_mode();
			continue;
		}
		if (key == KEY_CTRL('S')) {							/* Ctrl-S => toggle echo */
			printf("<Ctrl-S> ");
			cmd_echo(NULL);

			printf("> ");
			fflush(stdout);
			typed = 0;
			continue;
		}
		if (key == '\r' || key == '\n') {					/* return */
			printf("\n> ");
			fflush(stdout);
			typed = 0;
		} else {
			if (flags & FLAGS_ECHO) {
				if (key == 0x7f || key == '\b') {			/* backspace */
					if (typed) {
						printf("\b \b");
						fflush(stdout);
						typed--;
					}
				} else {
					if (key >= ' ' && key <= '~') {
						fputc(key, stdout);
						typed++;
					} else {
						switch(key) {
							case 0x1b:
								printf("<Esc>");
								break;

							case '\t':
								printf("<Tab>");
								break;

							default:
								printf("<Ctrl-%c>", key - 1 + 'A');
						}
						printf("\n> ");
						typed = 0;
					}
					fflush(stdout);
				}
			}
		}
/*
	put character in everyones input buffer
*/
		for(c = AllConns; c != NULL; c = c_next) {
			c_next = c->next;

			if (c->fd > 0) {
				seteuid(0);											/* regain root privs */
				if (ioctl(c->fd, TIOCSTI, &kar) == -1) {			/* simulate terminal input */
					seteuid(getuid());								/* drop root privs again */
					printf("\nioctl() : %s\n", strerror(errno));
					if (c->hostname != NULL)
						printf("detaching from %s#%s\n", c->hostname, c->dev);
					else
						printf("detaching from %s\n", c->dev);
					remove_Conn(c);
					destroy_Conn(c);
				} else
					seteuid(getuid());								/* drop the root privs */
			}
		}
		if (AllConns == NULL)
			command_mode();
	}
}