38 |
{ |
{ |
39 |
int key; |
int key; |
40 |
/* variables */ |
/* variables */ |
41 |
|
WINDOW *editor_box; |
42 |
WINDOW *editor; |
WINDOW *editor; |
43 |
contentPtr fileContent = NULL; |
contentPtr file_content = NULL; |
44 |
int x = 5, y; |
int x = 5, y, max_y, max_x; |
45 |
|
|
46 |
/* init */ |
/* init */ |
47 |
initscr (); |
initscr (); |
48 |
cbreak (); |
cbreak (); |
49 |
|
|
50 |
keypad (editor, TRUE); |
keypad (editor, TRUE); |
51 |
|
keypad (stdscr, TRUE); |
52 |
|
|
53 |
refresh (); |
refresh (); |
54 |
|
|
55 |
/* new window */ |
/* new window */ |
56 |
editor = createNewWin ( LINES, COLS, 0, 0); |
editor_box = create_new_win_with_box (LINES, COLS, 0, 0); |
57 |
|
|
58 |
|
editor = create_new_win (LINES - 2, COLS - 2 , 1, 1); |
59 |
|
getmaxyx (editor, max_y, max_x); |
60 |
/* we like to scroll */ |
/* we like to scroll */ |
61 |
scrollok (editor, TRUE); |
scrollok (editor, TRUE); |
62 |
setscrreg (1, COLS-1); |
|
63 |
|
wsetscrreg (editor, 0, LINES); |
64 |
|
|
65 |
/* here we will open the file and read all stuff */ |
/* here we will open the file and read all stuff */ |
66 |
if ((fileContent = (content *) malloc (sizeof (content))) == NULL) |
if ((file_content = (content *) malloc (sizeof (content))) == NULL) |
67 |
{ |
{ |
68 |
printf ("Memmory could not be allocated - exiting...\n"); |
printf ("Memmory could not be allocated - exiting...\n"); |
69 |
return 1; |
return 1; |
70 |
} |
} |
71 |
|
|
72 |
fileContent = readFile (argv[1]); |
file_content = read_file (argv[1]); |
73 |
|
|
74 |
for (y = 2; fileContent->next != NULL; y++, |
for (y = 0; (y <= max_y) && (file_content->next != NULL); y++, |
75 |
fileContent = fileContent->next) |
file_content = file_content->next) |
76 |
{ |
{ |
77 |
mvprintw (y, x, fileContent->text); |
mvwprintw (editor, y, 0, file_content->text); |
78 |
|
wrefresh (editor); |
79 |
} |
} |
80 |
|
|
81 |
/* end */ |
/* end */ |
83 |
{ |
{ |
84 |
key = getch(); |
key = getch(); |
85 |
if (key == KEY_F(1)) |
if (key == KEY_F(1)) |
86 |
break; |
{ |
87 |
|
destroy_win (editor); |
88 |
|
endwin (); |
89 |
|
return 0; |
90 |
|
} |
91 |
|
if ((key == KEY_DOWN) && (file_content->next != NULL)) |
92 |
|
{ |
93 |
|
getyx (editor, y, x); |
94 |
|
while (y < max_y) |
95 |
|
{ |
96 |
|
if (file_content->next != NULL) |
97 |
|
{ |
98 |
|
file_content = file_content->next; |
99 |
|
} |
100 |
|
y++; |
101 |
|
} |
102 |
|
wscrl (editor, 1); |
103 |
|
mvwprintw (editor, max_y, 0, file_content->text); |
104 |
|
wrefresh (editor); |
105 |
|
} |
106 |
|
if ((key == KEY_UP) && (file_content->prev != NULL)) |
107 |
|
{ |
108 |
|
getyx (editor, y, x); |
109 |
|
while (y > 0) |
110 |
|
{ |
111 |
|
if (file_content->prev != NULL) |
112 |
|
{ |
113 |
|
file_content = file_content->prev; |
114 |
|
} |
115 |
|
y--; |
116 |
|
} |
117 |
|
wscrl (editor, -1); |
118 |
|
mvwprintw (editor, 0, 0, file_content->text); |
119 |
|
wrefresh (editor); |
120 |
|
} |
121 |
} |
} |
|
destroyWin (editor); |
|
|
endwin (); |
|
|
return 0; |
|
122 |
} |
} |
123 |
|
|