mirror of
https://github.com/dankamongmen/notcurses
synced 2025-03-09 17:19:03 -04:00
demo: hook up Ctrl+'u' for about screen #338
This commit is contained in:
parent
9fc53e811f
commit
8beb5d66fd
@ -117,9 +117,17 @@ on blocking input, it can be tricky to guarantee that this doesn't happen.
|
||||
Failed escape sequences are not yet played back in their entirety; only an
|
||||
ESC (ASCII 0x1b) will be seen by the application.
|
||||
|
||||
The shift key is only indicated in conjunction with mouse button presses. If
|
||||
e.g. shift is used to generate a capital letter 'A', **id** will equal 'A', and
|
||||
shift will be **false**. This should be fixed in the future.
|
||||
The Shift key is only indicated in conjunction with mouse button presses. If
|
||||
e.g. Shift is used to generate a capital letter 'A', **id** will equal 'A', and
|
||||
**shift** will be **false**. This should be fixed in the future.
|
||||
|
||||
When Ctrl is pressed along with a letter, the letter will currently always be
|
||||
reported in its uppercase form. E.g., if Shift, Ctrl, and 'a' are all pressed,
|
||||
this is indistinguishable from Ctrl and 'a' without Shift. This should be fixed
|
||||
in the future.
|
||||
|
||||
Ctrl pressed along with 'J' or 'M', whether Shift is pressed or not, currently
|
||||
registers as **NCKEY_ENTER**. This will likely change in the future.
|
||||
|
||||
# SEE ALSO
|
||||
|
||||
|
@ -29,6 +29,7 @@ typedef struct elem {
|
||||
|
||||
static bool menu_unrolled;
|
||||
static struct ncmenu* menu;
|
||||
static struct ncplane* about; // "about" modal popup
|
||||
|
||||
static struct elem* elems;
|
||||
static struct elem* running;
|
||||
@ -67,9 +68,7 @@ hud_grabbed_bg(struct ncplane* n){
|
||||
|
||||
static void
|
||||
hud_toggle(struct notcurses* nc){
|
||||
if(menu){
|
||||
ncmenu_rollup(menu);
|
||||
}
|
||||
ncmenu_rollup(menu);
|
||||
if(hud){
|
||||
hud_destroy();
|
||||
}else{
|
||||
@ -77,6 +76,39 @@ hud_toggle(struct notcurses* nc){
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
about_toggle(struct notcurses* nc){
|
||||
ncmenu_rollup(menu);
|
||||
if(about){
|
||||
ncplane_destroy(about);
|
||||
about = NULL;
|
||||
return;
|
||||
}
|
||||
const int ABOUT_ROWS = 5;
|
||||
const int ABOUT_COLS = 40;
|
||||
struct ncplane* n = ncplane_aligned(notcurses_stdplane(nc),
|
||||
ABOUT_ROWS, ABOUT_COLS,
|
||||
3, NCALIGN_CENTER, NULL);
|
||||
cell ul = CELL_TRIVIAL_INITIALIZER, ur = CELL_TRIVIAL_INITIALIZER;
|
||||
cell lr = CELL_TRIVIAL_INITIALIZER, ll = CELL_TRIVIAL_INITIALIZER;
|
||||
cell hl = CELL_TRIVIAL_INITIALIZER, vl = CELL_TRIVIAL_INITIALIZER;
|
||||
if(cells_double_box(n, 0, 0, &ul, &ur, &ll, &lr, &hl, &vl) == 0){
|
||||
if(ncplane_perimeter(n, &ul, &ur, &ll, &lr, &hl, &vl, 0) == 0){
|
||||
cell_release(n, &ul); cell_release(n, &ur); cell_release(n, &hl);
|
||||
cell_release(n, &ll); cell_release(n, &lr); cell_release(n, &vl);
|
||||
if(ncplane_set_base(n, 0, 0, " ") > 0){
|
||||
ncplane_printf_aligned(n, 1, NCALIGN_CENTER, "notcurses-demo %s", notcurses_version());
|
||||
ncplane_putstr_aligned(n, 3, NCALIGN_CENTER, "\u00a9 nick black <nickblack@linux.com>");
|
||||
about = n;
|
||||
return;
|
||||
}
|
||||
cell_release(n, &ul); cell_release(n, &ur); cell_release(n, &hl);
|
||||
cell_release(n, &ll); cell_release(n, &lr); cell_release(n, &vl);
|
||||
}
|
||||
}
|
||||
ncplane_destroy(n);
|
||||
}
|
||||
|
||||
// returns true if the input was handled by the menu/HUD
|
||||
bool menu_or_hud_key(struct notcurses *nc, const struct ncinput *ni){
|
||||
// toggle the HUD
|
||||
@ -84,6 +116,10 @@ bool menu_or_hud_key(struct notcurses *nc, const struct ncinput *ni){
|
||||
hud_toggle(nc);
|
||||
return true;
|
||||
}
|
||||
if(ni->id == 'U' && !ni->alt && ni->ctrl){
|
||||
about_toggle(nc);
|
||||
return true;
|
||||
}
|
||||
if(!menu){
|
||||
return false;
|
||||
}
|
||||
@ -94,8 +130,13 @@ bool menu_or_hud_key(struct notcurses *nc, const struct ncinput *ni){
|
||||
if(strcmp(sel, MENUSTR_TOGGLE_HUD) == 0){
|
||||
hud_toggle(nc);
|
||||
return true;
|
||||
}else if(strcmp(sel, MENUSTR_ABOUT) == 0){
|
||||
about_toggle(nc);
|
||||
ncmenu_rollup(menu);
|
||||
return true;
|
||||
}else if(strcmp(sel, MENUSTR_RESTART) == 0){
|
||||
// FIXME
|
||||
}
|
||||
// FIXME handle other MENUSTR_ options
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user