한줄 또는 한글자의 색깔만 다르게 출력하는방법

jinstyner의 이미지

안녕하세요.
ncurses를 이용한 프로그래밍을 하다가,
한줄 또는 한글자의 색깔만 다르게 출력하는
방법을 알고 싶어 질문을 올립니다.

이전에 색상이 필요하면 ansi C를 이용한 코드로
색깔을 바꾸면서 썼는데, 이게 ncurses에서는 안되네요.
색깔이 바뀌지 않고 코드가 그대로 출력되네요.
ncurses는 윈도우 전체의 전경색과 배경색을 바꾸는
방법만 알고 있어서...

혹시 ncurses에서 방법을 아시거나,
ncurses의 윈도우에서 ansi C를 이용한 색상출력이
가능한 방법을 아시는 분은, 답변부탁드립니다.

익명 사용자의 이미지

#include <ncurses.h>
#include <signal.h>

static void finish(int sig);

main(int argc, char *argv[])
{
   /* initialize your non-curses data structures here */

   (void) signal(SIGINT, finish);      /* arrange interrupts to terminate */

   (void) initscr();      /* initialize the curses library */
   keypad(stdscr, TRUE);  /* enable keyboard mapping */
   (void) nonl();         /* tell curses not to do NL->CR/NL on output */
   (void) cbreak();       /* take input chars one at a time, no wait for \n */
   (void) noecho();       /* don't echo input */

   if (has_colors())
   {
      start_color();

      /*
       * Simple color assignment, often all we need.
       */
      init_pair(COLOR_BLACK, COLOR_BLACK, COLOR_BLACK);
      init_pair(COLOR_GREEN, COLOR_GREEN, COLOR_BLACK);
      init_pair(COLOR_RED, COLOR_RED, COLOR_BLACK);
      init_pair(COLOR_CYAN, COLOR_CYAN, COLOR_BLACK);
      init_pair(COLOR_WHITE, COLOR_WHITE, COLOR_BLACK);
      init_pair(COLOR_MAGENTA, COLOR_MAGENTA, COLOR_BLACK);
      init_pair(COLOR_BLUE, COLOR_BLUE, COLOR_BLACK);
      init_pair(COLOR_YELLOW, COLOR_YELLOW, COLOR_BLACK);
   }

   start_color();
   for (;;)
   {
      int c = getch();     /* accept a single keystroke of input */

      if ( c == 'A' ) {
         mvwaddch(stdscr, 10, 20, c);
         waddch(stdscr, 'X' | A_UNDERLINE);
         waddch(stdscr, 'X' | A_UNDERLINE);
         waddch(stdscr, 'X' | A_UNDERLINE | COLOR_PAIR(1));
         waddch(stdscr, 'X' | A_UNDERLINE | COLOR_PAIR(2));
         waddch(stdscr, 'X' | A_UNDERLINE | COLOR_PAIR(3));
         waddch(stdscr, 'X' | A_UNDERLINE | COLOR_PAIR(4));
         waddch(stdscr, 'X' | A_UNDERLINE | COLOR_PAIR(5));
         waddch(stdscr, 'X' | A_UNDERLINE | COLOR_PAIR(6));
         waddch(stdscr, 'X' | A_UNDERLINE | COLOR_PAIR(7));
         waddch(stdscr, 'X' | A_UNDERLINE | COLOR_PAIR(8));

      }
      /* process the command keystroke */

      refresh();           /* repaint the screen */
   }

   finish(0);               /* we're done */
}

static void finish(int sig)
{
   endwin();

   /* do your non-curses wrapup here */

   exit(0);
}

$ gcc -o test test.c -lncurses
$ ./test
대문자 A를 누른다.

* 일단 칼라출력과 속성(밑줄)이 되는 것만을 보임.
* curses를 아직도 사용하는곳이 제법 있나 봅니다.

jinstyner의 이미지

답변감사합니다.
많은 도움이 되었습니다.
ncurses를 이용해 채팅을 한번 짜보려고...
나름대로 삽집할고 있습니다.
정말 감사합니다.

좀 더 바보처럼 살 수 있을때,
바보처럼 산다.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.