tmux  3.2a
About: tmux is a terminal multiplexer that lets you switch easily between several programs in one terminal.
  Fossies Dox: tmux-3.2a.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

tty.c File Reference
#include <sys/types.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <curses.h>
#include <errno.h>
#include <fcntl.h>
#include <resolv.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
#include "tmux.h"
Include dependency graph for tty.c:

Go to the source code of this file.

Macros

#define tty_use_margin(tty)    (tty->term->flags & TERM_DECSLRM)
 
#define tty_full_width(tty, ctx)    ((ctx)->xoff == 0 && (ctx)->sx >= (tty)->sx)
 
#define TTY_BLOCK_INTERVAL   (100000 /* 100 milliseconds */)
 
#define TTY_BLOCK_START(tty)   (1 + ((tty)->sx * (tty)->sy) * 8)
 
#define TTY_BLOCK_STOP(tty)   (1 + ((tty)->sx * (tty)->sy) / 8)
 

Functions

static int tty_client_ready (struct client *)
 
static void tty_set_italics (struct tty *)
 
static int tty_try_colour (struct tty *, int, const char *)
 
static void tty_force_cursor_colour (struct tty *, const char *)
 
static void tty_cursor_pane (struct tty *, const struct tty_ctx *, u_int, u_int)
 
static void tty_cursor_pane_unless_wrap (struct tty *, const struct tty_ctx *, u_int, u_int)
 
static void tty_invalidate (struct tty *)
 
static void tty_colours (struct tty *, const struct grid_cell *)
 
static void tty_check_fg (struct tty *, int *, struct grid_cell *)
 
static void tty_check_bg (struct tty *, int *, struct grid_cell *)
 
static void tty_check_us (struct tty *, int *, struct grid_cell *)
 
static void tty_colours_fg (struct tty *, const struct grid_cell *)
 
static void tty_colours_bg (struct tty *, const struct grid_cell *)
 
static void tty_colours_us (struct tty *, const struct grid_cell *)
 
static void tty_region_pane (struct tty *, const struct tty_ctx *, u_int, u_int)
 
static void tty_region (struct tty *, u_int, u_int)
 
static void tty_margin_pane (struct tty *, const struct tty_ctx *)
 
static void tty_margin (struct tty *, u_int, u_int)
 
static int tty_large_region (struct tty *, const struct tty_ctx *)
 
static int tty_fake_bce (const struct tty *, const struct grid_cell *, u_int)
 
static void tty_redraw_region (struct tty *, const struct tty_ctx *)
 
static void tty_emulate_repeat (struct tty *, enum tty_code_code, enum tty_code_code, u_int)
 
static void tty_repeat_space (struct tty *, u_int)
 
static void tty_draw_pane (struct tty *, const struct tty_ctx *, u_int)
 
static void tty_default_attributes (struct tty *, const struct grid_cell *, int *, u_int)
 
void tty_create_log (void)
 
int tty_init (struct tty *tty, struct client *c)
 
void tty_resize (struct tty *tty)
 
void tty_set_size (struct tty *tty, u_int sx, u_int sy, u_int xpixel, u_int ypixel)
 
static void tty_read_callback (int fd, short events, void *data)
 
static void tty_timer_callback (int fd, short events, void *data)
 
static int tty_block_maybe (struct tty *tty)
 
static void tty_write_callback (int fd, short events, void *data)
 
int tty_open (struct tty *tty, char **cause)
 
static void tty_start_timer_callback (int fd, short events, void *data)
 
void tty_start_tty (struct tty *tty)
 
void tty_send_requests (struct tty *tty)
 
void tty_stop_tty (struct tty *tty)
 
void tty_close (struct tty *tty)
 
void tty_free (struct tty *tty)
 
void tty_update_features (struct tty *tty)
 
void tty_raw (struct tty *tty, const char *s)
 
void tty_putcode (struct tty *tty, enum tty_code_code code)
 
void tty_putcode1 (struct tty *tty, enum tty_code_code code, int a)
 
void tty_putcode2 (struct tty *tty, enum tty_code_code code, int a, int b)
 
void tty_putcode3 (struct tty *tty, enum tty_code_code code, int a, int b, int c)
 
