# HG changeset patch # User Matti Hamalainen # Date 1307103412 -10800 # Node ID 66b90d71548b31129da86627fe0d007da847d5a6 # Parent 1211b740fbdab67d8c54c48254f6dead80db47d7 Improve interactive prompts, etc. diff -r 1211b740fbda -r 66b90d71548b nnchat.c --- a/nnchat.c Fri Jun 03 14:23:18 2011 +0300 +++ b/nnchat.c Fri Jun 03 15:16:52 2011 +0300 @@ -75,7 +75,6 @@ char *setConfigFile = NULL, *setBrowser = NULL; cfgitem_t *cfg = NULL; -nn_ringbuf_t *backBuf = NULL; /* Logging mode flags @@ -1037,9 +1036,14 @@ { char tmpBuf[512], *ptr; ssize_t pos; + int curVis = curs_set(1); + echo(); waddstr(win, info); wgetnstr(win, tmpBuf, sizeof(tmpBuf) - 1); + noecho(); + if (curVis != ERR) + curs_set(curVis); for (pos = strlen(tmpBuf) - 1; pos > 0 && (tmpBuf[pos] == '\n' || tmpBuf[pos] == '\r' || th_isspace(tmpBuf[pos])); pos--) tmpBuf[pos] = 0; @@ -1055,26 +1059,26 @@ int main(int argc, char *argv[]) { nn_conn_t *conn = NULL; + struct hostent *tmpHost; int curVis = ERR, updateCount = 0; - struct hostent *tmpHost; BOOL argsOK, isError = FALSE, exitProg = FALSE, colorSet = FALSE, cursesInit = FALSE, networkInit = FALSE, - insertMode = TRUE; + insertMode = TRUE, + firstUpdate = TRUE; time_t prevTime; char *tmpStr; nn_editbuf_t *editBuf = nn_editbuf_new(NN_TMPBUF_SIZE); nn_editbuf_t *histBuf[SET_MAX_HISTORY+2]; int histPos = 0, histMax = 0; - BOOL firstUpdate = TRUE; + + nn_ringbuf_t *backBuf; cfgitem_t *tmpcfg; char *homeDir = NULL; - memset(histBuf, 0, sizeof(histBuf)); - backBuf = nn_ringbuf_new(SET_BACKBUF_LEN); /* Initialize */ th_init("NNChat", "Newbie Nudes chat client", NN_VERSION, @@ -1082,7 +1086,7 @@ "This software is freeware, use and distribute as you wish."); th_verbosityLevel = 0; - /* Read config */ + /* Read configuration file */ tmpcfg = NULL; th_cfg_add_comment(&tmpcfg, "General settings"); th_cfg_add_string(&tmpcfg, "username", &optUserName, NULL); @@ -1181,10 +1185,10 @@ initscr(); raw(); keypad(stdscr, TRUE); - echo(); + noecho(); meta(stdscr, TRUE); timeout(SET_DELAY); - curVis = curs_set(1); + curVis = curs_set(0); if (has_colors()) { start_color(); @@ -1269,7 +1273,7 @@ conn->errfunc = errorFunc; conn->msgfunc = messageFunc; - /* Log in */ + /* Send login command */ optUserNameEnc = nn_dblencode_str(optUserName); tmpStr = nn_dblencode_str(optSite); nn_conn_send_msg(conn, optUserNameEnc, "%%2Flogin%%20%%2Dsite%%20%s%%20%%2Dpassword%%20%s", tmpStr, optPassword); @@ -1280,9 +1284,12 @@ srandom((int) prevTime); if (cursesInit) { - noecho(); - curVis = curs_set(0); + /* Initialize rest of interactive UI code */ + memset(histBuf, 0, sizeof(histBuf)); + backBuf = nn_ringbuf_new(SET_BACKBUF_LEN); nn_editbuf_clear(editBuf); + + /* First update of screen */ printEditBuf("", editBuf); updateStatus(insertMode); } @@ -1312,7 +1319,7 @@ isError = TRUE; /* Handle user input */ - if (!optDaemon) { + if (cursesInit) { int c, cnt = 0; BOOL update = FALSE; @@ -1573,7 +1580,7 @@ updateStatus(insertMode); firstUpdate = FALSE; /* a nasty hack ... */ } - } /* !optDaemon */ + } /* cursesInit */ if (++updateCount > 10) { time_t tmpTime = time(NULL); @@ -1608,7 +1615,9 @@ #ifdef __WIN32 if (errorMessages || isError) { - char *tmp = promptRequester(editWin, "Press enter to quit.\n", FALSE); + char *tmp; + wclear(editWin); + tmp = promptRequester(editWin, "Press enter to quit.\n", FALSE); th_free(tmp); } #endif