diff --git a/src/console.c b/src/console.c index e964220..bdeaa9c 100644 --- a/src/console.c +++ b/src/console.c @@ -2615,6 +2615,35 @@ static void tick(Console* console) tic_mem* tic = console->tic; + { + if(isKeyWasDown(tic_key_up)) onHistoryUp(console); + else if(isKeyWasDown(tic_key_down)) onHistoryDown(console); + else if(isKeyWasDown(tic_key_left)) + { + if(console->inputPosition > 0) + console->inputPosition--; + } + else if(isKeyWasDown(tic_key_right)) + { + console->inputPosition++; + size_t len = strlen(console->inputBuffer); + if(console->inputPosition > len) + console->inputPosition = len; + } + else if(isKeyWasDown(tic_key_return)) processConsoleCommand(console); + else if(isKeyWasDown(tic_key_backspace)) processConsoleBackspace(console); + else if(isKeyWasDown(tic_key_delete)) processConsoleDel(console); + else if(isKeyWasDown(tic_key_home)) processConsoleHome(console); + else if(isKeyWasDown(tic_key_end)) processConsoleEnd(console); + else if(isKeyWasDown(tic_key_tab)) processConsoleTab(console); + + if(isAnyKeyWasDown()) + { + scrollConsole(console); + console->cursor.delay = CONSOLE_CURSOR_DELAY; + } + } + char sym = getKeyboardText(); if(sym) diff --git a/src/studio.c b/src/studio.c index f258d26..5b87248 100644 --- a/src/studio.c +++ b/src/studio.c @@ -51,6 +51,9 @@ // #define OFFSET_TOP ((TIC80_FULLHEIGHT-TIC80_HEIGHT)/2) #define POPUP_DUR (TIC_FRAMERATE*2) +#define KEYBOARD_HOLD 20 +#define KEYBOARD_PERIOD 3 + #if defined(TIC80_PRO) #define TIC_EDITOR_BANKS (TIC_BANKS) #else @@ -329,19 +332,40 @@ char getKeyboardText() static const char Symbols[] = "abcdefghijklmnopqrstuvwxyz0123456789-=[]\\;'`,./ "; static const char Shift[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ)!@#$%^&*(_+{}|:\"~<>? "; - enum{Count = sizeof Symbols, Hold = 20, Period = 3}; + enum{Count = sizeof Symbols}; for(s32 i = 0; i < TIC80_KEY_BUFFER; i++) { tic_key key = tic->ram.input.keyboard.keys[i]; - if(key > 0 && key < Count && tic->api.keyp(tic, key, Hold, Period)) + if(key > 0 && key < Count && tic->api.keyp(tic, key, KEYBOARD_HOLD, KEYBOARD_PERIOD)) return tic->api.key(tic, tic_key_shift) ? Shift[key-1] : Symbols[key-1]; } return 0; } +bool isKeyWasDown(tic_key key) +{ + tic_mem* tic = studioImpl.studio.tic; + return tic->api.keyp(tic, key, KEYBOARD_HOLD, KEYBOARD_PERIOD); +} + +bool isAnyKeyWasDown() +{ + tic_mem* tic = studioImpl.studio.tic; + + for(s32 i = 0; i < TIC80_KEY_BUFFER; i++) + { + tic_key key = tic->ram.input.keyboard.keys[i]; + + if(tic->api.keyp(tic, key, KEYBOARD_HOLD, KEYBOARD_PERIOD)) + return true; + } + + return false; +} + tic_tiles* getBankTiles() { return &studioImpl.studio.tic->cart.banks[studioImpl.bank.index.sprites].tiles; diff --git a/src/studio.h b/src/studio.h index 229279f..254c702 100644 --- a/src/studio.h +++ b/src/studio.h @@ -209,3 +209,5 @@ void studioTick(void* pixels); void studioClose(); char getKeyboardText(); +bool isKeyWasDown(tic_key key); +bool isAnyKeyWasDown();