void tty_putcode_ptr1 (struct tty *tty, enum tty_code_code code, const void *a)
 
void tty_putcode_ptr2 (struct tty *tty, enum tty_code_code code, const void *a, const void *b)
 
static void tty_add (struct tty *tty, const char *buf, size_t len)
 
void tty_puts (struct tty *tty, const char *s)
 
void tty_putc (struct tty *tty, u_char ch)
 
void tty_putn (struct tty *tty, const void *buf, size_t len, u_int width)
 
void tty_set_title (struct tty *tty, const char *title)
 
void tty_update_mode (struct tty *tty, int mode, struct screen *s)
 
int tty_window_bigger (struct tty *tty)
 
int tty_window_offset (struct tty *tty, u_int *ox, u_int *oy, u_int *sx, u_int *sy)
 
static int tty_window_offset1 (struct tty *tty, u_int *ox, u_int *oy, u_int *sx, u_int *sy)
 
void tty_update_window_offset (struct window *w)
 
void tty_update_client_offset (struct client *c)
 
static int tty_get_palette (int *palette, int c)
 
static int tty_is_visible (struct tty *tty, const struct tty_ctx *ctx, u_int px, u_int py, u_int nx, u_int ny)
 
static int tty_clamp_line (struct tty *tty, const struct tty_ctx *ctx, u_int px, u_int py, u_int nx, u_int *i, u_int *x, u_int *rx, u_int *ry)
 
static void tty_clear_line (struct tty *tty, const struct grid_cell *defaults, u_int py, u_int px, u_int nx, u_int bg)
 
static void tty_clear_pane_line (struct tty *tty, const struct tty_ctx *ctx, u_int py, u_int px, u_int nx, u_int bg)
 
static int tty_clamp_area (struct tty *tty, const struct tty_ctx *ctx, u_int px, u_int py, u_int nx, u_int ny, u_int *i, u_int *j, u_int *x, u_int *y, u_int *rx, u_int *ry)
 
static void tty_clear_area (struct tty *tty, const struct grid_cell *defaults, u_int py, u_int ny, u_int px, u_int nx, u_int bg)
 
static void tty_clear_pane_area (struct tty *tty, const struct tty_ctx *ctx, u_int py, u_int ny, u_int px, u_int nx, u_int bg)
 
static const struct grid_celltty_check_codeset (struct tty *tty, const struct grid_cell *gc)
 
static int tty_check_overlay (struct tty *tty, u_int px, u_int py)
 
void tty_draw_line (struct tty *tty, struct screen *s, u_int px, u_int py, u_int nx, u_int atx, u_int aty, const struct grid_cell *defaults, int *palette)
 
void tty_sync_start (struct tty *tty)
 
void tty_sync_end (struct tty *tty)
 
void tty_write (void(*cmdfn)(struct tty *, const struct tty_ctx *), struct tty_ctx *ctx)
 
void tty_cmd_insertcharacter (struct tty *tty, const struct tty_ctx *ctx)
 
void tty_cmd_deletecharacter (struct tty *tty, const struct tty_ctx *ctx)
 
void tty_cmd_clearcharacter (struct tty *tty, const struct tty_ctx *ctx)
 
void tty_cmd_insertline (struct tty *tty, const struct tty_ctx *ctx)
 
void tty_cmd_deleteline (struct tty *tty, const struct tty_ctx *ctx)
 
void tty_cmd_clearline (struct tty *tty, const struct tty_ctx *ctx)
 
void tty_cmd_clearendofline (struct tty *tty, const struct tty_ctx *ctx)
 
void tty_cmd_clearstartofline (struct tty *tty, const struct tty_ctx *ctx)
 
void tty_cmd_reverseindex (struct tty *tty, const struct tty_ctx *ctx)
 
void tty_cmd_linefeed (struct tty *tty, const struct tty_ctx *ctx)
 
void tty_cmd_scrollup (struct tty *tty, const struct tty_ctx *ctx)
 
void tty_cmd_scrolldown (struct tty *tty, const struct tty_ctx *ctx)
 
void tty_cmd_clearendofscreen (struct tty *tty, const struct tty_ctx *ctx)
 
void tty_cmd_clearstartofscreen (struct tty *tty, const struct tty_ctx *ctx)
 
