prevent text wrap
This commit is contained in:
1 parent
1d455dd66f
commit
0dd797b566
2 files changed
+59
-23
No files matched your search
+22
-8
@@ -7,6 +7,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <locale.h>
|
||||
|
||||
struct lineAndCharNum
|
||||
{
|
||||
@@ -70,7 +71,7 @@ int cursorToCharPos(char *content, int cursor_x, int cursor_y)
|
||||
numLines++;
|
||||
if (numLines == cursor_y)
|
||||
{
|
||||
return i + cursor_x+1;
|
||||
return i + cursor_x + 1;
|
||||
}
|
||||
across = 0;
|
||||
}
|
||||
@@ -110,6 +111,7 @@ int openFile(char *path)
|
||||
|
||||
struct FileData fileData = {&path, &content, &command, &mode, 0, 0, 0, 0, 0};
|
||||
|
||||
setlocale(LC_ALL, "");
|
||||
initscr();
|
||||
cbreak();
|
||||
keypad(stdscr, TRUE);
|
||||
@@ -167,9 +169,15 @@ int openFile(char *path)
|
||||
}
|
||||
break;
|
||||
case KEY_LEFT:
|
||||
if (across > 0)
|
||||
if (fileData.cursor_x > 0)
|
||||
{
|
||||
across--;
|
||||
fileData.cursor_x--;
|
||||
across = fileData.cursor_x;
|
||||
}
|
||||
else if (fileData.cursor_y > 0)
|
||||
{
|
||||
fileData.cursor_y--;
|
||||
across = lineLength(content, fileData.cursor_y);
|
||||
}
|
||||
cursorLineLength = lineLength(content, fileData.cursor_y);
|
||||
fileData.cursor_x = across;
|
||||
@@ -184,6 +192,11 @@ int openFile(char *path)
|
||||
{
|
||||
across++;
|
||||
}
|
||||
else
|
||||
{
|
||||
across = 0;
|
||||
fileData.cursor_y++;
|
||||
}
|
||||
cursorLineLength = lineLength(content, fileData.cursor_y);
|
||||
fileData.cursor_x = across;
|
||||
if (fileData.cursor_x > cursorLineLength)
|
||||
@@ -236,7 +249,7 @@ int openFile(char *path)
|
||||
{
|
||||
break;
|
||||
}
|
||||
int length = lineLength(content, fileData.cursor_y-1);
|
||||
int length = lineLength(content, fileData.cursor_y - 1);
|
||||
char *newContent = malloc(strlen(content));
|
||||
strncpy(newContent, content, cursorPos - 1);
|
||||
strncpy(newContent + cursorPos - 1, content + cursorPos, strlen(content) - cursorPos);
|
||||
@@ -306,7 +319,7 @@ int openFile(char *path)
|
||||
}
|
||||
break;
|
||||
case '\n':
|
||||
|
||||
|
||||
switch (command[0])
|
||||
{
|
||||
case 'w':
|
||||
@@ -320,7 +333,8 @@ int openFile(char *path)
|
||||
fclose(fptr);
|
||||
}
|
||||
}
|
||||
if (strlen(command)==1 || command[1] != 'q') break;
|
||||
if (strlen(command) == 1 || command[1] != 'q')
|
||||
break;
|
||||
case 'q':
|
||||
running = 0;
|
||||
break;
|
||||
@@ -344,8 +358,8 @@ int openFile(char *path)
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
command = realloc(command,1);
|
||||
|
||||
command = realloc(command, 1);
|
||||
command[0] = '\0';
|
||||
mode = 0;
|
||||
break;
|
||||
|
||||
@@ -12,11 +12,8 @@ void render(struct FileData fileData)
|
||||
clear();
|
||||
|
||||
// Display Header
|
||||
printw("%s - %s\n", programName, *fileData.path);
|
||||
for (int i = 0; i < COLS; i++)
|
||||
{
|
||||
printw("-");
|
||||
}
|
||||
|
||||
mvprintw(0, 0, "%s - %s\n", programName, *fileData.path);
|
||||
|
||||
// Display content
|
||||
char *line = malloc(1);
|
||||
@@ -27,14 +24,29 @@ void render(struct FileData fileData)
|
||||
int contentHeight = LINES - 4;
|
||||
int contentWidth = COLS - contentBeginX - 1;
|
||||
|
||||
for (int i = 0; i < COLS; i++)
|
||||
{
|
||||
if (i == contentBeginX - 2)
|
||||
{
|
||||
printw("╤");
|
||||
}
|
||||
else
|
||||
{
|
||||
printw("═");
|
||||
}
|
||||
}
|
||||
|
||||
move(contentBeginY, 0);
|
||||
|
||||
int LineNum = 1;
|
||||
int newLine = 1;
|
||||
int length = strlen(content);
|
||||
for (int i = 0; (i < length+1)&&(LineNum <= (fileData.scroll+contentHeight+contentBeginY-1)); i++)
|
||||
int lineLength = 0;
|
||||
for (int i = 0; (i < length + 1) && (LineNum <= (fileData.scroll + contentHeight + contentBeginY - 1)); i++)
|
||||
{
|
||||
if (LineNum < fileData.scroll+1)
|
||||
if (LineNum < fileData.scroll + 1)
|
||||
{
|
||||
if (i<length && content[i] == '\n')
|
||||
if (i < length && content[i] == '\n')
|
||||
{
|
||||
LineNum++;
|
||||
}
|
||||
@@ -42,25 +54,28 @@ void render(struct FileData fileData)
|
||||
}
|
||||
if (newLine)
|
||||
{
|
||||
char* line = malloc(1);
|
||||
char *line = malloc(1);
|
||||
lineLength = 0;
|
||||
sprintf(line, "%d", LineNum);
|
||||
for (int i = 0; i < widthOfLineNumText - strlen(line); i++)
|
||||
{
|
||||
printw(" ");
|
||||
}
|
||||
printw("%s", line);
|
||||
printw(" | ");
|
||||
free(line);
|
||||
printw(" │ ");
|
||||
LineNum++;
|
||||
newLine = 0;
|
||||
free(line);
|
||||
}
|
||||
if (i<length && content[i] == '\n')
|
||||
if (i < length && content[i] == '\n')
|
||||
{
|
||||
newLine = 1;
|
||||
|
||||
}
|
||||
if (i<length)
|
||||
if ((i < length) && (lineLength-1 < contentWidth))
|
||||
{
|
||||
printw("%c", content[i]);
|
||||
lineLength++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,7 +83,14 @@ void render(struct FileData fileData)
|
||||
move(LINES - 2, 0);
|
||||
for (int i = 0; i < COLS; i++)
|
||||
{
|
||||
printw("-");
|
||||
if (i == contentBeginX - 2)
|
||||
{
|
||||
printw("╧");
|
||||
}
|
||||
else
|
||||
{
|
||||
printw("═");
|
||||
}
|
||||
}
|
||||
switch (*fileData.mode)
|
||||
{
|
||||
@@ -89,7 +111,7 @@ void render(struct FileData fileData)
|
||||
{
|
||||
case 0:
|
||||
case 1:
|
||||
move(contentBeginY + fileData.cursor_y-fileData.scroll, contentBeginX + fileData.cursor_x);
|
||||
move(contentBeginY + fileData.cursor_y - fileData.scroll, contentBeginX + fileData.cursor_x);
|
||||
break;
|
||||
case 2:
|
||||
move(LINES - 1, 1 + strlen(*fileData.command));
|
||||
|
||||
Reference in new issue
Block a user