mirror of
1
0
Fork 0
This commit is contained in:
Tristan B. Kildaire 2020-05-06 10:13:07 +02:00
parent 77438b4d73
commit 3347eff4e5
2 changed files with 53 additions and 12 deletions

View File

@ -80,6 +80,12 @@ void newEditor(struct Session* session)
/* Output the file as of now */
redraw(session);
/* Update the tty's dimensions */
updateDimensions(session->teletype);
/* Debugging */
//debugTTY(open("/dev/pts/18",O_RDWR), session->teletype);
//output("hello world", strlen("hello world"));
while(session->isActive)
{
@ -102,12 +108,12 @@ void newEditor(struct Session* session)
/* Up arrow */
if(s == 65)
{
session->teletype->cursorY--;
}
/* Down arrow */
else if (s == 66)
{
session->teletype->cursorY++;
}
/* Right arrow */
else if(s == 67)
@ -117,6 +123,7 @@ void newEditor(struct Session* session)
seq[2] = 67;
session->position++;
session->teletype->cursorX++;
}
/* Left arrow */
else if (s == 68)
@ -129,6 +136,7 @@ void newEditor(struct Session* session)
if(session->position)
{
session->position--;
session->teletype->cursorX--;
}
}
@ -170,6 +178,7 @@ void newEditor(struct Session* session)
*(session->data+session->position) = s;
/* TODO: As we type position increases */
session->position++;
session->teletype->cursorX++;
//strncat(session->data, &s, 1);
session->size++;
}
@ -179,6 +188,11 @@ void newEditor(struct Session* session)
sprintf(l, "%u", s);
// output(l, strlen(l));
// output(&s, 1);
/* Update the tty's dimensions */
updateDimensions(session->teletype);
//debugTTY(open("/dev/pts/18",O_RDWR), session->teletype);
/* Redraw */
redraw(session);
@ -189,6 +203,16 @@ void newEditor(struct Session* session)
/* Restore tty settings */
stopTTY();
}
struct TTY* newTTY()
{
struct TTY* tty = malloc(sizeof(struct TTY));
updateDimensions(tty);
return tty;
}
struct Session* newSession(char* filename)
@ -228,12 +252,17 @@ struct Session* newSession(char* filename)
//printf("%s", temp);
/* Set initial position to 0 */
/* TODO: Use xy :: Set initial position to 0 */
session->position = session->size;
/* Set the tty */
session->teletype = newTTY();
session->teletype->cursorX = session->position;
/* Set the session to active */
session->isActive = 1;
/* On success, return the pointer to the session */
return session;
}

View File

@ -1,7 +1,9 @@
#include<termios.h>
#include<sys/ioctl.h>
#include "types.h"
#include<stdio.h>
#include<unistd.h>
#include<fcntl.h>
struct termios oldSettings;
void startTTY()
@ -25,21 +27,31 @@ void startTTY()
/* Set the tty to raw mode */
tcsetattr(0, 0, &termy);
testicle();
}
void testicle()
void updateDimensions(struct TTY* tty)
{
/* window size struct */
struct winsize size;
/* IOCTL the vnode via the fd that points to it */
ioctl(0, TIOCGWINSZ, &size);
printf("row: %u\n", size.ws_row);
printf("col: %u\n", size.ws_col);
/* Set the TTY's to be the same as the actual TTY's */
tty->rows = size.ws_row;
tty->columns = size.ws_col;
}
void debugTTY(int fd, struct TTY* tty)
{
FILE* f = fdopen(fd, "w+");
fprintf(f, "Row: %u\n", tty->rows);
fprintf(f, "Column: %u\n", tty->columns);
fprintf(f,"XPos: %u\n", tty->cursorX);
fprintf(f,"YPos: %u\n", tty->cursorY);
}
void stopTTY()