X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=keys.c;h=ce220b42fe7d2e79370e081d9f6f6b6a7872f239;hb=31fcbe71d130244af63a3519a7f2ce77f9e6d879;hp=f5b9b74f629a30fc1c54321a9c0d52584e088ffa;hpb=cdf059c8126a4e32e2e203ad295534002619f91f;p=xonotic%2Fdarkplaces.git diff --git a/keys.c b/keys.c index f5b9b74f..ce220b42 100644 --- a/keys.c +++ b/keys.c @@ -41,7 +41,10 @@ conbuffer_t history; #define HIST_TEXTSIZE 262144 #define HIST_MAXLINES 4096 -static void Key_History_Init() +extern cvar_t con_textsize; + + +static void Key_History_Init(void) { qfile_t *historyfile; ConBuffer_Init(&history, HIST_TEXTSIZE, HIST_MAXLINES, zonemempool); @@ -81,7 +84,7 @@ static void Key_History_Init() history_line = -1; } -static void Key_History_Shutdown() +static void Key_History_Shutdown(void) { // TODO write history to a file @@ -89,13 +92,15 @@ static void Key_History_Shutdown() if(historyfile) { int i; - for(i = 0; i < history.lines_count; ++i) + for(i = 0; i < CONBUFFER_LINES_COUNT(&history); ++i) FS_Printf(historyfile, "%s\n", ConBuffer_GetLine(&history, i)); FS_Close(historyfile); } + + ConBuffer_Shutdown(&history); } -static void Key_History_Push() +static void Key_History_Push(void) { if(key_line[1]) // empty? if(strcmp(key_line, "]quit")) // putting these into the history just sucks @@ -105,14 +110,14 @@ static void Key_History_Push() history_line = -1; } -static void Key_History_Up() +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 = history.lines_count - 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); @@ -127,12 +132,12 @@ static void Key_History_Up() } } -static void Key_History_Down() +static void Key_History_Down(void) { if(history_line == -1) // editing the "new" line return; - if(history_line < history.lines_count - 1) + if(history_line < CONBUFFER_LINES_COUNT(&history) - 1) { ++history_line; strlcpy(key_line + 1, ConBuffer_GetLine(&history, history_line), sizeof(key_line) - 1); @@ -390,7 +395,7 @@ Key_Console (int key, int ascii) break; } - if ((toupper(key) == 'V' && keydown[K_CTRL]) || ((key == K_INS || key == K_KP_INS) && keydown[K_SHIFT])) + if ((key == 'v' && keydown[K_CTRL]) || ((key == K_INS || key == K_KP_INS) && keydown[K_SHIFT])) { char *cbd, *p; if ((cbd = Sys_GetClipboardData()) != 0) @@ -400,11 +405,13 @@ Key_Console (int key, int ascii) p = cbd; while (*p) { - if (*p == '\n' || *p == '\r' || *p == '\b') + if (*p == '\r' && *(p+1) == '\n') { - *p++ = 0; - break; + *p++ = ';'; + *p++ = ' '; } + else if (*p == '\n' || *p == '\r' || *p == '\b') + *p++ = ';'; p++; } #else @@ -416,7 +423,7 @@ Key_Console (int key, int ascii) if (i > 0) { // terencehill: insert the clipboard text between the characters of the line - char *temp = Z_Malloc(MAX_INPUTLINE); + char *temp = (char *) Z_Malloc(MAX_INPUTLINE); cbd[i]=0; temp[0]=0; if ( key_linepos < (int)strlen(key_line) ) @@ -433,13 +440,29 @@ Key_Console (int key, int ascii) return; } - if (key == 'l') + if (key == 'l' && keydown[K_CTRL]) { - if (keydown[K_CTRL]) - { - Cbuf_AddText ("clear\n"); - return; - } + Cbuf_AddText ("clear\n"); + return; + } + + if (key == 'u' && keydown[K_CTRL]) // like vi/readline ^u: delete currently edited line + { + // clear line + key_line[0] = ']'; + key_line[1] = 0; + key_linepos = 1; + return; + } + + if (key == 'q' && keydown[K_CTRL]) // like zsh ^q: push line to history, don't execute, and clear + { + // clear line + Key_History_Push(); + key_line[0] = ']'; + key_line[1] = 0; + key_linepos = 1; + return; } if (key == K_ENTER || key == K_KP_ENTER) @@ -458,6 +481,57 @@ Key_Console (int key, int ascii) if (key == K_TAB) { + if(keydown[K_CTRL]) // append to the cvar its value + { + int cvar_len, cvar_str_len, chars_to_move; + char k; + char cvar[MAX_INPUTLINE]; + const char *cvar_str; + + // go to the start of the variable + while(--key_linepos) + { + k = key_line[key_linepos]; + if(k == '\"' || k == ';' || k == ' ' || k == '\'') + break; + } + key_linepos++; + + // save the variable name in cvar + for(cvar_len=0; (k = key_line[key_linepos + cvar_len]) != 0; cvar_len++) + { + if(k == '\"' || k == ';' || k == ' ' || k == '\'') + break; + cvar[cvar_len] = k; + } + if (cvar_len==0) + return; + cvar[cvar_len] = 0; + + // go to the end of the cvar + key_linepos += cvar_len; + + // save the content of the variable in cvar_str + cvar_str = Cvar_VariableString(cvar); + cvar_str_len = strlen(cvar_str); + if (cvar_str_len==0) + return; + + // insert space and cvar_str in key_line + chars_to_move = strlen(&key_line[key_linepos]); + if (key_linepos + 1 + cvar_str_len + chars_to_move < MAX_INPUTLINE) + { + if (chars_to_move) + memmove(&key_line[key_linepos + 1 + cvar_str_len], &key_line[key_linepos], chars_to_move); + key_line[key_linepos++] = ' '; + memcpy(&key_line[key_linepos], cvar_str, cvar_str_len); + key_linepos += cvar_str_len; + key_line[key_linepos + chars_to_move] = 0; + } + else + Con_Printf("Couldn't append cvar value, edit line too long.\n"); + return; + } // Enhanced command completion // by EvilTypeGuy eviltypeguy@qeradiant.com // Thanks to Fett, Taniwha @@ -480,6 +554,15 @@ Key_Console (int key, int ascii) int pos; char k; pos = key_linepos-1; + + if(pos) // skip all "; ' after the word + while(--pos) + { + k = key_line[pos]; + if (!(k == '\"' || k == ';' || k == ' ' || k == '\'')) + break; + } + if(pos) while(--pos) { @@ -501,6 +584,8 @@ Key_Console (int key, int ascii) pos-=5; else { + if(pos-1 > 0 && key_line[pos-1] == STRING_COLOR_TAG && key_line[pos] == STRING_COLOR_TAG) // consider ^^ as a character + pos--; pos--; break; } @@ -544,12 +629,21 @@ Key_Console (int key, int ascii) char k; len = (int)strlen(key_line); pos = key_linepos; + while(++pos < len) { k = key_line[pos]; if(k == '\"' || k == ';' || k == ' ' || k == '\'') break; } + + if (pos < len) // skip all "; ' after the word + while(++pos < len) + { + k = key_line[pos]; + if (!(k == '\"' || k == ';' || k == ' ' || k == '\'')) + break; + } key_linepos = pos; } else if(keydown[K_SHIFT]) // move cursor to the next character ignoring colors @@ -557,14 +651,22 @@ Key_Console (int key, int ascii) int pos, len; len = (int)strlen(key_line); pos = key_linepos; - // check if there is a color tag right after the cursor - if (key_line[pos] == STRING_COLOR_TAG) - { - if(isdigit(key_line[pos+1])) - pos+=1; - else if(key_line[pos+1] == STRING_COLOR_RGB_TAG_CHAR && isxdigit(key_line[pos+2]) && isxdigit(key_line[pos+3]) && isxdigit(key_line[pos+4])) - pos+=4; - } + + // go beyond all initial consecutive color tags, if any + if(pos < len) + while (key_line[pos] == STRING_COLOR_TAG) + { + if(isdigit(key_line[pos+1])) + pos+=2; + else if(key_line[pos+1] == STRING_COLOR_RGB_TAG_CHAR && isxdigit(key_line[pos+2]) && isxdigit(key_line[pos+3]) && isxdigit(key_line[pos+4])) + pos+=5; + else + break; + } + + // skip the char + if (key_line[pos] == STRING_COLOR_TAG && key_line[pos+1] == STRING_COLOR_TAG) // consider ^^ as a character + pos++; pos++; // now go beyond all next consecutive color tags, if any @@ -604,28 +706,74 @@ Key_Console (int key, int ascii) Key_History_Down(); return; } - - if (key == K_PGUP || key == K_KP_PGUP || key == K_MWHEELUP) + // ~1.0795 = 82/76 using con_textsize 64 76 is height of the char, 6 is the distance between 2 lines + if (key == K_PGUP || key == K_KP_PGUP) { if(keydown[K_CTRL]) { - con_backscroll += 3; + con_backscroll += (int)floor((vid_conheight.integer >> 2) / con_textsize.integer)-1; } else - con_backscroll += ((int) vid_conheight.integer >> 5); + con_backscroll += (int)floor((vid_conheight.integer >> 1) / con_textsize.integer)-3; return; } - if (key == K_PGDN || key == K_KP_PGDN || key == K_MWHEELDOWN) + if (key == K_PGDN || key == K_KP_PGDN) { if(keydown[K_CTRL]) { - con_backscroll -= 3; + con_backscroll -= (int)floor((vid_conheight.integer >> 2) / con_textsize.integer)-1; } else - con_backscroll -= ((int) vid_conheight.integer >> 5); + con_backscroll -= (int)floor((vid_conheight.integer >> 1) / con_textsize.integer)-3; return; } + + if (key == K_MWHEELUP) + { + if(keydown[K_CTRL]) + con_backscroll += 1; + else if(keydown[K_SHIFT]) + con_backscroll += (int)floor((vid_conheight.integer >> 2) / con_textsize.integer)-1; + else + con_backscroll += 5; + return; + } + + if (key == K_MWHEELDOWN) + { + if(keydown[K_CTRL]) + con_backscroll -= 1; + else if(keydown[K_SHIFT]) + con_backscroll -= (int)floor((vid_conheight.integer >> 2) / con_textsize.integer)-1; + else + con_backscroll -= 5; + return; + } + + if (keydown[K_CTRL]) + { + // text zoom in + if (key == '+' || key == K_KP_PLUS) + { + if (con_textsize.integer < 128) + Cvar_SetValueQuick(&con_textsize, con_textsize.integer + 1); + return; + } + // text zoom out + if (key == '-' || key == K_KP_MINUS) + { + if (con_textsize.integer > 1) + Cvar_SetValueQuick(&con_textsize, con_textsize.integer - 1); + return; + } + // text zoom reset + if (key == '0' || key == K_KP_INS) + { + Cvar_SetValueQuick(&con_textsize, atoi(Cvar_VariableDefString("con_textsize"))); + return; + } + } if (key == K_HOME || key == K_KP_HOME) {