Skip to content

Commit e4f25e4

Browse files
committed
patch 8.0.0693: no terminal emulator support
Problem: No terminal emulator support. Cannot properly run commands in the GUI. Cannot run a job interactively with an ssh connection. Solution: Very early implementation of the :terminal command. Includes libvterm converted to ANSI C. Many parts still missing.
1 parent da5116d commit e4f25e4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+11693
-13
lines changed

Filelist

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ SRC_ALL = \
8585
src/syntax.c \
8686
src/tag.c \
8787
src/term.c \
88+
src/terminal.c \
8889
src/term.h \
8990
src/termlib.c \
9091
src/ui.c \
@@ -187,13 +188,84 @@ SRC_ALL = \
187188
src/proto/syntax.pro \
188189
src/proto/tag.pro \
189190
src/proto/term.pro \
191+
src/proto/terminal.pro \
190192
src/proto/termlib.pro \
191193
src/proto/ui.pro \
192194
src/proto/undo.pro \
193195
src/proto/userfunc.pro \
194196
src/proto/version.pro \
195197
src/proto/winclip.pro \
196198
src/proto/window.pro \
199+
src/libvterm/.bzrignore \
200+
src/libvterm/.gitignore \
201+
src/libvterm/LICENSE \
202+
src/libvterm/Makefile \
203+
src/libvterm/README \
204+
src/libvterm/tbl2inc_c.pl \
205+
src/libvterm/vterm.pc.in \
206+
src/libvterm/bin/unterm.c \
207+
src/libvterm/bin/vterm-ctrl.c \
208+
src/libvterm/bin/vterm-dump.c \
209+
src/libvterm/doc/URLs \
210+
src/libvterm/doc/seqs.txt \
211+
src/libvterm/include/vterm.h \
212+
src/libvterm/include/vterm_keycodes.h \
213+
src/libvterm/src/encoding.c \
214+
src/libvterm/src/encoding/DECdrawing.inc \
215+
src/libvterm/src/encoding/DECdrawing.tbl \
216+
src/libvterm/src/encoding/uk.inc \
217+
src/libvterm/src/encoding/uk.tbl \
218+
src/libvterm/src/keyboard.c \
219+
src/libvterm/src/mouse.c \
220+
src/libvterm/src/parser.c \
221+
src/libvterm/src/pen.c \
222+
src/libvterm/src/rect.h \
223+
src/libvterm/src/screen.c \
224+
src/libvterm/src/state.c \
225+
src/libvterm/src/unicode.c \
226+
src/libvterm/src/utf8.h \
227+
src/libvterm/src/vterm.c \
228+
src/libvterm/src/vterm_internal.h \
229+
src/libvterm/t/02parser.test \
230+
src/libvterm/t/03encoding_utf8.test \
231+
src/libvterm/t/10state_putglyph.test \
232+
src/libvterm/t/11state_movecursor.test \
233+
src/libvterm/t/12state_scroll.test \
234+
src/libvterm/t/13state_edit.test \
235+
src/libvterm/t/14state_encoding.test \
236+
src/libvterm/t/15state_mode.test \
237+
src/libvterm/t/16state_resize.test \
238+
src/libvterm/t/17state_mouse.test \
239+
src/libvterm/t/18state_termprops.test \
240+
src/libvterm/t/20state_wrapping.test \
241+
src/libvterm/t/21state_tabstops.test \
242+
src/libvterm/t/22state_save.test \
243+
src/libvterm/t/25state_input.test \
244+
src/libvterm/t/26state_query.test \
245+
src/libvterm/t/27state_reset.test \
246+
src/libvterm/t/28state_dbl_wh.test \
247+
src/libvterm/t/29state_fallback.test \
248+
src/libvterm/t/30pen.test \
249+
src/libvterm/t/40screen_ascii.test \
250+
src/libvterm/t/41screen_unicode.test \
251+
src/libvterm/t/42screen_damage.test \
252+
src/libvterm/t/43screen_resize.test \
253+
src/libvterm/t/44screen_pen.test \
254+
src/libvterm/t/45screen_protect.test \
255+
src/libvterm/t/46screen_extent.test \
256+
src/libvterm/t/47screen_dbl_wh.test \
257+
src/libvterm/t/48screen_termprops.test \
258+
src/libvterm/t/90vttest_01-movement-1.test \
259+
src/libvterm/t/90vttest_01-movement-2.test \
260+
src/libvterm/t/90vttest_01-movement-3.test \
261+
src/libvterm/t/90vttest_01-movement-4.test \
262+
src/libvterm/t/90vttest_02-screen-1.test \
263+
src/libvterm/t/90vttest_02-screen-2.test \
264+
src/libvterm/t/90vttest_02-screen-3.test \
265+
src/libvterm/t/90vttest_02-screen-4.test \
266+
src/libvterm/t/92lp1640917.test \
267+
src/libvterm/t/harness.c \
268+
src/libvterm/t/run-test.pl \
197269

