From 12326f2e34cdfc028705ead5a2f6371bbec6ba1e Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Tue, 24 Jul 2012 18:51:22 +0200 Subject: [PATCH] Added $LINES and $COLUMNS to the shell. This tests the fancy new system call tcgetwinsize(2). --- utils/mxsh.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/utils/mxsh.cpp b/utils/mxsh.cpp index dfddb946..8e36d45e 100644 --- a/utils/mxsh.cpp +++ b/utils/mxsh.cpp @@ -29,6 +29,7 @@ #include #include #include +#include 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);