Skip to content

Instantly share code, notes, and snippets.

@sarum9in
Forked from duskborn/nya.c
Last active June 3, 2016 21:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sarum9in/4d013d9171ba2f4ec3dfb17a7320be4c to your computer and use it in GitHub Desktop.
Save sarum9in/4d013d9171ba2f4ec3dfb17a7320be4c to your computer and use it in GitHub Desktop.
LDFLAGS = -lcursesw
nya: nya.c
#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