2005-09-15 09:58:31 -04:00
|
|
|
#ifndef EL__TERMINAL_ITRM_H
|
|
|
|
#define EL__TERMINAL_ITRM_H
|
|
|
|
|
2020-10-05 14:14:55 -04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
#define ITRM_OUT_QUEUE_SIZE 16384
|
2006-10-30 16:15:43 -05:00
|
|
|
|
2007-07-27 09:50:37 -04:00
|
|
|
/** Currently, ELinks treats control sequences as text if they are
|
2006-10-30 16:15:43 -05:00
|
|
|
* longer than ITRM_IN_QUEUE_SIZE bytes. So it should be defined
|
|
|
|
* as greater than the length of any control sequence that ELinks
|
|
|
|
* is expected to receive. These are the longest so far:
|
2007-07-31 07:12:28 -04:00
|
|
|
* - VT420: "\E[?64;1;2;6;7;8;9;15;18;19;21c"
|
|
|
|
* - VT510: "\E[?64;1;2;7;8;9;12;15;18;21;23;24;42;44;45;46c" */
|
2006-10-30 16:15:43 -05:00
|
|
|
#define ITRM_IN_QUEUE_SIZE 64
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
struct itrm_queue {
|
2021-01-17 12:27:13 -05:00
|
|
|
unsigned char *data;
|
2006-07-24 12:35:58 -04:00
|
|
|
|
2007-07-27 09:50:37 -04:00
|
|
|
/** The amount of data in the queue, in bytes. This may be
|
2006-07-24 12:35:58 -04:00
|
|
|
* less than the amount of memory allocated for the buffer;
|
|
|
|
* struct itrm_queue does not keep track of that, and has
|
|
|
|
* no global policy on whether the buffer can be resized. */
|
2005-09-15 09:58:31 -04:00
|
|
|
int len;
|
|
|
|
};
|
|
|
|
|
2007-07-27 09:50:37 -04:00
|
|
|
/** Things coming into an itrm, whether from the terminal or from the
|
2006-07-24 12:35:58 -04:00
|
|
|
* master. */
|
2005-09-15 09:58:31 -04:00
|
|
|
struct itrm_in {
|
2007-07-27 09:50:37 -04:00
|
|
|
/** A file descriptor for the standard input. In some ports,
|
2006-07-24 12:35:58 -04:00
|
|
|
* this is the terminal device itself; in others, this is a
|
|
|
|
* pipe from an input thread. In principle, the data format
|
|
|
|
* depends on the terminal. */
|
2005-09-15 09:58:31 -04:00
|
|
|
int std;
|
2006-07-24 12:35:58 -04:00
|
|
|
|
2007-07-27 09:50:37 -04:00
|
|
|
/** In a slave process, a file descriptor for a socket from
|
2006-07-24 12:35:58 -04:00
|
|
|
* which it reads data sent by the master process. The other
|
|
|
|
* end of the socket connection is terminal.fdout in the
|
2006-07-27 03:55:31 -04:00
|
|
|
* master process. The format of these data is almost the
|
2007-07-27 09:50:37 -04:00
|
|
|
* same as could be sent to the terminal (via itrm_out.std),
|
2006-07-27 03:55:31 -04:00
|
|
|
* but there are special commands that begin with a null byte.
|
2006-07-24 12:35:58 -04:00
|
|
|
*
|
2007-07-27 09:50:37 -04:00
|
|
|
* In the master process, @c sock is the same as itrm_out.std,
|
2006-08-01 02:48:26 -04:00
|
|
|
* but nothing actually uses it. */
|
2005-09-15 09:58:31 -04:00
|
|
|
int sock;
|
2006-07-24 12:35:58 -04:00
|
|
|
|
2007-07-27 09:50:37 -04:00
|
|
|
/** A file descriptor for controlling the standard input. This
|
|
|
|
* is always the terminal device itself, thus the same as #std
|
2006-07-24 12:35:58 -04:00
|
|
|
* in some ports. ELinks doesn't read or write with this file
|
2007-07-27 09:50:37 -04:00
|
|
|
* descriptor; it only does things like tcsetattr(). */
|
2005-09-15 09:58:31 -04:00
|
|
|
int ctl;
|
2006-07-24 12:35:58 -04:00
|
|
|
|
2007-07-27 09:50:37 -04:00
|
|
|
/** Bytes that have been received from #std but not yet
|
|
|
|
* converted to events. itrm_queue.data is allocated for
|
|
|
|
* ::ITRM_IN_QUEUE_SIZE bytes and never resized. The itrm
|
2006-07-28 08:40:00 -04:00
|
|
|
* layer cannot parse control sequences longer than that.
|
2007-07-27 09:50:37 -04:00
|
|
|
* Anything that modifies itrm_queue.len should also call
|
2006-07-28 08:40:00 -04:00
|
|
|
* unhandle_itrm_stdin() if the queue becomes full, or
|
|
|
|
* handle_itrm_stdin() if the queue stops being full.
|
|
|
|
* Those functions are internal to kbd.c. */
|
2005-09-15 09:58:31 -04:00
|
|
|
struct itrm_queue queue;
|
|
|
|
};
|
|
|
|
|
2007-07-31 07:12:28 -04:00
|
|
|
/** Things going out from an itrm, whether to the terminal or to the
|
2006-07-24 12:35:58 -04:00
|
|
|
* master. */
|
2005-09-15 09:58:31 -04:00
|
|
|
struct itrm_out {
|
2007-07-27 09:50:37 -04:00
|
|
|
/** A file descriptor for the standard output. In some ports,
|
2006-07-24 12:35:58 -04:00
|
|
|
* this is the terminal device itself; in others, this is a
|
2006-07-27 03:55:31 -04:00
|
|
|
* pipe to an output thread. The data format depends on the
|
|
|
|
* terminal in principle, but this has not yet been
|
|
|
|
* implemented; see bug 96. */
|
2005-09-15 09:58:31 -04:00
|
|
|
int std;
|
2006-07-24 12:35:58 -04:00
|
|
|
|
2007-07-27 09:50:37 -04:00
|
|
|
/** A file descriptor for a pipe or socket to which this
|
2006-07-24 12:35:58 -04:00
|
|
|
* process sends input events. The other end of the pipe or
|
|
|
|
* socket connection is terminal.fdin in the master process.
|
|
|
|
* If the connection is from the master process to itself, it
|
|
|
|
* uses a pipe; otherwise a socket. The events are formatted
|
2006-08-05 04:49:57 -04:00
|
|
|
* as struct interlink_event, but at the beginning of the
|
2006-07-27 03:55:31 -04:00
|
|
|
* connection, a struct terminal_info and extra data are also
|
2006-07-24 12:35:58 -04:00
|
|
|
* sent. */
|
2005-09-15 09:58:31 -04:00
|
|
|
int sock;
|
2006-07-24 12:35:58 -04:00
|
|
|
|
2007-07-27 09:50:37 -04:00
|
|
|
/** Bytes that should be written to #sock. They will be
|
2006-07-24 12:35:58 -04:00
|
|
|
* written when select() indicates the write won't block. To
|
|
|
|
* add data here, call itrm_queue_event(), which reallocates
|
2007-07-27 09:50:37 -04:00
|
|
|
* itrm_queue.data if appropriate. The size of this queue is
|
|
|
|
* unrelated to ::ITRM_OUT_QUEUE_SIZE. */
|
2005-09-15 09:58:31 -04:00
|
|
|
struct itrm_queue queue;
|
|
|
|
};
|
|
|
|
|
2007-07-27 09:50:37 -04:00
|
|
|
/** A connection between a terminal and a master ELinks process.
|
2006-07-24 12:35:58 -04:00
|
|
|
* Normally, only one struct itrm exists in each master or slave
|
2007-07-27 09:50:37 -04:00
|
|
|
* process, and the global pointer ::ditrm (not declared here)
|
2006-07-24 12:35:58 -04:00
|
|
|
* points to it. */
|
2005-09-15 09:58:31 -04:00
|
|
|
struct itrm {
|
2007-07-27 09:50:37 -04:00
|
|
|
struct itrm_in in; /**< Input */
|
|
|
|
struct itrm_out out; /**< Output */
|
|
|
|
|
|
|
|
timer_id_T timer; /**< ESC timeout timer */
|
|
|
|
struct termios t; /**< For restoring original attributes */
|
|
|
|
void *mouse_h; /**< Mouse handle */
|
2021-01-02 10:20:27 -05:00
|
|
|
char *orig_title; /**< For restoring window title */
|
2007-07-27 09:50:37 -04:00
|
|
|
|
2008-01-13 16:49:31 -05:00
|
|
|
int verase; /**< Byte to map to KBD_BS, or -1 */
|
Bug 885: Proper charset support in xterm window title
When ELinks runs in an X11 terminal emulator (e.g. xterm), or in GNU
Screen, it tries to update the title of the window to match the title
of the current document. To do this, ELinks sends an "OSC 1 ; Pt BEL"
sequence to the terminal. Unfortunately, xterm expects the Pt string
to be in the ISO-8859-1 charset, making it impossible to display e.g.
Cyrillic characters. In xterm patch #210 (2006-03-12) however, there
is a menu item and a resource that can make xterm take the Pt string
in UTF-8 instead, allowing characters from all around the world.
The downside is that ELinks apparently cannot ask xterm whether the
setting is on or off; so add a terminal._template_.latin1_title option
to ELinks and let the user edit that instead.
Complete list of changes:
- Add the terminal._template_.latin1_title option. But do not add
that to the terminal options window because it's already rather
crowded there.
- In set_window_title(), take a new codepage argument. Use it to
decode the title into Unicode characters, and remove only actual
control characters. For example, CP437 has graphical characters in
the 0x80...0x9F range, so don't remove those, even though ISO-8859-1
has control characters in the same range. Likewise, don't
misinterpret single bytes of UTF-8 characters as control characters.
- In set_window_title(), do not truncate the title to the width of the
window. The font is likely to be different and proportional anyway.
But do truncate before 1024 bytes, an xterm limit.
- In struct itrm, add a title_codepage member to remember which
charset the master said it was going to use in the terminal window
title. Initialize title_codepage in handle_trm(), update it in
dispatch_special() if the master sends the new request
TERM_FN_TITLE_CODEPAGE, and use it in most set_window_title() calls;
but not in the one that sets $TERM as the title, because that string
was not received from the master and should consist of ASCII
characters only.
- In set_terminal_title(), convert the caller-provided title to
ISO-8859-1 or UTF-8 if appropriate, and report the codepage to the
slave with the new TERM_FN_TITLE_CODEPAGE request. The conversion
can run out of memory, so return a success/error flag, rather than
void. In display_window_title(), check this result and don't update
caches on error.
- Add a NEWS entry for all of this.
2008-12-28 20:09:53 -05:00
|
|
|
int title_codepage; /**< Codepage of terminal title */
|
2007-07-27 09:50:37 -04:00
|
|
|
unsigned int blocked:1; /**< Whether it was blocked */
|
|
|
|
unsigned int altscreen:1; /**< Whether to use alternate screen */
|
|
|
|
unsigned int touched_title:1; /**< Whether the term title was changed */
|
|
|
|
/*! The @c remote flag is not set in regular slave terminals.
|
2006-07-27 03:55:31 -04:00
|
|
|
* Instead, it means the itrm controls a preexisting terminal,
|
|
|
|
* and windows should not be displayed on the terminal of the
|
2007-07-31 07:14:08 -04:00
|
|
|
* itrm; thus the terminal init and done strings are not sent. */
|
2007-07-27 09:50:37 -04:00
|
|
|
unsigned int remote:1; /**< Whether it is a remote session */
|
2007-07-19 18:11:26 -04:00
|
|
|
unsigned int bracketed_pasting:1;/**< Received bracketed-paste escape*/
|
2005-09-15 09:58:31 -04:00
|
|
|
};
|
|
|
|
|
2020-10-05 14:14:55 -04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
#endif
|