Compare commits

...

6 Commits

Author SHA1 Message Date
Bram Moolenaar
e5886ccb51 patch 8.2.0804: libvterm code lags behind the upstream version
Problem:    Libvterm code lags behind the upstream version.
Solution:   Include revision 727, but add the index instead of switching
            between RGB and indexed.
2020-05-21 20:10:04 +02:00
Bram Moolenaar
83a52533b2 patch 8.2.0803: libvterm code lags behind the upstream version
Problem:    Libvterm code lags behind the upstream version.
Solution:   Include revisions 764 - 767
2020-05-20 19:30:19 +02:00
Bram Moolenaar
d863728913 patch 8.2.0802: libvterm code lags behind the upstream version
Problem:    Libvterm code lags behind the upstream version.
Solution:   Include revisions 759 - 762.
2020-05-20 18:41:41 +02:00
Bram Moolenaar
eaa3e0dae5 patch 8.2.0801: terminal test fails on Mac
Problem:    Terminal test fails on Mac.
Solution:   Concatenate OSC pieces.
2020-05-19 23:11:00 +02:00
Bram Moolenaar
a09195f29e patch 8.2.0800: errors from failing test are unclear
Problem:    Errors from failing test are unclear.
Solution:   Include text where parsing failed.
2020-05-19 22:38:59 +02:00
Bram Moolenaar
74c6963656 patch 8.2.0799: build fails if snprintf is not available
Problem:    Build fails if snprintf is not available.
Solution:   Use vim_snprintf().
2020-05-19 21:43:47 +02:00
23 changed files with 604 additions and 275 deletions

View File

@@ -3562,7 +3562,7 @@ objects/vterm_screen.o: libvterm/src/screen.c $(TERM_DEPS)
objects/vterm_state.o: libvterm/src/state.c $(TERM_DEPS)
$(CCCTERM) -o $@ libvterm/src/state.c
objects/vterm_unicode.o: libvterm/src/unicode.c $(TERM_DEPS)
objects/vterm_unicode.o: libvterm/src/unicode.c $(TERM_DEPS) libvterm/src/fullwidth.inc
$(CCCTERM) -o $@ libvterm/src/unicode.c
objects/vterm_vterm.o: libvterm/src/vterm.c $(TERM_DEPS)

View File

