Automatic dynamic detecting of users screensize

This commit is contained in:
Michiel Broek
2005-10-07 21:56:12 +00:00
parent 0f69e97f44
commit 8721afe4e4
27 changed files with 131 additions and 157 deletions

View File

@@ -44,6 +44,12 @@
#include "term.h"
#include "ttyio.h"
extern int cols;
extern int rows;
int Chg_Language(int NewMode)
{
FILE *pLang;
@@ -616,7 +622,7 @@ void Chg_Graphics()
Syslog('+', "Graphics mode now %s", exitinfo.GraphMode?"On":"Off");
Enter(2);
TermInit(exitinfo.GraphMode, 80, exitinfo.iScreenLen);
TermInit(exitinfo.GraphMode);
WriteExitinfo();
sleep(2);
}
@@ -712,38 +718,6 @@ void Chg_News()
void Chg_ScreenLen()
{
char *temp;
ReadExitinfo();
temp = calloc(81, sizeof(char));
Syslog('+', "Old screenlen %d", exitinfo.iScreenLen);
Enter(1);
/* Please enter your Screen Length? [24]: */
pout(LIGHTMAGENTA, BLACK, (char *) Language(64));
colour(CFG.InputColourF, CFG.InputColourB);
Getnum(temp, 2);
if((strcmp(temp, "")) == 0) {
exitinfo.iScreenLen = 24;
snprintf(temp, 81, "\r\n%s\r\n\r\n", (char *) Language(80));
} else {
exitinfo.iScreenLen = atoi(temp);
snprintf(temp, 81, "\r\n%s%d\r\n\r\n", (char *) Language(81), exitinfo.iScreenLen);
}
PUTSTR(temp);
TermInit(exitinfo.GraphMode, 80, exitinfo.iScreenLen);
Syslog('+', "New screenlen %d", exitinfo.iScreenLen);
WriteExitinfo();
Pause();
free(temp);
}
/*
* Check users Date of Birth, if it is ok, we calculate his age.
*/

View File

@@ -18,7 +18,6 @@ void Chg_Graphics(void); /* Toggle graphics */
void Chg_VoicePhone(void); /* Change voicephone */
void Chg_DataPhone(void); /* Change dataphone */
void Chg_News(void); /* Toggle News Bulletins */
void Chg_ScreenLen(void); /* Change screen len */
int Test_DOB(char *); /* Test of Date of Birth is valid */
void Chg_DOB(void); /* Change Date of Birth */
void Chg_Protocol(void); /* Change default transfer protocol. */

View File

