-1

Ncurses with box-drawing characters

I am using wsl 2 in windows 10, and i am using windows terminal the question's title tells my problem

#include <ncurses.h>
int main() {
  initscr();
  int height, width;
  int positionX, positionY;
  height = 10;
  width = 20;
  positionX = 0;
  positionY = 0;
  WINDOW * win = newwin(height, width, positionX, positionY);
  refresh();
  cchar_t verticalLine;
  /* setcchar(); */
  /* curs_getcchar(); */
  setcchar(&verticalLine, L"│", 0, 0, nullptr);
  cchar_t horizontalLine;
  setcchar(&horizontalLine, L"─", 0, 0, nullptr);
  cchar_t tlc, trc, brc, blc;
  setcchar(&tlc, L"u", 0, 0, nullptr);
  setcchar(&trc, L"u", 0, 0, nullptr);
  setcchar(&blc, L"u", 0, 0, nullptr);
  setcchar(&brc, L"u", 0, 0, nullptr);
  wborder_set(win, &verticalLine, &horizontalLine, &verticalLine, &verticalLine, &tlc, &trc, &blc, &brc);
  wrefresh(win);

  getch();

  endwin();
}

i tried this code but failed to get the output

terminal output

rafid100
  • 11
  • 3
  • Interesting, it does the same in Linux. I dunno why. But I note that it works with PDCurses. There's a bug in your wborder_set() parameters which you'll discover if you get to that point, but it's not the reason they're blank here. – William McBrine Jun 14 '23 at 17:10
  • 1
    The output isn't shown, but since it's using wide-character calls without initializing the locale (see [manpage](https://invisible-island.net/ncurses/man/ncurses.3x.html#h3-Initialization)), that's the first thing to check. That would be a [duplicate](https://stackoverflow.com/questions/43671649/how-does-ncurses-output-non-ascii-characters/43709097#43709097) of course. – Thomas Dickey Jun 14 '23 at 19:36
  • Does this answer your question? [How does ncurses output non-ascii characters?](https://stackoverflow.com/questions/43671649/how-does-ncurses-output-non-ascii-characters) – Thomas Dickey Jun 14 '23 at 20:51
  • sorry I didn't get this link when I searched in Stackoverflow. – rafid100 Jun 15 '23 at 11:20

1 Answers1

0

The problem was solve by this:

#include <ncurses.h>
#include <locale.h>
int main() {
  setlocale(LC_ALL, "");
  initscr();
  int height, width;
  int positionX, positionY;
  height = 10;
  width = 20;
  positionX = 0;
  positionY = 0;
  WINDOW * win = newwin(height, width, positionX, positionY);
  refresh();
  cchar_t verticalLine;
  /* setcchar(); */
  /* curs_getcchar(); */
  setcchar(&verticalLine, L"│", 0, 0, nullptr);
  cchar_t horizontalLine;
  setcchar(&horizontalLine, L"─", 0, 0, nullptr);
  cchar_t tlc, trc, brc, blc;
  setcchar(&tlc, L"u", 0, 0, nullptr);
  setcchar(&trc, L"u", 0, 0, nullptr);
  setcchar(&blc, L"u", 0, 0, nullptr);
  setcchar(&brc, L"u", 0, 0, nullptr);
  wborder_set(win, &verticalLine, &horizontalLine, &verticalLine, &verticalLine, &tlc, &trc, &blc, &brc);
  wrefresh(win);

  getch();

  endwin();
}

it was a duplicate of this How does ncurses output non-ascii characters?

rafid100
  • 11
  • 3
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 20 '23 at 22:32