换一个方式调整颜色

This commit is contained in:
anod 2022-08-04 12:44:37 +08:00
parent 4dbab2c366
commit 6e113c7580

View File

@ -120,7 +120,7 @@ scanEnd:
return res; return res;
} }
static void showDirList(const DirList *const dList, u32 start, u32 current) static void showDirList(const DirList *const dList, u32 start)
{ {
// Clear screen. // Clear screen.
ee_printf("\x1b[2J"); ee_printf("\x1b[2J");
@ -128,10 +128,10 @@ static void showDirList(const DirList *const dList, u32 start, u32 current)
const u32 listLength = (dList->num - start > SCREEN_ROWS ? start + SCREEN_ROWS : dList->num); const u32 listLength = (dList->num - start > SCREEN_ROWS ? start + SCREEN_ROWS : dList->num);
for(u32 i = start; i < listLength; i++) for(u32 i = start; i < listLength; i++)
{ {
const char *const printStr = "\x1b[%lu;H\x1b[%dm %.51s"; const char *const printStr =
bool isfile = *dList->ptrs[i] == ENT_TYPE_FILE; (*dList->ptrs[i] == ENT_TYPE_FILE ? "\x1b[%lu;H\x1b[37m %.51s" : "\x1b[%lu;H\x1b[36m %.51s");
ee_printf(printStr, i - start, i==current ? 33 : (isfile ? 37 : 36), &dList->ptrs[i][1]); ee_printf(printStr, i - start, &dList->ptrs[i][1]);
} }
} }
@ -149,7 +149,7 @@ Result browseFiles(const char *const basePath, char selected[512])
Result res; Result res;
if((res = scanDir(curDir, dList, ".gba")) != RES_OK) goto end; if((res = scanDir(curDir, dList, ".gba")) != RES_OK) goto end;
showDirList(dList, 0, 0); showDirList(dList, 0);
s32 cursorPos = 0; // Within the entire list. s32 cursorPos = 0; // Within the entire list.
u32 windowPos = 0; // Window start position within the list. u32 windowPos = 0; // Window start position within the list.
@ -157,7 +157,7 @@ Result browseFiles(const char *const basePath, char selected[512])
while(1) while(1)
{ {
ee_printf("\x1b[%lu;H ", oldCursorPos - windowPos); // Clear old cursor. ee_printf("\x1b[%lu;H ", oldCursorPos - windowPos); // Clear old cursor.
ee_printf("\x1b[%lu;H\x1b[37m>", cursorPos - windowPos); // Draw cursor. ee_printf("\x1b[%lu;H\x1b[33m> %.51s", cursorPos - windowPos, &dList->ptrs[cursorPos][1]); // Draw cursor.
u32 kDown; u32 kDown;
do do
@ -193,12 +193,12 @@ Result browseFiles(const char *const basePath, char selected[512])
if((u32)cursorPos < windowPos) if((u32)cursorPos < windowPos)
{ {
windowPos = cursorPos; windowPos = cursorPos;
showDirList(dList, windowPos, (u32)cursorPos); showDirList(dList, windowPos);
} }
if((u32)cursorPos >= windowPos + SCREEN_ROWS) if((u32)cursorPos >= windowPos + SCREEN_ROWS)
{ {
windowPos = cursorPos - (SCREEN_ROWS - 1); windowPos = cursorPos - (SCREEN_ROWS - 1);
showDirList(dList, windowPos, (u32)cursorPos); showDirList(dList, windowPos);
} }
if(kDown & (KEY_A | KEY_B)) if(kDown & (KEY_A | KEY_B))
@ -228,7 +228,7 @@ Result browseFiles(const char *const basePath, char selected[512])
if((res = scanDir(curDir, dList, ".gba")) != RES_OK) break; if((res = scanDir(curDir, dList, ".gba")) != RES_OK) break;
cursorPos = 0; cursorPos = 0;
windowPos = 0; windowPos = 0;
showDirList(dList, 0, 0); showDirList(dList, 0);
} }
} }