root/lib/tty/tty-ncurses.c

/* [previous][next][first][last][top][bottom][index][help]  */

DEFINITIONS

This source file includes following definitions.
  1. tty_setup_sigwinch
  2. sigwinch_handler
  3. tty_clip
  4. mc_tty_normalize_lines_char
  5. tty_init
  6. tty_shutdown
  7. tty_enter_ca_mode
  8. tty_exit_ca_mode
  9. tty_change_screen_size
  10. tty_reset_prog_mode
  11. tty_reset_shell_mode
  12. tty_raw_mode
  13. tty_noraw_mode
  14. tty_noecho
  15. tty_flush_input
  16. tty_keypad
  17. tty_nodelay
  18. tty_baudrate
  19. tty_lowlevel_getch
  20. tty_reset_screen
  21. tty_touch_screen
  22. tty_gotoyx
  23. tty_getyx
  24. tty_draw_hline
  25. tty_draw_vline
  26. tty_fill_region
  27. tty_colorize_area
  28. tty_set_alt_charset
  29. tty_display_8bit
  30. tty_print_char
  31. tty_print_anychar
  32. tty_print_alt_char
  33. tty_print_string
  34. tty_printf
  35. tty_tgetstr
  36. tty_refresh
  37. tty_beep

   1 /*
   2    Interface to the terminal controlling library.
   3    Ncurses wrapper.
   4 
   5    Copyright (C) 2005-2020
   6    Free Software Foundation, Inc.
   7 
   8    Written by:
   9    Andrew Borodin <aborodin@vmail.ru>, 2009.
  10    Ilia Maslakov <il.smind@gmail.com>, 2009.
  11 
  12    This file is part of the Midnight Commander.
  13 
  14    The Midnight Commander is free software: you can redistribute it
  15    and/or modify it under the terms of the GNU General Public License as
  16    published by the Free Software Foundation, either version 3 of the License,
  17    or (at your option) any later version.
  18 
  19    The Midnight Commander is distributed in the hope that it will be useful,
  20    but WITHOUT ANY WARRANTY; without even the implied warranty of
  21    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  22    GNU General Public License for more details.
  23 
  24    You should have received a copy of the GNU General Public License
  25    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  26  */
  27 
  28 /** \file
  29  *  \brief Source: NCurses-based tty layer of Midnight-commander
  30  */
  31 
  32 #include <config.h>
  33 
  34 #include <stdlib.h>
  35 #include <stdarg.h>
  36 #include <signal.h>
  37 #ifdef HAVE_SYS_IOCTL_H
  38 #include <sys/ioctl.h>
  39 #endif
  40 #include <termios.h>
  41 
  42 #include "lib/global.h"
  43 #include "lib/strutil.h"        /* str_term_form */
  44 
  45 #ifndef WANT_TERM_H
  46 #define WANT_TERM_H
  47 #endif
  48 
  49 #include "tty-internal.h"       /* mc_tty_normalize_from_utf8() */
  50 #include "tty.h"
  51 #include "color.h"              /* tty_setcolor */
  52 #include "color-internal.h"
  53 #include "key.h"
  54 #include "mouse.h"
  55 #include "win.h"
  56 
  57 /* include at last !!! */
  58 #ifdef WANT_TERM_H
  59 #ifdef HAVE_NCURSES_TERM_H
  60 #include <ncurses/term.h>
  61 #else
  62 #include <term.h>
  63 #endif /* HAVE_NCURSES_TERM_H */
  64 #endif /* WANT_TERM_H */
  65 
  66 /*** global variables ****************************************************************************/
  67 
  68 /*** file scope macro definitions ****************************************************************/
  69 
  70 #if !defined(CTRL)
  71 #define CTRL(x) ((x) & 0x1f)
  72 #endif
  73 
  74 #define yx_in_screen(y, x) \
  75     (y >= 0 && y < LINES && x >= 0 && x < COLS)
  76 
  77 /*** global variables ****************************************************************************/
  78 
  79 /*** file scope type declarations ****************************************************************/
  80 
  81 /*** file scope variables ************************************************************************/
  82 
  83 /* ncurses supports cursor positions only within window */
  84 /* We use our own cursor coordinates to support partially visible widgets */
  85 static int mc_curs_row, mc_curs_col;
  86 
  87 /*** file scope functions ************************************************************************/
  88 /* --------------------------------------------------------------------------------------------- */
  89 
  90 /* --------------------------------------------------------------------------------------------- */
  91 
  92 static void
  93 tty_setup_sigwinch (void (*handler) (int))
     /* [previous][next][first][last][top][bottom][index][help]  */
  94 {
  95 #if (NCURSES_VERSION_MAJOR >= 4) && defined (SIGWINCH)
  96     struct sigaction act, oact;
  97 
  98     memset (&act, 0, sizeof (act));
  99     act.sa_handler = handler;
 100     sigemptyset (&act.sa_mask);
 101 #ifdef SA_RESTART
 102     act.sa_flags = SA_RESTART;
 103 #endif /* SA_RESTART */
 104     sigaction (SIGWINCH, &act, &oact);
 105 #endif /* SIGWINCH */
 106 
 107     tty_create_winch_pipe ();
 108 }
 109 
 110 /* --------------------------------------------------------------------------------------------- */
 111 
 112 static void
 113 sigwinch_handler (int dummy)
     /* [previous][next][first][last][top][bottom][index][help]  */
 114 {
 115     ssize_t n = 0;
 116 
 117     (void) dummy;
 118 
 119     n = write (sigwinch_pipe[1], "", 1);
 120     (void) n;
 121 }
 122 
 123 /* --------------------------------------------------------------------------------------------- */
 124 
 125 /**
 126  * Get visible part of area.
 127  *
 128  * @returns TRUE if any part of area is in screen bounds, FALSE otherwise.
 129  */
 130 static gboolean
 131 tty_clip (int *y, int *x, int *rows, int *cols)
     /* [previous][next][first][last][top][bottom][index][help]  */
 132 {
 133     if (*y < 0)
 134     {
 135         *rows += *y;
 136 
 137         if (*rows <= 0)
 138             return FALSE;
 139 
 140         *y = 0;
 141     }
 142 
 143     if (*x < 0)
 144     {
 145         *cols += *x;
 146 
 147         if (*cols <= 0)
 148             return FALSE;
 149 
 150         *x = 0;
 151     }
 152 
 153     if (*y + *rows > LINES)
 154         *rows = LINES - *y;
 155     if (*x + *cols > COLS)
 156         *cols = COLS - *x;
 157 
 158     return TRUE;
 159 }
 160 
 161 /* --------------------------------------------------------------------------------------------- */
 162 /*** public functions ****************************************************************************/
 163 /* --------------------------------------------------------------------------------------------- */
 164 
 165 int
 166 mc_tty_normalize_lines_char (const char *ch)
     /* [previous][next][first][last][top][bottom][index][help]  */
 167 {
 168     char *str2;
 169     int res;
 170 
 171     struct mc_tty_lines_struct
 172     {
 173         const char *line;
 174         int line_code;
 175     } const lines_codes[] = {
 176         {"\342\224\230", ACS_LRCORNER}, /* ┌ */
 177         {"\342\224\224", ACS_LLCORNER}, /* └ */
 178         {"\342\224\220", ACS_URCORNER}, /* ┐ */
 179         {"\342\224\214", ACS_ULCORNER}, /* ┘ */
 180         {"\342\224\234", ACS_LTEE},     /* ├ */
 181         {"\342\224\244", ACS_RTEE},     /* ┤ */
 182         {"\342\224\254", ACS_TTEE},     /* ┬ */
 183         {"\342\224\264", ACS_BTEE},     /* ┴ */
 184         {"\342\224\200", ACS_HLINE},    /* ─ */
 185         {"\342\224\202", ACS_VLINE},    /* │ */
 186         {"\342\224\274", ACS_PLUS},     /* ┼ */
 187 
 188         {"\342\225\235", ACS_LRCORNER | A_BOLD},        /* ╔ */
 189         {"\342\225\232", ACS_LLCORNER | A_BOLD},        /* ╚ */
 190         {"\342\225\227", ACS_URCORNER | A_BOLD},        /* ╗ */
 191         {"\342\225\224", ACS_ULCORNER | A_BOLD},        /* ╝ */
 192         {"\342\225\237", ACS_LTEE | A_BOLD},    /* ╟ */
 193         {"\342\225\242", ACS_RTEE | A_BOLD},    /* ╢ */
 194         {"\342\225\244", ACS_TTEE | A_BOLD},    /* ╤ */
 195         {"\342\225\247", ACS_BTEE | A_BOLD},    /* ╧ */
 196         {"\342\225\220", ACS_HLINE | A_BOLD},   /* ═ */
 197         {"\342\225\221", ACS_VLINE | A_BOLD},   /* ║ */
 198 
 199         {NULL, 0}
 200     };
 201 
 202     if (ch == NULL)
 203         return (int) ' ';
 204 
 205     for (res = 0; lines_codes[res].line; res++)
 206     {
 207         if (strcmp (ch, lines_codes[res].line) == 0)
 208             return lines_codes[res].line_code;
 209     }
 210 
 211     str2 = mc_tty_normalize_from_utf8 (ch);
 212     res = g_utf8_get_char_validated (str2, -1);
 213 
 214     if (res < 0)
 215         res = (unsigned char) str2[0];
 216     g_free (str2);
 217 
 218     return res;
 219 }
 220 
 221 /* --------------------------------------------------------------------------------------------- */
 222 
 223 void
 224 tty_init (gboolean mouse_enable, gboolean is_xterm)
     /* [previous][next][first][last][top][bottom][index][help]  */
 225 {
 226     struct termios mode;
 227 
 228     initscr ();
 229 
 230 #ifdef HAVE_ESCDELAY
 231     /*
 232      * If ncurses exports the ESCDELAY variable, it should be set to
 233      * a low value, or you'll experience a delay in processing escape
 234      * sequences that are recognized by mc (e.g. Esc-Esc).  On the other
 235      * hand, making ESCDELAY too small can result in some sequences
 236      * (e.g. cursor arrows) being reported as separate keys under heavy
 237      * processor load, and this can be a problem if mc hasn't learned
 238      * them in the "Learn Keys" dialog.  The value is in milliseconds.
 239      */
 240     ESCDELAY = 200;
 241 #endif /* HAVE_ESCDELAY */
 242 
 243     tcgetattr (STDIN_FILENO, &mode);
 244     /* use Ctrl-g to generate SIGINT */
 245     mode.c_cc[VINTR] = CTRL ('g');      /* ^g */
 246     /* disable SIGQUIT to allow use Ctrl-\ key */
 247     mode.c_cc[VQUIT] = NULL_VALUE;
 248     tcsetattr (STDIN_FILENO, TCSANOW, &mode);
 249 
 250     /* curses remembers the "in-program" modes after this call */
 251     def_prog_mode ();
 252 
 253     tty_start_interrupt_key ();
 254 
 255     if (!mouse_enable)
 256         use_mouse_p = MOUSE_DISABLED;
 257     tty_init_xterm_support (is_xterm);  /* do it before tty_enter_ca_mode() call */
 258     tty_enter_ca_mode ();
 259     tty_raw_mode ();
 260     noecho ();
 261     keypad (stdscr, TRUE);
 262     nodelay (stdscr, FALSE);
 263 
 264     tty_setup_sigwinch (sigwinch_handler);
 265 }
 266 
 267 /* --------------------------------------------------------------------------------------------- */
 268 
 269 void
 270 tty_shutdown (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 271 {
 272     tty_destroy_winch_pipe ();
 273     tty_reset_shell_mode ();
 274     tty_noraw_mode ();
 275     tty_keypad (FALSE);
 276     tty_reset_screen ();
 277     tty_exit_ca_mode ();
 278 }
 279 
 280 /* --------------------------------------------------------------------------------------------- */
 281 
 282 void
 283 tty_enter_ca_mode (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 284 {
 285     if (mc_global.tty.xterm_flag && smcup != NULL)
 286     {
 287         fprintf (stdout, /* ESC_STR ")0" */ ESC_STR "7" ESC_STR "[?47h");
 288         fflush (stdout);
 289     }
 290 }
 291 
 292 /* --------------------------------------------------------------------------------------------- */
 293 
 294 void
 295 tty_exit_ca_mode (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 296 {
 297     if (mc_global.tty.xterm_flag && rmcup != NULL)
 298     {
 299         fprintf (stdout, ESC_STR "[?47l" ESC_STR "8" ESC_STR "[m");
 300         fflush (stdout);
 301     }
 302 }
 303 
 304 /* --------------------------------------------------------------------------------------------- */
 305 
 306 void
 307 tty_change_screen_size (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 308 {
 309 #if defined(TIOCGWINSZ) && NCURSES_VERSION_MAJOR >= 4
 310     struct winsize winsz;
 311 
 312     winsz.ws_col = winsz.ws_row = 0;
 313 
 314 #ifndef NCURSES_VERSION
 315     tty_noraw_mode ();
 316     tty_reset_screen ();
 317 #endif
 318 
 319     /* Ioctl on the STDIN_FILENO */
 320     ioctl (fileno (stdout), TIOCGWINSZ, &winsz);
 321     if (winsz.ws_col != 0 && winsz.ws_row != 0)
 322     {
 323 #if defined(NCURSES_VERSION) && defined(HAVE_RESIZETERM)
 324         resizeterm (winsz.ws_row, winsz.ws_col);
 325         clearok (stdscr, TRUE); /* sigwinch's should use a semaphore! */
 326 #else
 327         COLS = winsz.ws_col;
 328         LINES = winsz.ws_row;
 329 #endif
 330     }
 331 #endif /* defined(TIOCGWINSZ) || NCURSES_VERSION_MAJOR >= 4 */
 332 
 333 #ifdef ENABLE_SUBSHELL
 334     if (mc_global.tty.use_subshell)
 335         tty_resize (mc_global.tty.subshell_pty);
 336 #endif
 337 }
 338 
 339 /* --------------------------------------------------------------------------------------------- */
 340 
 341 void
 342 tty_reset_prog_mode (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 343 {
 344     reset_prog_mode ();
 345 }
 346 
 347 /* --------------------------------------------------------------------------------------------- */
 348 
 349 void
 350 tty_reset_shell_mode (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 351 {
 352     reset_shell_mode ();
 353 }
 354 
 355 /* --------------------------------------------------------------------------------------------- */
 356 
 357 void
 358 tty_raw_mode (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 359 {
 360     raw ();                     /* FIXME: uneeded? */
 361     cbreak ();
 362 }
 363 
 364 /* --------------------------------------------------------------------------------------------- */
 365 
 366 void
 367 tty_noraw_mode (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 368 {
 369     nocbreak ();                /* FIXME: unneeded? */
 370     noraw ();
 371 }
 372 
 373 /* --------------------------------------------------------------------------------------------- */
 374 
 375 void
 376 tty_noecho (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 377 {
 378     noecho ();
 379 }
 380 
 381 /* --------------------------------------------------------------------------------------------- */
 382 
 383 int
 384 tty_flush_input (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 385 {
 386     return flushinp ();
 387 }
 388 
 389 /* --------------------------------------------------------------------------------------------- */
 390 
 391 void
 392 tty_keypad (gboolean set)
     /* [previous][next][first][last][top][bottom][index][help]  */
 393 {
 394     keypad (stdscr, (bool) set);
 395 }
 396 
 397 /* --------------------------------------------------------------------------------------------- */
 398 
 399 void
 400 tty_nodelay (gboolean set)
     /* [previous][next][first][last][top][bottom][index][help]  */
 401 {
 402     nodelay (stdscr, (bool) set);
 403 }
 404 
 405 /* --------------------------------------------------------------------------------------------- */
 406 
 407 int
 408 tty_baudrate (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 409 {
 410     return baudrate ();
 411 }
 412 
 413 /* --------------------------------------------------------------------------------------------- */
 414 
 415 int
 416 tty_lowlevel_getch (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 417 {
 418     return getch ();
 419 }
 420 
 421 /* --------------------------------------------------------------------------------------------- */
 422 
 423 int
 424 tty_reset_screen (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 425 {
 426     return endwin ();
 427 }
 428 
 429 /* --------------------------------------------------------------------------------------------- */
 430 
 431 void
 432 tty_touch_screen (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 433 {
 434     touchwin (stdscr);
 435 }
 436 
 437 /* --------------------------------------------------------------------------------------------- */
 438 
 439 void
 440 tty_gotoyx (int y, int x)
     /* [previous][next][first][last][top][bottom][index][help]  */
 441 {
 442     mc_curs_row = y;
 443     mc_curs_col = x;
 444 
 445     if (y < 0)
 446         y = 0;
 447     if (y >= LINES)
 448         y = LINES - 1;
 449 
 450     if (x < 0)
 451         x = 0;
 452     if (x >= COLS)
 453         x = COLS - 1;
 454 
 455     move (y, x);
 456 }
 457 
 458 /* --------------------------------------------------------------------------------------------- */
 459 
 460 void
 461 tty_getyx (int *py, int *px)
     /* [previous][next][first][last][top][bottom][index][help]  */
 462 {
 463     *py = mc_curs_row;
 464     *px = mc_curs_col;
 465 }
 466 
 467 /* --------------------------------------------------------------------------------------------- */
 468 
 469 void
 470 tty_draw_hline (int y, int x, int ch, int len)
     /* [previous][next][first][last][top][bottom][index][help]  */
 471 {
 472     int x1;
 473 
 474     if (y < 0 || y >= LINES || x >= COLS)
 475         return;
 476 
 477     x1 = x;
 478 
 479     if (x < 0)
 480     {
 481         len += x;
 482         if (len <= 0)
 483             return;
 484         x = 0;
 485     }
 486 
 487     if ((chtype) ch == ACS_HLINE)
 488         ch = mc_tty_frm[MC_TTY_FRM_HORIZ];
 489 
 490     move (y, x);
 491     hline (ch, len);
 492     move (y, x1);
 493 
 494     mc_curs_row = y;
 495     mc_curs_col = x1;
 496 }
 497 
 498 /* --------------------------------------------------------------------------------------------- */
 499 
 500 void
 501 tty_draw_vline (int y, int x, int ch, int len)
     /* [previous][next][first][last][top][bottom][index][help]  */
 502 {
 503     int y1;
 504 
 505     if (x < 0 || x >= COLS || y >= LINES)
 506         return;
 507 
 508     y1 = y;
 509 
 510     if (y < 0)
 511     {
 512         len += y;
 513         if (len <= 0)
 514             return;
 515         y = 0;
 516     }
 517 
 518     if ((chtype) ch == ACS_VLINE)
 519         ch = mc_tty_frm[MC_TTY_FRM_VERT];
 520 
 521     move (y, x);
 522     vline (ch, len);
 523     move (y1, x);
 524 
 525     mc_curs_row = y1;
 526     mc_curs_col = x;
 527 }
 528 
 529 /* --------------------------------------------------------------------------------------------- */
 530 
 531 void
 532 tty_fill_region (int y, int x, int rows, int cols, unsigned char ch)
     /* [previous][next][first][last][top][bottom][index][help]  */
 533 {
 534     int i;
 535 
 536     if (!tty_clip (&y, &x, &rows, &cols))
 537         return;
 538 
 539     for (i = 0; i < rows; i++)
 540     {
 541         move (y + i, x);
 542         hline (ch, cols);
 543     }
 544 
 545     move (y, x);
 546 
 547     mc_curs_row = y;
 548     mc_curs_col = x;
 549 }
 550 
 551 /* --------------------------------------------------------------------------------------------- */
 552 
 553 void
 554 tty_colorize_area (int y, int x, int rows, int cols, int color)
     /* [previous][next][first][last][top][bottom][index][help]  */
 555 {
 556     cchar_t *ctext;
 557     wchar_t wch[10];            /* TODO not sure if the length is correct */
 558     attr_t attrs;
 559     short color_pair;
 560 
 561     if (!use_colors || !tty_clip (&y, &x, &rows, &cols))
 562         return;
 563 
 564     tty_setcolor (color);
 565     ctext = g_malloc (sizeof (cchar_t) * (cols + 1));
 566 
 567     for (int row = 0; row < rows; row++)
 568     {
 569         mvin_wchnstr (y + row, x, ctext, cols);
 570 
 571         for (int col = 0; col < cols; col++)
 572         {
 573             getcchar (&ctext[col], wch, &attrs, &color_pair, NULL);
 574             setcchar (&ctext[col], wch, attrs, color, NULL);
 575         }
 576 
 577         mvadd_wchnstr (y + row, x, ctext, cols);
 578     }
 579 
 580     g_free (ctext);
 581 }
 582 
 583 /* --------------------------------------------------------------------------------------------- */
 584 
 585 void
 586 tty_set_alt_charset (gboolean alt_charset)
     /* [previous][next][first][last][top][bottom][index][help]  */
 587 {
 588     (void) alt_charset;
 589 }
 590 
 591 /* --------------------------------------------------------------------------------------------- */
 592 
 593 void
 594 tty_display_8bit (gboolean what)
     /* [previous][next][first][last][top][bottom][index][help]  */
 595 {
 596     meta (stdscr, (int) what);
 597 }
 598 
 599 /* --------------------------------------------------------------------------------------------- */
 600 
 601 void
 602 tty_print_char (int c)
     /* [previous][next][first][last][top][bottom][index][help]  */
 603 {
 604     if (yx_in_screen (mc_curs_row, mc_curs_col))
 605         addch (c);
 606     mc_curs_col++;
 607 }
 608 
 609 /* --------------------------------------------------------------------------------------------- */
 610 
 611 void
 612 tty_print_anychar (int c)
     /* [previous][next][first][last][top][bottom][index][help]  */
 613 {
 614     if (mc_global.utf8_display || c > 255)
 615     {
 616         int res;
 617         unsigned char str[UTF8_CHAR_LEN + 1];
 618 
 619         res = g_unichar_to_utf8 (c, (char *) str);
 620         if (res == 0)
 621         {
 622             if (yx_in_screen (mc_curs_row, mc_curs_col))
 623                 addch ('.');
 624             mc_curs_col++;
 625         }
 626         else
 627         {
 628             const char *s;
 629 
 630             str[res] = '\0';
 631             s = str_term_form ((char *) str);
 632 
 633             if (yx_in_screen (mc_curs_row, mc_curs_col))
 634                 addstr (s);
 635 
 636             if (g_unichar_iswide (c))
 637                 mc_curs_col += 2;
 638             else if (!g_unichar_iszerowidth (c))
 639                 mc_curs_col++;
 640         }
 641     }
 642     else
 643     {
 644         if (yx_in_screen (mc_curs_row, mc_curs_col))
 645             addch (c);
 646         mc_curs_col++;
 647     }
 648 }
 649 
 650 /* --------------------------------------------------------------------------------------------- */
 651 
 652 void
 653 tty_print_alt_char (int c, gboolean single)
     /* [previous][next][first][last][top][bottom][index][help]  */
 654 {
 655     if (yx_in_screen (mc_curs_row, mc_curs_col))
 656     {
 657         if ((chtype) c == ACS_VLINE)
 658             c = mc_tty_frm[single ? MC_TTY_FRM_VERT : MC_TTY_FRM_DVERT];
 659         else if ((chtype) c == ACS_HLINE)
 660             c = mc_tty_frm[single ? MC_TTY_FRM_HORIZ : MC_TTY_FRM_DHORIZ];
 661         else if ((chtype) c == ACS_LTEE)
 662             c = mc_tty_frm[single ? MC_TTY_FRM_LEFTMIDDLE : MC_TTY_FRM_DLEFTMIDDLE];
 663         else if ((chtype) c == ACS_RTEE)
 664             c = mc_tty_frm[single ? MC_TTY_FRM_RIGHTMIDDLE : MC_TTY_FRM_DRIGHTMIDDLE];
 665         else if ((chtype) c == ACS_ULCORNER)
 666             c = mc_tty_frm[single ? MC_TTY_FRM_LEFTTOP : MC_TTY_FRM_DLEFTTOP];
 667         else if ((chtype) c == ACS_LLCORNER)
 668             c = mc_tty_frm[single ? MC_TTY_FRM_LEFTBOTTOM : MC_TTY_FRM_DLEFTBOTTOM];
 669         else if ((chtype) c == ACS_URCORNER)
 670             c = mc_tty_frm[single ? MC_TTY_FRM_RIGHTTOP : MC_TTY_FRM_DRIGHTTOP];
 671         else if ((chtype) c == ACS_LRCORNER)
 672             c = mc_tty_frm[single ? MC_TTY_FRM_RIGHTBOTTOM : MC_TTY_FRM_DRIGHTBOTTOM];
 673         else if ((chtype) c == ACS_PLUS)
 674             c = mc_tty_frm[MC_TTY_FRM_CROSS];
 675 
 676         addch (c);
 677     }
 678 
 679     mc_curs_col++;
 680 }
 681 
 682 /* --------------------------------------------------------------------------------------------- */
 683 
 684 void
 685 tty_print_string (const char *s)
     /* [previous][next][first][last][top][bottom][index][help]  */
 686 {
 687     int len;
 688     int start = 0;
 689 
 690     s = str_term_form (s);
 691     len = str_term_width1 (s);
 692 
 693     /* line is upper or below the screen or entire line is before or after screen */
 694     if (mc_curs_row < 0 || mc_curs_row >= LINES || mc_curs_col + len <= 0 || mc_curs_col >= COLS)
 695     {
 696         mc_curs_col += len;
 697         return;
 698     }
 699 
 700     /* skip invisible left part */
 701     if (mc_curs_col < 0)
 702     {
 703         start = -mc_curs_col;
 704         len += mc_curs_col;
 705         mc_curs_col = 0;
 706     }
 707 
 708     mc_curs_col += len;
 709     if (mc_curs_col >= COLS)
 710         len = COLS - (mc_curs_col - len);
 711 
 712     addstr (str_term_substring (s, start, len));
 713 }
 714 
 715 /* --------------------------------------------------------------------------------------------- */
 716 
 717 void
 718 tty_printf (const char *fmt, ...)
     /* [previous][next][first][last][top][bottom][index][help]  */
 719 {
 720     va_list args;
 721     char buf[BUF_1K];           /* FIXME: is it enough? */
 722 
 723     va_start (args, fmt);
 724     g_vsnprintf (buf, sizeof (buf), fmt, args);
 725     va_end (args);
 726     tty_print_string (buf);
 727 }
 728 
 729 /* --------------------------------------------------------------------------------------------- */
 730 
 731 char *
 732 tty_tgetstr (const char *cap)
     /* [previous][next][first][last][top][bottom][index][help]  */
 733 {
 734     char *unused = NULL;
 735 
 736     return tgetstr ((NCURSES_CONST char *) cap, &unused);
 737 }
 738 
 739 /* --------------------------------------------------------------------------------------------- */
 740 
 741 void
 742 tty_refresh (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 743 {
 744     refresh ();
 745     doupdate ();
 746 }
 747 
 748 /* --------------------------------------------------------------------------------------------- */
 749 
 750 void
 751 tty_beep (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 752 {
 753     beep ();
 754 }
 755 
 756 /* --------------------------------------------------------------------------------------------- */

/* [previous][next][first][last][top][bottom][index][help]  */