Skip to content

Commit 9cc5f75

Browse files
committed
patch 8.0.0763: libvterm can be improved
Problem: Libvterm can be improved. Solution: Various small improvements, more comments.
1 parent c31f9ae commit 9cc5f75

8 files changed

Lines changed: 26 additions & 15 deletions

File tree

src/libvterm/README

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
This is a MODIFIED version of libvterm.
22

33
The original can be found:
4-
On the original site (tar archive and Bazaar repository):
4+
- on the original site (tar archive and Bazaar repository):
55
http://www.leonerd.org.uk/code/libvterm/
6-
Cloned on Github:
6+
- cloned on Github:
77
https://github.com/neovim/libvterm
88

99
Modifications:
1010
- Add a .gitignore file.
1111
- Convert from C99 to C90.
1212
- Other changes to support embedding in Vim.
13-
-

src/libvterm/include/vterm.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ VTerm *vterm_new_with_allocator(int rows, int cols, VTermAllocatorFunctions *fun
160160
/* Free and cleanup a terminal and all its data. */
161161
void vterm_free(VTerm* vt);
162162

163+
/* Get the current size of the terminal and store in "rowsp" and "colsp". */
163164
void vterm_get_size(const VTerm *vt, int *rowsp, int *colsp);
165+
164166
void vterm_set_size(VTerm *vt, int rows, int cols);
165167

166168
int vterm_get_utf8(const VTerm *vt);
@@ -195,14 +197,14 @@ void vterm_mouse_button(VTerm *vt, int button, bool pressed, VTermModifier mod);
195197
*
196198
* Don't confuse this with the final byte of the CSI escape; 'a' in this case.
197199
*/
198-
#define CSI_ARG_FLAG_MORE (1<<31)
199-
#define CSI_ARG_MASK (~(1<<31))
200+
#define CSI_ARG_FLAG_MORE (1<<30)
201+
#define CSI_ARG_MASK (~(1<<30))
200202

201203
#define CSI_ARG_HAS_MORE(a) ((a) & CSI_ARG_FLAG_MORE)
202204
#define CSI_ARG(a) ((a) & CSI_ARG_MASK)
203205

204206
/* Can't use -1 to indicate a missing argument; use this instead */
205-
#define CSI_ARG_MISSING ((1UL<<31)-1)
207+
#define CSI_ARG_MISSING ((1<<30)-1)
206208

207209
#define CSI_ARG_IS_MISSING(a) (CSI_ARG(a) == CSI_ARG_MISSING)
208210
#define CSI_ARG_OR(a,def) (CSI_ARG(a) == CSI_ARG_MISSING ? (def) : CSI_ARG(a))
@@ -248,7 +250,9 @@ void *vterm_state_get_cbdata(VTermState *state);
248250
void vterm_state_set_unrecognised_fallbacks(VTermState *state, const VTermParserCallbacks *fallbacks, void *user);
249251
void *vterm_state_get_unrecognised_fbdata(VTermState *state);
250252

253+
/* Initialize the state. */
251254
void vterm_state_reset(VTermState *state, int hard);
255+
252256
void vterm_state_get_cursorpos(const VTermState *state, VTermPos *cursorpos);
253257
void vterm_state_get_default_colors(const VTermState *state, VTermColor *default_fg, VTermColor *default_bg);
254258
void vterm_state_get_palette_color(const VTermState *state, int index, VTermColor *col);
@@ -295,6 +299,7 @@ typedef struct {
295299
int (*sb_popline)(int cols, VTermScreenCell *cells, void *user);
296300
} VTermScreenCallbacks;
297301

302+
/* Return the screen of the vterm. */
298303
VTermScreen *vterm_obtain_screen(VTerm *vt);
299304

300305
/*
@@ -317,9 +322,15 @@ typedef enum {
317322
VTERM_DAMAGE_SCROLL /* entire screen + scrollrect */
318323
} VTermDamageSize;
319324

325+
/* Invoke the relevant callbacks to update the screen. */
320326
void vterm_screen_flush_damage(VTermScreen *screen);
327+
321328
void vterm_screen_set_damage_merge(VTermScreen *screen, VTermDamageSize size);
322329

330+
/*
331+
* Reset the screen. Also invokes vterm_state_reset().
332+
* Must be called before the terminal can be used.
333+
*/
323334
void vterm_screen_reset(VTermScreen *screen, int hard);
324335

325336
/* Neither of these functions NUL-terminate the buffer */

src/libvterm/include/vterm_keycodes.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ typedef enum {
2828
VTERM_KEY_PAGEUP,
2929
VTERM_KEY_PAGEDOWN,
3030

31+
/* F1 is VTERM_KEY_FUNCTION(1), F2 VTERM_KEY_FUNCTION(2), etc. */
3132
VTERM_KEY_FUNCTION_0 = 256,
3233
VTERM_KEY_FUNCTION_MAX = VTERM_KEY_FUNCTION_0 + 255,
3334

35+
/* keypad keys */
3436
VTERM_KEY_KP_0,
3537
VTERM_KEY_KP_1,
3638
VTERM_KEY_KP_2,

src/libvterm/src/keyboard.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ typedef struct {
6868
int csinum;
6969
} keycodes_s;
7070

71+
/* Order here must be exactly the same as VTermKey enum! */
7172
static keycodes_s keycodes[] = {
7273
{ KEYCODE_NONE, 0, 0 }, /* NONE */
7374

src/libvterm/src/parser.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ static size_t do_string(VTerm *vt, const char *str_frag, size_t len)
190190
size_t vterm_input_write(VTerm *vt, const char *bytes, size_t len)
191191
{
192192
size_t pos = 0;
193-
const char *string_start;
193+
const char *string_start = NULL; /* init to avoid gcc warning */
194194

195195
switch(vt->parser_state) {
196196
case NORMAL:

src/libvterm/src/screen.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -819,14 +819,9 @@ int vterm_screen_is_eol(const VTermScreen *screen, VTermPos pos)
819819

820820
VTermScreen *vterm_obtain_screen(VTerm *vt)
821821
{
822-
VTermScreen *screen;
823-
if(vt->screen)
824-
return vt->screen;
825-
826-
screen = screen_new(vt);
827-
vt->screen = screen;
828-
829-
return screen;
822+
if(!vt->screen)
823+
vt->screen = screen_new(vt);
824+
return vt->screen;
830825
}
831826

832827
void vterm_screen_enable_altscreen(VTermScreen *screen, int altscreen)

src/libvterm/src/state.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,6 +1194,7 @@ static int on_csi(const char *leader, const long args[], int argcount, const cha
11941194
break;
11951195

11961196
case LEADER('>', 0x63): /* DEC secondary Device Attributes */
1197+
/* This returns xterm version number 100. */
11971198
vterm_push_output_sprintf_ctrl(state->vt, C1_CSI, ">%d;%d;%dc", 0, 100, 0);
11981199
break;
11991200

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,8 @@ static char *(features[]) =
769769

770770
static int included_patches[] =
771771
{ /* Add new patch number below this line */
772+
/**/
773+
763,
772774
/**/
773775
762,
774776
/**/

0 commit comments

Comments
 (0)