ELinks 0.16.1.1
|
Support for keyboard interface. More...
#include <stdlib.h>
#include <string.h>
#include "elinks.h"
#include "config/options.h"
#include "intl/libintl.h"
#include "main/main.h"
#include "main/select.h"
#include "main/timer.h"
#include "osdep/ascii.h"
#include "osdep/osdep.h"
#include "terminal/hardio.h"
#include "terminal/itrm.h"
#include "terminal/kbd.h"
#include "terminal/mouse.h"
#include "terminal/terminal.h"
#include "util/error.h"
#include "util/memory.h"
#include "util/string.h"
#include "util/time.h"
#include "terminal/key.inc"
Macros | |
#define | HPUX_PIPE 1 |
#define | write_sequence(fd, seq) |
#define | INIT_TERMINAL_SEQ "\033)0\0337" |
Special Character and Line Drawing Set, Save Cursor. | |
#define | INIT_ALT_SCREEN_SEQ "\033[?47h" |
Use Alternate Screen Buffer. | |
#define | INIT_BRACKETED_PASTE_SEQ "\033[?2004h" |
Enable XTerm bracketed paste mode. | |
#define | DONE_CLS_SEQ "\033[2J" |
Erase in Display, Clear All. | |
#define | DONE_TERMINAL_SEQ "\0338\r \b" |
Restore Cursor (DECRC) + ? | |
#define | DONE_ALT_SCREEN_SEQ "\033[?47l" |
Use Normal Screen Buffer. | |
#define | DONE_BRACKETED_PASTE_SEQ "\033[?2004l" |
Disable XTerm bracketed paste mode. | |
#define | RD(xx) |
Functions | |
static void | free_itrm (struct itrm *) |
static void | in_kbd (struct itrm *itrm) |
A select_handler_T read_func for itrm_in.std. | |
static void | in_sock (struct itrm *itrm) |
A select_handler_T read_func for itrm_in.sock. | |
static int | process_queue (struct itrm *itrm) |
Parse one event from itrm_in.queue and append to itrm_out.queue. | |
static void | handle_itrm_stdin (struct itrm *itrm) |
Enable reading from itrm_in.std. | |
static void | unhandle_itrm_stdin (struct itrm *itrm) |
Disable reading from itrm_in.std. | |
int | is_blocked (void) |
void | free_all_itrms (void) |
static void | itrm_queue_write (struct itrm *itrm) |
A select_handler_T write_func for itrm_out.sock. | |
void | itrm_queue_event (struct itrm *itrm, char *data, int len) |
void | kbd_ctrl_c (void) |
static void | send_init_sequence (int h, int altscreen) |
static void | send_done_sequence (int h, int altscreen) |
void | resize_terminal (void) |
void | get_terminal_name (char name[MAX_TERM_LEN]) |
static int | setraw (struct itrm *itrm, int save_orig) |
void | handle_trm (int std_in, int std_out, int sock_in, int sock_out, int ctl_in, void *init_string, int init_len, int remote) |
Construct the struct itrm of this process, make ditrm point to it, set up select() handlers, and send the initial interlink packet. | |
static void | unblock_itrm_x (void *h) |
A select_handler_T read_func and error_func for the pipe (intptr_t) h. | |
int | unblock_itrm (void) |
void | block_itrm (void) |
static void | resize_terminal_from_str (const char *text_) |
Resize terminal to dimensions specified by text string. | |
void | dispatch_special (const char *text) |
static void | safe_hard_write (int fd, const char *buf, int len) |
static int | get_esc_code (unsigned char *str, int len, char *final_byte, int *first_param_value) |
Parse an ECMA-48 control sequence that was received from a terminal. | |
static int | get_ui_double_esc (void) |
static int | decode_terminal_escape_sequence (struct itrm *itrm, struct interlink_event *ev) |
Decode a control sequence that begins with CSI (CONTROL SEQUENCE INTRODUCER) encoded as ESC [, and set *ev accordingly. | |
static int | decode_terminal_application_key (struct itrm *itrm, struct interlink_event *ev) |
Decode an escape sequence that begins with SS3 (SINGLE SHIFT 3). | |
static void | set_kbd_event (const struct itrm *itrm, struct interlink_event *ev, int key, term_event_modifier_T modifier) |
Initialize *ev to match the byte key received from the terminal. | |
static void | kbd_timeout (struct itrm *itrm) |
Timer callback for itrm.timer. |
Variables | |
struct itrm * | ditrm = NULL |
static enum term_event_special_key | dummy_term_event_special_key |
This hack makes GCC put enum term_event_special_key in the debug information even though it is not otherwise used. | |
int | ui_double_esc |
Support for keyboard interface.
#define DONE_ALT_SCREEN_SEQ "\033[?47l" |
Use Normal Screen Buffer.
#define DONE_BRACKETED_PASTE_SEQ "\033[?2004l" |
Disable XTerm bracketed paste mode.
#define DONE_CLS_SEQ "\033[2J" |
Erase in Display, Clear All.
#define DONE_TERMINAL_SEQ "\0338\r \b" |
Restore Cursor (DECRC) + ?
??
#define HPUX_PIPE 1 |
#define INIT_ALT_SCREEN_SEQ "\033[?47h" |
Use Alternate Screen Buffer.
#define INIT_BRACKETED_PASTE_SEQ "\033[?2004h" |
Enable XTerm bracketed paste mode.
#define INIT_TERMINAL_SEQ "\033)0\0337" |
Special Character and Line Drawing Set, Save Cursor.
#define RD | ( | xx | ) |
#define write_sequence | ( | fd, | |
seq ) |
void block_itrm | ( | void | ) |
|
static |
Decode an escape sequence that begins with SS3 (SINGLE SHIFT 3).
These are used for application cursor keys and the application keypad.
|
static |
Decode a control sequence that begins with CSI (CONTROL SEQUENCE INTRODUCER) encoded as ESC [, and set *ev accordingly.
(ECMA-48 also allows 0x9B as a single-byte CSI, but we don't support that here.)
void dispatch_special | ( | const char * | text | ) |
void free_all_itrms | ( | void | ) |
|
static |
|
inlinestatic |
Parse an ECMA-48 control sequence that was received from a terminal.
Extract the Final Byte (if there are no Intermediate Bytes) and the value of the first parameter (if it is an integer).
This function assumes the control sequence begins with a CSI - CONTROL SEQUENCE INTRODUCER encoded as ESC [. (ECMA-48 also allows 0x9B as a single-byte CSI, but we don't support that here.)
void get_terminal_name | ( | char | name[MAX_TERM_LEN] | ) |
|
inlinestatic |
|
static |
Enable reading from itrm_in.std.
ELinks will read any available bytes from the tty into itrm->in.queue and then parse them. Reading should be enabled whenever itrm->in.queue is not full and itrm->blocked is 0.
void handle_trm | ( | int | std_in, |
int | std_out, | ||
int | sock_in, | ||
int | sock_out, | ||
int | ctl_in, | ||
void * | init_string, | ||
int | init_len, | ||
int | remote ) |
Construct the struct itrm of this process, make ditrm point to it, set up select() handlers, and send the initial interlink packet.
The first five parameters are file descriptors that this function saves in submembers of struct itrm, and for which this function may set select() handlers. Please see the definitions of struct itrm_in and struct itrm_out for further explanations.
std_in | itrm_in.std: read tty device (or pipe) |
std_out | itrm_out.std: write tty device (or pipe) |
sock_in | itrm_in.sock
|
sock_out | itrm_out.sock
|
ctl_in | itrm_in.ctl: control tty device |
The remaining three parameters control the initial interlink packet.
init_string | A string to be passed to the master process. Need not be null-terminated. If remote == 0, this is a URI. Otherwise, this is a remote command. |
init_len | The length of init_string, in bytes. |
remote | = 0 if asking the master to start a new session and display it via this process. Otherwise, enum remote_session_flags. |
|
static |
A select_handler_T read_func for itrm_in.std.
This is called when characters typed by the user arrive from the terminal.
|
static |
A select_handler_T read_func for itrm_in.sock.
A slave process calls this when the master sends it data to be displayed. The master process never calls this.
int is_blocked | ( | void | ) |
void itrm_queue_event | ( | struct itrm * | itrm, |
char * | data, | ||
int | len ) |
|
static |
A select_handler_T write_func for itrm_out.sock.
This is called when there is data in itrm->out.queue
and it is possible to write it to itrm->out.sock
. When itrm->out.queue
becomes empty, this handler is temporarily removed.
void kbd_ctrl_c | ( | void | ) |
|
static |
Timer callback for itrm.timer.
As explained in install_timer(), this function must erase the expired timer ID from all variables.
|
static |
Parse one event from itrm_in.queue and append to itrm_out.queue.
void resize_terminal | ( | void | ) |
|
inlinestatic |
Resize terminal to dimensions specified by text string.
text should look like "width,height,old-width,old-height" where width and height are integers.
|
inlinestatic |
|
static |
|
static |
|
static |
Initialize *ev to match the byte key received from the terminal.
key must not be a value from enum term_event_special_key.
|
static |
int unblock_itrm | ( | void | ) |
|
static |
A select_handler_T read_func and error_func for the pipe (intptr_t) h.
This is called when the subprocess started on the terminal of this ELinks process exits. ELinks then resumes using the terminal.
|
static |
Disable reading from itrm_in.std.
Reading should be disabled whenever itrm->in.queue is full (there is no room for the data) or itrm->blocked is 1 (other processes may read the data).
|
static |
This hack makes GCC put enum term_event_special_key in the debug information even though it is not otherwise used.
The const prevents an unused-variable warning.
int ui_double_esc |