198270

199271
# source files for Unix only

runtime/doc/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ DOCS = \
101101
tabpage.txt \
102102
tagsrch.txt \
103103
term.txt \
104+
terminal.txt \
104105
tips.txt \
105106
todo.txt \
106107
uganda.txt \
@@ -236,6 +237,7 @@ HTMLS = \
236237
tabpage.html \
237238
tagsrch.html \
238239
term.html \
240+
terminal.html \
239241
tips.html \
240242
todo.html \
241243
uganda.html \

runtime/doc/terminal.txt

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
*terminal.txt* For Vim version 8.0. Last change: 2017 Jul 04
2+
3+
4+
VIM REFERENCE MANUAL by Bram Moolenaar
5+
6+
7+
Terminal window support *terminal*
8+
9+
10+
WARNING: THIS IS ONLY PARTLY IMPLEMENTED, ANYTHING CAN STILL CHANGE
11+
12+
13+
1. Basic use |terminal-use|
14+
2. Remote testing |terminal-testing|
15+
3. Debugging |terminal-debug|
16+
17+
{Vi does not have any of these commands}
18+
19+
==============================================================================
20+
1. Basic use *terminal-use*
21+
22+
This feature is for running a terminal emulator in a Vim window. A job can be
23+
started connected to the terminal emulator. For example, to run a shell: >
24+
:term bash
25+
26+
Or to run a debugger: >
27+
:term gdb vim
28+
29+
The job runs asynchronously from Vim, the window will be updated to show
30+
output from the job, also while editing in any other window.
31+
32+
When the keyboard focus is in the terminal window, typed keys will be send to
33+
the job. This uses a pty when possible.
34+
35+
Navigate between windows with CTRL-W commands (and mouse).
36+
E.g. CTRL-W CTRL-W moves focus to the next window.
37+
38+
Option 'termkey'
39+
Specify key for Vim command in terminal window. local to window.
40+
Default is CTRL-W.
41+
42+
Option 'termsize'
43+
Specify terminal size. Local to window.
44+
When empty the terminal gets the size from the window.
45+
When set (e.g., "24x80") the terminal size is fixed. If the window is smaller
46+
only the top-left part is displayed. (TODO: scrolling?)
47+
48+
Syntax ~
49+
*:ter* *:terminal*
50+
:terminal[!] [command] Open a new terminal window.
51+
52+
If [command] is provided run it as a job and connect
53+
the input and output to the terminal.
54+
If [command] is not given the 'shell' option is used.
55+
56+
A new buffer will be created, using [command] or
57+
'shell' as the name. If a buffer by this name already
58+
exists a number is added in parenthesis.
59+
E.g. if "gdb" exists the second terminal buffer will
60+
use "gdb (1)".
61+
62+
The window can be closed, in which case the buffer
63+
becomes hidden. The command will not be stopped. The
64+
`:buffer` command can be used to turn the current
65+
window into a terminal window, using the existing
66+
buffer. If there are unsaved changes this fails, use
67+
! to force, as usual.
68+
69+
Resizing ~
70+
71+
The size of the terminal can be in one of three modes:
72+
73+
1. The 'termsize' option is empty: The terminal size follows the window size.
74+
The minimal size is 2 screen lines with 10 cells.
75+
76+
2. The 'termsize' option is "rows*cols", where "rows" is the minimal number of
77+
screen rows and "cols" is the minial number of cells.
78+
79+
3. The 'termsize' option is "rowsXcols" (where the x is upper or lower case).
80+
The terminal size is fixed to the specified number of screen lines and
81+
cells. If the window is bigger there will be unused empty space.
82+
83+
If the window is smaller than the terminal size, only part of the terminal can
84+
be seen (the lower-left part).
85+
86+
The |term_getsize()| function can be used to get the current size of the
87+
terminal. |term_setsize()| can be used only when in the first or second mode,
88+
not when 'termsize' is "rowsXcols".
89+
90+
==============================================================================
91+
2. Remote testing *terminal-testing*
92+
93+
Most Vim tests execute a script inside Vim. For some tests this does not
94+
work, running the test interferes with the code being tested. To avoid this
95+
Vim is executed in a terminal window. The test sends keystrokes to it and
96+
inspects the resulting screen state.
97+
98+
Functions ~
99+
100+
term_sendkeys() send keystrokes to a terminal
101+
term_wait() wait for screen to be updated
102+
term_scrape() inspect terminal screen
103+
104+
105+
==============================================================================
106+
3. Debugging *terminal-debug*
107+
108+
The Terminal debugging plugin can be used to debug a program with gdb and view
109+
the source code in a Vim window. For example: >
110+
111+
:TermDebug vim
112+
113+
This opens three windows:
114+
- A terminal window in which "gdb vim" is executed. Here you can directly
115+
interact with gdb.
116+
- A terminal window for the executed program. When "run" is used in gdb the
117+
program I/O will happen in this window, so that it does not interfere with
118+
controlling gdb.
119+
- A normal Vim window used to show the source code. When gdb jumps to a
120+
source file location this window will display the code, if possible. Values
121+
of variables can be inspected, breakpoints set and cleared, etc.
122+
123+
This uses two terminal windows. To open the gdb window: >
124+
:term gdb [arguments]
125+
To open the terminal to run the tested program |term_open()| is used.
126+
127+
TODO
128+
129+
130+
vim:tw=78:ts=8:ft=help:norl:

