- Timestamp:
- Jun 15, 2008, 2:40:24 PM (13 years ago)
- Location:
- neercs/trunk/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
neercs/trunk/src/main.c
r2395 r2400 49 49 int eof = 0, refresh = 1, command = 0; 50 50 51 /* Add-ons*/52 int mini = 1;53 int status = 1;54 int help = 0;55 56 51 57 52 nt = argc - 1; … … 101 96 screen_list->count = 0; 102 97 screen_list->width = cucul_get_canvas_width(cv); 103 screen_list->height = cucul_get_canvas_height(cv) - ((mini*6) + (status)); 98 screen_list->mini = 1; 99 screen_list->help = 0; 100 screen_list->status = 1; 101 screen_list->height = cucul_get_canvas_height(cv) - ((screen_list->mini*6) + (screen_list->status)); 104 102 screen_list->wm_type = WM_VSPLIT; 105 103 screen_list->in_bell = 0; … … 163 161 } 164 162 else if(ret) 165 for(i = 0; i < screen_list->count; i++) 166 { 167 /* FIXME: try a new strategy: read all filedescriptors until 168 * each of them starved at least once. */ 169 170 if(screen_list->screen[i]->fd < 0 || 171 !FD_ISSET(screen_list->screen[i]->fd, &fdset)) 172 continue; 173 174 for(;;) 175 { 176 ssize_t nr; 177 178 screen_list->screen[i]->buf = 179 realloc(screen_list->screen[i]->buf, 180 screen_list->screen[i]->total + 1024); 181 nr = read(screen_list->screen[i]->fd, 182 screen_list->screen[i]->buf + 183 screen_list->screen[i]->total, 1024); 184 185 if(nr > 0) 186 { 187 screen_list->screen[i]->total += nr; 188 continue; 189 } 190 191 if(nr == 0 || errno != EWOULDBLOCK) { 192 close(screen_list->screen[i]->fd); 193 screen_list->screen[i]->fd = -1; 194 destroy_screen(screen_list->screen[i]); 195 remove_screen(screen_list, i, 0); 196 if(i < prevpty) prevpty--; 197 if(i == pty) 198 { 199 pty = prevpty; 200 prevpty = 0; 201 } 202 if(i < pty) pty--; 203 refresh = 1; 204 } 205 206 break; 207 } 208 } 209 163 { 164 /* Read each terminal content */ 165 refresh |= update_screens_contents(screen_list, &fdset, &pty, &prevpty); 166 } 167 /* No more screens, exit */ 210 168 if(!screen_list->count) break; 211 169 212 for(i = 0; i < screen_list->count; i++) 213 if(screen_list->screen[i]->total) 214 { 215 unsigned long int bytes; 216 217 bytes = import_term(screen_list, 218 screen_list->screen[i], 219 screen_list->screen[i]->buf, 220 screen_list->screen[i]->total); 221 222 if(bytes > 0) 223 { 224 screen_list->screen[i]->total -= bytes; 225 memmove(screen_list->screen[i]->buf, 226 screen_list->screen[i]->buf + bytes, 227 screen_list->screen[i]->total); 228 refresh = 1; 229 } 230 } 170 /* Update each screen canvas */ 171 refresh |= update_terms(screen_list); 231 172 232 173 /* Get events, if any */ … … 250 191 case 'm': 251 192 case 0x0d: //CACA_KEY_CTRL_M: 252 mini = !mini;193 screen_list->mini = !screen_list->mini; 253 194 refresh = 1; 254 195 break; … … 289 230 case 'h': 290 231 case 0x08: //CACA_KEY_CTRL_H: 291 help = !help;232 screen_list->help = !screen_list->help; 292 233 refresh = 1; 293 234 break; … … 309 250 write(screen_list->screen[pty]->fd, "\x1b[D", 3); break; 310 251 case CACA_KEY_ESCAPE: 311 if( help)help = 0;252 if(screen_list->help) screen_list->help = 0; 312 253 default: 313 254 write(screen_list->screen[pty]->fd, &c, 1); break; … … 327 268 } 328 269 329 /* Re fresh screen */270 /* Resfresh screen */ 330 271 if(refresh || screen_list->in_bell) 331 272 { 332 273 refresh = 0; 333 334 screen_list->width = cucul_get_canvas_width(cv); 335 screen_list->height = cucul_get_canvas_height(cv) - (mini*6); 336 337 update_windows_props(cv, screen_list, pty); 338 339 if(screen_list->screen[pty]->title) 340 caca_set_display_title(dp, screen_list->screen[pty]->title); 341 else 342 caca_set_display_title(dp, PACKAGE_STRING); 343 344 cucul_set_color_ansi(cv, CUCUL_DEFAULT, CUCUL_DEFAULT); 345 cucul_clear_canvas(cv); 346 cucul_set_color_ansi(cv, CUCUL_LIGHTRED, CUCUL_BLACK); 347 348 for(i = screen_list->count - 1; i >=0; i--) 349 { 350 if(i!=pty) 351 { 352 cucul_blit(cv, 353 screen_list->screen[i]->x, 354 screen_list->screen[i]->y, 355 screen_list->screen[i]->cv, NULL); 356 cucul_draw_cp437_box(cv, 357 screen_list->screen[i]->x - 1, 358 screen_list->screen[i]->y - 1, 359 screen_list->screen[i]->w + 2, 360 screen_list->screen[i]->h + 2); 361 if(screen_list->screen[i]->title) 362 cucul_printf(cv, 363 screen_list->screen[i]->x, 364 screen_list->screen[i]->y - 1, 365 " %.*s ", 366 screen_list->screen[i]->w - 3, 367 screen_list->screen[i]->title); 368 } 369 370 } 371 372 cucul_blit(cv, 373 screen_list->screen[pty]->x, 374 screen_list->screen[pty]->y, 375 screen_list->screen[pty]->cv, NULL); 376 377 if(screen_list->screen[pty]->bell) 378 { 379 cucul_set_color_ansi(cv, CUCUL_RED, CUCUL_BLACK); 380 screen_list->screen[pty]->bell = 0; 381 screen_list->in_bell--; 382 } 383 else 384 { 385 cucul_set_color_ansi(cv, CUCUL_LIGHTGREEN, CUCUL_BLACK); 386 } 387 388 cucul_draw_cp437_box(cv, 389 screen_list->screen[pty]->x - 1, 390 screen_list->screen[pty]->y - 1, 391 screen_list->screen[pty]->w + 2, 392 screen_list->screen[pty]->h + 2); 393 394 if(screen_list->screen[pty]->title) 395 { 396 cucul_printf(cv, 397 screen_list->screen[pty]->x, 398 screen_list->screen[pty]->y - 1, 399 " %.*s ", 400 screen_list->screen[pty]->w - 3, 401 screen_list->screen[pty]->title); 402 } 403 404 cucul_gotoxy(cv, 405 screen_list->screen[pty]->x + 406 cucul_get_cursor_x(screen_list->screen[pty]->cv), 407 screen_list->screen[pty]->y + 408 cucul_get_cursor_y(screen_list->screen[pty]->cv)); 409 410 411 if(mini) 412 { 413 draw_thumbnails(cv, screen_list, pty); 414 } 415 if(status) 416 { 417 draw_status(cv, screen_list, pty); 418 } 419 if(help) 420 { 421 draw_help(cv, screen_list, pty); 422 } 423 424 caca_refresh_display(dp); 274 refresh_screens(cv, dp, screen_list, pty); 425 275 } 426 276 … … 499 349 } 500 350 351 352 353 int update_terms(struct screen_list* screen_list) 354 { 355 int i, refresh = 0; 356 for(i = 0; i < screen_list->count; i++) 357 { 358 if(screen_list->screen[i]->total) 359 { 360 unsigned long int bytes; 361 362 bytes = import_term(screen_list, 363 screen_list->screen[i], 364 screen_list->screen[i]->buf, 365 screen_list->screen[i]->total); 366 367 if(bytes > 0) 368 { 369 screen_list->screen[i]->total -= bytes; 370 memmove(screen_list->screen[i]->buf, 371 screen_list->screen[i]->buf + bytes, 372 screen_list->screen[i]->total); 373 refresh = 1; 374 } 375 } 376 } 377 return refresh; 378 } 379 380 381 382 383 int update_screens_contents(struct screen_list* screen_list, 384 fd_set *fdset, 385 int *pty, int *prevpty) 386 { 387 int i, refresh = 0; 388 for(i = 0; i < screen_list->count; i++) 389 { 390 /* FIXME: try a new strategy: read all filedescriptors until 391 * each of them starved at least once. */ 392 393 if(screen_list->screen[i]->fd < 0 || 394 !FD_ISSET(screen_list->screen[i]->fd, fdset)) 395 continue; 396 397 for(;;) 398 { 399 ssize_t nr; 400 401 screen_list->screen[i]->buf = 402 realloc(screen_list->screen[i]->buf, 403 screen_list->screen[i]->total + 1024); 404 nr = read(screen_list->screen[i]->fd, 405 screen_list->screen[i]->buf + 406 screen_list->screen[i]->total, 1024); 407 408 if(nr > 0) 409 { 410 screen_list->screen[i]->total += nr; 411 continue; 412 } 413 414 if(nr == 0 || errno != EWOULDBLOCK) { 415 close(screen_list->screen[i]->fd); 416 screen_list->screen[i]->fd = -1; 417 destroy_screen(screen_list->screen[i]); 418 remove_screen(screen_list, i, 0); 419 if(i < (*prevpty)) (*prevpty)--; 420 if(i == *pty) 421 { 422 *pty = *prevpty; 423 *prevpty = 0; 424 } 425 if(i < (*pty)) (*pty)--; 426 refresh = 1; 427 } 428 429 break; 430 } 431 } 432 return refresh; 433 } 434 435 void refresh_screens(cucul_canvas_t *cv, 436 caca_display_t *dp, 437 struct screen_list *screen_list, 438 int pty) 439 { 440 int i; 441 442 screen_list->width = cucul_get_canvas_width(cv); 443 screen_list->height = cucul_get_canvas_height(cv) - (screen_list->mini*6); 444 445 update_windows_props(cv, screen_list, pty); 446 447 if(screen_list->screen[pty]->title) 448 caca_set_display_title(dp, screen_list->screen[pty]->title); 449 else 450 caca_set_display_title(dp, PACKAGE_STRING); 451 452 cucul_set_color_ansi(cv, CUCUL_DEFAULT, CUCUL_DEFAULT); 453 cucul_clear_canvas(cv); 454 cucul_set_color_ansi(cv, CUCUL_LIGHTRED, CUCUL_BLACK); 455 456 for(i = screen_list->count - 1; i >=0; i--) 457 { 458 if(i!=pty) 459 { 460 cucul_blit(cv, 461 screen_list->screen[i]->x, 462 screen_list->screen[i]->y, 463 screen_list->screen[i]->cv, NULL); 464 cucul_draw_cp437_box(cv, 465 screen_list->screen[i]->x - 1, 466 screen_list->screen[i]->y - 1, 467 screen_list->screen[i]->w + 2, 468 screen_list->screen[i]->h + 2); 469 if(screen_list->screen[i]->title) 470 cucul_printf(cv, 471 screen_list->screen[i]->x, 472 screen_list->screen[i]->y - 1, 473 " %.*s ", 474 screen_list->screen[i]->w - 3, 475 screen_list->screen[i]->title); 476 } 477 } 478 479 cucul_blit(cv, 480 screen_list->screen[pty]->x, 481 screen_list->screen[pty]->y, 482 screen_list->screen[pty]->cv, NULL); 483 484 if(screen_list->screen[pty]->bell) 485 { 486 cucul_set_color_ansi(cv, CUCUL_RED, CUCUL_BLACK); 487 screen_list->screen[pty]->bell = 0; 488 screen_list->in_bell--; 489 } 490 else 491 { 492 cucul_set_color_ansi(cv, CUCUL_LIGHTGREEN, CUCUL_BLACK); 493 } 494 495 cucul_draw_cp437_box(cv, 496 screen_list->screen[pty]->x - 1, 497 screen_list->screen[pty]->y - 1, 498 screen_list->screen[pty]->w + 2, 499 screen_list->screen[pty]->h + 2); 500 501 if(screen_list->screen[pty]->title) 502 { 503 cucul_printf(cv, 504 screen_list->screen[pty]->x, 505 screen_list->screen[pty]->y - 1, 506 " %.*s ", 507 screen_list->screen[pty]->w - 3, 508 screen_list->screen[pty]->title); 509 } 510 511 cucul_gotoxy(cv, 512 screen_list->screen[pty]->x + 513 cucul_get_cursor_x(screen_list->screen[pty]->cv), 514 screen_list->screen[pty]->y + 515 cucul_get_cursor_y(screen_list->screen[pty]->cv)); 516 517 518 if(screen_list->mini) 519 { 520 draw_thumbnails(cv, screen_list, pty); 521 } 522 if(screen_list->status) 523 { 524 draw_status(cv, screen_list, pty); 525 } 526 if(screen_list->help) 527 { 528 draw_help(cv, screen_list, pty); 529 } 530 531 caca_refresh_display(dp); 532 } 501 533 502 534 -
neercs/trunk/src/neercs.h
r2382 r2400 54 54 int wm_type; 55 55 int in_bell; 56 /* Add-ons*/ 57 int mini; 58 int status; 59 int help; 60 56 61 int count; 57 62 int width, height; … … 63 68 long int import_term(struct screen_list *screen_list, struct screen *sc, void const *data, unsigned int size); 64 69 int set_tty_size(int fd, unsigned int w, unsigned int h); 65 70 int update_terms(struct screen_list* screen_list); 71 void refresh_screens(cucul_canvas_t *cv, 72 caca_display_t *dp, 73 struct screen_list *screen_list, 74 int pty); 75 int update_screens_contents(struct screen_list* screen_list, 76 fd_set *fdset, 77 int *pty, int *prevpty); 66 78 67 79 /* Screens management */
Note: See TracChangeset
for help on using the changeset viewer.