1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-09-27 02:56:18 -04:00
elinks/src/terminal/itrm.h

124 lines
4.7 KiB
C
Raw Permalink Normal View History

#ifndef EL__TERMINAL_ITRM_H
#define EL__TERMINAL_ITRM_H
#ifdef __cplusplus
extern "C" {
#endif
#define ITRM_OUT_QUEUE_SIZE 16384
2007-07-27 09:50:37 -04:00
/** Currently, ELinks treats control sequences as text if they are
* 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:
* - 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" */
#define ITRM_IN_QUEUE_SIZE 64
struct itrm_queue {
unsigned char *data;
2007-07-27 09:50:37 -04:00
/** The amount of data in the queue, in bytes. This may be
* 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. */
int len;
};
2007-07-27 09:50:37 -04:00
/** Things coming into an itrm, whether from the terminal or from the
* master. */
struct itrm_in {
2007-07-27 09:50:37 -04:00
/** A file descriptor for the standard input. In some ports,
* 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. */
int std;
2007-07-27 09:50:37 -04:00
/** In a slave process, a file descriptor for a socket from
* which it reads data sent by the master process. The other
* end of the socket connection is terminal.fdout in the
* 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),
* but there are special commands that begin with a null byte.
*
2007-07-27 09:50:37 -04:00
* In the master process, @c sock is the same as itrm_out.std,
* but nothing actually uses it. */
int sock;
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
* 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(). */
int ctl;
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
* 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
* 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. */
struct itrm_queue queue;
};
/** Things going out from an itrm, whether to the terminal or to the
* master. */
struct itrm_out {
2007-07-27 09:50:37 -04:00
/** A file descriptor for the standard output. In some ports,
* this is the terminal device itself; in others, this is a
* pipe to an output thread. The data format depends on the
* terminal in principle, but this has not yet been
* implemented; see bug 96. */
int std;
2007-07-27 09:50:37 -04:00
/** A file descriptor for a pipe or socket to which this
* 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
* as struct interlink_event, but at the beginning of the
* connection, a struct terminal_info and extra data are also
* sent. */
int sock;
2007-07-27 09:50:37 -04:00
/** Bytes that should be written to #sock. They will be
* 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. */
struct itrm_queue queue;
};
2007-07-27 09:50:37 -04:00
/** A connection between a terminal and a master ELinks process.
* 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)
* points to it. */
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 */
char *orig_title; /**< For restoring window title */
2007-07-27 09:50:37 -04: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.
* Instead, it means the itrm controls a preexisting terminal,
* and windows should not be displayed on the terminal of the
* 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 */
unsigned int bracketed_pasting:1;/**< Received bracketed-paste escape*/
};
#ifdef __cplusplus
}
#endif
#endif