리눅스에서 ncurses 질문드립니다!

kungfumong의 이미지

#include <ncurses.h>
#include <stdlib.h>
#include <unistd.h>
#include <locale.h>
#define ESCAPE 27
#define ENTER 10
char *file_item[] = {"","처음으로", "종료",};
char *help_item[] = {"", "족보보기", "about"};
 
WINDOW **file_menu_list(int start_col)
{
    int i;
    WINDOW **items;
 
    items=(WINDOW **)malloc(5 * sizeof(WINDOW *)); 
 
    items[0]=newwin(4,19,1,start_col);
    wbkgd(items[0], COLOR_PAIR(2));
    box(items[0],ACS_VLINE, ACS_HLINE);
 
    items[1]=subwin(items[0], 1, 17, 2, start_col+1);
    items[2]=subwin(items[0], 1, 17, 3, start_col+1);
    items[3]=subwin(items[0], 1, 17, 4, start_col+1);
	items[4]=subwin(items[0], 1, 17, 5, start_col+1);
    for (i =1; i < 5; i++)
 
        wprintw(items[i], "%s",file_item[i]);
    wbkgd(items[1], COLOR_PAIR(1));
    wrefresh(items[0]);
    return items;
}
 
void about_window()		//help-about 메뉴
{
    WINDOW *about;
    about = newwin(6, 40, 5, 10);
    box(about, ACS_VLINE, ACS_HLINE);
    wmove(about, 1, 2);
    wprintw(about, "섯다 Test Verson 0.1"); 
    wmove(about, 2, 2);
    wprintw(about, "Made : 공설민,김현영"); 
    wmove(about, 3, 2);
    wprintw(about, "Date : 2016.6.7"); 
    wmove(about, 4, 2);
    wprintw(about, "Press any key.. "); 
    wbkgd(about, COLOR_PAIR(3));
    refresh();
    wgetch(about);
    delwin(about);
}
 
int check_quit()		//종료할때
{
    WINDOW *check;
    int key;
    check = newwin(3, 40, 5, 10);
    wmove(check, 1, 2);
    wprintw(check, "Exit program (y/n) ? "); 
    wbkgd(check, COLOR_PAIR(2));
    box(check, ACS_VLINE, ACS_HLINE);
    refresh();
    key = wgetch(check);
    delwin(check);
    if (key == 'y')
        return 1;
    else 
        return 0;
}
 
WINDOW **help_menu_list(int start_col)		//help리스트
{
    int i;
    WINDOW **items;
 
    items=(WINDOW **)malloc(3 * sizeof(WINDOW *));
 
    items[0]=newwin(4,19,1,start_col);
    wbkgd(items[0], COLOR_PAIR(2));
    box(items[0],ACS_VLINE, ACS_HLINE);
 
    items[1]=subwin(items[0], 1, 17, 2, start_col+1);
    items[2]=subwin(items[0], 1, 17, 3, start_col+1);
    for (i = 1; i < 3; i++)
        wprintw(items[i], "%s", help_item[i]);
    wbkgd(items[1], COLOR_PAIR(1));
    wrefresh(items[0]);
    return items;
}
 
void delete_menu(WINDOW **items, int count)
{
    int i;
    for (i = 0; i < count; i++)
        delwin(items[i]);
    free(items);
}
 
int scroll_menu(WINDOW **items,int count,int menu_start_col, int index_num)		//메뉴에서 키받음
{
    int key;
    int selected=0;
    while (1) 
    {
        key=getch();
        if (key==KEY_DOWN || key==KEY_UP) 
        {
            wbkgd(items[selected+1],COLOR_PAIR(2));
            wnoutrefresh(items[selected+1]);
            if (key==KEY_DOWN) 
            {
                selected=(selected+1) % count;
            } 
            else 
            {
                selected=(selected+count-1) % count;
            }
            wbkgd(items[selected+1],COLOR_PAIR(1));
            wnoutrefresh(items[selected+1]);
            doupdate();
        } 
        else if (key==ESCAPE) 		//esc
        {
            return -1;
        } 
        else if (key==ENTER) 	//엔터
        {
            return selected;
        }
    }
}
 
void init_scr()
{
    initscr();
    start_color();
    init_pair(1, COLOR_WHITE, COLOR_BLUE);
    init_pair(2, COLOR_BLUE, COLOR_WHITE);
    init_pair(3, COLOR_RED, COLOR_WHITE);
    curs_set(2);
    noecho();
    keypad(stdscr, TRUE);
}
 
