MCPcopy Create free account
hub / github.com/NetHack/NetHack / resize_tty

Function resize_tty

win/tty/wintty.c:391–467  ·  view source on GitHub ↗

query the system for tty size (vis getwindowsz()), and adapt the game's windows to match */

Source from the content-addressed store, hash-verified

389/* query the system for tty size (vis getwindowsz()), and adapt the game's
390 windows to match */
391static void
392resize_tty(void)
393{
394 int oldLI = LI, oldCO = CO, mapx, mapy, oldtoplin, i;
395 boolean map_active;
396 struct WinDesc *cw;
397
398 /* reset to 0 rather than just decrement */
399 program_state.resize_pending = 0;
400 resize_mesg = 0;
401
402 getwindowsz(); /* update LI and CO */
403 if (!ttyDisplay || (LI == oldLI && CO == oldCO))
404 return;
405
406 ttyDisplay->rows = LI;
407 ttyDisplay->cols = CO;
408
409 cw = wins[BASE_WINDOW];
410 cw->rows = ttyDisplay->rows;
411 cw->cols = ttyDisplay->cols;
412
413 if (!iflags.window_inited)
414 return;
415
416 /* try to figure out where we'll want to leave the cursor */
417 cw = (WIN_MAP != WIN_ERR) ? wins[WIN_MAP] : NULL;
418 map_active = (cw && cw->active);
419 if (!map_active)
420 mapx = 1, mapy = 0;
421 else if (gg.getposx < 1)
422 mapx = u.ux, mapy = u.uy;
423 else
424 mapx = gg.getposx, mapy = gg.getposy;
425
426 oldtoplin = ttyDisplay->toplin;
427 ttyDisplay->toplin = TOPLINE_EMPTY; /* (before term_clear_screen()) */
428 /* whatever used to be on the screen has become suspect;
429 blank it all out, then redo the display */
430 term_clear_screen();
431 new_status_window();
432
433 /* if the map window is shown, redisplay it (also status, perminv) */
434 if (map_active) {
435 docrt_flags(docrtRefresh);
436 bot(); /* context.botlx=1 gets set by docrt() */
437 for (i = 0; i < MAXWIN; ++i) {
438 if (i == BASE_WINDOW
439 || i == WIN_MAP /* docrt() updates it */
440 || i == WIN_STATUS /* docrt()+bot() updates it */
441#ifdef TTY_PERM_INVENT
442 || i == WIN_INVEN /* docrt() again */
443#endif
444 || i == WIN_MESSAGE) /* we fake it here */
445 continue;
446 if (wins[i] && wins[i]->active) {
447 /* cop-out */
448 oldtoplin = TOPLINE_EMPTY; /* don't restore it below */

Callers 2

winch_handlerFunction · 0.85
tty_nhgetchFunction · 0.85

Calls 9

new_status_windowFunction · 0.85
docrt_flagsFunction · 0.85
botFunction · 0.85
addtoplFunction · 0.85
newclippingFunction · 0.85
tty_cursFunction · 0.85
tty_display_nhwindowFunction · 0.85
term_clear_screenFunction · 0.70
getwindowszFunction · 0.50

Tested by

no test coverage detected