【问题标题】:window/panel always seems to be 3 chars width窗口/面板似乎总是 3 个字符宽度
【发布时间】:2022-11-02 16:09:22
【问题描述】:

我正在尝试使用带有移动窗口的 c++ 创建一个 ncursesw 程序。但我的窗口似乎总是 3 个字符。即使使用 getmaxyx 我得到正确大小的窗口,我也不知道我做错了什么。

这是我的代码:

#ifndef MAIN_CPP
#define MAIN_CPP

#include <iostream>
#include <ncursesw/ncurses.h>
#include <panel.h>

using namespace std;

void quit();

int main(int argc, char* argv[]) {
  // Init Curses ----------
  setlocale(LC_ALL, "");
  WINDOW* win = initscr();
  atexit(quit);
  curs_set(0);
  start_color();
  clear();
  noecho();
  cbreak();
  keypad(stdscr, true);

  // Create window / panel
  WINDOW* win2 = newwin(9, 18, 0, 0);
  PANEL* pan2 = new_panel(win2);

  waddstr(win, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");

  waddstr(win2, "abcdefghijklmnopqrstuvwxyz");

  box(win2, 0, 0);

  update_panels();
  doupdate();

  getch();

  return 0;
}

void quit() {
  endwin();
}

#endif

我编译使用:

g++ -o wintest main.cpp -lncursesw -lpanel

我的输出总是这样:

窗口和面板仅占用 3 的宽度 waddstr 清楚地写入 18 个字符并在 18 个字符之后中断为另一个,并且该框也尝试输出正确的大小,但只有前 3 列可见。 (这由在 stdwin(var name win)上可见的大写字符的输出和从第二行的字母 s(框后面)开始的小写字符表示,这是输出中的 19 个字符。)

【问题讨论】:

    标签: c++ terminal ncurses


    【解决方案1】:

    那是从一个窗口/刷新覆盖另一个。这是一个调试跟踪(省略了keypad 的一些细节,以保持简短):

    TRACING NCURSES version 6.3.20221029 (tracelevel=0x24)
    - TRACE_UPDATE (4)
    - TRACE_CALLS (32)
    called {initscr()
    _nc_alloc_screen_sp screen1
    your terminal name is screen.xterm-new
    using 2048 for getstr limit
    duplicate /usr/local/ncurses/share/terminfo
    duplicate /usr/share/terminfo
    duplicate /usr/local/ncurses/share/terminfo
    not found /users/tom/.terminfo
    _nc_next_db 1 /usr/local/ncurses/share/terminfo
    _nc_setup_tinfo returns 1
    screen size: terminfo lines = 24 columns = 80
    SYS screen size: environment LINES = 40 COLUMNS = 80
    screen size: environment LINES = 24
    screen size is 24x80
    TABSIZE = 8
    created SP screen1
    screen size: terminfo lines = 24 columns = 80
    SYS screen size: environment LINES = 40 COLUMNS = 80
    screen size: environment LINES = 24
    screen size is 24x80
    TABSIZE = 8
    create :screen screen.xterm-new 24x80
    initializing ACS map
    READ acs_chars "``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~"
    DIFF acs_chars "+>,<-^.v0#A+B+C+D+E+F+G+H+I+J+K+L+M+N+Q-R-T+U+V+W+X|Y|``aaffggh#iijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~"
    2 REPEATS OF _nc_unicode_locale(UTF-8) ->1
    initializing WIDE-ACS map (Unicode is active)
    _nc_get_locale "en_US.UTF-8"
    legacy-coding 0
    creating newscr
    create :window newscr
    creating curscr
    create :window curscr
    creating stdscr
    create :window stdscr
    _nc_tiparm: format is null
    CatchIfDefault - will catch SIGINT
    CatchIfDefault - will catch SIGTERM
    CatchIfDefault - will catch SIGWINCH
    return }stdscr
    called {curs_set(screen1,0)
    return }1
    called {start_color(screen1)
    started color: COLORS = 8, COLOR_PAIRS = 64
    return }0
    called {clear()
    return }0
    called {noecho(screen1)
    return }0
    called {cbreak(screen1)
    return }0
    called {keypad(stdscr,1)
    return }0
    called {newwin(screen1, 9,18,0,0)
    create :window window0
    return }window0
    called {new_panel(window0)
    create :root_panel panel0
    create :user_ptr user_ptr0
    create :new_panel panel1
    create :user_ptr user_ptr1
    --> show_panel "user_ptr1"
    <lt1> b="user_ptr0" t="user_ptr0"
    pan id="user_ptr1"
    stk id="user_ptr0" b=-- a=-- y=0 x=0
    <lt9> b="user_ptr0" t="user_ptr1"
    pan id="user_ptr1"
    stk id="user_ptr0" b=-- a="user_ptr1" y=0 x=0
    stk id="user_ptr1" b="user_ptr0" a=-- y=0 x=0
    return }panel1
    RUN of waddnstr()s: stdscr, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    RUN of waddnstr()s: window0, "abcdefghijklmnopqrstuvwxyz"
    called {box(window0,{000},{000})
    using {ACS_VLINE}, {ACS_VLINE}, {ACS_HLINE}, {ACS_HLINE}, {ACS_ULCORNER}, {ACS_URCORNER}, {ACS_LLCORNER}, {ACS_LRCORNER}
    return }0
    called {update_panels(screen1)
    --> update_panels
    wnoutrefresh id="user_ptr0" b=-- a="user_ptr1" y=0 x=0
    ...win[ 0]   0 79 ='ABCDEFGHIJKLMNOPQRSTUVWXYZ '
    ...win[ 1]   0 79 ='                           '
    ...win[ 2]   0 79 ='                           '
    ...win[ 3]   0 79 ='                           '
    ...win[ 4]   0 79 ='                           '
    ...win[ 5]   0 79 ='                           '
    ...win[ 6]   0 79 ='                           '
    ...win[ 7]   0 79 ='                           '
    ...win[ 8]   0 79 ='                           '
    ...win[ 9]   0 79 ='                           '
    ...win[10]   0 79 ='                           '
    ...win[11]   0 79 ='                           '
    ...win[12]   0 79 ='                           '
    ...win[13]   0 79 ='                           '
    ...win[14]   0 79 ='                           '
    ...win[15]   0 79 ='                           '
    ...win[16]   0 79 ='                           '
    ...win[17]   0 79 ='                           '
    ...win[18]   0 79 ='                           '
    ...win[19]   0 79 ='                           '
    ...win[20]   0 79 ='                           '
    ...win[21]   0 79 ='                           '
    ...win[22]   0 79 ='                           '
    ...win[23]   0 79 ='                           '
    newscr[ 0]   0 79 ='ABCDEFGHIJKLMNOPQRSTUVWXYZ '
    newscr[ 1]   0 79 ='                           '
    newscr[ 2]   0 79 ='                           '
    newscr[ 3]   0 79 ='                           '
    newscr[ 4]   0 79 ='                           '
    newscr[ 5]   0 79 ='                           '
    newscr[ 6]   0 79 ='                           '
    newscr[ 7]   0 79 ='                           '
    newscr[ 8]   0 79 ='                           '
    newscr[ 9]   0 79 ='                           '
    newscr[10]   0 79 ='                           '
    newscr[11]   0 79 ='                           '
    newscr[12]   0 79 ='                           '
    newscr[13]   0 79 ='                           '
    newscr[14]   0 79 ='                           '
    newscr[15]   0 79 ='                           '
    newscr[16]   0 79 ='                           '
    newscr[17]   0 79 ='                           '
    newscr[18]   0 79 ='                           '
    newscr[19]   0 79 ='                           '
    newscr[20]   0 79 ='                           '
    newscr[21]   0 79 ='                           '
    newscr[22]   0 79 ='                           '
    newscr[23]   0 79 ='                           '
    wnoutrefresh id="user_ptr1" b="user_ptr0" a=-- y=0 x=0
    ...win[ 0]   0 17 ='lqqqqqqqqqqqqqqqqk'
    attrs1[ 0]        ='444444444444444444'
    ...win[ 1]   0 17 ='xtuvwxyz         x'
    attrs1[ 1]        ='4                4'
    ...win[ 2]   0 17 ='x                x'
    attrs1[ 2]        ='4                4'
    ...win[ 3]   0 17 ='x                x'
    attrs1[ 3]        ='4                4'
    ...win[ 4]   0 17 ='x                x'
    attrs1[ 4]        ='4                4'
    ...win[ 5]   0 17 ='x                x'
    attrs1[ 5]        ='4                4'
    ...win[ 6]   0 17 ='x                x'
    attrs1[ 6]        ='4                4'
    ...win[ 7]   0 17 ='x                x'
    attrs1[ 7]        ='4                4'
    ...win[ 8]   0 17 ='mqqqqqqqqqqqqqqqqj'
    attrs1[ 8]        ='444444444444444444'
    newscr[ 0]   0 79 ='lqqqqqqqqqqqqqqqqkSTUVWXYZ '
    attrs1[ 0]        ='444444444444444444         '
    newscr[ 1]   0 79 ='xtuvwxyz         x         '
    attrs1[ 1]        ='4                4         '
    newscr[ 2]   0 79 ='x                x         '
    attrs1[ 2]        ='4                4         '
    newscr[ 3]   0 79 ='x                x         '
    attrs1[ 3]        ='4                4         '
    newscr[ 4]   0 79 ='x                x         '
    attrs1[ 4]        ='4                4         '
    newscr[ 5]   0 79 ='x                x         '
    attrs1[ 5]        ='4                4         '
    newscr[ 6]   0 79 ='x                x         '
    attrs1[ 6]        ='4                4         '
    newscr[ 7]   0 79 ='x                x         '
    attrs1[ 7]        ='4                4         '
    newscr[ 8]   0 79 ='mqqqqqqqqqqqqqqqqj         '
    attrs1[ 8]        ='444444444444444444         '
    newscr[ 9]   0 79 ='                           '
    newscr[10]   0 79 ='                           '
    newscr[11]   0 79 ='                           '
    newscr[12]   0 79 ='                           '
    newscr[13]   0 79 ='                           '
    newscr[14]   0 79 ='                           '
    newscr[15]   0 79 ='                           '
    newscr[16]   0 79 ='                           '
    newscr[17]   0 79 ='                           '
    newscr[18]   0 79 ='                           '
    newscr[19]   0 79 ='                           '
    newscr[20]   0 79 ='                           '
    newscr[21]   0 79 ='                           '
    newscr[22]   0 79 ='                           '
    newscr[23]   0 79 ='                           '
    return }
    called {_nc_tinfo:doupdate(screen1)
    curscr[ 0]   0 79 ='  '
    curscr[ 1]   0 79 ='  '
    curscr[ 2]   0 79 ='  '
    curscr[ 3]   0 79 ='  '
    curscr[ 4]   0 79 ='  '
    curscr[ 5]   0 79 ='  '
    curscr[ 6]   0 79 ='  '
    curscr[ 7]   0 79 ='  '
    curscr[ 8]   0 79 ='  '
    curscr[ 9]   0 79 ='  '
    curscr[10]   0 79 ='  '
    curscr[11]   0 79 ='  '
    curscr[12]   0 79 ='  '
    curscr[13]   0 79 ='  '
    curscr[14]   0 79 ='  '
    curscr[15]   0 79 ='  '
    curscr[16]   0 79 ='  '
    curscr[17]   0 79 ='  '
    curscr[18]   0 79 ='  '
    curscr[19]   0 79 ='  '
    curscr[20]   0 79 ='  '
    curscr[21]   0 79 ='  '
    curscr[22]   0 79 ='  '
    curscr[23]   0 79 ='  '
    newscr[ 0]   0 79 ='lqqqqqqqqqqqqqqqqkSTUVWXYZ '
    attrs1[ 0]        ='444444444444444444         '
    newscr[ 1]   0 79 ='xtuvwxyz         x         '
    attrs1[ 1]        ='4                4         '
    newscr[ 2]   0 79 ='x                x         '
    attrs1[ 2]        ='4                4         '
    newscr[ 3]   0 79 ='x                x         '
    attrs1[ 3]        ='4                4         '
    newscr[ 4]   0 79 ='x                x         '
    attrs1[ 4]        ='4                4         '
    newscr[ 5]   0 79 ='x                x         '
    attrs1[ 5]        ='4                4         '
    newscr[ 6]   0 79 ='x                x         '
    attrs1[ 6]        ='4                4         '
    newscr[ 7]   0 79 ='x                x         '
    attrs1[ 7]        ='4                4         '
    newscr[ 8]   0 79 ='mqqqqqqqqqqqqqqqqj         '
    attrs1[ 8]        ='444444444444444444         '
    newscr[ 9]   0 79 ='                           '
    newscr[10]   0 79 ='                           '
    newscr[11]   0 79 ='                           '
    newscr[12]   0 79 ='                           '
    newscr[13]   0 79 ='                           '
    newscr[14]   0 79 ='                           '
    newscr[15]   0 79 ='                           '
    newscr[16]   0 79 ='                           '
    newscr[17]   0 79 ='                           '
    newscr[18]   0 79 ='                           '
    newscr[19]   0 79 ='                           '
    newscr[20]   0 79 ='                           '
    newscr[21]   0 79 ='                           '
    newscr[22]   0 79 ='                           '
    newscr[23]   0 79 ='                           '
    ClearScreen() called
    screen cleared
    updating screen from scratch
    return }0
    called {wgetch(stdscr)
    wgetch returning : 012
    return }10
    called {endwin(screen1)
    return }0
    

    这些中的每一个都会显式地或作为副作用进行刷新:

      update_panels();
      doupdate();
    
      getch();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-23
      • 2012-06-09
      相关资源
      最近更新 更多