resize_term
是一個ncurses函數。
resize_term
功能不會更改您的終端的大小;它改變了ncurses假定的尺寸。
由於沒有任何內容被curses顯示,並且(請參閱notes in the manual page),您的示例沒有getch
,因此curses沒有任何內容顯示爲更改。
有趣的是,PDCurses實現了一個名稱相同的函數(受ncurses啓發:其中有幾個),它們的描述有所不同。從註釋中引用的pdcurses/initscr.c
:
和功能與此開始:
int resize_term(int nlines, int ncols)
{
PDC_LOG(("resize_term() - called: nlines %d\n", nlines));
if (!stdscr || PDC_resize_screen(nlines, ncols) == ERR)
return ERR;
SP->lines = PDC_get_rows();
LINES = SP->lines - SP->linesrippedoff - SP->slklines;
SP->cols = COLS = PDC_get_columns();
進而調用這個for Windows控制檯:
int PDC_resize_screen(int nlines, int ncols)
{
SMALL_RECT rect;
COORD size, max;
if (nlines < 2 || ncols < 2)
return ERR;
max = GetLargestConsoleWindowSize(pdc_con_out);
rect.Left = rect.Top = 0;
rect.Right = ncols - 1;
if (rect.Right > max.X)
rect.Right = max.X;
rect.Bottom = nlines - 1;
if (rect.Bottom > max.Y)
rect.Bottom = max.Y;
size.X = rect.Right + 1;
size.Y = rect.Bottom + 1;
_fit_console_window(pdc_con_out, &rect);
SetConsoleScreenBufferSize(pdc_con_out, size);
_fit_console_window(pdc_con_out, &rect);
SetConsoleScreenBufferSize(pdc_con_out, size);
SetConsoleActiveScreenBuffer(pdc_con_out);
return OK;
}
,這樣你可以看到結果是不兼容的功能。 (有一個與SDL相似的端口)。有相關PDCurses行爲幾個問題:
然而,PDCurses通常安裝其頭文件爲<xcurses.h>
從詛咒(或ncurses的)表示其差異。我認爲這個問題是關於ncurses的,問題是關於庫函數做什麼的困惑:
回到PDCurses,奇怪的是,它使相同的兩個電話兩次。該PDCurses功能使得可能多次嘗試,減少了給定的值,直到它們適應 - 與否:
/* Calls SetConsoleWindowInfo with the given parameters, but fits them
if a scoll bar shrinks the maximum possible value. The rectangle
must at least fit in a half-sized window. */
static BOOL _fit_console_window(HANDLE con_out, CONST SMALL_RECT *rect)
{
SMALL_RECT run;
SHORT mx, my;
if (SetConsoleWindowInfo(con_out, TRUE, rect))
return TRUE;
run = *rect;
run.Right /= 2;
run.Bottom /= 2;
mx = run.Right;
my = run.Bottom;
if (!SetConsoleWindowInfo(con_out, TRUE, &run))
return FALSE;
for (run.Right = rect->Right; run.Right >= mx; run.Right--)
if (SetConsoleWindowInfo(con_out, TRUE, &run))
break;
if (run.Right < mx)
return FALSE;
for (run.Bottom = rect->Bottom; run.Bottom >= my; run.Bottom--)
if (SetConsoleWindowInfo(con_out, TRUE, &run))
return TRUE;
return FALSE;
}
的代碼如下......奇怪,除了做同樣的事情兩次。參考SetConsoleWindowInfo的MSDN描述,矩形參數是參數中的(未修改)。通過,它採取的請求的大小,並紛紛試圖
- 下面的參數設置請求的大小,或
- 設置請求線,同時減少列到一半的初始大小,或
- 集請求的列,同時將行數減少到初始大小的一半。
也許這樣做兩次的原因是因爲控制檯API中存在一些不確定的行爲。代碼中的評論沒有任何幫助。
如果你在Win64上,爲什麼不使用標準控制檯功能而不是一些unix-port的東西? – BitTickler