+static void Key_History_Push(void)
+{
+ if(key_line[1]) // empty?
+ if(strcmp(key_line, "]quit")) // putting these into the history just sucks
+ if(strncmp(key_line, "]quit ", 6)) // putting these into the history just sucks
+ ConBuffer_AddLine(&history, key_line + 1, strlen(key_line) - 1, 0);
+ Con_Printf("%s\n", key_line); // don't mark empty lines as history
+ history_line = -1;
+}
+
+static void Key_History_Up(void)
+{
+ if(history_line == -1) // editing the "new" line
+ strlcpy(history_savedline, key_line + 1, sizeof(history_savedline));
+
+ if(history_line == -1)
+ {
+ history_line = CONBUFFER_LINES_COUNT(&history) - 1;
+ if(history_line != -1)
+ {
+ strlcpy(key_line + 1, ConBuffer_GetLine(&history, history_line), sizeof(key_line) - 1);
+ key_linepos = strlen(key_line);
+ }
+ }
+ else if(history_line > 0)
+ {
+ --history_line; // this also does -1 -> 0, so it is good
+ strlcpy(key_line + 1, ConBuffer_GetLine(&history, history_line), sizeof(key_line) - 1);
+ key_linepos = strlen(key_line);
+ }
+}
+
+static void Key_History_Down(void)
+{
+ if(history_line == -1) // editing the "new" line
+ return;
+
+ if(history_line < CONBUFFER_LINES_COUNT(&history) - 1)
+ {
+ ++history_line;
+ strlcpy(key_line + 1, ConBuffer_GetLine(&history, history_line), sizeof(key_line) - 1);
+ }
+ else
+ {
+ history_line = -1;
+ strlcpy(key_line + 1, history_savedline, sizeof(key_line) - 1);
+ }
+
+ key_linepos = strlen(key_line);
+}
+
+static int key_bmap, key_bmap2;
+static unsigned char keydown[MAX_KEYS]; // 0 = up, 1 = down, 2 = repeating
+
+typedef struct keyname_s
+{