void tty_cmd_clearscreen (struct tty *tty, const struct tty_ctx *ctx)
 
void tty_cmd_alignmenttest (struct tty *tty, const struct tty_ctx *ctx)
 
void tty_cmd_cell (struct tty *tty, const struct tty_ctx *ctx)
 
void tty_cmd_cells (struct tty *tty, const struct tty_ctx *ctx)
 
void tty_cmd_setselection (struct tty *tty, const struct tty_ctx *ctx)
 
void tty_set_selection (struct tty *tty, const char *buf, size_t len)
 
void tty_cmd_rawstring (struct tty *tty, const struct tty_ctx *ctx)
 
void tty_cmd_syncstart (struct tty *tty, const struct tty_ctx *ctx)
 
void tty_cell (struct tty *tty, const struct grid_cell *gc, const struct grid_cell *defaults, int *palette)
 
void tty_reset (struct tty *tty)
 
void tty_region_off (struct tty *tty)
 
void tty_margin_off (struct tty *tty)
 
void tty_cursor (struct tty *tty, u_int cx, u_int cy)
 
void tty_attributes (struct tty *tty, const struct grid_cell *gc, const struct grid_cell *defaults, int *palette)
 
static void tty_window_default_style (struct grid_cell *gc, struct window_pane *wp)
 
void tty_default_colours (struct grid_cell *gc, struct window_pane *wp)
 

Variables

static int tty_log_fd = -1
 

Macro Definition Documentation

◆ TTY_BLOCK_INTERVAL

#define TTY_BLOCK_INTERVAL   (100000 /* 100 milliseconds */)

Definition at line 76 of file tty.c.

◆ TTY_BLOCK_START

#define TTY_BLOCK_START (   tty)    (1 + ((tty)->sx * (tty)->sy) * 8)

Definition at line 77 of file tty.c.

◆ TTY_BLOCK_STOP

#define TTY_BLOCK_STOP (   tty)    (1 + ((tty)->sx * (tty)->sy) / 8)

Definition at line 78 of file tty.c.

◆ tty_full_width

#define tty_full_width (   tty,
  ctx 
)     ((ctx)->xoff == 0 && (ctx)->sx >= (tty)->sx)

Definition at line 73 of file tty.c.

◆ tty_use_margin

#define tty_use_margin (   tty)     (tty->term->flags & TERM_DECSLRM)

Definition at line 71 of file tty.c.

Function Documentation

◆ tty_add()

static void tty_add ( struct tty tty,
const char *  buf,
size_t  len 
)
static

◆ tty_attributes()

◆ tty_block_maybe()

static int tty_block_maybe ( struct tty tty)
static

◆ tty_cell()

void tty_cell ( struct tty tty,
const struct grid_cell gc,
const struct grid_cell defaults,
int *  palette 
)

◆ tty_check_bg()

static void tty_check_bg ( struct tty tty,
int *  palette,
struct grid_cell gc 
)
static

◆ tty_check_codeset()

static const struct grid_cell* tty_check_codeset ( struct tty tty,
const struct grid_cell gc 
)
static

◆ tty_check_fg()

◆ tty_check_overlay()

static int tty_check_overlay ( struct tty tty,
u_int  px,
u_int  py 
)
static

Definition at line 1271 of file tty.c.

References tty::client, and client::overlay_check.

Referenced by tty_draw_line().

◆ tty_check_us()

static void tty_check_us ( struct tty tty,
int *  palette,
struct grid_cell gc 
)
static

◆ tty_clamp_area()

static int tty_clamp_area ( struct tty tty,
const struct tty_ctx ctx,
u_int  px,
u_int  py,
u_int  nx,
u_int  ny,
u_int *  i,
u_int *  j,
u_int *  x,
u_int *  y,
u_int *  rx,
u_int *  ry 
)
static

◆ tty_clamp_line()

static int tty_clamp_line ( struct tty tty,
const struct tty_ctx ctx,
u_int  px,
u_int  py,
u_int  nx,
u_int *  i,
u_int *  x,
u_int *  rx,
u_int *  ry 
)
static

◆ tty_clear_area()

