r458 - in trunk: . scripts
DONOTREPLY at icculus.org
DONOTREPLY at icculus.org
Thu Jan 24 04:04:07 EST 2008
Author: icculus
Date: 2008-01-24 04:03:53 -0500 (Thu, 24 Jan 2008)
New Revision: 458
Modified:
trunk/gui_ncurses.c
trunk/scripts/localization.lua
Log:
Deal with badly-sized terminals in ncurses UI, instead of crashing if the
window shrinks too much.
Modified: trunk/gui_ncurses.c
===================================================================
--- trunk/gui_ncurses.c 2008-01-24 08:43:53 UTC (rev 457)
+++ trunk/gui_ncurses.c 2008-01-24 09:03:53 UTC (rev 458)
@@ -234,6 +234,50 @@
} // drawBackground
+static void confirmTerminalSize(void)
+{
+ int scrw = 0;
+ int scrh = 0;
+ char *msg = NULL;
+ int len = 0;
+ int x = 0;
+ int y = 0;
+
+ while (1) // loop until the window meets a minimum dimension requirement.
+ {
+ getmaxyx(stdscr, scrh, scrw);
+ scrh--; // -1 to save the title at the top of the screen...
+
+ if (scrw < 30) // too thin
+ msg = entry->xstrdup(entry->_("[Make the window wider!]"));
+ else if (scrh < 10) // too short
+ msg = entry->xstrdup(entry->_("[Make the window taller!]"));
+ else
+ break; // we're good, get out.
+
+ len = strcells(msg);
+ y = scrh / 2;
+ x = ((scrw - len) / 2);
+
+ if (y < 0) y = 0;
+ if (x < 0) x = 0;
+
+ wclear(stdscr);
+ wmove(stdscr, y, x);
+ wrefresh(stdscr);
+ wmove(stdscr, y, x);
+ wattron(stdscr, COLOR_PAIR(MOJOCOLOR_BACKGROUND) | A_BOLD);
+ waddstr(stdscr, msg);
+ wattroff(stdscr, COLOR_PAIR(MOJOCOLOR_BACKGROUND) | A_BOLD);
+ nodelay(stdscr, 0);
+ wrefresh(stdscr);
+ free(msg);
+
+ while (wgetch(stdscr) != KEY_RESIZE) { /* no-op. */ }
+ } // while
+} // confirmTerminalSize
+
+
static MojoBox *makeBox(const char *title, const char *text,
char **buttons, int bcount,
boolean ndelay, boolean hidecursor)
@@ -250,10 +294,10 @@
int texth = 0;
int i;
+ confirmTerminalSize(); // blocks until window is large enough to continue.
+
getmaxyx(stdscr, scrh, scrw);
scrh--; // -1 to save the title at the top of the screen...
- if ((scrw < 16) || (scrh < 16))
- return NULL;
retval = (MojoBox *) entry->xmalloc(sizeof (MojoBox));
retval->hidecursor = hidecursor;
@@ -299,6 +343,13 @@
x = (scrw - w) / 2;
y = ((scrh - h) / 2) + 1;
+
+ // can't have negative coordinates, so in case we survived the call to
+ // confirmTerminalSize() but still need more, just draw as much as
+ // possible from the top/left to fill the window.
+ if (x < 0) x = 0;
+ if (y < 0) y = 0;
+
win = retval->mainwin = newwin(h, w, y, x);
keypad(win, TRUE);
nodelay(win, ndelay);
Modified: trunk/scripts/localization.lua
===================================================================
--- trunk/scripts/localization.lua 2008-01-24 08:43:53 UTC (rev 457)
+++ trunk/scripts/localization.lua 2008-01-24 09:03:53 UTC (rev 458)
@@ -967,6 +967,26 @@
-- This is shown to the user in a message box when uninstallation is done.
["Uninstall complete"] = {
};
+
+ -- This is written to the terminal in the ncurses UI when the window is
+ -- too thin to be usable; it's asking the user to resize the terminal
+ -- window horizontally. Since space may be extremely tight, try to be as
+ -- terse as possible (but we can wrap the text if possible, so don't be
+ -- cryptic). The '[' and ']' characters are just decoration to imply this
+ -- is a system problem outside the scope of the application, but they
+ -- aren't required.
+ ["[Make the window wider!]"] = {
+ };
+
+ -- This is written to the terminal in the ncurses UI when the window is
+ -- too short to be usable; it's asking the user to resize the terminal
+ -- window vertically. Since space may be extremely tight, try to be as
+ -- terse as possible (but we can wrap the text if possible, so don't be
+ -- cryptic). The '[' and ']' characters are just decoration to imply this
+ -- is a system problem outside the scope of the application, but they
+ -- aren't required.
+ ["[Make the window taller!]"] = {
+ };
};
-- end of localization.lua ...
More information about the mojosetup-commits
mailing list