+typedef struct {
+ /* Display buffers and pointers within them */
+ unsigned long *text; /* buffer of text on terminal screen */
+ unsigned long *scrtop; /* top of working screen */
+ unsigned long *disptop; /* top of displayed screen */
+ unsigned long *sbtop; /* top of scrollback */
+ unsigned long *cpos; /* cursor position (convenience) */
+ unsigned long *disptext; /* buffer of text on real screen */
+ unsigned long *wanttext; /* buffer of text we want on screen */
+ unsigned long *alttext; /* buffer of text on alt. screen */
+ unsigned char *selspace; /* buffer for building selections in */
+
+ /* Current state */
+ unsigned long curr_attr;
+ int curs_x, curs_y; /* cursor */
+ int cset; /* 0 or 1: which char set is in GL */
+ unsigned long cset_attr[2]; /* G0 and G1 char sets */
+
+ /* Saved state */
+ unsigned long save_attr;
+ int save_x, save_y; /* saved cursor position */
+ int save_cset, save_csattr; /* saved with cursor position */
+
+ int marg_t, marg_b; /* scroll margins */
+
+ /* Flags */
+ int dec_om; /* DEC origin mode flag */
+ int wrap, wrapnext; /* wrap flags */
+ int insert; /* insert-mode flag */
+ int rvideo; /* global reverse video flag */
+
+ /*
+ * Saved settings on the alternate screen.
+ */
+ int alt_x, alt_y, alt_om, alt_wrap, alt_wnext, alt_ins, alt_cset;
+ int alt_t, alt_b;
+ int alt_which;
+
+ /* Escape sequence handler state */
+#define ARGS_MAX 32 /* max # of esc sequence arguments */
+ int esc_args[ARGS_MAX];
+ int esc_nargs;
+ int esc_query;
+#define OSC_STR_MAX 2048
+ int osc_strlen;
+ char osc_string[OSC_STR_MAX+1];
+ int osc_w;
+
+ unsigned char *tabs;
+ int nl_count;
+
+ enum {
+ TOPLEVEL, IGNORE_NEXT,
+ SEEN_ESC, SEEN_CSI, SET_GL, SET_GR,
+ SEEN_OSC, SEEN_OSC_P, SEEN_OSC_W, OSC_STRING, OSC_MAYBE_ST,
+ SEEN_ESCHASH
+ } termstate;
+
+ enum {
+ NO_SELECTION, ABOUT_TO, DRAGGING, SELECTED
+ } selstate;
+ enum {
+ SM_CHAR, SM_WORD, SM_LINE
+ } selmode;
+ unsigned long *selstart, *selend, *selanchor;
+ short wordness[256];
+} Term_State;
+
+typedef struct Session {
+ /* Config that created this session */
+ Config cfg;
+ /* Terminal emulator internal state */
+ Term_State ts;
+ /* Display state */
+ int rows, cols, savelines;
+ int font_width, font_height;
+ int has_focus;
+ /* Buffers */
+ unsigned char inbuf[INBUF_SIZE];
+ int inbuf_head, inbuf_reap;
+ unsigned char outbuf[OUTBUF_SIZE];
+ int outbuf_head, outbuf_reap;
+ /* Emulator state */
+ int app_cursor_keys, app_keypad_keys;
+ /* Backend */
+ Backend *back;
+ /* Conveniences */
+ unsigned long attr_mask; /* Mask of attributes to display */
+#ifdef macintosh
+ short fontnum;
+ int font_ascent;
+ int font_leading;
+ int font_boldadjust;
+ WindowPtr window;
+ PaletteHandle palette;
+ ControlHandle scrollbar;
+ WCTabHandle wctab;
+#endif
+} Session;
+
+typedef struct Socket Socket;
+
+/*
+ * Exports from display system
+ */
+extern void request_resize(Session *, int, int);
+extern void do_text(Session *, int, int, char *, int, unsigned long);
+extern void set_title(Session *, char *);
+extern void set_icon(Session *, char *);
+extern void set_sbar(Session *, int, int, int);
+extern void pre_paint(Session *);
+extern void post_paint(Session *);
+extern void palette_set(Session *, int, int, int, int);
+extern void palette_reset(Session *);
+extern void write_clip (void *, int);
+extern void get_clip (void **, int *);
+extern void do_scroll(Session *, int, int, int);
+extern void fatalbox(const char *, ...);
+#ifdef macintosh
+#pragma noreturn (fatalbox)
+#endif
+extern void beep(Session *s);
+extern void lognegot(const char *);