static void tty_clear_area ( struct tty tty,
const struct grid_cell defaults,
u_int  py,
u_int  ny,
u_int  px,
u_int  nx,
u_int  bg 
)
static

◆ tty_clear_line()

static void tty_clear_line ( struct tty tty,
const struct grid_cell defaults,
u_int  py,
u_int  px,
u_int  nx,
u_int  bg 
)
static

◆ tty_clear_pane_area()

static void tty_clear_pane_area ( struct tty tty,
const struct tty_ctx ctx,
u_int  py,
u_int  ny,
u_int  px,
u_int  nx,
u_int  bg 
)
static

◆ tty_clear_pane_line()

static void tty_clear_pane_line ( struct tty tty,
const struct tty_ctx ctx,
u_int  py,
u_int  px,
u_int  nx,
u_int  bg 
)
static

◆ tty_client_ready()

static int tty_client_ready ( struct client c)
static

◆ tty_close()

void tty_close ( struct tty tty)

◆ tty_cmd_alignmenttest()

void tty_cmd_alignmenttest ( struct tty tty,
const struct tty_ctx ctx 
)

◆ tty_cmd_cell()

◆ tty_cmd_cells()

◆ tty_cmd_clearcharacter()

void tty_cmd_clearcharacter ( struct tty tty,
const struct tty_ctx ctx 
)

◆ tty_cmd_clearendofline()

void tty_cmd_clearendofline ( struct tty tty,
const struct tty_ctx ctx 
)

◆ tty_cmd_clearendofscreen()

void tty_cmd_clearendofscreen ( struct tty tty,
const struct tty_ctx ctx 
)

◆ tty_cmd_clearline()

void tty_cmd_clearline ( struct tty tty,
const struct tty_ctx ctx 
)

◆ tty_cmd_clearscreen()

void tty_cmd_clearscreen ( struct tty tty,
const struct tty_ctx ctx 
)

◆ tty_cmd_clearstartofline()

void tty_cmd_clearstartofline ( struct tty tty,
const struct tty_ctx ctx 
)

◆ tty_cmd_clearstartofscreen()

void tty_cmd_clearstartofscreen ( struct tty tty,
const struct tty_ctx ctx 
)

◆ tty_cmd_deletecharacter()

◆ tty_cmd_deleteline()

◆ tty_cmd_insertcharacter()

◆ tty_cmd_insertline()

◆ tty_cmd_linefeed()

◆ tty_cmd_rawstring()

void tty_cmd_rawstring ( struct tty tty,
const struct tty_ctx ctx 
)

Definition at line 1917 of file tty.c.

References tty_ctx::num, tty_ctx::ptr, tty_add(), and tty_invalidate().

Referenced by screen_write_rawstring().

◆ tty_cmd_reverseindex()

◆ tty_cmd_scrolldown()

◆ tty_cmd_scrollup()

◆ tty_cmd_setselection()

void tty_cmd_setselection ( struct tty tty,
const struct tty_ctx ctx 
)

Definition at line 1891 of file tty.c.

References tty_ctx::num, tty_ctx::ptr, and tty_set_selection().

Referenced by screen_write_setselection().

◆ tty_cmd_syncstart()

void tty_cmd_syncstart ( struct tty tty,
const struct tty_ctx ctx 
)

Definition at line 1924 of file tty.c.

References tty_sync_start().

Referenced by screen_write_initctx().

◆ tty_colours()

static void tty_colours ( struct tty tty,
const struct grid_cell gc 
)
static

◆ tty_colours_bg()

static void tty_colours_bg ( struct tty tty,
const struct grid_cell gc 
)
static

◆ tty_colours_fg()

static void tty_colours_fg ( struct tty tty,
const struct grid_cell gc 
)
static

◆ tty_colours_us()

static void tty_colours_us ( struct tty tty,
const struct grid_cell gc 
)
static

◆ tty_create_log()

void tty_create_log ( void  )

Definition at line 81 of file tty.c.

References fatal(), name, tty_log_fd, and xsnprintf().

Referenced by server_start().

◆ tty_cursor()

◆ tty_cursor_pane()

static void tty_cursor_pane ( struct tty tty,
const struct tty_ctx ctx,
u_int  cx,
u_int  cy 
)
static

◆ tty_cursor_pane_unless_wrap()

