Skip to content

Commit 6c30e95

Browse files
authored
phase2 window and navigation and visual mode basic
1 parent 7f2e008 commit 6c30e95

2 files changed

Lines changed: 69 additions & 1 deletion

File tree

Phase2.c

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//Pay respect to: www.cyberciti.biz/faq/linux-install-ncurses-library-headers-on-debian-ubuntu-centos-fedora/
2+
//Pay respect to: https://tldp.org/HOWTO/NCURSES-Programming-HOWTO/index.html
3+
14
#include <stdlib.h>
25
#include <stdio.h>
36
#include <string.h>
@@ -26,6 +29,9 @@ WINDOW * mainwin;
2629

2730
int cursor_row = BASEROW, cursor_col = BASECOL;
2831

32+
//visual mode:
33+
int icr, icc; //initial_cursor_row and col
34+
2935
void phase2display(const char file_name[maxCharInAStr], int row, int col, int current_line){
3036
//Erase:
3137
erase();
@@ -39,7 +45,39 @@ void phase2display(const char file_name[maxCharInAStr], int row, int col, int cu
3945
//move(row, col);
4046
while((c = fgetc(mainFile)) != EOF){
4147
//addch(temp);
42-
mvaddch(row, col, c);
48+
if(current_mode == VIM_VISUAL){
49+
/*if(cursor_row > icr){
50+
if((row > icr) || ((row == icr) && (col >= icc))){
51+
attron(A_BLINK);
52+
mvaddch(row, col, c);
53+
attroff(A_BLINK);
54+
}
55+
else mvaddch(row, col, c);
56+
}
57+
else if(cursor_row < icr){
58+
if((row < icr) || ((row == icr) && (col <= icc))){
59+
attron(A_BLINK);
60+
mvaddch(row, col, c);
61+
attroff(A_BLINK);
62+
}
63+
else mvaddch(row, col, c);
64+
}*/
65+
if(cursor_row == icr){
66+
if((((icc >= col) && (col >= cursor_col)) || ((icc <= col) && (col <= cursor_col))) && (row == icr)){
67+
start_color();
68+
init_pair(1, COLOR_WHITE, COLOR_BLACK);
69+
init_pair(2, COLOR_BLACK, COLOR_WHITE);
70+
attron(COLOR_PAIR(2));
71+
mvaddch(row, col, c);
72+
attroff(COLOR_PAIR(1));
73+
}
74+
else mvaddch(row, col, c);
75+
}
76+
else{
77+
mvaddch(row, col, c);
78+
}
79+
}
80+
else mvaddch(row, col, c);
4381
if(c == '\n'){
4482
if(row == cursor_row){
4583
if(cursor_col >= col) cursor_col = col - 1;
@@ -173,6 +211,8 @@ int main(void) {
173211
}
174212
else if(!strcmp(strCommand, "v")){ //VISUAL MODE
175213
current_mode = VIM_VISUAL;
214+
icr = cursor_row;
215+
icc = cursor_col;
176216
}
177217
}
178218
else{
@@ -219,6 +259,29 @@ int main(void) {
219259
if(ch == 'n'){
220260
current_mode = VIM_NORMAL;
221261
}
262+
263+
if(current_mode == VIM_VISUAL){
264+
if(ch == 'k'){ //up
265+
if(cursor_row > BASEROW){
266+
cursor_row--;
267+
}
268+
}
269+
else if(ch == 'j'){ //down
270+
if(cursor_row < max_row - 5){
271+
cursor_row++;
272+
}
273+
}
274+
else if(ch == 'h'){ //left
275+
if(cursor_col > BASECOL){
276+
cursor_col--;
277+
}
278+
}
279+
else if(ch == 'l'){ //right{
280+
if(cursor_col < max_col - BASECOL - 1){
281+
cursor_col++;
282+
}
283+
}
284+
}
222285
}
223286
}
224287

phase2buffer.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
abc
2+
def ghi
3+
jkl mnop
4+
-----------------------------------------------------------------------------------------------------------------------
5+
this is a test file for phase2 GUI

0 commit comments

Comments
 (0)