Added $LINES and $COLUMNS to the shell.

This tests the fancy new system call tcgetwinsize(2).
This commit is contained in:
Jonas 'Sortie' Termansen 2012-07-24 18:51:22 +02:00
parent 143120d160
commit 12326f2e34
1 changed files with 15 additions and 0 deletions

View File

@ -29,6 +29,7 @@
#include <errno.h>
#include <error.h>
#include <fcntl.h>
#include <termios.h>
int status = 0;
@ -41,6 +42,19 @@ void updatepwd()
setenv("PWD", wd, 1);
}
void updateenv()
{
char str[128];
struct winsize ws;
if ( tcgetwinsize(0, &ws) == 0 )
{
sprintf(str, "%zu", ws.ws_col);
setenv("COLUMNS", str, 1);
sprintf(str, "%zu", ws.ws_row);
setenv("LINES", str, 1);
}
}
int runcommandline(const char** tokens)
{
int result = 127;
@ -192,6 +206,7 @@ readcmd:
}
}
updateenv();
char statusstr[32];
sprintf(statusstr, "%i", status);
setenv("?", statusstr, 1);