Skip to content

Commit

Permalink
patch 9.0.0774: the libvterm code is outdated
Browse files Browse the repository at this point in the history
Problem:    The libvterm code is outdated.
Solution:   Include libvterm changes from revision 802 to 817.  Revert some
            changes made for C89.
  • Loading branch information
brammool committed Oct 16, 2022
1 parent d094e58 commit 6a12d26
Show file tree
Hide file tree
Showing 24 changed files with 655 additions and 254 deletions.
4 changes: 2 additions & 2 deletions src/libvterm/CONTRIBUTING
Expand Up @@ -6,8 +6,8 @@ The main resources for this library are:
Launchpad
https://launchpad.net/libvterm

Freenode:
##tty or #tickit on irc.freenode.net
IRC:
##tty or #tickit on irc.libera.chat

Email:
Paul "LeoNerd" Evans <leonerd@leonerd.org.uk>
Expand Down
2 changes: 1 addition & 1 deletion src/libvterm/Makefile
Expand Up @@ -37,7 +37,7 @@ INCFILES=$(TBLFILES:.tbl=.inc)
HFILES_INT=$(sort $(wildcard src/*.h)) $(HFILES)

VERSION_MAJOR=0
VERSION_MINOR=2
VERSION_MINOR=3

VERSION_CURRENT=0
VERSION_REVISION=0
Expand Down
7 changes: 5 additions & 2 deletions src/libvterm/README
Expand Up @@ -7,8 +7,11 @@ The original can be found:
https://github.com/neovim/libvterm

Modifications:
- Add a .gitignore file.
- Convert some code from C99 to C90.
- revisions up to 817 have been included
- Added a .gitignore file.
- use TRUE and FALSE instead of true and false
- use int or unsigned int instead of bool
- Converted some code from C99 to C90.
- Other changes to support embedding in Vim.

To get the latest version of libvterm you need the "bzr" command and do:
Expand Down
4 changes: 4 additions & 0 deletions src/libvterm/doc/seqs.txt
Expand Up @@ -122,6 +122,7 @@ x = xterm
123x CSI l = RM, Reset mode
123x CSI ? l = DECRM, DEC reset mode
123x CSI m = SGR, Set Graphic Rendition
CSI ? m = DECSGR, private Set Graphic Rendition
123x CSI n = DSR, Device Status Report
23x 5 = operating status
23x 6 = CPR = cursor position
Expand Down Expand Up @@ -198,6 +199,9 @@ x = xterm
x SGR 40-47 = Background ANSI
x SGR 48 = Background alternative palette
x SGR 49 = Background default
SGR 73 = Superscript on
SGR 74 = Subscript on
SGR 75 = Superscript/subscript off
x SGR 90-97 = Foreground ANSI high-intensity
x SGR 100-107 = Background ANSI high-intensity

Expand Down
36 changes: 29 additions & 7 deletions src/libvterm/include/vterm.h
Expand Up @@ -12,16 +12,17 @@ extern "C" {

#include "vterm_keycodes.h"

// VIM: use TRUE and FALSE instead of true and false
#define TRUE 1
#define FALSE 0

// from stdint.h
// VIM: from stdint.h
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;

#define VTERM_VERSION_MAJOR 0
#define VTERM_VERSION_MINOR 2
#define VTERM_VERSION_MINOR 3

#define VTERM_CHECK_VERSION \
vterm_check_version(VTERM_VERSION_MAJOR, VTERM_VERSION_MINOR)
Expand Down Expand Up @@ -131,7 +132,7 @@ typedef enum {
VTERM_COLOR_DEFAULT_MASK = 0x06,

/**
* If set, indicates that the color is invalid.
* VIM: If set, indicates that the color is invalid.
*/
VTERM_COLOR_INVALID = 0x08
} VTermColorType;
Expand Down Expand Up @@ -172,6 +173,7 @@ typedef enum {
*/
#define VTERM_COLOR_IS_INVALID(col) (!!((col)->type & VTERM_COLOR_INVALID))

// VIM: this was a union, but that doesn't always work.
typedef struct {
/**
* Tag indicating which member is actually valid.
Expand Down Expand Up @@ -237,6 +239,8 @@ typedef enum {
VTERM_ATTR_FONT, // number: 10-19
VTERM_ATTR_FOREGROUND, // color: 30-39 90-97
VTERM_ATTR_BACKGROUND, // color: 40-49 100-107
VTERM_ATTR_SMALL, // bool: 73, 74, 75
VTERM_ATTR_BASELINE, // number: 73, 74, 75

VTERM_N_ATTRS
} VTermAttr;
Expand All @@ -251,7 +255,7 @@ typedef enum {
VTERM_PROP_REVERSE, // bool
VTERM_PROP_CURSORSHAPE, // number
VTERM_PROP_MOUSE, // number
VTERM_PROP_CURSORCOLOR, // string
VTERM_PROP_CURSORCOLOR, // VIM - string

VTERM_N_PROPS
} VTermProp;
Expand Down Expand Up @@ -312,7 +316,6 @@ typedef struct {
void (*free)(void *ptr, void *allocdata);
} VTermAllocatorFunctions;

/* A convenient shortcut for default cases */
void vterm_check_version(int major, int minor);

struct VTermBuilder {
Expand All @@ -333,7 +336,6 @@ VTerm *vterm_build(const struct VTermBuilder *builder);
/* A convenient shortcut for default cases */
// Allocate and initialize a new terminal with default allocators.
VTerm *vterm_new(int rows, int cols);

/* These shortcuts are generally discouraged in favour of just using vterm_build() */

// Allocate and initialize a new terminal with specified allocators.
Expand Down Expand Up @@ -396,6 +398,7 @@ void vterm_mouse_button(VTerm *vt, int button, int pressed, VTermModifier mod);
#define CSI_ARG(a) ((a) & CSI_ARG_MASK)

/* Can't use -1 to indicate a missing argument; use this instead */
// VIM: changed 31 to 30 to avoid an overflow warning
#define CSI_ARG_MISSING ((1<<30)-1)

#define CSI_ARG_IS_MISSING(a) (CSI_ARG(a) == CSI_ARG_MISSING)
Expand Down Expand Up @@ -436,8 +439,10 @@ typedef struct {
int (*bell)(void *user);
int (*resize)(int rows, int cols, VTermStateFields *fields, void *user);
int (*setlineinfo)(int row, const VTermLineInfo *newinfo, const VTermLineInfo *oldinfo, void *user);
int (*sb_clear)(void *user);
} VTermStateCallbacks;

// VIM: added
typedef struct {
VTermPos pos;
int buttons;
Expand Down Expand Up @@ -478,6 +483,7 @@ void *vterm_state_get_unrecognised_fbdata(VTermState *state);
void vterm_state_reset(VTermState *state, int hard);

void vterm_state_get_cursorpos(const VTermState *state, VTermPos *cursorpos);
// VIM: added
void vterm_state_get_mousestate(const VTermState *state, VTermMouseState *mousestate);
void vterm_state_get_default_colors(const VTermState *state, VTermColor *default_fg, VTermColor *default_bg);
void vterm_state_get_palette_color(const VTermState *state, int index, VTermColor *col);
Expand Down Expand Up @@ -522,6 +528,8 @@ typedef struct {
unsigned int font : 4; /* 0 to 9 */
unsigned int dwl : 1; /* On a DECDWL or DECDHL line */
unsigned int dhl : 2; /* On a DECDHL line (1=top 2=bottom) */
unsigned int small : 1;
unsigned int baseline : 2;
} VTermScreenCellAttrs;

enum {
Expand All @@ -531,6 +539,12 @@ enum {
VTERM_UNDERLINE_CURLY,
};

enum {
VTERM_BASELINE_NORMAL,
VTERM_BASELINE_RAISE,
VTERM_BASELINE_LOWER,
};

typedef struct {
uint32_t chars[VTERM_MAX_CHARS_PER_CELL];
char width;
Expand All @@ -551,6 +565,7 @@ typedef struct {
// Return value is unused.
int (*sb_pushline)(int cols, const VTermScreenCell *cells, void *user);
int (*sb_popline)(int cols, VTermScreenCell *cells, void *user);
int (*sb_clear)(void* user);
} VTermScreenCallbacks;

// Return the screen of the vterm.
Expand All @@ -566,6 +581,11 @@ void *vterm_screen_get_cbdata(VTermScreen *screen);
void vterm_screen_set_unrecognised_fallbacks(VTermScreen *screen, const VTermStateFallbacks *fallbacks, void *user);
void *vterm_screen_get_unrecognised_fbdata(VTermScreen *screen);

void vterm_screen_enable_reflow(VTermScreen *screen, int reflow);

// Back-compat alias for the brief time it was in 0.3-RC1
#define vterm_screen_set_reflow vterm_screen_enable_reflow

// Enable support for using the alternate screen if "altscreen" is non-zero.
// Before that switching to the alternate screen won't work.
// Calling with "altscreen" zero has no effect.
Expand Down Expand Up @@ -606,8 +626,10 @@ typedef enum {
VTERM_ATTR_FOREGROUND_MASK = 1 << 7,
VTERM_ATTR_BACKGROUND_MASK = 1 << 8,
VTERM_ATTR_CONCEAL_MASK = 1 << 9,
VTERM_ATTR_SMALL_MASK = 1 << 10,
VTERM_ATTR_BASELINE_MASK = 1 << 11,

VTERM_ALL_ATTRS_MASK = (1 << 10) - 1
VTERM_ALL_ATTRS_MASK = (1 << 12) - 1
} VTermAttrMask;

int vterm_screen_get_attrs_extent(const VTermScreen *screen, VTermRect *extent, VTermPos pos, VTermAttrMask attrs);
Expand Down
4 changes: 2 additions & 2 deletions src/libvterm/src/encoding.c
Expand Up @@ -49,6 +49,7 @@ static void decode_utf8(VTermEncoding *enc UNUSED, void *data_,
if(data->bytes_remaining) {
data->bytes_remaining = 0;
cp[(*cpi)++] = UNICODE_INVALID;
// VIM: avoid going over the end
if (*cpi >= cplen)
break;
}
Expand Down Expand Up @@ -226,8 +227,7 @@ encodings[] = {
/* This ought to be INTERNAL but isn't because it's used by unit testing */
VTermEncoding *vterm_lookup_encoding(VTermEncodingType type, char designation)
{
int i;
for(i = 0; encodings[i].designation; i++)
for(int i = 0; encodings[i].designation; i++)
if(encodings[i].type == type && encodings[i].designation == designation)
return encodings[i].enc;
return NULL;
Expand Down
32 changes: 16 additions & 16 deletions src/libvterm/src/keyboard.c
Expand Up @@ -4,6 +4,7 @@

#include "utf8.h"

// VIM: added
int vterm_is_modify_other_keys(VTerm *vt)
{
return vt->state->mode.modify_other_keys;
Expand All @@ -12,8 +13,7 @@ int vterm_is_modify_other_keys(VTerm *vt)

void vterm_keyboard_unichar(VTerm *vt, uint32_t c, VTermModifier mod)
{
int needs_CSIu;

// VIM: added modifyOtherKeys support
if (vt->state->mode.modify_other_keys && mod != 0) {
vterm_push_output_sprintf_ctrl(vt, C1_CSI, "27;%d;%d~", mod+1, c);
return;
Expand All @@ -33,6 +33,7 @@ void vterm_keyboard_unichar(VTerm *vt, uint32_t c, VTermModifier mod)
return;
}

int needs_CSIu;
switch(c) {
/* Special Ctrl- letters that can't be represented elsewise */
case 'i': case 'j': case 'm': case '[':
Expand Down Expand Up @@ -93,12 +94,12 @@ static keycodes_s keycodes[] = {
{ KEYCODE_CSI_CURSOR, 'D', 0 }, // LEFT
{ KEYCODE_CSI_CURSOR, 'C', 0 }, // RIGHT

{ KEYCODE_CSINUM, '~', 2 }, // INS
{ KEYCODE_CSINUM, '~', 3 }, // DEL
{ KEYCODE_CSINUM, '~', 2 }, // INS
{ KEYCODE_CSINUM, '~', 3 }, // DEL
{ KEYCODE_CSI_CURSOR, 'H', 0 }, // HOME
{ KEYCODE_CSI_CURSOR, 'F', 0 }, // END
{ KEYCODE_CSINUM, '~', 5 }, // PAGEUP
{ KEYCODE_CSINUM, '~', 6 }, // PAGEDOWN
{ KEYCODE_CSINUM, '~', 5 }, // PAGEUP
{ KEYCODE_CSINUM, '~', 6 }, // PAGEDOWN
};

static keycodes_s keycodes_fn[] = {
Expand All @@ -107,14 +108,14 @@ static keycodes_s keycodes_fn[] = {
{ KEYCODE_SS3, 'Q', 0 }, // F2
{ KEYCODE_SS3, 'R', 0 }, // F3
{ KEYCODE_SS3, 'S', 0 }, // F4
{ KEYCODE_CSINUM, '~', 15 }, // F5
{ KEYCODE_CSINUM, '~', 17 }, // F6
{ KEYCODE_CSINUM, '~', 18 }, // F7
{ KEYCODE_CSINUM, '~', 19 }, // F8
{ KEYCODE_CSINUM, '~', 20 }, // F9
{ KEYCODE_CSINUM, '~', 21 }, // F10
{ KEYCODE_CSINUM, '~', 23 }, // F11
{ KEYCODE_CSINUM, '~', 24 }, // F12
{ KEYCODE_CSINUM, '~', 15 }, // F5
{ KEYCODE_CSINUM, '~', 17 }, // F6
{ KEYCODE_CSINUM, '~', 18 }, // F7
{ KEYCODE_CSINUM, '~', 19 }, // F8
{ KEYCODE_CSINUM, '~', 20 }, // F9
{ KEYCODE_CSINUM, '~', 21 }, // F10
{ KEYCODE_CSINUM, '~', 23 }, // F11
{ KEYCODE_CSINUM, '~', 24 }, // F12
};

static keycodes_s keycodes_kp[] = {
Expand All @@ -140,11 +141,10 @@ static keycodes_s keycodes_kp[] = {

void vterm_keyboard_key(VTerm *vt, VTermKey key, VTermModifier mod)
{
keycodes_s k;

if(key == VTERM_KEY_NONE)
return;

keycodes_s k;
if(key < VTERM_KEY_FUNCTION_0) {
if(key >= sizeof(keycodes)/sizeof(keycodes[0]))
return;
Expand Down
5 changes: 2 additions & 3 deletions src/libvterm/src/parser.c
Expand Up @@ -142,7 +142,6 @@ size_t vterm_input_write(VTerm *vt, const char *bytes, size_t len)
for( ; pos < len; pos++) {
unsigned char c = bytes[pos];
int c1_allowed = !vt->mode.utf8;
size_t string_len;

if(c == 0x00 || c == 0x7f) { // NUL, DEL
if(IS_STRING_STATE()) {
Expand Down Expand Up @@ -187,7 +186,7 @@ size_t vterm_input_write(VTerm *vt, const char *bytes, size_t len)
}
// else fallthrough

string_len = bytes + pos - string_start;
size_t string_len = bytes + pos - string_start;

if(vt->parser.in_esc) {
// Hoist an ESC letter into a C1 if we're not in a string mode
Expand Down Expand Up @@ -247,7 +246,7 @@ size_t vterm_input_write(VTerm *vt, const char *bytes, size_t len)
vt->parser.v.csi.argi++;
vt->parser.intermedlen = 0;
vt->parser.state = CSI_INTERMED;
// fallthrough
// FALLTHROUGH
case CSI_INTERMED:
if(is_intermed(c)) {
if(vt->parser.intermedlen < INTERMED_MAX-1)
Expand Down

0 comments on commit 6a12d26

Please sign in to comment.