void make_menubar(WINDOW *menubar)		//위에 보이는 메뉴값
{
    wbkgd(menubar, COLOR_PAIR(2));
 
    wattron(menubar, COLOR_PAIR(3));
    waddstr(menubar, "메뉴");
    wattron(menubar, COLOR_PAIR(3));
    waddstr(menubar, "(a)");
    wmove(menubar, 0, 20);
    wattron(menubar, COLOR_PAIR(3));
    waddstr(menubar, "Help");
    wattron(menubar, COLOR_PAIR(3));
    waddstr(menubar, "(h)");
    wattron(menubar, COLOR_PAIR(3));
}
 
 
 
int main()
{
	setlocale(LC_CTYPE,"ko_KR.utf-8");
	WINDOW *win_menu,*win_status,*win_pan,*win_com,*win_player;
    WINDOW *menubar, *statusbar, *about;
    int key;
	int i,row,col;
    init_scr();
    bkgd(COLOR_PAIR(1));
	getmaxyx(stdscr,row,col);
    menubar = subwin(stdscr, 1, 30, 0, 0);
    statusbar = subwin(stdscr, 1, 79, 23, 1);
    make_menubar(menubar);
    move(2, 1);
    printw("Press 'a' or 'h' to open the menus. ");
    printw("ESC or 'q' quits.");
    refresh();
 
 
 
	/* 오른쪽 상태창 */
	win_status = subwin(stdscr,row/2, col/6, 2, col-row/2-5);
	box(win_status, 0, 0);
	wrefresh(win_status);
 
	/* 밑에 출력창 */
	win_menu = subwin(stdscr,row/4, col-10, row/2+5, 1);
	box(win_menu, 0, 0);
	wrefresh(win_menu);
 
 
	/* 컴퓨터 */
	win_com = subwin(stdscr,3, 10, 2, col/2-2);
	box(win_com, 0, 0);
	wrefresh(win_com);
 
	/* 플레이어 */
	win_player = subwin(stdscr,3, 10, row/2, col/2-2);
	box(win_player, 0, 0);
	wrefresh(win_player);
 
 
 
 
 
 
 
    while(1)
    {
		wrefresh(win_menu);
		wrefresh(win_status);
		wrefresh(win_com);
		wrefresh(win_player);
        WINDOW **menu_items;            
        int selected_item;
 
        key = getch();
        werase(statusbar);
        wrefresh(statusbar);
 
        if (key == 'a')
        {
            menu_items=file_menu_list(0);
            selected_item = scroll_menu(menu_items, 4, 20, 0); 
            //delete_menu(menu_items, 5);
            if (selected_item < 0)
                wprintw(statusbar, "You haven't selected any item");
            else
                wprintw(statusbar, "You have selected menu item %d.", selected_item);
            touchwin(stdscr);
            refresh();
 
        }
        if (key == 'h')
        {
            menu_items=help_menu_list(20);
            selected_item = scroll_menu(menu_items, 2, 0, 1); 
            //delete_menu(menu_items, 3);
            if (selected_item == 1)
            {
                about_window();
            }
            if (selected_item < 0)
                wprintw(statusbar, "You haven't selected any item");
 
 
 
        }
        if (key == ESCAPE || key == 'q')
        {
            if (check_quit() == 1)
                break;
        }
        touchwin(stdscr);
        refresh();
 
    }
    endwin();
}

window로 화면만들고 배경색깔을 입혔습니다.
scanf받으니까 입력받은 값이 보이지가 않더군요
printw로 출력을 하면 아주 잘 보입니다!
scanw로 받을려고 해도, 명령어는 먹는데 현재 입력하는 값이 보이질 않아 사용자가 얼마만큼의 값을 입력했는지 알 수가 없습니다 ㅠ
좋은 방법 없을까요

bushi의 이미지

공부하시는 거라면 전체적으로 코드 분석을 하면서 잘못된 것들부터 고치시고요.
숙제하시는 거라면 복붙한 코드 중에서 init_scr() 만이라도 분석하세요.

kungfumong의 이미지

급하다보니 수정하지 못하고 바로 원본을 썼네요..
소스분석은 다 했는데
말씀드렸다 싶이 배경 window로 가리니까 scanw나 scanf를 받았을때 입력하는 공간이 가려져 보이지 않습니다

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.