📄 winio.c
字号:
#include <stdio.h>
#include <curses.h>
#include <stdarg.h>
#include <stdlib.h>
#include <unistd.h>
#include "zped.h"
#include "myExternal.h"
void update_line(int editLineNum,Rnode * updateNow)
{
long sum = 0;
long temp = 0;
long begin = 0;
long space = 0;
int count = 0;
int cursor_x = 0;
int i;
int n;
Cnode * p;
if(current_R == updateNow) {
if(current_x <= COLS-3) {
for(p = current_R->rowHead;sum <= COLS - 3 && p != 0; p = p->next) {
mvwaddch(edit,editLineNum,sum,p->ch);
sum++;
}
if(sum == COLS - 2) {
mvwaddch(edit,editLineNum,sum++,'\\');
}
space = sum;
while(space <= COLS - 2)
mvwaddch(edit,editLineNum,space++,' ');
cursor_x = whereisX();
wmove(edit,editLineNum,cursor_x);
} else {
for(n = 1; current_x - (COLS-3)-n*((COLS-4)-3) > 0; n++) ;
begin = (COLS-3)+(n-1)*((COLS-4)-3)-4;
p = current_R->rowHead;
while(temp < begin && p!= 0) {
p = p->next;
temp++;
}
mvwaddch(edit,editLineNum,0,'\\');
for(sum = 1; sum < COLS - 3 && p != 0; p = p->next,sum++) {
mvwaddch(edit,editLineNum,sum,p->ch);
}
if(sum == COLS - 3) {
mvwaddch(edit,editLineNum,sum++,'\\');
}
space = sum;
while(space <= COLS - 3)
mvwaddch(edit,editLineNum,space++,' ');
cursor_x = whereisX();
wmove(edit,editLineNum,cursor_x);
}
} else {
for(p = updateNow->rowHead;sum <= COLS - 3 && p != 0; p = p->next) {
mvwaddch(edit,editLineNum,sum,p->ch);
sum++;
}
if(sum == COLS - 2) {
mvwaddch(edit,editLineNum,sum++,'\\');
}
space = sum;
while(space <= COLS - 2)
mvwaddch(edit,editLineNum,space++,' ');
cursor_x = whereisX();
wmove(edit,editLineNum,cursor_x);
}
}
void update_select_line(int editLineNum,Rnode * updateNow)
{
long sum = 0;
long temp = 0;
long begin = 0;
long space = 0;
int count = 0;
int cursor_x = 0;
int i;
int n;
Cnode * p;
if(current_R == updateNow) {
if(current_x <= COLS-3) {
for(p = current_R->rowHead;sum <= COLS - 3 && p != 0; p = p->next) {
if(p == startPoint && startPoint != endPoint)
wattron(edit,A_REVERSE);
else if(p == endPoint)
wattroff(edit,A_REVERSE);
mvwaddch(edit,editLineNum,sum,p->ch);
sum++;
}
wattroff(edit,A_REVERSE);
if(sum == COLS - 2) {
mvwaddch(edit,editLineNum,sum++,'\\');
}
space = sum;
while(space <= COLS - 2)
mvwaddch(edit,editLineNum,space++,' ');
cursor_x = whereisX();
//wmove(edit,editLineNum,cursor_x);
} else {
for(n = 1; current_x - (COLS-3)-n*((COLS-4)-3) > 0; n++) ;
begin = (COLS-3)+(n-1)*((COLS-4)-3)-4;
p = current_R->rowHead;
while(temp < begin && p!= 0) {
p = p->next;
temp++;
}
mvwaddch(edit,editLineNum,0,'\\');
wattron(edit,A_REVERSE);
for(sum = 1; sum < COLS - 3 && p != 0; p = p->next,sum++) {
if(p == endPoint)
wattroff(edit,A_REVERSE);
mvwaddch(edit,editLineNum,sum,p->ch);
}
wattroff(edit,A_REVERSE);
if(sum == COLS - 3) {
mvwaddch(edit,editLineNum,sum++,'\\');
}
space = sum;
while(space <= COLS - 3)
mvwaddch(edit,editLineNum,space++,' ');
cursor_x = whereisX();
//wmove(edit,editLineNum,cursor_x);
}
} else {
for(p = updateNow->rowHead;sum <= COLS - 3 && p != 0; p = p->next) {
if(p == startPoint && startPoint != endPoint)
wattron(edit,A_REVERSE);
if(p == endPoint)
wattroff(edit,A_REVERSE);
if(p->ch == '\n'&& updateNow->rowHead == p)
mvwaddch(edit,editLineNum,sum,' ');
else
mvwaddch(edit,editLineNum,sum,p->ch);
sum++;
}
wattroff(edit,A_REVERSE);
if(sum == COLS - 2) {
mvwaddch(edit,editLineNum,sum++,'\\');
}
space = sum;
while(space <= COLS - 2)
mvwaddch(edit,editLineNum,space++,' ');
cursor_x = whereisX();
//wmove(edit,editLineNum,cursor_x);
}
cursor_x = whereisX();
wmove(edit,cursor_y,cursor_x);
}
void edit_refresh()
{
long int cursor_x;
Rnode * tempR = editTop;
int i = 0;
int j = 0;
while(tempR != 0 && i < LINES - 2) {
update_line(i,tempR);
tempR = tempR->next;
i++;
}
if(i < LINES - 2) {
while(i < LINES - 2) {
j = 0;
while(j < COLS - 2) {
mvwaddch(edit,i,j,' ');
j++;
}
i++;
}
}
cursor_x = whereisX();
wmove(edit,cursor_y,cursor_x);
wrefresh(edit);
}
bool midwinBarUpdate(char * pathName)
{
int percent = current_y * 100 / totalLine;
int i = 0;
wclear(midwin);
if(COLS < 15)
return 0;
wattron(midwin,A_REVERSE);
for(i = 0; i < COLS-1; i++)
mvwaddch(midwin,0,i,' ');
if(change)
mvwprintw(midwin,0,1,"%s [+]",pathName);
else
mvwprintw(midwin,0,1,"%s",pathName);
mvwprintw(midwin,0,COLS-14,"R:%ld C:%ld %d%%",current_y+1,current_x+1,percent);
wattroff(midwin,A_REVERSE);
wrefresh(midwin);
wrefresh(edit);
return 1;
}
bool selectUpdate()
{
Rnode * Rtemp;
int count = 0;
long cursor_x = whereisX();
bool flag = false;/*if the editTop is abovt the startLine flag = true else flag = false.*/
Rtemp = fileTop;
while(Rtemp != editTop && Rtemp != startLine)
Rtemp = Rtemp->next;
if(Rtemp == editTop) {
flag = true;
while(Rtemp != startLine) {
count++;
Rtemp = Rtemp->next;
}
} else if(Rtemp == startLine) {
flag = false;
count = 0;
Rtemp = editTop;
}
if(flag) {
if(startLine == endLine) {
update_select_line(count,startLine);
} else if(startLine == endLine->pre) {
update_select_line(count++,startLine);
wattron(edit,A_REVERSE);
update_select_line(count,endLine);
} else {
update_select_line(count++,startLine);
Rtemp = startLine->next;
wattron(edit,A_REVERSE);
while(Rtemp != endLine->next) {
wattron(edit,A_REVERSE);
update_select_line(count++,Rtemp);
Rtemp = Rtemp->next;
}
wattroff(edit,A_REVERSE);
}
} else {
wattron(edit,A_REVERSE);
while(Rtemp != endLine->next) {
wattron(edit,A_REVERSE);
update_select_line(count++,Rtemp);
Rtemp = Rtemp->next;
}
wattroff(edit,A_REVERSE);
}
if(current_x < 0) {
mvwaddch(edit,4,4,'o');
sleep(2);
wrefresh(edit);
}
return 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -