-
-
Save sarum9in/4d013d9171ba2f4ec3dfb17a7320be4c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LDFLAGS = -lcursesw | |
nya: nya.c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <fnmatch.h> | |
#include <ncurses.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
int color[20]; | |
int position[20]; | |
bool flag; | |
int cursor; | |
WINDOW *wnd; | |
WINDOW *submask; | |
WINDOW *subfile; | |
WINDOW *submessage; | |
void movescan(int count, char s1[], char s2[]); | |
int main(int args, char **argv) { | |
initscr(); | |
cbreak(); | |
char file[20]; | |
char mask[20]; | |
printw("Enter the mask\n"); | |
scanw("%s", mask); | |
printw("Enter the file name\n"); | |
scanw("%s", file); | |
clear(); | |
cursor = 3; | |
start_color(); | |
refresh(); | |
noecho(); | |
init_pair(1, COLOR_WHITE, COLOR_GREEN); | |
init_pair(2, COLOR_WHITE, COLOR_RED); | |
init_pair(3, COLOR_WHITE, COLOR_BLACK); | |
init_pair(4, COLOR_WHITE, COLOR_BLUE); | |
wbkgd(stdscr, COLOR_PAIR(4)); | |
refresh(); | |
wnd = newwin(20, 40, 2, 4); | |
box(wnd, '|', '-'); | |
submask = derwin(wnd, 8, 19, 1, 1); | |
subfile = derwin(wnd, 8, 19, 10, 1); | |
submessage = derwin(wnd, 18, 19, 1, 20); | |
wbkgd(submask, COLOR_PAIR(3) | A_BOLD); | |
wbkgd(subfile, COLOR_PAIR(3) | A_BOLD); | |
wbkgd(submessage, COLOR_PAIR(1) | A_BOLD); | |
wprintw(submask, mask); | |
wprintw(subfile, file); | |
switch (fnmatch(mask, file, 0)) { | |
case 0: | |
wprintw(submessage, "File satisfies the mask"); | |
break; | |
case FNM_NOMATCH: | |
wbkgd(submessage, COLOR_PAIR(2) | A_BOLD); | |
wprintw(submessage, "File does not satisfy the mask"); | |
break; | |
} | |
wrefresh(submask); | |
wrefresh(subfile); | |
wrefresh(submessage); | |
wrefresh(wnd); | |
int ch; | |
keypad(stdscr, true); | |
printw("Press F1 for exit.."); | |
move(3, 5); | |
while ((ch = getch()) != KEY_F(1)) { | |
switch (ch) { | |
case KEY_LEFT: | |
movescan(-1, mask, file); | |
break; | |
case KEY_RIGHT: | |
movescan(1, mask, file); | |
break; | |
} | |
} | |
delwin(submask); | |
delwin(subfile); | |
delwin(submessage); | |
delwin(wnd); | |
endwin(); | |
return 0; | |
} | |
void movescan(int count, char s1[], char s2[]) { | |
cursor += count; | |
if (cursor - 5 < 0) { | |
cursor = 5; | |
} | |
if (cursor - 5 > sizeof(s1) - 1) { | |
cursor = 5 + sizeof(s1) - 1; | |
} | |
move(3, cursor); | |
wclear(subfile); | |
wclear(submessage); | |
waddch(submessage, s1[cursor - 5]); | |
for (int i = 0; i < sizeof(s2); i++) { | |
if (position[i] == cursor - 5) { | |
wattron(subfile, COLOR_PAIR(color[i])); | |
waddch(subfile, s2[i]); | |
wattroff(subfile, COLOR_PAIR(color[i])); | |
if (color[i] == 1) { | |
waddstr(submessage, " satisfy "); | |
waddch(submessage, s2[i]); | |
} else { | |
waddstr(submessage, " not satisfy "); | |
waddch(submessage, s2[i]); | |
} | |
} else { | |
waddch(subfile, s2[i]); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment