2016-10-26 44 views
1
#include <iostream> 
#include <curses.h> 
#include "SourceFiles/generalFunc.h" 

int main() 
{ 

    initscr(); 
    int x = resize_term(51, 79); 
    sleepMilli(5000); //sleep for 5 seconds 
    endwin(); 
    std::cout << x << " " << int(ERR) << " " << int(OK); 

} 

屏幕,我的電腦上,是不是在這種情況下調整,儘管x就返回0indicating the resizing was successful)。它與原始終端窗口保持相同的大小。但是,如果我將79增加到80,或者將51減小到50,那麼屏幕就像正常一樣在我的屏幕上調整大小。我的屏幕足夠大以容納這些尺寸一英里 - 甚至仍然是,從80更改爲79是窗口大小的減少,但由於某些原因它不起作用。它似乎不喜歡低於某個縱橫比。Pdcurses' resize_term似乎工作隨機

有沒有關於爲什麼我可以做的調整大小似乎有限制的更多信息,即使這些數字遠不及我的屏幕可以容納的限制?這是64位Windows上的pdcurses。

+0

如果你在Win64上,爲什麼不使用標準控制檯功能而不是一些unix-port的東西? – BitTickler

回答

2

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描述,矩形參數是參數中的(未修改)。通過,它採取的請求的大小,並紛紛試圖

  1. 下面的參數設置請求的大小,或
  2. 設置請求線,同時減少列到一半的初始大小,或
  3. 集請求的列,同時將行數減少到初始大小的一半。

也許這樣做兩次的原因是因爲控制檯API中存在一些不確定的行爲。代碼中的評論沒有任何幫助。

+0

對不起,我不夠清楚。問題是關於64位Windows上的PDcurses。我會編輯我的OP。 – SergeantPenguin