src/Makefile

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,11 @@ CClink = $(CC)
482482
# Uncomment this when you do not want inter process communication.
483483
#CONF_OPT_CHANNEL = --disable-channel
484484

485+
# TERMINAL - Terminal emulator support, :terminal command. Requires the
486+
# channel feature.
487+
# Uncomment this when you want terminal emulator support.
488+
#CONF_OPT_TERMINAL = --enable-terminal
489+
485490
# MULTIBYTE - To edit multi-byte characters.
486491
# Uncomment this when you want to edit a multibyte language.
487492
# It's automatically enabled with normal features, GTK or IME support.
@@ -598,6 +603,9 @@ CClink = $(CC)
598603

599604
# Use this with GCC to check for mistakes, unused arguments, etc.
600605
#CFLAGS = -g -Wall -Wextra -Wshadow -Wmissing-prototypes -Wunreachable-code -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
606+
# Add -Wpedantic to find // comments and other C99 constructs.
607+
# Better disable Perl and Python to avoid a lot of warnings.
608+
#CFLAGS = -g -Wall -Wextra -Wshadow -Wmissing-prototypes -Wpedantic -Wunreachable-code -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
601609
#CFLAGS = -g -O2 -Wall -Wextra -Wmissing-prototypes -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DU_DEBUG
602610
#PYTHON_CFLAGS_EXTRA = -Wno-missing-field-initializers
603611
#MZSCHEME_CFLAGS_EXTRA = -Wno-unreachable-code -Wno-unused-parameter
@@ -1371,6 +1379,13 @@ ALL_GUI_PRO = gui.pro gui_gtk.pro gui_motif.pro gui_xmdlg.pro gui_athena.pro gu
13711379

13721380
# }}}
13731381

1382+
TERM_DEPS = \
1383+
libvterm/include/vterm.h \
1384+
libvterm/include/vterm_keycodes.h \
1385+
libvterm/src/rect.h \
1386+
libvterm/src/utf8.h \
1387+
libvterm/src/vterm_internal.h
1388+
13741389
### Command to create dependencies based on #include "..."
13751390
### prototype headers are ignored due to -DPROTO, system
13761391
### headers #include <...> are ignored if we use the -MM option, as
@@ -1560,6 +1575,7 @@ BASIC_SRC = \
15601575
syntax.c \
15611576
tag.c \
15621577
term.c \
1578+
terminal.c \
15631579
ui.c \
15641580
undo.c \
15651581
userfunc.c \
@@ -1569,6 +1585,7 @@ BASIC_SRC = \
15691585

