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. mc_tty_normalize_lines_char
  4. tty_init
  5. tty_shutdown
  6. tty_enter_ca_mode
  7. tty_exit_ca_mode
  8. tty_change_screen_size
  9. tty_reset_prog_mode
  10. tty_reset_shell_mode
  11. tty_raw_mode
  12. tty_noraw_mode
  13. tty_noecho
  14. tty_flush_input
  15. tty_keypad
  16. tty_nodelay
  17. tty_baudrate
  18. tty_lowlevel_getch
  19. tty_reset_screen
  20. tty_touch_screen
  21. tty_gotoyx
  22. tty_getyx
  23. tty_draw_hline
  24. tty_draw_vline
  25. tty_fill_region
  26. tty_set_alt_charset
  27. tty_display_8bit
  28. tty_print_char
  29. tty_print_anychar
  30. tty_print_alt_char
  31. tty_print_string
  32. tty_printf
  33. tty_tgetstr
  34. tty_refresh
  35. tty_beep

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

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