comparison nnchat.c @ 46:65b1ac6a1e2e

Support for resizing the terminal on fly. Not perfect, but works.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 29 Oct 2008 01:34:27 +0200
parents ceec75116aa7
children 0bcc38910a77
comparison
equal deleted inserted replaced
45:ceec75116aa7 46:65b1ac6a1e2e
1054 else 1054 else
1055 return -1; 1055 return -1;
1056 } 1056 }
1057 1057
1058 1058
1059 BOOL initializeWindows(void)
1060 {
1061 if (mainWin) delwin(mainWin);
1062 if (statusWin) delwin(statusWin);
1063 if (editWin) delwin(editWin);
1064
1065 mainWin = newwin(LINES - 4, COLS, 0, 0);
1066 statusWin = newwin(1, COLS, LINES - 4, 0);
1067 editWin = newwin(3, COLS, LINES - 3, 0);
1068
1069 if (mainWin == NULL || statusWin == NULL || editWin == NULL) {
1070 THERR("Could not create ncurses windows!\n");
1071 return FALSE;
1072 }
1073 scrollok(mainWin, 1);
1074
1075 return TRUE;
1076 }
1077
1078
1059 int main(int argc, char *argv[]) 1079 int main(int argc, char *argv[])
1060 { 1080 {
1061 int tmpSocket, curVis, updateCount = 0; 1081 int tmpSocket, curVis, updateCount = 0;
1062 struct hostent *tmpHost; 1082 struct hostent *tmpHost;
1063 BOOL argsOK, isError = FALSE, 1083 BOOL argsOK, isError = FALSE,
1073 int histPos = 0, histMax = 0; 1093 int histPos = 0, histMax = 0;
1074 1094
1075 memset(histBuf, 0, sizeof(histBuf)); 1095 memset(histBuf, 0, sizeof(histBuf));
1076 1096
1077 /* Initialize */ 1097 /* Initialize */
1078 th_init("NNChat", "Newbie Nudes chat client", "0.6.2", 1098 th_init("NNChat", "Newbie Nudes chat client", "0.6.3",
1079 "Written and designed by Anonymous Finnish Guy (C) 2008", 1099 "Written and designed by Anonymous Finnish Guy (C) 2008",
1080 "This software is freeware, use and distribute as you wish."); 1100 "This software is freeware, use and distribute as you wish.");
1081 th_verbosityLevel = 0; 1101 th_verbosityLevel = 0;
1082 1102
1083 /* Parse arguments */ 1103 /* Parse arguments */
1174 init_pair(15, COLOR_MAGENTA, COLOR_RED); 1194 init_pair(15, COLOR_MAGENTA, COLOR_RED);
1175 init_pair(16, COLOR_CYAN, COLOR_RED); 1195 init_pair(16, COLOR_CYAN, COLOR_RED);
1176 1196
1177 } 1197 }
1178 1198
1179 mainWin = newwin(LINES - 4, COLS, 0, 0); 1199 cursesInit = TRUE;
1180 statusWin = newwin(1, COLS, LINES - 4, 0); 1200
1181 editWin = newwin(3, COLS, LINES - 3, 0); 1201 if (!initializeWindows())
1182
1183 if (mainWin == NULL || statusWin == NULL || editWin == NULL) {
1184 THERR("Could not create ncurses windows!\n");
1185 goto err_exit; 1202 goto err_exit;
1186 }
1187 scrollok(mainWin, 1);
1188 1203
1189 clearBuf(editBuf); 1204 clearBuf(editBuf);
1190 printEditBuf("", editBuf); 1205 printEditBuf("", editBuf);
1191 updateStatus(insertMode); 1206 updateStatus(insertMode);
1192
1193 cursesInit = TRUE;
1194 } 1207 }
1195 1208
1196 1209
1197 /* Enter mainloop */ 1210 /* Enter mainloop */
1198 FD_ZERO(&sockfds); 1211 FD_ZERO(&sockfds);
1245 1258
1246 /* Handle several buffered keypresses at once */ 1259 /* Handle several buffered keypresses at once */
1247 do { 1260 do {
1248 c = getch(); 1261 c = getch();
1249 switch (c) { 1262 switch (c) {
1263 case KEY_RESIZE:
1264 if (!initializeWindows()) {
1265 THERR("Error resizing ncurses windows\n");
1266 isError = TRUE;
1267 }
1268 break;
1269
1250 case KEY_ENTER: 1270 case KEY_ENTER:
1251 case '\n': 1271 case '\n':
1252 case '\r': 1272 case '\r':
1253 /* Call the user input handler */ 1273 /* Call the user input handler */
1254 if (editBuf->len > 0) { 1274 if (editBuf->len > 0) {