15701586
SRC = $(BASIC_SRC) \
15711587
$(GUI_SRC) \
1588+
$(TERM_SRC) \
15721589
$(HANGULIN_SRC) \
15731590
$(LUA_SRC) \
15741591
$(MZSCHEME_SRC) \
@@ -1610,7 +1627,7 @@ ALL_SRC = $(BASIC_SRC) $(ALL_GUI_SRC) $(UNITTEST_SRC) $(EXTRA_SRC)
16101627
LINT_SRC = $(BASIC_SRC) $(GUI_SRC) $(HANGULIN_SRC) \
16111628
$(PYTHON_SRC) $(PYTHON3_SRC) $(TCL_SRC) \
16121629
$(WORKSHOP_SRC) $(WSDEBUG_SRC) \
1613-
$(NETBEANS_SRC) $(CHANNEL_SRC)
1630+
$(NETBEANS_SRC) $(CHANNEL_SRC) $(TERM_SRC)
16141631
#LINT_SRC = $(SRC)
16151632
#LINT_SRC = $(ALL_SRC)
16161633
#LINT_SRC = $(BASIC_SRC)
@@ -1665,12 +1682,14 @@ OBJ_COMMON = \
16651682
objects/syntax.o \
16661683
objects/tag.o \
16671684
objects/term.o \
1685+
objects/terminal.o \
16681686
objects/ui.o \
16691687
objects/undo.o \
16701688
objects/userfunc.o \
16711689
objects/version.o \
16721690
objects/window.o \
16731691
$(GUI_OBJ) \
1692+
$(TERM_OBJ) \
16741693
$(LUA_OBJ) \
16751694
$(MZSCHEME_OBJ) \
16761695
$(PERL_OBJ) \
@@ -1795,6 +1814,7 @@ PRO_AUTO = \
17951814
syntax.pro \
17961815
tag.pro \
17971816
term.pro \
1817+
terminal.pro \
17981818
termlib.pro \
17991819
ui.pro \
18001820
undo.pro \
@@ -1848,7 +1868,7 @@ config auto/config.mk: auto/configure config.mk.in config.h.in
18481868
$(CONF_OPT_OUTPUT) $(CONF_OPT_GPM) $(CONF_OPT_WORKSHOP) \
18491869
$(CONF_OPT_FEAT) $(CONF_TERM_LIB) \
18501870
$(CONF_OPT_COMPBY) $(CONF_OPT_ACL) $(CONF_OPT_NETBEANS) \
1851-
$(CONF_OPT_CHANNEL) \
1871+
$(CONF_OPT_CHANNEL) $(CONF_OPT_TERMINAL) \
18521872
$(CONF_ARGS) $(CONF_OPT_MZSCHEME) $(CONF_OPT_PLTHOME) \
18531873
$(CONF_OPT_LUA) $(CONF_OPT_LUA_PREFIX) \
18541874
$(CONF_OPT_SYSMOUSE); \
@@ -3228,6 +3248,9 @@ objects/tag.o: tag.c
32283248
objects/term.o: term.c
32293249
$(CCC) -o $@ term.c
32303250

3251+
objects/terminal.o: terminal.c $(TERM_DEPS)
3252+
$(CCC) -o $@ terminal.c
3253+
32313254
objects/ui.o: ui.c
32323255
$(CCC) -o $@ ui.c
32333256

@@ -3255,6 +3278,34 @@ objects/channel.o: channel.c
32553278
Makefile:
32563279
@echo The name of the makefile MUST be "Makefile" (with capital M)!!!!
32573280

3281+
CCCTERM = $(CCC) -Ilibvterm/include -DINLINE=""
3282+
objects/term_encoding.o: libvterm/src/encoding.c $(TERM_DEPS)
3283+
$(CCCTERM) -o $@ libvterm/src/encoding.c
3284+
3285+
objects/term_keyboard.o: libvterm/src/keyboard.c $(TERM_DEPS)
3286+
$(CCCTERM) -o $@ libvterm/src/keyboard.c
3287+
3288+
objects/term_mouse.o: libvterm/src/mouse.c $(TERM_DEPS)
3289+
$(CCCTERM) -o $@ libvterm/src/mouse.c
3290+
3291+
objects/term_parser.o: libvterm/src/parser.c $(TERM_DEPS)
3292+
$(CCCTERM) -o $@ libvterm/src/parser.c
3293+
3294+
objects/term_pen.o: libvterm/src/pen.c $(TERM_DEPS)
3295+
$(CCCTERM) -o $@ libvterm/src/pen.c
3296+
3297+
objects/term_screen.o: libvterm/src/screen.c $(TERM_DEPS)
3298+
$(CCCTERM) -o $@ libvterm/src/screen.c
3299+
3300+
objects/term_state.o: libvterm/src/state.c $(TERM_DEPS)
3301+
$(CCCTERM) -o $@ libvterm/src/state.c
3302+
3303+
objects/term_unicode.o: libvterm/src/unicode.c $(TERM_DEPS)
3304+
$(CCCTERM) -o $@ libvterm/src/unicode.c
3305+
3306+
objects/term_vterm.o: libvterm/src/vterm.c $(TERM_DEPS)
3307+
$(CCCTERM) -o $@ libvterm/src/vterm.c
3308+
32583309
###############################################################################
32593310
### MacOS X installation
32603311
###
@@ -3399,7 +3450,7 @@ objects/ex_cmds2.o: ex_cmds2.c vim.h auto/config.h feature.h os_unix.h \
33993450
objects/ex_docmd.o: ex_docmd.c vim.h auto/config.h feature.h os_unix.h \
34003451
auto/osdef.h ascii.h keymap.h term.h macros.h option.h structs.h \
34013452
regexp.h gui.h gui_beval.h proto/gui_beval.pro alloc.h ex_cmds.h spell.h \
3402-
proto.h globals.h farsi.h arabic.h
3453+
proto.h globals.h farsi.h arabic.h ex_cmdidxs.h
34033454
objects/ex_eval.o: ex_eval.c vim.h auto/config.h feature.h os_unix.h auto/osdef.h \
34043455
ascii.h keymap.h term.h macros.h option.h structs.h regexp.h gui.h \
34053456
gui_beval.h proto/gui_beval.pro alloc.h ex_cmds.h spell.h proto.h \

0 commit comments

Comments
 (0)