-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
67 lines (54 loc) · 1.31 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ncurses.h>
#include "src/fetchBody.h"
#include "src/getTagContent.h"
#include "src/rmWhitespaces.h"
int main(void) {
int h,w;
char url[250];
initscr();
getmaxyx(stdscr, h, w);
WINDOW *win = newwin(h,w,0,0);
noecho();
keypad(stdscr, TRUE);
// Draw box around the window
for(int i = 0; i<h; i++){
for(int j = 0; j<w; j++){
if((i==0) || (i==h-1) || (i==h-3)){
mvwaddch(win,i,j,ACS_BLOCK);
}else{
mvwaddch(win, i, 0, ACS_BLOCK);
mvwaddch(win, i, w-1, ACS_BLOCK);
}
}
}
refresh();
wrefresh(win);
int cursorPos = 0;
wmove(win, h-2, cursorPos+2);
for(;;) {
int c = getch();
if(c == 10){
break;
}
else if(c == KEY_BACKSPACE){
url[cursorPos] = '\0';
mvwdelch(win, h-2, cursorPos+1);
cursorPos -= 1;
}
else{
url[cursorPos] = c;
mvwaddch(win, h-2, cursorPos+2, url[cursorPos]);
cursorPos += 1;
}
wrefresh(win);
}
endwin();
FILE *fp = fopen("out", "w");
fprintf(fp, "%s%s", url, "\n");
fetchBody(url);
rmWhitespaces();
return 0;
}