有谁知道如何%在基于ncurses的C++/C =程序中显示百分比字符?
我已经尝试使用\x25和%,但他们没有工作.
我正在创建一个类似客户端 - 服务器聊天的应用程序C++,我正在做UI ncurses.我想存储所有消息,vector<char *> msgVector以便能够定期重绘整个屏幕.然而,当我想打印出值时,所有项目都具有相同的值 - 最后接受的消息.
void acceptMessages() {
char buffer[256];
fd = c->createClient2Fd("localhost", 12345);
while (true) {
memset(buffer, 0, sizeof ( buffer));
int l = recv(fd, buffer, sizeof ( buffer), 0);
msgVector.push_back(buffer);
redrawScreen();
}
void redrawScreen() {
erase();
mvhline(0, 0, ACS_HLINE, COLS);
mvhline(LINES - 2, 0, ACS_HLINE, COLS);
mvaddstr(LINES - 1, 0, "MESSAGE:");
move(LINES - 1, 9);
// prints right count of messages
// but on every line is printed only the …Run Code Online (Sandbox Code Playgroud) 我目前正在尝试使用 ncurses 绘制一组框。此时我有代表这些框的长度和宽度的变量。一件事是我不允许使用像“ WINDOW * win = newwin(10, 10, 1, 1);”这样的命令。
如果我可以提供任何其他信息来帮助您帮助我,请告诉我。
假设有一个 ncurses pad。
1.) 我可以创建pad 的子窗口吗?理论上,subwin 会与 pad 共享内存。但是当我调用这个子窗口时会发生什么wrefresh?
2.) 我可以创建pad 的子 pad吗?wrefresh如果是,拨打电话或prefresh在副台上有意义吗?
我目前的理解是,必须为 pad 创建一个 subpad。传递给subpad函数的坐标指定(父)焊盘的位置。返回的子板在概念上是一个窗口(不能大于其父结构),尽管它必须使用该prefresh函数放置到屏幕上。它与父垫共享内存。正确的?
我正在尝试为嵌入式系统编译 ncurses 5.9(使用 buildroot),但收到以下错误消息:
\n\nIn file included from ../c++/cursesm.h:39:0,\n from ../c++/cursesm.cc:35:\n../c++/cursesp.h: In member function \xe2\x80\x98T* NCursesUserPanel<T>::UserData() const\xe2\x80\x99:\n../c++/cursesp.h:256:43: error: no matching function for call to \n\xe2\x80\x98NCursesUserPanel<T>::get_user() const\xe2\x80\x99\n return reinterpret_cast<T*>(get_user ());\nRun Code Online (Sandbox Code Playgroud)\n\n这是有问题的代码:
\n\n/* We use templates to provide a typesafe mechanism to associate\n * user data with a panel. A NCursesUserPanel<T> is a panel\n * associated with some user data of type T.\n */\ntemplate<class T> class NCursesUserPanel : public NCursesPanel\n{\npublic:\n NCursesUserPanel (int nlines,\n int ncols,\n int begin_y = 0,\n …Run Code Online (Sandbox Code Playgroud) 在 terminfo(5) 中:
Variable String Capname TCapCode Description
---------------------------------------------------------------
cursor_up cuu1 up up one line
key_up kcuu1 ku up-arrow key
Run Code Online (Sandbox Code Playgroud)
我尝试使用 tput 并且它们产生相同的输出:
[STEP 102] # tput cuu1 | hd -C
00000000 1b 5b 41 |.[A|
00000003
[STEP 103] # tput kcuu1 | hd -C
00000000 1b 5b 41 |.[A|
00000003
[STEP 104] #
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 编译任何内容ncurses,但出现某种链接错误。为什么?在此先感谢您的帮助。
#include <stdlib.h>
#include <ncurses.h>
int main(void)
{
initscr();
printw("Hello World!!");
refresh();
getch();
endwin();
return 0;
}
lore% gcc -o helloworld helloworld.c -lncurses
/usr/lib/gcc/x86_64-pc-linux-gnu/8.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: /tmp/cc37p6Qp.o: un
defined reference to symbol 'stdscr' /lib64/libtinfo.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud) 所以我目前正在做一个ncurses用于输出和输入的项目。在这个程序中,用户应该能够,例如,写下他的名字。我遇到的问题是getnstr,因为它会导致一些非常奇怪且无法解释的分段错误。例如,这里的代码可以正常工作:
#include <ncurses.h>
#include <string>
int main()
{
char *word;
initscr();
WINDOW *window = newwin(100, 100, 0, 0);
nodelay(window, false);
refresh();
mvwgetnstr(window, 0, 0, word, 10);
mvwprintw(window, 0, 0, "Word written is %s", word);
wrefresh(window);
getch();
endwin();
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我只在主函数中添加一个字符串变量,例如以这种形式:
#include <ncurses.h>
#include <string>
int main()
{
std::string crashMe;
char *word;
initscr();
WINDOW *window = newwin(100, 100, 0, 0);
nodelay(window, false);
refresh();
mvwgetnstr(window, 0, 0, word, 10);
mvwprintw(window, 0, 0, "Word written is %s", word);
wrefresh(window);
getch(); …Run Code Online (Sandbox Code Playgroud) 下面的代码只能更改属性并保留颜色。
init_color(1, 255);
init_color(2, 1);
init_pair(1, 1, 2);
attron(COLOR_PAIR(1)); // only change the pair of foreground and background color
addstr("aaa");
attron(A_BOLD); // only change the attribute
addstr("aaa");
attrset(COLOR_PAIR(1)|A_BOLD); // change both
Run Code Online (Sandbox Code Playgroud)
我想知道我们是否可以只改变前景色,但保留背景色。
attron_fg(BACKGROUND_YELLOW); // only change the foreground color
addstr("aaa");
Run Code Online (Sandbox Code Playgroud) 我正在尝试制作一个非常简单的类似蛇的游戏,如果您尝试使用已经访问过的斧头坐标,则会输掉该游戏。
到目前为止,这是起作用的代码(您可以使用箭头键移动播放器1并使用wasd移动播放器2):
import UI.NCurses
main :: IO ()
main = runCurses $ do
w <- defaultWindow
updateWindow w $ do
drawBorder Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing
render
loop w [] 1 1 0 0 10 10 0 0
loop :: Window -> [(Integer, Integer)] -> Integer -> Integer -> Integer -> Integer -> Integer -> Integer -> Integer -> Integer -> Curses ()
loop w list p1x p1y p1oldDx p1oldDy p2x p2y p2oldDx p2oldDy = do
e …Run Code Online (Sandbox Code Playgroud)