void CursorLeft(tFile *File);\r
\r
void Term_SetPos(int Row, int Col);\r
+void Term_ScrollUp(int Count);\r
\r
// === GLOBALS ===\r
int giProgramState = 0;\r
#if USE_LOCAL\r
struct termios gOldTermios;\r
#endif\r
+ int giTabSize = 8; // Someday this will be per-file (maybe)\r
int giTerminal_Width = 80;\r
int giTerminal_Height = 25;\r
\r
char *line;\r
\r
line = File->LineBuffer[LineNum];\r
+ Term_SetPos(Y, X);\r
+ printf("\x1B[2K"); // Clear line\r
printf("%6i ", LineNum+1);\r
j = 8;\r
for( k = 0; j < W-1 && line[k]; j++, k++ )\r
\r
if( lastLine > gpCurrentFile->LineCount )\r
lastLine = gpCurrentFile->LineCount;\r
- \r
+\r
+ Term_SetPos( giTerminal_Height - 1, 0 ); \r
printf("--- Line %i/%i (showing %i to %i)",\r
gpCurrentFile->CurrentLine + 1, gpCurrentFile->LineCount,\r
- gpCurrentFile->FirstLine, lastLine);\r
+ gpCurrentFile->FirstLine + 1, lastLine);\r
}\r
\r
-void CursorUp(tFile *File)\r
+void UpdateCursorPosition(void)\r
{\r
- if( File->CurrentLine > 0 )\r
+ tFile *File = gpCurrentFile;\r
+ int screen_x, i;\r
+ const char *tmp;\r
+\r
+ // Determine the position (handling tab characters)\r
+ screen_x = 0;\r
+ tmp = File->LineBuffer[File->CurrentLine];\r
+ for( i = 0; tmp[i] && i < File->CurrentPos; i ++ )\r
{\r
- File->CurrentLine --;\r
- if( File->FirstLine > File->CurrentLine )\r
+ switch(*tmp)\r
{\r
- File->FirstLine = File->CurrentLine;\r
- UpdateDisplayFull();\r
- }\r
- else\r
- {\r
- UpdateDisplayLine(File->CurrentLine + 1);\r
- UpdateDisplayLine(File->CurrentLine);\r
- UpdateDisplayStatus();\r
+ case '\t': screen_x += giTabSize; break;\r
+ default: screen_x ++; break;\r
}\r
}\r
+\r
+ Term_SetPos( File->CurrentLine - File->FirstLine, 8 + screen_x);\r
+}\r
+\r
+void CursorUp(tFile *File)\r
+{\r
+ if( File->CurrentLine <= 0 )\r
+ return ;\r
+ \r
+ File->CurrentLine --;\r
+ if( File->FirstLine > File->CurrentLine )\r
+ {\r
+ Term_ScrollUp(File->FirstLine - File->CurrentLine);\r
+ File->FirstLine = File->CurrentLine;\r
+// UpdateDisplayLine(File->FirstLine + giTerminal_Height-2);\r
+ UpdateDisplayLine(File->FirstLine);\r
+// UpdateDisplayFull();\r
+ }\r
+ else\r
+ {\r
+ UpdateDisplayLine(File->CurrentLine + 1);\r
+ UpdateDisplayLine(File->CurrentLine);\r
+ }\r
+ UpdateDisplayStatus();\r
+ \r
+ UpdateCursorPosition();\r
}\r
\r
void CursorDown(tFile *File)\r
{\r
- if( File->CurrentLine+1 < File->LineCount )\r
+ int threshold;\r
+ // Bounds check\r
+ if( File->CurrentLine + 1 >= File->LineCount )\r
+ return ;\r
+ \r
+ File->CurrentLine ++;\r
+ // Check if scroll is needed\r
+ threshold = File->CurrentLine - (giTerminal_Height-2); \r
+ if( File->FirstLine < threshold )\r
{\r
- File->CurrentLine ++;\r
- if( File->FirstLine < File->CurrentLine - (giTerminal_Height-2) )\r
- {\r
- File->FirstLine = File->CurrentLine - (giTerminal_Height-2);\r
- UpdateDisplayFull();\r
- }\r
- else\r
- {\r
- UpdateDisplayLine(File->CurrentLine - 1);\r
- UpdateDisplayLine(File->CurrentLine);\r
- UpdateDisplayStatus();\r
- }\r
+ Term_ScrollUp( File->FirstLine - threshold );\r
+ File->FirstLine = threshold;\r
+ UpdateDisplayLine(File->FirstLine + giTerminal_Height-2);\r
}\r
+ else\r
+ {\r
+ // Else, just update the previous and new lines (and status)\r
+ UpdateDisplayLine(File->CurrentLine - 1);\r
+ UpdateDisplayLine(File->CurrentLine);\r
+ }\r
+ UpdateDisplayStatus();\r
+ \r
+ UpdateCursorPosition();\r
}\r
\r
-void CursorRight(tFile *File)\r
+void CursorLeft(tFile *File)\r
{\r
if( File->CurrentPos > 0 )\r
{\r
UpdateDisplayLine(File->CurrentLine);\r
UpdateDisplayStatus();\r
}\r
+ UpdateCursorPosition();\r
}\r
\r
-void CursorLeft(tFile *File)\r
+void CursorRight(tFile *File)\r
{\r
if( File->LineBuffer[File->CurrentLine][File->CurrentPos+1] )\r
{\r
- File->CurrentPos --;\r
+ File->CurrentPos ++;\r
UpdateDisplayLine(File->CurrentLine);\r
UpdateDisplayStatus();\r
}\r
+ UpdateCursorPosition();\r
}\r
\r
void Term_SetPos(int Row, int Col)\r
printf("\x1B[%i;%iH", Row+1, Col+1); // Set cursor\r
fflush(stdout);\r
}\r
+\r
+void Term_ScrollUp(int Count)\r
+{\r
+ printf("\x1B[r");\r
+// printf("\x1B[1;%ir", giTerminal_Height-1);\r
+ if(Count < 0)\r
+ printf("\x1B[%iM", -Count);\r
+ else\r
+ printf("\x1B[%iL", Count);\r
+ fflush(stdout);\r
+}\r