static void tty_cursor_pane_unless_wrap ( struct tty tty,
const struct tty_ctx ctx,
u_int  cx,
u_int  cy 
)
static

◆ tty_default_attributes()

◆ tty_default_colours()

◆ tty_draw_line()

◆ tty_draw_pane()

static void tty_draw_pane ( struct tty tty,
const struct tty_ctx ctx,
u_int  py 
)
static

◆ tty_emulate_repeat()

static void tty_emulate_repeat ( struct tty tty,
enum tty_code_code  code,
enum tty_code_code  code1,
u_int  n 
)
static

◆ tty_fake_bce()

◆ tty_force_cursor_colour()

static void tty_force_cursor_colour ( struct tty tty,
const char *  ccolour 
)
static

Definition at line 647 of file tty.c.

References tty::ccolour, tty_putcode(), tty_putcode_ptr1(), TTYC_CR, TTYC_CS, and xstrdup().

Referenced by tty_start_tty(), and tty_update_mode().

◆ tty_free()

void tty_free ( struct tty tty)

Definition at line 445 of file tty.c.

References tty::ccolour, and tty_close().

Referenced by server_client_lost().

◆ tty_get_palette()

static int tty_get_palette ( int *  palette,
int  c 
)
static

Definition at line 896 of file tty.c.

References COLOUR_FLAG_256.

Referenced by tty_check_bg(), tty_check_fg(), and tty_check_us().

◆ tty_init()

int tty_init ( struct tty tty,
struct client c 
)

Definition at line 93 of file tty.c.

References tty::ccolour, tty::client, tty::cstyle, client::fd, tty::tio, and xstrdup().

Referenced by server_client_dispatch_identify().

◆ tty_invalidate()

◆ tty_is_visible()

static int tty_is_visible ( struct tty tty,
const struct tty_ctx ctx,
u_int  px,
u_int  py,
u_int  nx,
u_int  ny 
)
static

◆ tty_large_region()

static int tty_large_region ( struct tty tty,
const struct tty_ctx ctx 
)
static

Definition at line 921 of file tty.c.

References tty_ctx::orlower, tty_ctx::orupper, and tty_ctx::sy.

Referenced by tty_redraw_region().

◆ tty_margin()

static void tty_margin ( struct tty tty,
u_int  rleft,
u_int  rright 
)
static

◆ tty_margin_off()

◆ tty_margin_pane()

static void tty_margin_pane ( struct tty tty,
const struct tty_ctx ctx 
)
static

◆ tty_open()

◆ tty_putc()

◆ tty_putcode()

◆ tty_putcode1()

◆ tty_putcode2()

void tty_putcode2 ( struct tty tty,
enum tty_code_code  code,
int  a,
int  b 
)

Definition at line 505 of file tty.c.

References tty::term, tty_puts(), and tty_term_string2().

Referenced by tty_cursor(), tty_margin(), tty_putc(), and tty_region().

◆ tty_putcode3()

void tty_putcode3 ( struct tty tty,
enum tty_code_code  code,
int  a,
int  b,
int  c 
)

Definition at line 513 of file tty.c.

References tty::term, tty_puts(), and tty_term_string3().

Referenced by tty_try_colour().

◆ tty_putcode_ptr1()

void tty_putcode_ptr1 ( struct tty tty,
enum tty_code_code  code,
const void *  a 
)

Definition at line 521 of file tty.c.

References tty::term, tty_puts(), and tty_term_ptr1().

Referenced by tty_force_cursor_colour().

◆ tty_putcode_ptr2()

void tty_putcode_ptr2 ( struct tty tty,
enum tty_code_code  code,
const void *  a,
const void *  b 
)

Definition at line 528 of file tty.c.

References tty::term, tty_puts(), and tty_term_ptr2().

Referenced by tty_set_selection().

◆ tty_putn()

void tty_putn ( struct tty tty,
const void *  buf,
size_t  len,
u_int  width 
)

◆ tty_puts()

◆ tty_raw()

void tty_raw ( struct tty tty,
const char *  s 
)

Definition at line 470 of file tty.c.

References tty::client, and client::fd.

Referenced by server_lock_client(), and tty_stop_tty().

◆ tty_read_callback()