@@ -40,15 +40,35 @@
extern int cols;
extern int rows;
void CheckScreen(void)
{
struct winsize ws;
if (ioctl(1, TIOCGWINSZ, &ws) != -1 && (ws.ws_col > 0) && (ws.ws_row > 0)) {
if ((ws.ws_col != cols) || (ws.ws_row != rows)) {
cols = ws.ws_col;
rows = ws.ws_row;
Syslog('+', "User screensize changed to %dx%d", cols, rows);
}
}
}
/*
* Wait for a character for a maximum of wtime * 10 mSec.
*/
int Waitchar(unsigned char *ch, int wtime)
{
int i, rc = TIMEOUT;
int i, rc = TIMEOUT;
for (i = 0; i < wtime; i++) {
CheckScreen();
rc = GETCHAR(0);
if (tty_status == STAT_SUCCESS) {
*ch = (unsigned char)rc;

View File

@@ -4,6 +4,7 @@
#define _INPUT_H
void CheckScreen(void); /* Detect screensize changes */
long Speed(void); /* Get (locked) tty speed */
int Waitchar(unsigned char *, int); /* Wait n* 10mSec for char */
int Escapechar(unsigned char *); /* Escape sequence test */

View File

@@ -109,7 +109,6 @@ int main(int argc, char **argv)
Syslog(' ', "MBNEWUSR v%s", VERSION);
if (ioctl(1, TIOCGWINSZ, &ws) != -1 && (ws.ws_col > 0) && (ws.ws_row > 0)) {
Syslog('b', "columns=%d lines=%d", ws.ws_col, ws.ws_row);
cols = ws.ws_col;
rows = ws.ws_row;
}
@@ -131,7 +130,9 @@ int main(int argc, char **argv)
if ((p = getenv("REMOTEHOST")) != NULL)
Syslog('+', "REMOTEHOST %s", p);
if ((p = getenv("TERM")) != NULL)
Syslog('+', "TERM=%s", p);
Syslog('+', "TERM=%s %dx%d", p, cols, rows);
else
Syslog('+', "TERM=invalid %dx%d", cols, rows);
sUnixName[0] = '\0';
@@ -171,7 +172,7 @@ int main(int argc, char **argv)
* Default set the terminal to ANSI mode. If your logo
* is in color, the user will see color no mather what.
*/
TermInit(1, cols, rows);
TermInit(1);
/*
* Now it's time to check if the bbs is open. If not, we

View File

@@ -103,7 +103,6 @@ int main(int argc, char **argv)
Syslog(' ', "MBSEBBS v%s", VERSION);
if (ioctl(1, TIOCGWINSZ, &ws) != -1 && (ws.ws_col > 0) && (ws.ws_row > 0)) {
Syslog('b', "columns=%d lines=%d", ws.ws_col, ws.ws_row);
cols = ws.ws_col;
rows = ws.ws_row;
}
@@ -124,7 +123,9 @@ int main(int argc, char **argv)
if ((p = getenv("REMOTEHOST")) != NULL)
Syslog('+', "REMOTEHOST %s", p);
if ((p = getenv("TERM")) != NULL)
Syslog('+', "TERM=%s", p);
Syslog('+', "TERM=%s %dx%d", p, cols, rows);
else
Syslog('+', "TERM=invalid %dx%d", cols, rows);
if ((p = getenv("LANG")) != NULL)
Syslog('+', "LANG=%s", p);
if ((p = getenv("LC_ALL")) != NULL)
@@ -169,7 +170,7 @@ int main(int argc, char **argv)
* Default set the terminal to ANSI mode. If your logo
* is in color, the user will see color no mather what.
*/
TermInit(1, ws.ws_col, ws.ws_row);
TermInit(1);
/*
* Now it's time to check if the bbs is open. If not, we

View File

@@ -607,10 +607,6 @@ void DoMenu(int Type)
Chg_News();
break;
case 308:
Chg_ScreenLen();
break;
case 309:
Chg_DOB();
break;

View File

@@ -211,7 +211,7 @@ int newuser(void)
usrconfig.GraphMode = FALSE;
}
exitinfo.GraphMode = usrconfig.GraphMode;
TermInit(exitinfo.GraphMode, 80, 24);
TermInit(exitinfo.GraphMode);
if (CFG.iVoicePhone) {
while (1) {
@@ -447,27 +447,6 @@ int newuser(void)
usrconfig.HotKeys = TRUE; /* Default set it to Hotkeys */
usrconfig.iTimeLeft = 20; /* Set Timeleft in users file to 20 */
if ((rows > 18) && (rows < 100)) {
usrconfig.iScreenLen = rows;
Syslog('+', "Using detected screenlength %d", rows);
} else if (CFG.AskScreenlen) {
Enter(1);
/* Please enter your Screen Length [24]: */
pout(LIGHTMAGENTA, BLACK, (char *) Language(64));
colour(CFG.InputColourF, CFG.InputColourB);
alarm_on();
Getnum(temp, 3);
if(strlen(temp) == 0)
usrconfig.iScreenLen = 24;
else
usrconfig.iScreenLen = atoi(temp);
} else {
usrconfig.iScreenLen = 24;
}
rows = usrconfig.iScreenLen;
TermInit(usrconfig.GraphMode, cols, rows);
alarm_on();
usrconfig.tLastPwdChange = ltime; /* Days Since Last Password Change */

View File

@@ -36,16 +36,14 @@
#include "ttyio.h"
int termmode; /* 0 = tty, 1 = ANSI */
int termx = 80;
int termy = 24;
int termmode; /* 0 = tty, 1 = ANSI */
extern int cols;
extern int rows;
void TermInit(int mode, int x, int y)
void TermInit(int mode)
{
termmode = mode;
termx = x;
termy = y;
}
@@ -147,7 +145,7 @@ void colour(int fg, int bg)
void Center(char *string)
{
int Strlen;
int Maxlen = termx;
int Maxlen = cols;
int i, x, z;
char *Str;
@@ -191,7 +189,7 @@ void locate(int y, int x)
char temp[61];
if (termmode > 0) {
if (y > termy || x > termx) {
if (y > rows || x > cols) {
snprintf(temp, 61, "ANSI: Invalid screen coordinates: %i, %i\n", y, x);
} else {
snprintf(temp, 61, "\x1B[%i;%iH", y, x);
@@ -222,7 +220,7 @@ void fLine(int Len)
void sLine()
{
fLine(termx -1);
fLine(cols -1);
}

View File

@@ -3,7 +3,7 @@
/* $Id$ */
void TermInit(int, int, int);
void TermInit(int);
void Enter(int);
void pout(int, int, char *);
void poutCR(int, int, char *);

View File

@@ -259,7 +259,7 @@ void user(void)
UserCity(mypid, usrconfig.Name, usrconfig.sLocation);
else
UserCity(mypid, usrconfig.Name, (char *)"N/A");
TermInit(usrconfig.GraphMode, cols, rows);
TermInit(usrconfig.GraphMode);
/*
* Count simultaneous logins