279
280
281
282
283
284
285
286
287
288
289
290
291
292
|
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
|
+
|
if (sscanf(buf+2,"%d;%d",&rows,&cols) != 2) return -1;
return cols;
}
/* Try to get the number of columns in the current terminal, or assume 80
* if it fails. */
static int getColumns(int ifd, int ofd) {
#if !defined(__sun__)
struct winsize ws;
if (ioctl(1, TIOCGWINSZ, &ws) == -1 || ws.ws_col == 0) {
/* ioctl() failed. Try to query the terminal itself. */
int start, cols;
/* Get the initial position so we can restore it later. */
|
308
309
310
311
312
313
314
315
316
317
318
319
320
321
|
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
|
+
|
}
return cols;
} else {
return ws.ws_col;
}
failed:
#endif
return 80;
}
/* Clear the screen. Used to handle ctrl+l */
void linenoiseClearScreen(void) {
if (write(STDOUT_FILENO,"\x1b[H\x1b[2J",7) <= 0) {
/* nothing to do, just to avoid warning. */
|