static void tty_read_callback ( int  fd,
short  events,
void *  data 
)
static

◆ tty_redraw_region()

static void tty_redraw_region ( struct tty tty,
const struct tty_ctx ctx 
)
static

◆ tty_region()

static void tty_region ( struct tty tty,
u_int  rupper,
u_int  rlower 
)
static

◆ tty_region_off()

void tty_region_off ( struct tty tty)

Definition at line 2003 of file tty.c.

References tty::sy, and tty_region().

Referenced by server_client_reset_state(), tty_draw_line(), and tty_invalidate().

◆ tty_region_pane()

static void tty_region_pane ( struct tty tty,
const struct tty_ctx ctx,
u_int  rupper,
u_int  rlower 
)
static

◆ tty_repeat_space()

static void tty_repeat_space ( struct tty tty,
u_int  n 
)
static

Definition at line 753 of file tty.c.

References tty_putn().

Referenced by tty_clear_line().

◆ tty_reset()

◆ tty_resize()

void tty_resize ( struct tty tty)

◆ tty_send_requests()

void tty_send_requests ( struct tty tty)

◆ tty_set_italics()

static void tty_set_italics ( struct tty tty)
static

Definition at line 620 of file tty.c.

References global_options, options_get_string(), tty::term, tty_putcode(), tty_term_has(), TTYC_SITM, and TTYC_SMSO.

Referenced by tty_attributes().

◆ tty_set_selection()

void tty_set_selection ( struct tty tty,
const char *  buf,
size_t  len 
)

◆ tty_set_size()

void tty_set_size ( struct tty tty,
u_int  sx,
u_int  sy,
u_int  xpixel,
u_int  ypixel 
)

Definition at line 142 of file tty.c.

References tty::sx, tty::sy, tty::xpixel, and tty::ypixel.

Referenced by tty_resize().

◆ tty_set_title()

void tty_set_title ( struct tty tty,
const char *  title 
)

Definition at line 635 of file tty.c.

References tty::term, client::title, tty_putcode(), tty_puts(), tty_term_has(), TTYC_FSL, and TTYC_TSL.

Referenced by server_client_set_title().

◆ tty_start_timer_callback()

static void tty_start_timer_callback ( int  fd,
short  events,
void *  data 
)
static

Definition at line 283 of file tty.c.

References tty::client, tty::flags, log_debug(), client::name, TTY_HAVEDA, TTY_HAVEXDA, and tty_update_features().

Referenced by tty_start_tty().

◆ tty_start_tty()

◆ tty_stop_tty()

◆ tty_sync_end()

void tty_sync_end ( struct tty tty)

◆ tty_sync_start()

void tty_sync_start ( struct tty tty)

◆ tty_timer_callback()

static void tty_timer_callback ( int  fd,
short  events,
void *  data 
)
static

◆ tty_try_colour()

static int tty_try_colour ( struct tty tty,
int  colour,
const char *  type 
)
static

◆ tty_update_client_offset()

◆ tty_update_features()

◆ tty_update_mode()

◆ tty_update_window_offset()

void tty_update_window_offset ( struct window w)

◆ tty_window_bigger()

int tty_window_bigger ( struct tty tty)

◆ tty_window_default_style()

static void tty_window_default_style ( struct grid_cell gc,
struct window_pane wp 
)
static

Definition at line 2660 of file tty.c.

References grid_cell::bg, window_pane::bg, grid_cell::fg, window_pane::fg, and grid_default_cell.

Referenced by tty_default_colours().

◆ tty_window_offset()

int tty_window_offset ( struct tty tty,
u_int *  ox,
u_int *  oy,
u_int *  sx,
u_int *  sy 
)

◆ tty_window_offset1()

◆ tty_write()

◆ tty_write_callback()

static void tty_write_callback ( int  fd,
short  events,
void *  data 
)
static

Definition at line 221 of file tty.c.

References tty::client, tty::event_out, client::fd, log_debug(), client::name, tty::out, client::redraw, and tty_block_maybe().

Referenced by tty_open().

Variable Documentation

◆ tty_log_fd

int tty_log_fd = -1
static

Definition at line 35 of file tty.c.

Referenced by tty_add(), and tty_create_log().