@@ -20,6 +20,8 @@
static int json_encode_item(garray_T *gap, typval_T *val, int copyID, int options);
static char e_json_error[] = N_("E491: json decode error at '%s'");
/*
* Encode "val" into a JSON format string.
* The result is added to "gap"
@@ -740,7 +742,7 @@ json_decode_item(js_read_T *reader, typval_T *res, int options)
retval = json_decode_string(reader, cur_item, *p);
else
{
emsg(_(e_invarg));
semsg(_(e_json_error), p);
retval = FAIL;
}
break;
@@ -748,7 +750,7 @@ json_decode_item(js_read_T *reader, typval_T *res, int options)
case ',': // comma: empty item
if ((options & JSON_JS) == 0)
{
emsg(_(e_invarg));
semsg(_(e_json_error), p);
retval = FAIL;
break;
}
@@ -778,7 +780,7 @@ json_decode_item(js_read_T *reader, typval_T *res, int options)
}
if (!VIM_ISDIGIT(*sp))
{
emsg(_(e_invarg));
semsg(_(e_json_error), p);
retval = FAIL;
break;
}
@@ -809,7 +811,7 @@ json_decode_item(js_read_T *reader, typval_T *res, int options)
&nr, NULL, 0, TRUE);
if (len == 0)
{
emsg(_(e_invarg));
semsg(_(e_json_error), p);
retval = FAIL;
goto theend;
}
@@ -962,7 +964,7 @@ item_end:
retval = MAYBE;
else
{
emsg(_(e_invarg));
semsg(_(e_json_error), p);
retval = FAIL;
}
goto theend;
@@ -980,7 +982,7 @@ item_end:
retval = MAYBE;
else
{
emsg(_(e_invarg));
semsg(_(e_json_error), p);
retval = FAIL;
}
goto theend;
@@ -1036,7 +1038,7 @@ item_end:
retval = MAYBE;
else
{
emsg(_(e_invarg));
semsg(_(e_json_error), p);
retval = FAIL;
}
goto theend;
@@ -1055,7 +1057,7 @@ item_end:
res->v_type = VAR_SPECIAL;
res->vval.v_number = VVAL_NONE;
}
emsg(_(e_invarg));
semsg(_(e_json_error), p);
theend:
ga_clear(&stack);
@@ -1079,7 +1081,7 @@ json_decode_all(js_read_T *reader, typval_T *res, int options)
if (ret != OK)
{
if (ret == MAYBE)
emsg(_(e_invarg));
semsg(_(e_json_error), reader->js_buf);
return FAIL;
}
json_skip_white(reader);

View File

@@ -170,6 +170,7 @@ between states.
SGR 4:x = Underline style
123 SGR 5 = Blink on
123 SGR 7 = Reverse on
SGR 8 = Conceal on
SGR 9 = Strikethrough on
SGR 10-19 = Select font
SGR 21 = Underline double
@@ -178,6 +179,7 @@ between states.
23 SGR 24 = Underline off
23 SGR 25 = Blink off
23 SGR 27 = Reverse off
SGR 28 = Conceal off
SGR 29 = Strikethrough off
SGR 30-37 = Foreground ANSI
SGR 38 = Foreground alternative palette

View File

@@ -3,16 +3,12 @@
use strict;
use warnings;
use Unicode::UCD qw( charprop );
STDOUT->autoflush(1);
sub iswide
{
my ( $cp ) = @_;
my $width = charprop( $cp, "East_Asian_Width" ) or return;
return $width eq "Wide" || $width eq "Fullwidth";
return chr($cp) =~ m/\p{East_Asian_Width=Wide}|\p{East_Asian_Width=Fullwidth}/;
}
my ( $start, $end );

View File

@@ -85,18 +85,107 @@ INLINE void vterm_rect_move(VTermRect *rect, int row_delta, int col_delta)
}
#endif
// The ansi_index is used for the lower 16 colors, which can be set to any
// color.
#define VTERM_ANSI_INDEX_DEFAULT 0 // color cleared
#define VTERM_ANSI_INDEX_MIN 1
#define VTERM_ANSI_INDEX_MAX 16
#define VTERM_ANSI_INDEX_NONE 255 // non-ANSI color, use red/green/blue
/**
* Bit-field describing the value of VTermColor.type
*/
typedef enum {
/**
* If the lower bit of `type` is not set, the colour is 24-bit RGB.
*/
VTERM_COLOR_RGB = 0x00,
/**
* The colour is an index into a palette of 256 colours.
*/
VTERM_COLOR_INDEXED = 0x01,
/**
* Mask that can be used to extract the RGB/Indexed bit.
*/
VTERM_COLOR_TYPE_MASK = 0x01,
/**
* If set, indicates that this colour should be the default foreground
* color, i.e. there was no SGR request for another colour. When
* rendering this colour it is possible to ignore "idx" and just use a
* colour that is not in the palette.
*/
VTERM_COLOR_DEFAULT_FG = 0x02,
/**
* If set, indicates that this colour should be the default background
* color, i.e. there was no SGR request for another colour. A common
* option when rendering this colour is to not render a background at
* all, for example by rendering the window transparently at this spot.
*/
VTERM_COLOR_DEFAULT_BG = 0x04,
/**
* Mask that can be used to extract the default foreground/background bit.
*/
VTERM_COLOR_DEFAULT_MASK = 0x06
} VTermColorType;
/**
* Returns true if the VTERM_COLOR_RGB `type` flag is set, indicating that the
* given VTermColor instance is an indexed colour.
*/
#define VTERM_COLOR_IS_INDEXED(col) \
(((col)->type & VTERM_COLOR_TYPE_MASK) == VTERM_COLOR_INDEXED)
/**
* Returns true if the VTERM_COLOR_INDEXED `type` flag is set, indicating that
* the given VTermColor instance is an rgb colour.
*/
#define VTERM_COLOR_IS_RGB(col) \
(((col)->type & VTERM_COLOR_TYPE_MASK) == VTERM_COLOR_RGB)
/**
* Returns true if the VTERM_COLOR_DEFAULT_FG `type` flag is set, indicating
* that the given VTermColor instance corresponds to the default foreground
* color.
*/
#define VTERM_COLOR_IS_DEFAULT_FG(col) \
(!!((col)->type & VTERM_COLOR_DEFAULT_FG))
/**
* Returns true if the VTERM_COLOR_DEFAULT_BG `type` flag is set, indicating
* that the given VTermColor instance corresponds to the default background
* color.
*/
#define VTERM_COLOR_IS_DEFAULT_BG(col) \
(!!((col)->type & VTERM_COLOR_DEFAULT_BG))
typedef struct {
/**
* Tag indicating which member is actually valid.
* Please use the `VTERM_COLOR_IS_*` test macros to check whether a
* particular type flag is set.
*/
uint8_t type;
uint8_t red, green, blue;
uint8_t ansi_index;
uint8_t index;
} VTermColor;
/**
* Constructs a new VTermColor instance representing the given RGB values.
*/
void vterm_color_rgb(VTermColor *col, uint8_t red, uint8_t green, uint8_t blue);
/**
* Construct a new VTermColor instance representing an indexed color with the
* given index.
*/
void vterm_color_indexed(VTermColor *col, uint8_t idx);
/**
* Compares two colours. Returns true if the colors are equal, false otherwise.
*/
int vterm_color_is_equal(const VTermColor *a, const VTermColor *b);
typedef enum {
// VTERM_VALUETYPE_NONE = 0
VTERM_VALUETYPE_BOOL = 1,
@@ -128,6 +217,7 @@ typedef enum {
VTERM_ATTR_ITALIC, // bool: 3, 23
VTERM_ATTR_BLINK, // bool: 5, 25
VTERM_ATTR_REVERSE, // bool: 7, 27
VTERM_ATTR_CONCEAL, // bool: 8, 28
VTERM_ATTR_STRIKE, // bool: 9, 29
VTERM_ATTR_FONT, // number: 10-19
VTERM_ATTR_FOREGROUND, // color: 30-39 90-97
@@ -314,13 +404,19 @@ typedef struct {
// useful to add protocol?
} VTermMouseState;
typedef struct {
int (*control)(unsigned char control, void *user);
int (*csi)(const char *leader, const long args[], int argcount, const char *intermed, char command, void *user);
int (*osc)(int command, VTermStringFragment frag, void *user);
int (*dcs)(const char *command, size_t commandlen, VTermStringFragment frag, void *user);
} VTermStateFallbacks;
VTermState *vterm_obtain_state(VTerm *vt);
void vterm_state_set_callbacks(VTermState *state, const VTermStateCallbacks *callbacks, void *user);
void *vterm_state_get_cbdata(VTermState *state);
// Only invokes control, csi, osc, dcs
void vterm_state_set_unrecognised_fallbacks(VTermState *state, const VTermParserCallbacks *fallbacks, void *user);
void vterm_state_set_unrecognised_fallbacks(VTermState *state, const VTermStateFallbacks *fallbacks, void *user);
void *vterm_state_get_unrecognised_fbdata(VTermState *state);
// Initialize the state.
@@ -339,6 +435,18 @@ void vterm_state_focus_in(VTermState *state);
void vterm_state_focus_out(VTermState *state);
const VTermLineInfo *vterm_state_get_lineinfo(const VTermState *state, int row);
/**
* Makes sure that the given color `col` is indeed an RGB colour. After this
* function returns, VTERM_COLOR_IS_RGB(col) will return true, while all other
* flags stored in `col->type` will have been reset.
*
* @param state is the VTermState instance from which the colour palette should
* be extracted.
* @param col is a pointer at the VTermColor instance that should be converted
* to an RGB colour.
*/
void vterm_state_convert_color_to_rgb(const VTermState *state, VTermColor *col);
// ------------
// Screen layer
// ------------
@@ -349,6 +457,7 @@ typedef struct {
unsigned int italic : 1;
unsigned int blink : 1;
unsigned int reverse : 1;
unsigned int conceal : 1;
unsigned int strike : 1;
unsigned int font : 4; // 0 to 9
unsigned int dwl : 1; // On a DECDWL or DECDHL line
@@ -395,8 +504,7 @@ VTermScreen *vterm_obtain_screen(VTerm *vt);
void vterm_screen_set_callbacks(VTermScreen *screen, const VTermScreenCallbacks *callbacks, void *user);
void *vterm_screen_get_cbdata(VTermScreen *screen);
// Only invokes control, csi, osc, dcs
void vterm_screen_set_unrecognised_fallbacks(VTermScreen *screen, const VTermParserCallbacks *fallbacks, void *user);
void vterm_screen_set_unrecognised_fallbacks(VTermScreen *screen, const VTermStateFallbacks *fallbacks, void *user);
void *vterm_screen_get_unrecognised_fbdata(VTermScreen *screen);
// Enable support for using the alternate screen if "altscreen" is non-zero.
@@ -438,8 +546,9 @@ typedef enum {
VTERM_ATTR_FONT_MASK = 1 << 6,
VTERM_ATTR_FOREGROUND_MASK = 1 << 7,
VTERM_ATTR_BACKGROUND_MASK = 1 << 8,
VTERM_ATTR_CONCEAL_MASK = 1 << 9,
VTERM_ALL_ATTRS_MASK = (1 << 9) - 1
VTERM_ALL_ATTRS_MASK = (1 << 10) - 1
} VTermAttrMask;
int vterm_screen_get_attrs_extent(const VTermScreen *screen, VTermRect *extent, VTermPos pos, VTermAttrMask attrs);
@@ -448,6 +557,12 @@ int vterm_screen_get_cell(const VTermScreen *screen, VTermPos pos, VTermScreenCe
int vterm_screen_is_eol(const VTermScreen *screen, VTermPos pos);
/**
* Same as vterm_state_convert_color_to_rgb(), but takes a `screen` instead of a `state`
* instance.
*/
void vterm_screen_convert_color_to_rgb(const VTermScreen *screen, VTermColor *col);
// ---------
// Utilities
// ---------

View File

@@ -40,14 +40,13 @@
{ 0x3000, 0x303e },
{ 0x3041, 0x3096 },
{ 0x3099, 0x30ff },
{ 0x3105, 0x312d },
{ 0x3105, 0x312f },
{ 0x3131, 0x318e },
{ 0x3190, 0x31ba },
{ 0x31c0, 0x31e3 },
{ 0x31f0, 0x321e },
{ 0x3220, 0x3247 },
{ 0x3250, 0x32fe },
{ 0x3300, 0x4dbf },
{ 0x3250, 0x4dbf },
{ 0x4e00, 0xa48c },
{ 0xa490, 0xa4c6 },
{ 0xa960, 0xa97c },
@@ -59,10 +58,13 @@
{ 0xfe68, 0xfe6b },
{ 0xff01, 0xff60 },
{ 0xffe0, 0xffe6 },
{ 0x16fe0, 0x16fe0 },
{ 0x17000, 0x187ec },
{ 0x16fe0, 0x16fe3 },
{ 0x17000, 0x187f7 },
{ 0x18800, 0x18af2 },
{ 0x1b000, 0x1b001 },
{ 0x1b000, 0x1b11e },
{ 0x1b150, 0x1b152 },
{ 0x1b164, 0x1b167 },
{ 0x1b170, 0x1b2fb },
{ 0x1f004, 0x1f004 },
{ 0x1f0cf, 0x1f0cf },
{ 0x1f18e, 0x1f18e },
@@ -71,6 +73,7 @@
{ 0x1f210, 0x1f23b },
{ 0x1f240, 0x1f248 },
{ 0x1f250, 0x1f251 },
{ 0x1f260, 0x1f265 },
{ 0x1f300, 0x1f320 },
{ 0x1f32d, 0x1f335 },
{ 0x1f337, 0x1f37c },
@@ -92,13 +95,17 @@
{ 0x1f680, 0x1f6c5 },
{ 0x1f6cc, 0x1f6cc },
{ 0x1f6d0, 0x1f6d2 },
{ 0x1f6d5, 0x1f6d5 },
{ 0x1f6eb, 0x1f6ec },
{ 0x1f6f4, 0x1f6f6 },
{ 0x1f910, 0x1f91e },
{ 0x1f920, 0x1f927 },
{ 0x1f930, 0x1f930 },
{ 0x1f933, 0x1f93e },
{ 0x1f940, 0x1f94b },
{ 0x1f950, 0x1f95e },
{ 0x1f980, 0x1f991 },
{ 0x1f9c0, 0x1f9c0 },
{ 0x1f6f4, 0x1f6fa },
{ 0x1f7e0, 0x1f7eb },
{ 0x1f90d, 0x1f971 },
{ 0x1f973, 0x1f976 },
{ 0x1f97a, 0x1f9a2 },
{ 0x1f9a5, 0x1f9aa },
{ 0x1f9ae, 0x1f9ca },
{ 0x1f9cd, 0x1f9ff },
{ 0x1fa70, 0x1fa73 },
{ 0x1fa78, 0x1fa7a },
{ 0x1fa80, 0x1fa82 },
{ 0x1fa90, 0x1fa95 },

View File

@@ -119,13 +119,15 @@ size_t vterm_input_write(VTerm *vt, const char *bytes, size_t len)
#define ENTER_STATE(st) do { vt->parser.state = st; string_start = NULL; } while(0)
#define ENTER_NORMAL_STATE() ENTER_STATE(NORMAL)
#define IS_STRING_STATE() (vt->parser.state >= OSC_COMMAND)
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(vt->parser.state >= OSC) {
if(IS_STRING_STATE()) {
string_fragment(vt, string_start, bytes + pos - string_start, FALSE);
string_start = bytes + pos + 1;
}
@@ -138,13 +140,13 @@ size_t vterm_input_write(VTerm *vt, const char *bytes, size_t len)
}
else if(c == 0x1b) { // ESC
vt->parser.intermedlen = 0;
if(vt->parser.state < OSC)
if(!IS_STRING_STATE())
vt->parser.state = NORMAL;
vt->parser.in_esc = TRUE;
continue;
}
else if(c == 0x07 && // BEL, can stand for ST in OSC or DCS state
vt->parser.state >= OSC) {
IS_STRING_STATE()) {
// fallthrough
}
else if(c < 0x20) { // other C0
@@ -155,10 +157,10 @@ size_t vterm_input_write(VTerm *vt, const char *bytes, size_t len)
if(pos + 2 < len && bytes[pos + 1] == 0x20 && bytes[pos + 2] == 0x08)
vt->in_backspace = 2; // Trigger when count down to 1
}
if(vt->parser.state >= OSC)
if(IS_STRING_STATE())
string_fragment(vt, string_start, bytes + pos - string_start, FALSE);
do_control(vt, c);
if(vt->parser.state >= OSC)
if(IS_STRING_STATE())
string_start = bytes + pos + 1;
continue;
}
@@ -171,7 +173,7 @@ size_t vterm_input_write(VTerm *vt, const char *bytes, size_t len)
// Always accept ESC \ == ST even in string mode
if(!vt->parser.intermedlen &&
c >= 0x40 && c < 0x60 &&
((vt->parser.state < OSC || c == 0x5c))) {
((!IS_STRING_STATE() || c == 0x5c))) {
c += 0x40;
c1_allowed = TRUE;
string_len -= 1;
@@ -260,6 +262,7 @@ size_t vterm_input_write(VTerm *vt, const char *bytes, size_t len)
/* else fallthrough */
string_start = bytes + pos;
string_len = 0;
vt->parser.state = OSC;
goto string_state;
@@ -312,6 +315,7 @@ string_state:
case 0x9d: // OSC
vt->parser.v.osc.command = -1;
vt->parser.string_initial = TRUE;
string_start = bytes + pos + 1;
ENTER_STATE(OSC_COMMAND);
break;
default:

View File

@@ -2,26 +2,34 @@
#include <stdio.h>
static const VTermColor ansi_colors[] = {
// R G B index
{ 0, 0, 0, 1 }, // black
{ 224, 0, 0, 2 }, // red
{ 0, 224, 0, 3 }, // green
{ 224, 224, 0, 4 }, // yellow
{ 0, 0, 224, 5 }, // blue
{ 224, 0, 224, 6 }, // magenta
{ 0, 224, 224, 7 }, // cyan
{ 224, 224, 224, 8 }, // white == light grey
/**
* Structure used to store RGB triples without the additional metadata stored in
* VTermColor.
*/
typedef struct {
uint8_t red, green, blue;
} VTermRGB;
static const VTermRGB ansi_colors[] = {
// R G B
{ 0, 0, 0 }, // black
{ 224, 0, 0 }, // red
{ 0, 224, 0 }, // green
{ 224, 224, 0 }, // yellow
{ 0, 0, 224 }, // blue
{ 224, 0, 224 }, // magenta
{ 0, 224, 224 }, // cyan
{ 224, 224, 224 }, // white == light grey
// high intensity
{ 128, 128, 128, 9 }, // black
{ 255, 64, 64, 10 }, // red
{ 64, 255, 64, 11 }, // green
{ 255, 255, 64, 12 }, // yellow
{ 64, 64, 255, 13 }, // blue
{ 255, 64, 255, 14 }, // magenta
{ 64, 255, 255, 15 }, // cyan
{ 255, 255, 255, 16 }, // white for real
{ 128, 128, 128 }, // black
{ 255, 64, 64 }, // red
{ 64, 255, 64 }, // green
{ 255, 255, 64 }, // yellow
{ 64, 64, 255 }, // blue
{ 255, 64, 255 }, // magenta
{ 64, 255, 255 }, // cyan
{ 255, 255, 255 }, // white for real
};
static int ramp6[] = {
@@ -34,6 +42,15 @@ static int ramp24[] = {
0x81, 0x8A, 0x94, 0x9E, 0xA8, 0xB2, 0xBC, 0xC6, 0xD0, 0xDA, 0xE4, 0xEE,
};
static void lookup_default_colour_ansi(long idx, VTermColor *col)
{
vterm_color_rgb(
col,
ansi_colors[idx].red, ansi_colors[idx].green, ansi_colors[idx].blue);
col->index = idx;
col->type = VTERM_COLOR_INDEXED;
}
static int lookup_colour_ansi(const VTermState *state, long index, VTermColor *col)
{
if(index >= 0 && index < 16) {
@@ -54,10 +71,9 @@ static int lookup_colour_palette(const VTermState *state, long index, VTermColor
// 216-colour cube
index -= 16;
col->blue = ramp6[index % 6];
col->green = ramp6[index/6 % 6];
col->red = ramp6[index/6/6 % 6];
col->ansi_index = VTERM_ANSI_INDEX_NONE;
vterm_color_rgb(col, ramp6[index/6/6 % 6],
ramp6[index/6 % 6],
ramp6[index % 6]);
return TRUE;
}
@@ -65,10 +81,7 @@ static int lookup_colour_palette(const VTermState *state, long index, VTermColor
// 24 greyscales
index -= 232;
col->blue = ramp24[index];
col->green = ramp24[index];
col->red = ramp24[index];
col->ansi_index = VTERM_ANSI_INDEX_NONE;
vterm_color_rgb(col, ramp24[index], ramp24[index], ramp24[index]);
return TRUE;
}
@@ -76,25 +89,23 @@ static int lookup_colour_palette(const VTermState *state, long index, VTermColor
return FALSE;
}
static int lookup_colour(const VTermState *state, int palette, const long args[], int argcount, VTermColor *col, int *index)
static int lookup_colour(const VTermState *state, int palette, const long args[], int argcount, VTermColor *col)
{
switch(palette) {
case 2: // RGB mode - 3 args contain colour values directly
if(argcount < 3)
return argcount;
col->red = (uint8_t)CSI_ARG(args[0]);
col->green = (uint8_t)CSI_ARG(args[1]);
col->blue = (uint8_t)CSI_ARG(args[2]);
col->ansi_index = VTERM_ANSI_INDEX_NONE;
vterm_color_rgb(col, CSI_ARG(args[0]), CSI_ARG(args[1]), CSI_ARG(args[2]));
return 3;
case 5: // XTerm 256-colour mode
if(index)
*index = CSI_ARG_OR(args[0], -1);
if (!argcount || CSI_ARG_IS_MISSING(args[0])) {
return argcount ? 1 : 0;
}
lookup_colour_palette(state, argcount ? CSI_ARG_OR(args[0], -1) : -1, col);
lookup_colour_palette(state, args[0], col);
return argcount ? 1 : 0;
@@ -154,13 +165,12 @@ INTERNAL void vterm_state_newpen(VTermState *state)
int col;
// 90% grey so that pure white is brighter
state->default_fg.red = state->default_fg.green = state->default_fg.blue = 240;
state->default_fg.ansi_index = VTERM_ANSI_INDEX_DEFAULT;
state->default_bg.red = state->default_bg.green = state->default_bg.blue = 0;
state->default_bg.ansi_index = VTERM_ANSI_INDEX_DEFAULT;
vterm_color_rgb(&state->default_fg, 240, 240, 240);
vterm_color_rgb(&state->default_bg, 0, 0, 0);
vterm_state_set_default_colors(state, &state->default_fg, &state->default_bg);
for(col = 0; col < 16; col++)
state->colors[col] = ansi_colors[col];
lookup_default_colour_ansi(col, &state->colors[col]);
}
INTERNAL void vterm_state_resetpen(VTermState *state)
@@ -170,11 +180,10 @@ INTERNAL void vterm_state_resetpen(VTermState *state)
state->pen.italic = 0; setpenattr_bool(state, VTERM_ATTR_ITALIC, 0);
state->pen.blink = 0; setpenattr_bool(state, VTERM_ATTR_BLINK, 0);
state->pen.reverse = 0; setpenattr_bool(state, VTERM_ATTR_REVERSE, 0);
state->pen.conceal = 0; setpenattr_bool(state, VTERM_ATTR_CONCEAL, 0);
state->pen.strike = 0; setpenattr_bool(state, VTERM_ATTR_STRIKE, 0);
state->pen.font = 0; setpenattr_int( state, VTERM_ATTR_FONT, 0);
state->fg_index = -1;
state->bg_index = -1;
state->pen.fg = state->default_fg; setpenattr_col(state, VTERM_ATTR_FOREGROUND, state->default_fg);
state->pen.bg = state->default_bg; setpenattr_col(state, VTERM_ATTR_BACKGROUND, state->default_bg);
}
@@ -192,6 +201,7 @@ INTERNAL void vterm_state_savepen(VTermState *state, int save)
setpenattr_bool(state, VTERM_ATTR_ITALIC, state->pen.italic);
setpenattr_bool(state, VTERM_ATTR_BLINK, state->pen.blink);
setpenattr_bool(state, VTERM_ATTR_REVERSE, state->pen.reverse);
setpenattr_bool(state, VTERM_ATTR_CONCEAL, state->pen.conceal);
setpenattr_bool(state, VTERM_ATTR_STRIKE, state->pen.strike);
setpenattr_int( state, VTERM_ATTR_FONT, state->pen.font);
setpenattr_col( state, VTERM_ATTR_FOREGROUND, state->pen.fg);
@@ -199,6 +209,40 @@ INTERNAL void vterm_state_savepen(VTermState *state, int save)
}
}
void vterm_color_rgb(VTermColor *col, uint8_t red, uint8_t green, uint8_t blue)
{
col->type = VTERM_COLOR_RGB;
col->red = red;
col->green = green;
col->blue = blue;
}
void vterm_color_indexed(VTermColor *col, uint8_t idx)
{
col->type = VTERM_COLOR_INDEXED;
col->index = idx;
}
int vterm_color_is_equal(const VTermColor *a, const VTermColor *b)
{
/* First make sure that the two colours are of the same type (RGB/Indexed) */
if (a->type != b->type) {
return FALSE;
}
/* Depending on the type inspect the corresponding members */
if (VTERM_COLOR_IS_INDEXED(a)) {
return a->index == b->index;
}
else if (VTERM_COLOR_IS_RGB(a)) {
return (a->red == b->red)
&& (a->green == b->green)
&& (a->blue == b->blue);
}
return 0;
}
void vterm_state_get_default_colors(const VTermState *state, VTermColor *default_fg, VTermColor *default_bg)
{
*default_fg = state->default_fg;
@@ -212,8 +256,15 @@ void vterm_state_get_palette_color(const VTermState *state, int index, VTermColo
void vterm_state_set_default_colors(VTermState *state, const VTermColor *default_fg, const VTermColor *default_bg)
{
/* Copy the given colors */
state->default_fg = *default_fg;
state->default_bg = *default_bg;
/* Make sure the correct type flags are set */
state->default_fg.type = (state->default_fg.type & ~VTERM_COLOR_DEFAULT_MASK)
| VTERM_COLOR_DEFAULT_FG;
state->default_bg.type = (state->default_bg.type & ~VTERM_COLOR_DEFAULT_MASK)
| VTERM_COLOR_DEFAULT_BG;
}
void vterm_state_set_palette_color(VTermState *state, int index, const VTermColor *col)
@@ -221,10 +272,18 @@ void vterm_state_set_palette_color(VTermState *state, int index, const VTermColo
if(index >= 0 && index < 16)
{
state->colors[index] = *col;
state->colors[index].ansi_index = index + VTERM_ANSI_INDEX_MIN;
state->colors[index].index = index + 1;
}
}
void vterm_state_convert_color_to_rgb(const VTermState *state, VTermColor *col)
{
if (VTERM_COLOR_IS_INDEXED(col)) { /* Convert indexed colors to RGB */
lookup_colour_palette(state, col->index, col);
}
col->type &= VTERM_COLOR_TYPE_MASK; /* Reset any metadata but the type */
}
void vterm_state_set_bold_highbright(VTermState *state, int bold_is_highbright)
{
state->bold_is_highbright = bold_is_highbright;
@@ -249,12 +308,14 @@ INTERNAL void vterm_state_setpen(VTermState *state, const long args[], int argco
vterm_state_resetpen(state);
break;
case 1: // Bold on
case 1: { // Bold on
const VTermColor *fg = &state->pen.fg;
state->pen.bold = 1;
setpenattr_bool(state, VTERM_ATTR_BOLD, 1);
if(state->fg_index > -1 && state->fg_index < 8 && state->bold_is_highbright)
set_pen_col_ansi(state, VTERM_ATTR_FOREGROUND, state->fg_index + (state->pen.bold ? 8 : 0));
if(!VTERM_COLOR_IS_DEFAULT_FG(fg) && VTERM_COLOR_IS_INDEXED(fg) && fg->index < 8 && state->bold_is_highbright)
set_pen_col_ansi(state, VTERM_ATTR_FOREGROUND, fg->index + (state->pen.bold ? 8 : 0));
break;
}
case 3: // Italic on
state->pen.italic = 1;
@@ -293,6 +354,11 @@ INTERNAL void vterm_state_setpen(VTermState *state, const long args[], int argco
setpenattr_bool(state, VTERM_ATTR_REVERSE, 1);
break;
case 8: // Conceal on
state->pen.conceal = 1;
setpenattr_bool(state, VTERM_ATTR_CONCEAL, 1);
break;
case 9: // Strikethrough on
state->pen.strike = 1;
setpenattr_bool(state, VTERM_ATTR_STRIKE, 1);
@@ -334,6 +400,11 @@ INTERNAL void vterm_state_setpen(VTermState *state, const long args[], int argco
setpenattr_bool(state, VTERM_ATTR_REVERSE, 0);
break;
case 28: // Conceal off (Reveal)
state->pen.conceal = 0;
setpenattr_bool(state, VTERM_ATTR_CONCEAL, 0);
break;
case 29: // Strikethrough off
state->pen.strike = 0;
setpenattr_bool(state, VTERM_ATTR_STRIKE, 0);
@@ -342,22 +413,19 @@ INTERNAL void vterm_state_setpen(VTermState *state, const long args[], int argco
case 30: case 31: case 32: case 33:
case 34: case 35: case 36: case 37: // Foreground colour palette
value = CSI_ARG(args[argi]) - 30;
state->fg_index = value;
if(state->pen.bold && state->bold_is_highbright)
value += 8;
set_pen_col_ansi(state, VTERM_ATTR_FOREGROUND, value);
break;
case 38: // Foreground colour alternative palette
state->fg_index = -1;
if(argcount - argi < 1)
return;
argi += 1 + lookup_colour(state, CSI_ARG(args[argi+1]), args+argi+2, argcount-argi-2, &state->pen.fg, &state->fg_index);
argi += 1 + lookup_colour(state, CSI_ARG(args[argi+1]), args+argi+2, argcount-argi-2, &state->pen.fg);
setpenattr_col(state, VTERM_ATTR_FOREGROUND, state->pen.fg);
break;
case 39: // Foreground colour default
state->fg_index = -1;
state->pen.fg = state->default_fg;
setpenattr_col(state, VTERM_ATTR_FOREGROUND, state->pen.fg);
break;
@@ -365,20 +433,17 @@ INTERNAL void vterm_state_setpen(VTermState *state, const long args[], int argco
case 40: case 41: case 42: case 43:
case 44: case 45: case 46: case 47: // Background colour palette
value = CSI_ARG(args[argi]) - 40;
state->bg_index = value;
set_pen_col_ansi(state, VTERM_ATTR_BACKGROUND, value);
break;
case 48: // Background colour alternative palette
state->bg_index = -1;
if(argcount - argi < 1)
return;
argi += 1 + lookup_colour(state, CSI_ARG(args[argi+1]), args+argi+2, argcount-argi-2, &state->pen.bg, &state->bg_index);
argi += 1 + lookup_colour(state, CSI_ARG(args[argi+1]), args+argi+2, argcount-argi-2, &state->pen.bg);
setpenattr_col(state, VTERM_ATTR_BACKGROUND, state->pen.bg);
break;
case 49: // Default background
state->bg_index = -1;
state->pen.bg = state->default_bg;
setpenattr_col(state, VTERM_ATTR_BACKGROUND, state->pen.bg);
break;
@@ -386,14 +451,12 @@ INTERNAL void vterm_state_setpen(VTermState *state, const long args[], int argco
case 90: case 91: case 92: case 93:
case 94: case 95: case 96: case 97: // Foreground colour high-intensity palette
value = CSI_ARG(args[argi]) - 90 + 8;
state->fg_index = value;
set_pen_col_ansi(state, VTERM_ATTR_FOREGROUND, value);
break;
case 100: case 101: case 102: case 103:
case 104: case 105: case 106: case 107: // Background colour high-intensity palette
value = CSI_ARG(args[argi]) - 100 + 8;
state->bg_index = value;
set_pen_col_ansi(state, VTERM_ATTR_BACKGROUND, value);
break;
@@ -412,6 +475,39 @@ INTERNAL void vterm_state_setpen(VTermState *state, const long args[], int argco
}
}
static int vterm_state_getpen_color(const VTermColor *col, int argi, long args[], int fg)
{
/* Do nothing if the given color is the default color */
if (( fg && VTERM_COLOR_IS_DEFAULT_FG(col)) ||
(!fg && VTERM_COLOR_IS_DEFAULT_BG(col))) {
return argi;
}
/* Decide whether to send an indexed color or an RGB color */
if (VTERM_COLOR_IS_INDEXED(col)) {
const uint8_t idx = col->index;
if (idx < 8) {
args[argi++] = (idx + (fg ? 30 : 40));
}
else if (idx < 16) {
args[argi++] = (idx - 8 + (fg ? 90 : 100));
}
else {
args[argi++] = CSI_ARG_FLAG_MORE | (fg ? 38 : 48);
args[argi++] = CSI_ARG_FLAG_MORE | 5;
args[argi++] = idx;
}
}
else if (VTERM_COLOR_IS_RGB(col)) {
args[argi++] = CSI_ARG_FLAG_MORE | (fg ? 38 : 48);
args[argi++] = CSI_ARG_FLAG_MORE | 2;
args[argi++] = CSI_ARG_FLAG_MORE | col->red;
args[argi++] = CSI_ARG_FLAG_MORE | col->green;
args[argi++] = col->blue;
}
return argi;
}
INTERNAL int vterm_state_getpen(VTermState *state, long args[], int argcount UNUSED)
{
int argi = 0;
@@ -433,6 +529,9 @@ INTERNAL int vterm_state_getpen(VTermState *state, long args[], int argcount UNU
if(state->pen.reverse)
args[argi++] = 7;
if(state->pen.conceal)
args[argi++] = 8;
if(state->pen.strike)
args[argi++] = 9;
@@ -442,49 +541,9 @@ INTERNAL int vterm_state_getpen(VTermState *state, long args[], int argcount UNU
if(state->pen.underline == VTERM_UNDERLINE_DOUBLE)
args[argi++] = 21;
if(state->fg_index >= 0 && state->fg_index < 8)
args[argi++] = 30 + state->fg_index;
else if(state->fg_index >= 8 && state->fg_index < 16)
args[argi++] = 90 + state->fg_index - 8;
else if(state->fg_index >= 16 && state->fg_index < 256) {
args[argi++] = CSI_ARG_FLAG_MORE|38;
args[argi++] = CSI_ARG_FLAG_MORE|5;
args[argi++] = state->fg_index;
}
else if(state->fg_index == -1) {
// Send palette 2 if the actual FG colour is not default
if(state->pen.fg.red != state->default_fg.red ||
state->pen.fg.green != state->default_fg.green ||
state->pen.fg.blue != state->default_fg.blue ) {
args[argi++] = CSI_ARG_FLAG_MORE|38;
args[argi++] = CSI_ARG_FLAG_MORE|2;
args[argi++] = CSI_ARG_FLAG_MORE | state->pen.fg.red;
args[argi++] = CSI_ARG_FLAG_MORE | state->pen.fg.green;
args[argi++] = state->pen.fg.blue;
}
}
argi = vterm_state_getpen_color(&state->pen.fg, argi, args, TRUE);
if(state->bg_index >= 0 && state->bg_index < 8)
args[argi++] = 40 + state->bg_index;
else if(state->bg_index >= 8 && state->bg_index < 16)
args[argi++] = 100 + state->bg_index - 8;
else if(state->bg_index >= 16 && state->bg_index < 256) {
args[argi++] = CSI_ARG_FLAG_MORE|48;
args[argi++] = CSI_ARG_FLAG_MORE|5;
args[argi++] = state->bg_index;
}
else if(state->bg_index == -1) {
// Send palette 2 if the actual BG colour is not default
if(state->pen.bg.red != state->default_bg.red ||
state->pen.bg.green != state->default_bg.green ||
state->pen.bg.blue != state->default_bg.blue ) {
args[argi++] = CSI_ARG_FLAG_MORE|48;
args[argi++] = CSI_ARG_FLAG_MORE|2;
args[argi++] = CSI_ARG_FLAG_MORE | state->pen.bg.red;
args[argi++] = CSI_ARG_FLAG_MORE | state->pen.bg.green;
args[argi++] = state->pen.bg.blue;
}
}
argi = vterm_state_getpen_color(&state->pen.bg, argi, args, FALSE);
return argi;
}
@@ -512,6 +571,10 @@ int vterm_state_get_penattr(const VTermState *state, VTermAttr attr, VTermValue
val->boolean = state->pen.reverse;
return 1;
case VTERM_ATTR_CONCEAL:
val->boolean = state->pen.conceal;
return 1;
case VTERM_ATTR_STRIKE:
val->boolean = state->pen.strike;
return 1;

View File

@@ -21,6 +21,7 @@ typedef struct
unsigned int italic : 1;
unsigned int blink : 1;
unsigned int reverse : 1;
unsigned int conceal : 1;
unsigned int strike : 1;
unsigned int font : 4; // 0 to 9
@@ -420,6 +421,9 @@ static int setpenattr(VTermAttr attr, VTermValue *val, void *user)
case VTERM_ATTR_REVERSE:
screen->pen.reverse = val->boolean;
return 1;
case VTERM_ATTR_CONCEAL:
screen->pen.conceal = val->boolean;
return 1;
case VTERM_ATTR_STRIKE:
screen->pen.strike = val->boolean;
return 1;
@@ -544,6 +548,7 @@ static void resize_buffer(VTermScreen *screen, int bufidx, int new_rows, int new
dst->pen.italic = src->attrs.italic;
dst->pen.blink = src->attrs.blink;
dst->pen.reverse = src->attrs.reverse ^ screen->global_reverse;
dst->pen.conceal = src->attrs.conceal;
dst->pen.strike = src->attrs.strike;
dst->pen.font = src->attrs.font;
@@ -553,6 +558,8 @@ static void resize_buffer(VTermScreen *screen, int bufidx, int new_rows, int new
if(src->width == 2 && pos.col < (new_cols-1))
(dst + 1)->chars[0] = (uint32_t) -1;
}
for( ; pos.col < new_cols; pos.col++)
clearcell(screen, &new_buffer[pos.row * new_cols + pos.col]);
new_row--;
if(active)
@@ -815,6 +822,7 @@ int vterm_screen_get_cell(const VTermScreen *screen, VTermPos pos, VTermScreenCe
cell->attrs.italic = intcell->pen.italic;
cell->attrs.blink = intcell->pen.blink;
cell->attrs.reverse = intcell->pen.reverse ^ screen->global_reverse;
cell->attrs.conceal = intcell->pen.conceal;
cell->attrs.strike = intcell->pen.strike;
cell->attrs.font = intcell->pen.font;
@@ -890,7 +898,7 @@ void *vterm_screen_get_cbdata(VTermScreen *screen)
return screen->cbdata;
}
void vterm_screen_set_unrecognised_fallbacks(VTermScreen *screen, const VTermParserCallbacks *fallbacks, void *user)
void vterm_screen_set_unrecognised_fallbacks(VTermScreen *screen, const VTermStateFallbacks *fallbacks, void *user)
{
vterm_state_set_unrecognised_fallbacks(screen->state, fallbacks, user);
}
@@ -935,13 +943,15 @@ static int attrs_differ(VTermAttrMask attrs, ScreenCell *a, ScreenCell *b)
return 1;
if((attrs & VTERM_ATTR_REVERSE_MASK) && (a->pen.reverse != b->pen.reverse))
return 1;
if((attrs & VTERM_ATTR_CONCEAL_MASK) && (a->pen.conceal != b->pen.conceal))
return 1;
if((attrs & VTERM_ATTR_STRIKE_MASK) && (a->pen.strike != b->pen.strike))
return 1;
if((attrs & VTERM_ATTR_FONT_MASK) && (a->pen.font != b->pen.font))
return 1;
if((attrs & VTERM_ATTR_FOREGROUND_MASK) && !vterm_color_equal(a->pen.fg, b->pen.fg))
if((attrs & VTERM_ATTR_FOREGROUND_MASK) && !vterm_color_is_equal(&a->pen.fg, &b->pen.fg))
return 1;
if((attrs & VTERM_ATTR_BACKGROUND_MASK) && !vterm_color_equal(a->pen.bg, b->pen.bg))
if((attrs & VTERM_ATTR_BACKGROUND_MASK) && !vterm_color_is_equal(&a->pen.bg, &b->pen.bg))
return 1;
return 0;
@@ -974,3 +984,8 @@ int vterm_screen_get_attrs_extent(const VTermScreen *screen, VTermRect *extent,
return 1;
}
void vterm_screen_convert_color_to_rgb(const VTermScreen *screen, VTermColor *col)
{
vterm_state_convert_color_to_rgb(screen->state, col);
}

View File

@@ -1478,6 +1478,14 @@ static int on_csi(const char *leader, const long args[], int argcount, const cha
state->scrollregion_bottom = -1;
}
// Setting the scrolling region restores the cursor to the home position
state->pos.row = 0;
state->pos.col = 0;
if(state->mode.origin) {
state->pos.row += state->scrollregion_top;
state->pos.col += SCROLLREGION_LEFT(state);
}
break;
case 0x73: // DECSLRM - DEC custom
@@ -1499,6 +1507,14 @@ static int on_csi(const char *leader, const long args[], int argcount, const cha
state->scrollregion_right = -1;
}
// Setting the scrolling region restores the cursor to the home position
state->pos.row = 0;
state->pos.col = 0;
if(state->mode.origin) {
state->pos.row += state->scrollregion_top;
state->pos.col += SCROLLREGION_LEFT(state);
}
break;
case 0x74:
@@ -1664,8 +1680,6 @@ static void request_status_string(VTermState *state, VTermStringFragment frag)
if(!frag.final)
return;
fprintf(stderr, "DECRQSS on <%s>\n", tmp);
switch(tmp[0] | tmp[1]<<8 | tmp[2]<<16) {
case 'm': {
// Query SGR
@@ -1674,13 +1688,13 @@ static void request_status_string(VTermState *state, VTermStringFragment frag)
size_t cur = 0;
int argi;
cur += snprintf(vt->tmpbuffer + cur, vt->tmpbuffer_len - cur,
cur += SNPRINTF(vt->tmpbuffer + cur, vt->tmpbuffer_len - cur,
vt->mode.ctrl8bit ? "\x90" "1$r" : ESC_S "P" "1$r"); // DCS 1$r ...
if(cur >= vt->tmpbuffer_len)
return;
for(argi = 0; argi < argc; argi++) {
cur += snprintf(vt->tmpbuffer + cur, vt->tmpbuffer_len - cur,
cur += SNPRINTF(vt->tmpbuffer + cur, vt->tmpbuffer_len - cur,
argi == argc - 1 ? "%ld" :
CSI_ARG_HAS_MORE(args[argi]) ? "%ld:" :
"%ld;",
@@ -1689,7 +1703,7 @@ static void request_status_string(VTermState *state, VTermStringFragment frag)
return;
}
cur += snprintf(vt->tmpbuffer + cur, vt->tmpbuffer_len - cur,
cur += SNPRINTF(vt->tmpbuffer + cur, vt->tmpbuffer_len - cur,
vt->mode.ctrl8bit ? "m" "\x9C" : "m" ESC_S "\\"); // ... m ST
if(cur >= vt->tmpbuffer_len)
return;
@@ -1979,7 +1993,7 @@ void *vterm_state_get_cbdata(VTermState *state)
return state->cbdata;
}
void vterm_state_set_unrecognised_fallbacks(VTermState *state, const VTermParserCallbacks *fallbacks, void *user)
void vterm_state_set_unrecognised_fallbacks(VTermState *state, const VTermStateFallbacks *fallbacks, void *user)
{
if(fallbacks) {
state->fallbacks = fallbacks;

View File

@@ -261,6 +261,7 @@ VTermValueType vterm_get_attr_type(VTermAttr attr)
case VTERM_ATTR_ITALIC: return VTERM_VALUETYPE_BOOL;
case VTERM_ATTR_BLINK: return VTERM_VALUETYPE_BOOL;
case VTERM_ATTR_REVERSE: return VTERM_VALUETYPE_BOOL;
case VTERM_ATTR_CONCEAL: return VTERM_VALUETYPE_BOOL;
case VTERM_ATTR_STRIKE: return VTERM_VALUETYPE_BOOL;
case VTERM_ATTR_FONT: return VTERM_VALUETYPE_INT;
case VTERM_ATTR_FOREGROUND: return VTERM_VALUETYPE_COLOR;

View File

@@ -53,19 +53,11 @@ struct VTermPen
unsigned int italic:1;
unsigned int blink:1;
unsigned int reverse:1;
unsigned int conceal:1;
unsigned int strike:1;
unsigned int font:4; // To store 0-9
};
int vterm_color_equal(VTermColor a, VTermColor b);
#if defined(DEFINE_INLINES) || USE_INLINE
INLINE int vterm_color_equal(VTermColor a, VTermColor b)
{
return a.red == b.red && a.green == b.green && a.blue == b.blue;
}
#endif
struct VTermState
{
VTerm *vt;
@@ -73,7 +65,7 @@ struct VTermState
const VTermStateCallbacks *callbacks;
void *cbdata;
const VTermParserCallbacks *fallbacks;
const VTermStateFallbacks *fallbacks;
void *fbdata;
int rows;
@@ -143,8 +135,6 @@ struct VTermState
VTermColor default_bg;
VTermColor colors[16]; // Store the 8 ANSI and the 8 ANSI high-brights only
int fg_index;
int bg_index;
int bold_is_highbright;
unsigned int protected_cell : 1;
@@ -186,9 +176,9 @@ struct VTerm
CSI_LEADER,
CSI_ARGS,
CSI_INTERMED,
OSC_COMMAND,
DCS_COMMAND,
// below here are the "string states"
/* below here are the "string states" */
OSC_COMMAND,
OSC,
DCS,
} state;

View File

@@ -150,6 +150,14 @@ PUSH "def"
PUSH "ghi\e\\"
osc "ghi"]
!OSC BEL without semicolon
PUSH "\e]1234\x07"
osc [1234 ]
!OSC ST without semicolon
PUSH "\e]1234\e\\"
osc [1234 ]
!Escape cancels OSC, starts Escape
PUSH "\e]Something\e9"
escape "9"

View File

@@ -40,8 +40,8 @@ PUSH "\n"
?cursor = 20,0
!Index in DECSTBM
PUSH "\e[10H"
PUSH "\e[9;10r"
PUSH "\e[10H"
PUSH "\eM"
?cursor = 8,0
PUSH "\eM"
@@ -148,3 +148,9 @@ PUSH "\e[2T"
moverect 0..23,0..80 -> 2..25,0..80
erase 0..2,0..80
?cursor = 0,0
!DECSTBM resets cursor position
PUSH "\e[5;5H"
?cursor = 4,4
PUSH "\e[r"
?cursor = 0,0

View File

@@ -41,10 +41,10 @@ PUSH "\e[0;93;104m"
PUSH "\eP\$qm\e\\"
output "\eP1\$r93;104m\e\\"
!DECRQSS on SGR 256-palette colours
PUSH "\e[0;38:5:56;48:5:78m"
PUSH "\eP\$qm\e\\"
output "\eP1\$r38:5:56;48:5:78m\e\\"
##!DECRQSS on SGR 256-palette colours
#PUSH "\e[0;38:5:56;48:5:78m"
#PUSH "\eP\$qm\e\\"
# output "\eP1\$r38:5:56;48:5:78m\e\\"
!DECRQSS on SGR RGB8 colours
PUSH "\e[0;38:2:24:68:112;48:2:13:57:101m"

View File

@@ -10,8 +10,8 @@ PUSH "\e[m"
?pen blink = off
?pen reverse = off
?pen font = 0
?pen foreground = rgb(240,240,240)
?pen background = rgb(0,0,0)
?pen foreground = rgb(240,240,240,is_default_fg)
?pen background = rgb(0,0,0,is_default_bg)
!Bold
PUSH "\e[1m"
@@ -75,40 +75,40 @@ PUSH "\e[11m\e[m"
!Foreground
PUSH "\e[31m"
?pen foreground = rgb(224,0,0)
?pen foreground = idx(1)
PUSH "\e[32m"
?pen foreground = rgb(0,224,0)
?pen foreground = idx(2)
PUSH "\e[34m"
?pen foreground = rgb(0,0,224)
?pen foreground = idx(4)
PUSH "\e[91m"
?pen foreground = rgb(255,64,64)
?pen foreground = idx(9)
PUSH "\e[38:2:10:20:30m"
?pen foreground = rgb(10,20,30)
PUSH "\e[38:5:1m"
?pen foreground = rgb(224,0,0)
?pen foreground = idx(1)
PUSH "\e[39m"
?pen foreground = rgb(240,240,240)
?pen foreground = rgb(240,240,240,is_default_fg)
!Background
PUSH "\e[41m"
?pen background = rgb(224,0,0)
?pen background = idx(1)
PUSH "\e[42m"
?pen background = rgb(0,224,0)
?pen background = idx(2)
PUSH "\e[44m"
?pen background = rgb(0,0,224)
?pen background = idx(4)
PUSH "\e[101m"
?pen background = rgb(255,64,64)
?pen background = idx(9)
PUSH "\e[48:2:10:20:30m"
?pen background = rgb(10,20,30)
PUSH "\e[48:5:1m"
?pen background = rgb(224,0,0)
?pen background = idx(1)
PUSH "\e[49m"
?pen background = rgb(0,0,0)
?pen background = rgb(0,0,0,is_default_bg)
!Bold+ANSI colour == highbright
PUSH "\e[m\e[1;37m"
?pen bold = on
?pen foreground = rgb(255,255,255)
?pen foreground = idx(15)
PUSH "\e[m\e[37;1m"
?pen bold = on
?pen foreground = rgb(255,255,255)
?pen foreground = idx(15)

View File

@@ -29,27 +29,27 @@ PUSH "\e[11mF\e[m"
!Foreground
PUSH "\e[31mG\e[m"
?screen_cell 0,6 = {0x47} width=1 attrs={} fg=rgb(224,0,0) bg=rgb(0,0,0)
?screen_cell 0,6 = {0x47} width=1 attrs={} fg=idx(1) bg=rgb(0,0,0)
!Background
PUSH "\e[42mH\e[m"
?screen_cell 0,7 = {0x48} width=1 attrs={} fg=rgb(240,240,240) bg=rgb(0,224,0)
?screen_cell 0,7 = {0x48} width=1 attrs={} fg=rgb(240,240,240) bg=idx(2)
!EL sets reverse and colours to end of line
PUSH "\e[H\e[7;33;44m\e[K"
?screen_cell 0,0 = {} width=1 attrs={R} fg=rgb(224,224,0) bg=rgb(0,0,224)
?screen_cell 0,79 = {} width=1 attrs={R} fg=rgb(224,224,0) bg=rgb(0,0,224)
?screen_cell 0,0 = {} width=1 attrs={R} fg=idx(3) bg=idx(4)
?screen_cell 0,79 = {} width=1 attrs={R} fg=idx(3) bg=idx(4)
!DECSCNM xors reverse for entire screen
PUSH "\e[?5h"
?screen_cell 0,0 = {} width=1 attrs={} fg=rgb(224,224,0) bg=rgb(0,0,224)
?screen_cell 0,79 = {} width=1 attrs={} fg=rgb(224,224,0) bg=rgb(0,0,224)
?screen_cell 0,0 = {} width=1 attrs={} fg=idx(3) bg=idx(4)
?screen_cell 0,79 = {} width=1 attrs={} fg=idx(3) bg=idx(4)
?screen_cell 1,0 = {} width=1 attrs={R} fg=rgb(240,240,240) bg=rgb(0,0,0)
PUSH "\e[?5\$p"
output "\e[?5;1\$y"
PUSH "\e[?5l"
?screen_cell 0,0 = {} width=1 attrs={R} fg=rgb(224,224,0) bg=rgb(0,0,224)
?screen_cell 0,79 = {} width=1 attrs={R} fg=rgb(224,224,0) bg=rgb(0,0,224)
?screen_cell 0,0 = {} width=1 attrs={R} fg=idx(3) bg=idx(4)
?screen_cell 0,79 = {} width=1 attrs={R} fg=idx(3) bg=idx(4)
?screen_cell 1,0 = {} width=1 attrs={} fg=rgb(240,240,240) bg=rgb(0,0,0)
PUSH "\e[?5\$p"
output "\e[?5;2\$y"

View File

@@ -60,6 +60,26 @@ static VTermKey strp_key(char *str)
return VTERM_KEY_NONE;
}
static void print_color(const VTermColor *col)
{
if (VTERM_COLOR_IS_RGB(col)) {
printf("rgb(%d,%d,%d", col->red, col->green, col->blue);
}
else if (VTERM_COLOR_IS_INDEXED(col)) {
printf("idx(%d", col->index);
}
else {
printf("invalid(%d", col->type);
}
if (VTERM_COLOR_IS_DEFAULT_FG(col)) {
printf(",is_default_fg");
}
if (VTERM_COLOR_IS_DEFAULT_BG(col)) {
printf(",is_default_bg");
}
printf(")");
}
static VTerm *vt;
static VTermState *state;
static VTermScreen *screen;
@@ -206,7 +226,14 @@ static VTermParserCallbacks parser_cbs = {
NULL // resize
};
// These callbacks are shared by State and Screen
static VTermStateFallbacks fallbacks = {
parser_control, // control
parser_csi, // csi
parser_osc, // osc
parser_dcs // dcs
};
/* These callbacks are shared by State and Screen */
static int want_movecursor = 0;
static VTermPos state_pos;
@@ -266,7 +293,9 @@ static int settermprop(VTermProp prop, VTermValue *val, void *user UNUSED)
val->string.initial ? "[" : "", val->string.len, val->string.str, val->string.final ? "]" : "");
return 1;
case VTERM_VALUETYPE_COLOR:
printf("settermprop %d rgb(%d,%d,%d)\n", prop, val->color.red, val->color.green, val->color.blue);
printf("settermprop %d ", prop);
print_color(&val->color);
printf("\n");
return 1;
case VTERM_N_VALUETYPES:
@@ -319,6 +348,7 @@ static struct {
int italic;
int blink;
int reverse;
int conceal;
int strike;
int font;
VTermColor foreground;
@@ -342,6 +372,9 @@ static int state_setpenattr(VTermAttr attr, VTermValue *val, void *user UNUSED)
case VTERM_ATTR_REVERSE:
state_pen.reverse = val->boolean;
break;
case VTERM_ATTR_CONCEAL:
state_pen.conceal = val->boolean;
break;
case VTERM_ATTR_STRIKE:
state_pen.strike = val->boolean;
break;
@@ -552,7 +585,7 @@ int main(int argc UNUSED, char **argv UNUSED)
want_settermprop = sense;
break;
case 'f':
vterm_state_set_unrecognised_fallbacks(state, sense ? &parser_cbs : NULL, NULL);
vterm_state_set_unrecognised_fallbacks(state, sense ? &fallbacks : NULL, NULL);
break;
default:
fprintf(stderr, "Unrecognised WANTSTATE flag '%c'\n", line[i]);
@@ -823,10 +856,12 @@ int main(int argc UNUSED, char **argv UNUSED)
printf("%d\n", state_pen.font);
}
else if(streq(linep, "foreground")) {
printf("rgb(%d,%d,%d)\n", state_pen.foreground.red, state_pen.foreground.green, state_pen.foreground.blue);
print_color(&state_pen.foreground);
printf("\n");
}
else if(streq(linep, "background")) {
printf("rgb(%d,%d,%d)\n", state_pen.background.red, state_pen.background.green, state_pen.background.blue);
print_color(&state_pen.background);
printf("\n");
}
else
printf("?\n");
@@ -941,8 +976,13 @@ int main(int argc UNUSED, char **argv UNUSED)
printf("} ");
if(cell.attrs.dwl) printf("dwl ");
if(cell.attrs.dhl) printf("dhl-%s ", cell.attrs.dhl == 2 ? "bottom" : "top");
printf("fg=rgb(%d,%d,%d) ", cell.fg.red, cell.fg.green, cell.fg.blue);
printf("bg=rgb(%d,%d,%d)\n", cell.bg.red, cell.bg.green, cell.bg.blue);
printf("fg=");
vterm_screen_convert_color_to_rgb(screen, &cell.fg);
print_color(&cell.fg);
printf(" bg=");
vterm_screen_convert_color_to_rgb(screen, &cell.bg);
print_color(&cell.bg);
printf("\n");
}
else if(strstartswith(line, "?screen_eol ")) {
VTermPos pos;

View File

@@ -112,7 +112,7 @@ sub do_line
$initial //= "";
$initial .= ";" if $initial =~ m/\d+/;
$line = "$cmd $initial" . join( "", map sprintf("%02x", $_), unpack "C*", eval($data) ) . "$final";
$line = "$cmd $initial" . join( "", map sprintf("%02x", $_), unpack "C*", length $data ? eval($data) : "" ) . "$final";
}
elsif( $line =~ m/^(escape|dcs) (\[?)(.*?)(\]?)$/ ) {
$line = "$1 $2" . join( "", map sprintf("%02x", $_), unpack "C*", eval($3) ) . "$4";

View File

@@ -6357,12 +6357,6 @@ static int grey_ramp[] = {
0x80, 0x8A, 0x94, 0x9E, 0xA8, 0xB2, 0xBC, 0xC6, 0xD0, 0xDA, 0xE4, 0xEE
};
# ifdef FEAT_TERMINAL
# include "libvterm/include/vterm.h" // for VTERM_ANSI_INDEX_NONE
# else
# define VTERM_ANSI_INDEX_NONE 0
# endif
static char_u ansi_table[16][4] = {
// R G B idx
{ 0, 0, 0, 1}, // black
@@ -6384,6 +6378,8 @@ static char_u ansi_table[16][4] = {
{255, 255, 255, 16}, // white
};
#define ANSI_INDEX_NONE 0
void
cterm_color2rgb(int nr, char_u *r, char_u *g, char_u *b, char_u *ansi_idx)
{
@@ -6403,7 +6399,7 @@ cterm_color2rgb(int nr, char_u *r, char_u *g, char_u *b, char_u *ansi_idx)
*r = cube_value[idx / 36 % 6];
*g = cube_value[idx / 6 % 6];
*b = cube_value[idx % 6];
*ansi_idx = VTERM_ANSI_INDEX_NONE;
*ansi_idx = ANSI_INDEX_NONE;
}
else if (nr < 256)
{
@@ -6412,14 +6408,14 @@ cterm_color2rgb(int nr, char_u *r, char_u *g, char_u *b, char_u *ansi_idx)
*r = grey_ramp[idx];
*g = grey_ramp[idx];
*b = grey_ramp[idx];
*ansi_idx = VTERM_ANSI_INDEX_NONE;
*ansi_idx = ANSI_INDEX_NONE;
}
else
{
*r = 0;
*g = 0;
*b = 0;
*ansi_idx = 0;
*ansi_idx = ANSI_INDEX_NONE;
}
}
#endif

View File

@@ -162,6 +162,7 @@ struct terminal_S {
char_u *tl_cursor_color; // NULL or allocated
int tl_using_altscreen;
garray_T tl_osc_buf; // incomplete OSC string
};
#define TMODE_ONCE 1 // CTRL-\ CTRL-N used
@@ -445,6 +446,7 @@ term_start(
#endif
ga_init2(&term->tl_scrollback, sizeof(sb_line_T), 300);
ga_init2(&term->tl_scrollback_postponed, sizeof(sb_line_T), 300);
ga_init2(&term->tl_osc_buf, sizeof(char), 300);
CLEAR_FIELD(split_ea);
if (opt->jo_curwin)
@@ -1015,6 +1017,7 @@ free_unused_terminals()
terminals_to_free = term->tl_next;
free_scrollback(term);
ga_clear(&term->tl_osc_buf);
term_free_vterm(term);
vim_free(term->tl_api);
@@ -1623,7 +1626,8 @@ cell2cellattr(const VTermScreenCell *cell, cellattr_T *attr)
static int
equal_celattr(cellattr_T *a, cellattr_T *b)
{
// Comparing the colors should be sufficient.
// We only compare the RGB colors, ignoring the ANSI index and type.
// Thus black set explicitly is equal the background black.
return a->fg.red == b->fg.red
&& a->fg.green == b->fg.green
&& a->fg.blue == b->fg.blue
@@ -2689,10 +2693,13 @@ color2index(VTermColor *color, int fg, int *boldp)
int blue = color->blue;
int green = color->green;
if (color->ansi_index != VTERM_ANSI_INDEX_NONE)
if (VTERM_COLOR_IS_DEFAULT_FG(color)
|| VTERM_COLOR_IS_DEFAULT_BG(color))
return 0;
if (VTERM_COLOR_IS_INDEXED(color))
{
// The first 16 colors and default: use the ANSI index.
switch (color->ansi_index)
switch (color->index + 1)
{
case 0: return 0;
case 1: return lookup_color( 0, fg, boldp) + 1; // black
@@ -3829,7 +3836,14 @@ term_get_attr(win_T *wp, linenr_T lnum, int col)
static void
cterm_color2vterm(int nr, VTermColor *rgb)
{
cterm_color2rgb(nr, &rgb->red, &rgb->green, &rgb->blue, &rgb->ansi_index);
cterm_color2rgb(nr, &rgb->red, &rgb->green, &rgb->blue, &rgb->index);
if (rgb->index == 0)
rgb->type = VTERM_COLOR_RGB;
else
{
rgb->type = VTERM_COLOR_INDEXED;
--rgb->index;
}
}
/*
@@ -3861,7 +3875,8 @@ init_default_colors(term_T *term, win_T *wp)
}
fg->red = fg->green = fg->blue = fgval;
bg->red = bg->green = bg->blue = bgval;
fg->ansi_index = bg->ansi_index = VTERM_ANSI_INDEX_DEFAULT;
fg->type = VTERM_COLOR_RGB | VTERM_COLOR_DEFAULT_FG;
bg->type = VTERM_COLOR_RGB | VTERM_COLOR_DEFAULT_BG;
// The 'wincolor' or the highlight group overrules the defaults.
if (wp != NULL && *wp->w_p_wcr != NUL)
@@ -4202,14 +4217,25 @@ parse_osc(int command, VTermStringFragment frag, void *user)
typval_T tv;
channel_T *channel = term->tl_job == NULL ? NULL
: term->tl_job->jv_channel;
garray_T *gap = &term->tl_osc_buf;
// We recognize only OSC 5 1 ; {command}
if (command != 51)
return 0;
reader.js_buf = vim_strnsave((char_u *)frag.str, (int)(frag.len));
if (reader.js_buf == NULL)
// Concatenate what was received until the final piece is found.
if (ga_grow(gap, (int)frag.len + 1) == FAIL)
{
ga_clear(gap);
return 1;
}
mch_memmove((char *)gap->ga_data + gap->ga_len, frag.str, frag.len);
gap->ga_len += frag.len;
if (!frag.final)
return 1;
((char *)gap->ga_data)[gap->ga_len] = 0;
reader.js_buf = gap->ga_data;
reader.js_fill = NULL;
reader.js_used = 0;
if (json_decode(&reader, &tv, 0) == OK
@@ -4243,7 +4269,7 @@ parse_osc(int command, VTermStringFragment frag, void *user)
else
ch_log(channel, "Invalid JSON received");
vim_free(reader.js_buf);
ga_clear(gap);
clear_tv(&tv);
return 1;
}
@@ -4307,14 +4333,11 @@ parse_csi(
return 1;
}
static VTermParserCallbacks parser_fallbacks = {
NULL, // text
static VTermStateFallbacks state_fallbacks = {
NULL, // control
NULL, // escape
parse_csi, // csi
parse_osc, // osc
NULL, // dcs
NULL // resize
NULL // dcs
};
/*
@@ -4397,7 +4420,7 @@ create_vterm(term_T *term, int rows, int cols)
value.boolean = 0;
#endif
vterm_state_set_termprop(state, VTERM_PROP_CURSORBLINK, &value);
vterm_state_set_unrecognised_fallbacks(state, &parser_fallbacks, term);
vterm_state_set_unrecognised_fallbacks(state, &state_fallbacks, term);
return OK;
}
@@ -4498,21 +4521,30 @@ term_get_buf(typval_T *argvars, char *where)
return buf;
}
static int
same_color(VTermColor *a, VTermColor *b)
static void
clear_cell(VTermScreenCell *cell)
{
return a->red == b->red
&& a->green == b->green
&& a->blue == b->blue
&& a->ansi_index == b->ansi_index;
CLEAR_FIELD(*cell);
cell->fg.type = VTERM_COLOR_DEFAULT_FG;
cell->bg.type = VTERM_COLOR_DEFAULT_BG;
}
static void
dump_term_color(FILE *fd, VTermColor *color)
{
int index;
if (VTERM_COLOR_IS_INDEXED(color))
index = color->index + 1;
else if (color->type == 0)
// use RGB values
index = 255;
else
// default color
index = 0;
fprintf(fd, "%02x%02x%02x%d",
(int)color->red, (int)color->green, (int)color->blue,
(int)color->ansi_index);
index);
}
/*
@@ -4596,7 +4628,7 @@ f_term_dumpwrite(typval_T *argvars, typval_T *rettv UNUSED)
return;
}
CLEAR_FIELD(prev_cell);
clear_cell(&prev_cell);
screen = vterm_obtain_screen(term->tl_vterm);
state = vterm_obtain_state(term->tl_vterm);
@@ -4618,7 +4650,7 @@ f_term_dumpwrite(typval_T *argvars, typval_T *rettv UNUSED)
&& pos.row == cursor_pos.row);
if (vterm_screen_get_cell(screen, pos, &cell) == 0)
CLEAR_FIELD(cell);
clear_cell(&cell);
for (i = 0; i < VTERM_MAX_CHARS_PER_CELL; ++i)
{
@@ -4638,8 +4670,8 @@ f_term_dumpwrite(typval_T *argvars, typval_T *rettv UNUSED)
}
same_attr = vtermAttr2hl(cell.attrs)
== vtermAttr2hl(prev_cell.attrs)
&& same_color(&cell.fg, &prev_cell.fg)
&& same_color(&cell.bg, &prev_cell.bg);
&& vterm_color_is_equal(&cell.fg, &prev_cell.fg)
&& vterm_color_is_equal(&cell.bg, &prev_cell.bg);
if (same_chars && cell.width == prev_cell.width && same_attr
&& !is_cursor_pos)
{
@@ -4686,14 +4718,14 @@ f_term_dumpwrite(typval_T *argvars, typval_T *rettv UNUSED)
else
{
fprintf(fd, "%d", vtermAttr2hl(cell.attrs));
if (same_color(&cell.fg, &prev_cell.fg))
if (vterm_color_is_equal(&cell.fg, &prev_cell.fg))
fputs("&", fd);
else
{
fputs("#", fd);
dump_term_color(fd, &cell.fg);
}
if (same_color(&cell.bg, &prev_cell.bg))
if (vterm_color_is_equal(&cell.bg, &prev_cell.bg))
fputs("&", fd);
else
{
@@ -4736,6 +4768,14 @@ append_cell(garray_T *gap, cellattr_T *cell)
}
}
static void
clear_cellattr(cellattr_T *cell)
{
CLEAR_FIELD(*cell);
cell->fg.type = VTERM_COLOR_DEFAULT_FG;
cell->bg.type = VTERM_COLOR_DEFAULT_BG;
}
/*
* Read the dump file from "fd" and append lines to the current buffer.
* Return the cell width of the longest line.
@@ -4756,8 +4796,8 @@ read_dump_file(FILE *fd, VTermPos *cursor_pos)
ga_init2(&ga_text, 1, 90);
ga_init2(&ga_cell, sizeof(cellattr_T), 90);
CLEAR_FIELD(cell);
CLEAR_FIELD(empty_cell);
clear_cellattr(&cell);
clear_cellattr(&empty_cell);
cursor_pos->row = -1;
cursor_pos->col = -1;
@@ -4867,7 +4907,7 @@ read_dump_file(FILE *fd, VTermPos *cursor_pos)
}
else if (c == '#')
{
int red, green, blue, index = 0;
int red, green, blue, index = 0, type;
c = fgetc(fd);
red = hex2nr(c);
@@ -4889,20 +4929,37 @@ read_dump_file(FILE *fd, VTermPos *cursor_pos)
index = index * 10 + (c - '0');
c = fgetc(fd);
}
if (is_bg)
if (index == 0 || index == 255)
{
cell.bg.red = red;
cell.bg.green = green;
cell.bg.blue = blue;
cell.bg.ansi_index = index;
type = VTERM_COLOR_RGB;
if (index == 0)
{
if (is_bg)
type |= VTERM_COLOR_DEFAULT_BG;
else
type |= VTERM_COLOR_DEFAULT_FG;
}
}
else
{
type = VTERM_COLOR_INDEXED;
index -= 1;
}
if (is_bg)
{
cell.bg.type = type;
cell.bg.red = red;
cell.bg.green = green;
cell.bg.blue = blue;
cell.bg.index = index;
}
else
{
cell.fg.type = type;
cell.fg.red = red;
cell.fg.green = green;
cell.fg.blue = blue;
cell.fg.ansi_index = index;
cell.fg.index = index;
}
}
else
@@ -5215,10 +5272,10 @@ term_load_dump(typval_T *argvars, typval_T *rettv, int do_diff)
if ((cellattr1 + col)->width
!= (cellattr2 + col)->width)
textline[col] = 'w';
else if (!same_color(&(cellattr1 + col)->fg,
else if (!vterm_color_is_equal(&(cellattr1 + col)->fg,
&(cellattr2 + col)->fg))
textline[col] = 'f';
else if (!same_color(&(cellattr1 + col)->bg,
else if (!vterm_color_is_equal(&(cellattr1 + col)->bg,
&(cellattr2 + col)->bg))
textline[col] = 'b';
else if (vtermAttr2hl((cellattr1 + col)->attrs)
@@ -5797,6 +5854,7 @@ f_term_scrape(typval_T *argvars, typval_T *rettv)
else
{
VTermScreenCell cell;
if (vterm_screen_get_cell(screen, pos, &cell) == 0)
break;
for (i = 0; i < VTERM_MAX_CHARS_PER_CELL; ++i)

View File

@@ -148,36 +148,36 @@ func Test_json_decode()
call assert_fails("call json_decode('{\"\": \"ok\", \"\": \"bad\"}')", 'E938:')
call assert_equal({'n': 1}, json_decode('{"n":1,}'))
call assert_fails("call json_decode(\"{'n':'1',}\")", 'E474:')
call assert_fails("call json_decode(\"'n'\")", 'E474:')
call assert_fails("call json_decode(\"{'n':'1',}\")", 'E491:')
call assert_fails("call json_decode(\"'n'\")", 'E491:')
call assert_fails('call json_decode("\"")', "E474:")
call assert_fails('call json_decode("blah")', "E474:")
call assert_fails('call json_decode("\"")', "E491:")
call assert_fails('call json_decode("blah")', "E491:")
call assert_fails('call json_decode("true blah")', "E488:")
call assert_fails('call json_decode("<foobar>")', "E474:")
call assert_fails('call json_decode("<foobar>")', "E491:")
call assert_fails('call json_decode("{\"a\":1,\"a\":2}")', "E938:")
call assert_fails('call json_decode("{")', "E474:")
call assert_fails('call json_decode("{foobar}")', "E474:")
call assert_fails('call json_decode("{\"n\",")', "E474:")
call assert_fails('call json_decode("{\"n\":")', "E474:")
call assert_fails('call json_decode("{\"n\":1")', "E474:")
call assert_fails('call json_decode("{\"n\":1,")', "E474:")
call assert_fails('call json_decode("{\"n\",1}")', "E474:")
call assert_fails('call json_decode("{-}")', "E474:")
call assert_fails('call json_decode("{")', "E491:")
call assert_fails('call json_decode("{foobar}")', "E491:")
call assert_fails('call json_decode("{\"n\",")', "E491:")
call assert_fails('call json_decode("{\"n\":")', "E491:")
call assert_fails('call json_decode("{\"n\":1")', "E491:")
call assert_fails('call json_decode("{\"n\":1,")', "E491:")
call assert_fails('call json_decode("{\"n\",1}")', "E491:")
call assert_fails('call json_decode("{-}")', "E491:")
call assert_fails('call json_decode("[foobar]")', "E474:")
call assert_fails('call json_decode("[")', "E474:")
call assert_fails('call json_decode("[1")', "E474:")
call assert_fails('call json_decode("[1,")', "E474:")
call assert_fails('call json_decode("[1 2]")', "E474:")
call assert_fails('call json_decode("[foobar]")', "E491:")
call assert_fails('call json_decode("[")', "E491:")
call assert_fails('call json_decode("[1")', "E491:")
call assert_fails('call json_decode("[1,")', "E491:")
call assert_fails('call json_decode("[1 2]")', "E491:")
call assert_fails('call json_decode("[1,,2]")', "E474:")
call assert_fails('call json_decode("[1,,2]")', "E491:")
call assert_fails('call json_decode("{{}:42}")', "E474:")
call assert_fails('call json_decode("{[]:42}")', "E474:")
call assert_fails('call json_decode("{{}:42}")', "E491:")
call assert_fails('call json_decode("{[]:42}")', "E491:")
call assert_fails('call json_decode("\"\\u111Z\"")', 'E474:')
call assert_fails('call json_decode("\"\\u111Z\"")', 'E491:')
call assert_equal('[😂]', json_decode('"[\uD83D\uDE02]"'))
call assert_equal('a😂b', json_decode('"a\uD83D\uDE02b"'))
endfunc

View File

@@ -746,6 +746,18 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
804,
/**/
803,
/**/
802,
/**/
801,
/**/
800,
/**/
799,
/**/
798,
/**/