1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00

Add keyboard number selection to chvideomode(1).

This commit is contained in:
Jonas 'Sortie' Termansen 2015-12-27 22:19:36 +01:00
parent 5ba7ce6802
commit 794cfd057a

View file

@ -444,22 +444,22 @@ retry_pick_mode:
if ( settermmode(0, TERMMODE_KBKEY | TERMMODE_UNICODE | TERMMODE_SIGNAL) < 0 )
error(1, errno, "settermmode");
bool redraw = false;
while ( !redraw && !decided )
{
uint32_t codepoint;
ssize_t numbytes;
int kbkey = 0;
while ( 0 < (numbytes = read(0, &codepoint, sizeof(codepoint))) &&
(kbkey = KBKEY_DECODE(codepoint)) == 0 )
continue;
if ( settermmode(0, oldtermmode) < 0 )
error(1, errno, "settermmode");
ssize_t numbytes = read(0, &codepoint, sizeof(codepoint));
if ( numbytes < 0 )
error(1, errno, "read");
int kbkey = KBKEY_DECODE(codepoint);
if ( kbkey )
{
switch ( kbkey )
{
case KBKEY_ESC:
if ( settermmode(0, oldtermmode) < 0 )
error(1, errno, "settermmode");
printf("\n");
exit(10);
break;
@ -468,20 +468,41 @@ retry_pick_mode:
selection--;
else
selection = num_modes -1;
redraw = true;
break;
case KBKEY_DOWN:
if ( selection + 1 == num_modes )
selection = 0;
else
selection++;
redraw = true;
break;
case KBKEY_ENTER:
if ( settermmode(0, oldtermmode) < 0 )
error(1, errno, "settermmode");
fgetc(stdin);
printf("\n");
decided = true;
break;
}
}
else
{
if ( L'0' <= codepoint && codepoint <= '9' )
{
uint32_t requested = codepoint - '0';
if ( requested < num_modes )
{
selection = requested;
redraw = true;
}
}
}
}
if ( settermmode(0, oldtermmode) < 0 )
error(1, errno, "settermmode");
}
struct dispmsg_crtc_mode mode = modes[selection];
if ( mode.control & DISPMSG_CONTROL_OTHER_RESOLUTIONS )