Markus Rechberger / ncurses
 
StartSeite | MarkusRechberger/ | Neues | TestSeite | ForumSeite | Teilnehmer | Kategorien | Index | Hilfe | Einstellungen | Ändern

ncurses

form beispiel:

#include <form.h>


int main(void)
{
    int ch;

    FORM *formp;
    FIELD *fields[3];

    initscr();
    cbreak();
    noecho();
    keypad(stdscr, TRUE);

    fields[0] = new_field(1, 32, 4, 18, 0, 0);
    fields[1] = new_field(4, 32, 6, 18, 0, 0);
    fields[2] = NULL;

    set_field_back(fields[0], A_STANDOUT);
    field_opts_off(fields[0], O_AUTOSKIP);

    set_field_back(fields[1], A_STANDOUT);
    field_opts_off(fields[1], O_AUTOSKIP);

    formp = new_form(fields);
    post_form(formp);
    refresh();

    mvprintw(4, 5, "IP Address:");
    mvprintw(6, 5, "Message:");
    move(4, 18);
    refresh();

    while( (ch = getch()) != KEY_F(1) )
    {
       switch(ch)
       {
          case KEY_DOWN:
               form_driver(formp, REQ_NEXT_FIELD);
               form_driver(formp, REQ_END_LINE);
               break;

          case KEY_UP:
               form_driver(formp, REQ_PREV_FIELD);
               form_driver(formp, REQ_END_LINE);
               break;

          default:
               form_driver(formp, ch);
               break;
       }
    }

    unpost_form(formp);
    free_form(formp);
    free_field(fields[0]);
    free_field(fields[1]);

    endwin();

    return 0;
}

compile with:

 gcc -lform -g test.c -o test

Ncurses intro: http://dickey.his.com/ncurses/ncurses-intro.html

Form auslesen:
    form_driver(formp, REQ_VALIDATION);
    dvddevice=malloc(strlen(field_buffer(fields[0],0))+1);
    sprintf(dvddevice,field_buffer(fields[0],0));

#include <curses.h>

void doexit(int exitcode);

int main(void){
        initscr();
        cbreak;
        noecho;
        start_color();
        clear();
        if(!has_colors()){
                printw("I'm sorry, but your terminal doesn't allow color changes.\n");
                doexit(255);
        }
        init_pair(1,COLOR_RED,COLOR_BLACK);
        attrset(COLOR_PAIR(1));
        printw("Here's something in a nice red. Maybe useful for a warning\n");
        printw("message.\n\n");
        attrset(COLOR_PAIR(1)| A_BOLD);
        printw("Notice how you can get bright colors by adding the A_BOLD\n");
        printw("attribute.\n\n");
        init_pair(2, COLOR_WHITE, COLOR_BLUE);
        attrset(COLOR_PAIR(2) | A_BOLD);
        printw("And this is a lighter white on blue.\n\n");

        init_pair(3, COLOR_YELLOW, COLOR_BLACK);
        attrset(COLOR_PAIR(3));
        printw("Notice that the \"dark\" yellow appears brown on some terminals.\n");
        attrset(COLOR_PAIR(3) | A_BOLD);
        printw("But it becomes yellow when the bright version is used.\n\n");
        attrset(COLOR_PAIR(0));
        printw("Press any key to watch what happens when a pair is redefined.\n");
        refresh();
        getch();
        init_pair(1,COLOR_GREEN,COLOR_BLACK);
        attrset(COLOR_PAIR(1));
        printw("Notice the existing text printed to the screen with this\n");
        printw("pair is modified\n");

        attrset(A_NORMAL);
        printw("You can use A_NORMAL or COLOR_PAIR(0) to return to\n");
        printw("the terminal's default color.\n\n");

        doexit(0);
}

void doexit(int exitcode){
        printw("Press any key to exit.\n");
        refresh();
        cbreak();
        noecho();
        getch();
        endwin();
        exit(exitcode);
}
gcc -lcurses main.c -o main


StartSeite | MarkusRechberger/ | Neues | TestSeite | ForumSeite | Teilnehmer | Kategorien | Index | Hilfe | Einstellungen | Ändern
Text dieser Seite ändern (zuletzt geändert: 9. April 2005 18:20 (diff))
Suchbegriff: gesucht wird
im Titel
im Text