mirror of
1
0
Fork 0

Fixed terminal screen

This commit is contained in:
Tristan B. Kildaire 2020-05-06 12:02:29 +02:00
parent 5beaf8cbe7
commit 06006e7a2f
1 changed files with 56 additions and 28 deletions

View File

@ -55,9 +55,16 @@ void ttyPut(struct Session* session, char byte)
session->teletype->cursorX = 0; session->teletype->cursorX = 0;
session->teletype->cursorY++; session->teletype->cursorY++;
} }
else if(byte == 13)
{
session->teletype->cursorX = 0;
}
} }
/**
* Moves us back to the beginning of the terminal
*/
void goHome(struct Session* session) void goHome(struct Session* session)
{ {
/* Move up */ /* Move up */
@ -68,10 +75,6 @@ void goHome(struct Session* session)
session->teletype->cursorY--; session->teletype->cursorY--;
} }
/* Move home */
char cr = 13;
output(&cr, 1);
session->teletype->cursorX = 0;
} }
void redraw2(struct Session* session) void redraw2(struct Session* session)
@ -83,9 +86,12 @@ void redraw2(struct Session* session)
/* General counter */ /* General counter */
unsigned int i = 0; unsigned int i = 0;
/* This moves y back up */
goHome(session); goHome(session);
/* tty put carriage return */
ttyPut(session, 13);
ttyPut(session, '['); ttyPut(session, '[');
/* Draw name */ /* Draw name */
@ -100,35 +106,56 @@ void redraw2(struct Session* session)
i = 0; i = 0;
while(i < columns-strlen(session->name)-2) while(i < columns-strlen(session->name)-2)
{ {
char symbol = '-'; ttyPut(session, '-');
output(&symbol, 1);
i++; i++;
} }
ttyPut(session, 10); ttyPut(session, 10);
ttyPut(session, 13);
} }
void redraw(struct Session* session) void redraw(struct Session* session)
{ {
redraw2(session); redraw2(session);
/* Move cursor back home */ /* Move cursor back home */
char cr = 13; char cr = 13;
output(&cr, 1);
/* Print all the data */ /* Write all the buffer data */
output(session->data, session->size); unsigned int i = 0;
while(i < session->size)
{
ttyPut(session, *(session->data+i));
i++;
}
/* Move cursor back home */ /* Move cursor back home */
output(&cr, 1); ttyPut(session, 13);
unsigned int i = 0; /* Move editor cursor to x-offset */
while(i < session->position) i = 0;
while(i < session->fileX)
{ {
char seq[3] = {27, 91, 67}; session->teletype->cursorX++;
char seq[3] = {27,91,67};
output(seq, 3); output(seq, 3);
i++; i++;
} }
/* Move editor cursor to y-offset */
i = 0;
while(i < session->fileY)
{
char seq[3] = {27,91,66};
output(seq, 3);
//ttyPut(session, 27);
//ttyPut(session, 91);
//ttyPut(session, 66);
session->teletype->cursorY++;
i++;
}
} }
void newEditor(struct Session* session) void newEditor(struct Session* session)
@ -167,12 +194,15 @@ void newEditor(struct Session* session)
/* Up arrow */ /* Up arrow */
if(s == 65) if(s == 65)
{ {
session->teletype->cursorY--; if(session->fileY)
{
session->fileY--;
}
} }
/* Down arrow */ /* Down arrow */
else if (s == 66) else if (s == 66)
{ {
session->teletype->cursorY++; session->fileY++;
} }
/* Right arrow */ /* Right arrow */
else if(s == 67) else if(s == 67)
@ -181,8 +211,7 @@ void newEditor(struct Session* session)
seq[1] = 91; seq[1] = 91;
seq[2] = 67; seq[2] = 67;
session->position++; session->fileX++;
session->teletype->cursorX++;
} }
/* Left arrow */ /* Left arrow */
else if (s == 68) else if (s == 68)
@ -192,10 +221,9 @@ void newEditor(struct Session* session)
seq[2] = 68; seq[2] = 68;
/* Only move cursor back if we not at home */ /* Only move cursor back if we not at home */
if(session->position) if(session->fileX)
{ {
session->position--; session->fileX--;
session->teletype->cursorX--;
} }
} }
@ -235,10 +263,10 @@ void newEditor(struct Session* session)
else else
{ {
/* Set data at current position */ /* Set data at current position */
*(session->data+session->position) = s; *(session->data+session->fileX) = s;
/* TODO: As we type position increases */ /* TODO: As we type position increases */
session->position++; session->fileX++;
session->teletype->cursorX++; //session->teletype->cursorX++;
//strncat(session->data, &s, 1); //strncat(session->data, &s, 1);
session->size++; session->size++;
} }
@ -316,10 +344,10 @@ struct Session* newSession(char* filename)
/* TODO: Use xy :: Set initial position to 0 */ /* TODO: Use xy :: Set initial position to 0 */
session->position = session->size; session->fileX = session->size;
/* Set the tty */ /* Set the tty */
session->teletype = newTTY(); session->teletype = newTTY();
session->teletype->cursorX = session->position; session->teletype->cursorX = session->fileX;
/* Set the session to active */ /* Set the session to active */
session->isActive = 1; session->isActive = 1;