Updated
This commit is contained in:
parent
77438b4d73
commit
3347eff4e5
37
src/ped.c
37
src/ped.c
|
@ -80,6 +80,12 @@ void newEditor(struct Session* session)
|
||||||
/* Output the file as of now */
|
/* Output the file as of now */
|
||||||
redraw(session);
|
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"));
|
//output("hello world", strlen("hello world"));
|
||||||
while(session->isActive)
|
while(session->isActive)
|
||||||
{
|
{
|
||||||
|
@ -102,12 +108,12 @@ void newEditor(struct Session* session)
|
||||||
/* Up arrow */
|
/* Up arrow */
|
||||||
if(s == 65)
|
if(s == 65)
|
||||||
{
|
{
|
||||||
|
session->teletype->cursorY--;
|
||||||
}
|
}
|
||||||
/* Down arrow */
|
/* Down arrow */
|
||||||
else if (s == 66)
|
else if (s == 66)
|
||||||
{
|
{
|
||||||
|
session->teletype->cursorY++;
|
||||||
}
|
}
|
||||||
/* Right arrow */
|
/* Right arrow */
|
||||||
else if(s == 67)
|
else if(s == 67)
|
||||||
|
@ -117,6 +123,7 @@ void newEditor(struct Session* session)
|
||||||
seq[2] = 67;
|
seq[2] = 67;
|
||||||
|
|
||||||
session->position++;
|
session->position++;
|
||||||
|
session->teletype->cursorX++;
|
||||||
}
|
}
|
||||||
/* Left arrow */
|
/* Left arrow */
|
||||||
else if (s == 68)
|
else if (s == 68)
|
||||||
|
@ -129,6 +136,7 @@ void newEditor(struct Session* session)
|
||||||
if(session->position)
|
if(session->position)
|
||||||
{
|
{
|
||||||
session->position--;
|
session->position--;
|
||||||
|
session->teletype->cursorX--;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -170,6 +178,7 @@ void newEditor(struct Session* session)
|
||||||
*(session->data+session->position) = s;
|
*(session->data+session->position) = s;
|
||||||
/* TODO: As we type position increases */
|
/* TODO: As we type position increases */
|
||||||
session->position++;
|
session->position++;
|
||||||
|
session->teletype->cursorX++;
|
||||||
//strncat(session->data, &s, 1);
|
//strncat(session->data, &s, 1);
|
||||||
session->size++;
|
session->size++;
|
||||||
}
|
}
|
||||||
|
@ -179,6 +188,11 @@ void newEditor(struct Session* session)
|
||||||
sprintf(l, "%u", s);
|
sprintf(l, "%u", s);
|
||||||
// output(l, strlen(l));
|
// output(l, strlen(l));
|
||||||
// output(&s, 1);
|
// output(&s, 1);
|
||||||
|
|
||||||
|
/* Update the tty's dimensions */
|
||||||
|
updateDimensions(session->teletype);
|
||||||
|
|
||||||
|
//debugTTY(open("/dev/pts/18",O_RDWR), session->teletype);
|
||||||
|
|
||||||
/* Redraw */
|
/* Redraw */
|
||||||
redraw(session);
|
redraw(session);
|
||||||
|
@ -189,6 +203,16 @@ void newEditor(struct Session* session)
|
||||||
|
|
||||||
/* Restore tty settings */
|
/* Restore tty settings */
|
||||||
stopTTY();
|
stopTTY();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
struct TTY* newTTY()
|
||||||
|
{
|
||||||
|
struct TTY* tty = malloc(sizeof(struct TTY));
|
||||||
|
|
||||||
|
updateDimensions(tty);
|
||||||
|
|
||||||
|
return tty;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Session* newSession(char* filename)
|
struct Session* newSession(char* filename)
|
||||||
|
@ -228,12 +252,17 @@ struct Session* newSession(char* filename)
|
||||||
//printf("%s", temp);
|
//printf("%s", temp);
|
||||||
|
|
||||||
|
|
||||||
/* Set initial position to 0 */
|
/* TODO: Use xy :: Set initial position to 0 */
|
||||||
session->position = session->size;
|
session->position = session->size;
|
||||||
|
/* Set the tty */
|
||||||
|
session->teletype = newTTY();
|
||||||
|
session->teletype->cursorX = session->position;
|
||||||
|
|
||||||
/* Set the session to active */
|
/* Set the session to active */
|
||||||
session->isActive = 1;
|
session->isActive = 1;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* On success, return the pointer to the session */
|
/* On success, return the pointer to the session */
|
||||||
return session;
|
return session;
|
||||||
}
|
}
|
||||||
|
|
28
src/tty.c
28
src/tty.c
|
@ -1,7 +1,9 @@
|
||||||
#include<termios.h>
|
#include<termios.h>
|
||||||
#include<sys/ioctl.h>
|
#include<sys/ioctl.h>
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
#include<stdio.h>
|
||||||
|
#include<unistd.h>
|
||||||
|
#include<fcntl.h>
|
||||||
struct termios oldSettings;
|
struct termios oldSettings;
|
||||||
|
|
||||||
void startTTY()
|
void startTTY()
|
||||||
|
@ -25,21 +27,31 @@ void startTTY()
|
||||||
|
|
||||||
/* Set the tty to raw mode */
|
/* Set the tty to raw mode */
|
||||||
tcsetattr(0, 0, &termy);
|
tcsetattr(0, 0, &termy);
|
||||||
|
|
||||||
|
|
||||||
testicle();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void testicle()
|
void updateDimensions(struct TTY* tty)
|
||||||
{
|
{
|
||||||
/* window size struct */
|
/* window size struct */
|
||||||
struct winsize size;
|
struct winsize size;
|
||||||
|
|
||||||
/* IOCTL the vnode via the fd that points to it */
|
/* IOCTL the vnode via the fd that points to it */
|
||||||
ioctl(0, TIOCGWINSZ, &size);
|
ioctl(0, TIOCGWINSZ, &size);
|
||||||
|
|
||||||
printf("row: %u\n", size.ws_row);
|
/* Set the TTY's to be the same as the actual TTY's */
|
||||||
printf("col: %u\n", size.ws_col);
|
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()
|
void stopTTY()
|
||||||
|
|
Loading…
Reference in New Issue