annotate src/terminal.c @ 11804:5630978ae089 v8.0.0784

patch 8.0.0784: job of terminal may be garbage collected commit https://github.com/vim/vim/commit/a2c45a17c174d815fd1d160f92ec6c277201e111 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Jul 27 22:14:59 2017 +0200 patch 8.0.0784: job of terminal may be garbage collected Problem: Job of terminal may be garbage collected. Solution: Set copyID on job in terminal. (Ozaki Kiichi)
author Christian Brabandt <cb@256bit.org>
date Thu, 27 Jul 2017 22:30:04 +0200
parents b1fd49b4eea7
children d3d0db111d17
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2 *
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4 *
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8 */
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 /*
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11 * Terminal window support, see ":help :terminal".
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 *
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
13 * There are three parts:
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
14 * 1. Generic code for all systems.
11741
b4d8f956eb18 patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents: 11729
diff changeset
15 * Uses libvterm for the terminal emulator.
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
16 * 2. The MS-Windows implementation.
11741
b4d8f956eb18 patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents: 11729
diff changeset
17 * Uses winpty.
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
18 * 3. The Unix-like implementation.
11741
b4d8f956eb18 patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents: 11729
diff changeset
19 * Uses pseudo-tty's (pty's).
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
20 *
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
21 * For each terminal one VTerm is constructed. This uses libvterm. A copy of
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
22 * that library is in the libvterm directory.
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23 *
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
24 * When a terminal window is opened, a job is started that will be connected to
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
25 * the terminal emulator.
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
26 *
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
27 * If the terminal window has keyboard focus, typed keys are converted to the
11774
edf1a2a247fa patch 8.0.0769: build problems with terminal on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11772
diff changeset
28 * terminal encoding and writing to the job over a channel.
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
29 *
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
30 * If the job produces output, it is written to the terminal emulator. The
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
31 * terminal emulator invokes callbacks when its screen content changes. The
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
32 * line range is stored in tl_dirty_row_start and tl_dirty_row_end. Once in a
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
33 * while, if the terminal window is visible, the screen contents is drawn.
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34 *
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
35 * TODO:
11778
e8005055f845 patch 8.0.0771: cursor in terminal window not always updated in GUI
Christian Brabandt <cb@256bit.org>
parents: 11774
diff changeset
36 * - include functions from #1871
e8005055f845 patch 8.0.0771: cursor in terminal window not always updated in GUI
Christian Brabandt <cb@256bit.org>
parents: 11774
diff changeset
37 * - do not store terminal buffer in viminfo. Or prefix term:// ?
11790
4dfebc1b2674 patch 8.0.0777: compiler warnings with 64 bit compiler
Christian Brabandt <cb@256bit.org>
parents: 11786
diff changeset
38 * - Make CTRL-W . send CTRL-W to terminal?
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
39 * - Add a scrollback buffer (contains lines to scroll off the top).
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
40 * Can use the buf_T lines, store attributes somewhere else?
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
41 * - When the job ends:
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
42 * - Write "-- JOB ENDED --" in the terminal.
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
43 * - Put the terminal contents in the scrollback buffer.
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
44 * - Free the terminal emulator.
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
45 * - Display the scrollback buffer (but with attributes).
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
46 * Make the buffer not modifiable, drop attributes when making changes.
11772
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
47 * - Need an option or argument to drop the window+buffer right away, to be
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
48 * used for a shell or Vim.
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
49 * - add a character in :ls output
11684
1ce1376fbbf8 patch 8.0.0725: a terminal window does not handle keyboard input
Christian Brabandt <cb@256bit.org>
parents: 11670
diff changeset
50 * - when closing window and job has not ended, make terminal hidden?
11725
22cef8face93 patch 8.0.0745: multi-byte characters in a terminal don't display well
Christian Brabandt <cb@256bit.org>
parents: 11723
diff changeset
51 * - don't allow exiting Vim when a terminal is still running a job
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
52 * - use win_del_lines() to make scroll-up efficient.
11684
1ce1376fbbf8 patch 8.0.0725: a terminal window does not handle keyboard input
Christian Brabandt <cb@256bit.org>
parents: 11670
diff changeset
53 * - command line completion for :terminal
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
54 * - add test for giving error for invalid 'termsize' value.
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
55 * - support minimal size when 'termsize' is "rows*cols".
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
56 * - support minimal size when 'termsize' is empty?
11723
1922710ee8fa patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents: 11719
diff changeset
57 * - implement "term" for job_start(): more job options when starting a
1922710ee8fa patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents: 11719
diff changeset
58 * terminal.
11690
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
59 * - implement term_list() list of buffers with a terminal
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
60 * - implement term_getsize(buf)
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
61 * - implement term_setsize(buf)
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
62 * - implement term_sendkeys(buf, keys) send keystrokes to a terminal
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
63 * - implement term_wait(buf) wait for screen to be updated
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
64 * - implement term_scrape(buf, row) inspect terminal screen
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
65 * - implement term_open(command, options) open terminal window
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
66 * - implement term_getjob(buf)
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
67 * - when 'encoding' is not utf-8, or the job is using another encoding, setup
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
68 * conversions.
11764
b82dad3fa176 patch 8.0.0764: 'termkey' does not work yet
Christian Brabandt <cb@256bit.org>
parents: 11757
diff changeset
69 * - In the GUI use a terminal emulator for :!cmd.
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
70 */
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
71
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
72 #include "vim.h"
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
73
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
74 #ifdef FEAT_TERMINAL
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
75
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
76 #ifdef WIN3264
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
77 # define MIN(x,y) (x < y ? x : y)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
78 # define MAX(x,y) (x > y ? x : y)
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
79 #endif
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
80
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
81 #include "libvterm/include/vterm.h"
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
82
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
83 /* typedef term_T in structs.h */
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
84 struct terminal_S {
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
85 term_T *tl_next;
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
86
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
87 #ifdef WIN3264
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
88 void *tl_winpty_config;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
89 void *tl_winpty;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
90 #endif
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
91 VTerm *tl_vterm;
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
92 job_T *tl_job;
11670
3b2afa2b77b3 patch 8.0.0718: output of job in terminal is not displayed
Christian Brabandt <cb@256bit.org>
parents: 11668
diff changeset
93 buf_T *tl_buffer;
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
94
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
95 /* last known vterm size */
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
96 int tl_rows;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
97 int tl_cols;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
98 /* vterm size does not follow window size */
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
99 int tl_rows_fixed;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
100 int tl_cols_fixed;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
101
11772
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
102 char_u *tl_title; /* NULL or allocated */
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
103 char_u *tl_status_text; /* NULL or allocated */
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
104
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
105 /* Range of screen rows to update. Zero based. */
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
106 int tl_dirty_row_start; /* -1 if nothing dirty */
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
107 int tl_dirty_row_end; /* row below last one to update */
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
108
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
109 pos_T tl_cursor;
11786
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
110 int tl_cursor_visible;
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
111 };
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
112
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
113 /*
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
114 * List of all active terminals.
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
115 */
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
116 static term_T *first_term = NULL;
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
117
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
118
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
119 #define MAX_ROW 999999 /* used for tl_dirty_row_end to update all rows */
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
120 #define KEY_BUF_LEN 200
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
121
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
122 /*
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
123 * Functions with separate implementation for MS-Windows and Unix-like systems.
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
124 */
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
125 static int term_and_job_init(term_T *term, int rows, int cols, char_u *cmd);
11753
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
126 static void term_report_winsize(term_T *term, int rows, int cols);
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
127 static void term_free(term_T *term);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
128
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
129 /**************************************
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
130 * 1. Generic code for all systems.
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
131 */
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
132
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
133 /*
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
134 * Determine the terminal size from 'termsize' and the current window.
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
135 * Assumes term->tl_rows and term->tl_cols are zero.
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
136 */
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
137 static void
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
138 set_term_and_win_size(term_T *term)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
139 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
140 if (*curwin->w_p_tms != NUL)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
141 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
142 char_u *p = vim_strchr(curwin->w_p_tms, 'x') + 1;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
143
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
144 term->tl_rows = atoi((char *)curwin->w_p_tms);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
145 term->tl_cols = atoi((char *)p);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
146 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
147 if (term->tl_rows == 0)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
148 term->tl_rows = curwin->w_height;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
149 else
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
150 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
151 win_setheight_win(term->tl_rows, curwin);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
152 term->tl_rows_fixed = TRUE;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
153 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
154 if (term->tl_cols == 0)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
155 term->tl_cols = curwin->w_width;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
156 else
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
157 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
158 win_setwidth_win(term->tl_cols, curwin);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
159 term->tl_cols_fixed = TRUE;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
160 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
161 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
162
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
163 /*
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
164 * ":terminal": open a terminal window and execute a job in it.
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
165 */
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
166 void
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
167 ex_terminal(exarg_T *eap)
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
168 {
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
169 exarg_T split_ea;
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
170 win_T *old_curwin = curwin;
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
171 term_T *term;
11729
1c8ec1029233 patch 8.0.0747: :terminal without an argument doesn't work
Christian Brabandt <cb@256bit.org>
parents: 11727
diff changeset
172 char_u *cmd = eap->arg;
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
173
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
174 if (check_restricted() || check_secure())
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
175 return;
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
176
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
177 term = (term_T *)alloc_clear(sizeof(term_T));
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
178 if (term == NULL)
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
179 return;
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
180 term->tl_dirty_row_end = MAX_ROW;
11786
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
181 term->tl_cursor_visible = TRUE;
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
182
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
183 /* Open a new window or tab. */
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
184 vim_memset(&split_ea, 0, sizeof(split_ea));
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
185 split_ea.cmdidx = CMD_new;
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
186 split_ea.cmd = (char_u *)"new";
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
187 split_ea.arg = (char_u *)"";
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
188 ex_splitview(&split_ea);
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
189 if (curwin == old_curwin)
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
190 {
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
191 /* split failed */
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
192 vim_free(term);
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
193 return;
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
194 }
11670
3b2afa2b77b3 patch 8.0.0718: output of job in terminal is not displayed
Christian Brabandt <cb@256bit.org>
parents: 11668
diff changeset
195 term->tl_buffer = curbuf;
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
196 curbuf->b_term = term;
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
197
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
198 /* Link the new terminal in the list of active terminals. */
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
199 term->tl_next = first_term;
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
200 first_term = term;
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
201
11794
2e7e77e28063 patch 8.0.0779: :term without an argument uses empty buffer name
Christian Brabandt <cb@256bit.org>
parents: 11792
diff changeset
202 if (cmd == NULL || *cmd == NUL)
2e7e77e28063 patch 8.0.0779: :term without an argument uses empty buffer name
Christian Brabandt <cb@256bit.org>
parents: 11792
diff changeset
203 cmd = p_sh;
2e7e77e28063 patch 8.0.0779: :term without an argument uses empty buffer name
Christian Brabandt <cb@256bit.org>
parents: 11792
diff changeset
204
11757
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
205 if (buflist_findname(cmd) == NULL)
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
206 curbuf->b_ffname = vim_strsave(cmd);
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
207 else
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
208 {
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
209 int i;
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
210 size_t len = STRLEN(cmd) + 10;
11790
4dfebc1b2674 patch 8.0.0777: compiler warnings with 64 bit compiler
Christian Brabandt <cb@256bit.org>
parents: 11786
diff changeset
211 char_u *p = alloc((int)len);
11757
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
212
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
213 for (i = 1; p != NULL; ++i)
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
214 {
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
215 vim_snprintf((char *)p, len, "%s (%d)", cmd, i);
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
216 if (buflist_findname(p) == NULL)
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
217 {
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
218 curbuf->b_ffname = p;
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
219 break;
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
220 }
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
221 }
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
222 }
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
223 curbuf->b_fname = curbuf->b_ffname;
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
224
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
225 /* Mark the buffer as changed, so that it's not easy to abandon the job. */
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
226 curbuf->b_changed = TRUE;
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
227 curbuf->b_p_ma = FALSE;
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
228 set_string_option_direct((char_u *)"buftype", -1,
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
229 (char_u *)"terminal", OPT_FREE|OPT_LOCAL, 0);
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
230
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
231 set_term_and_win_size(term);
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
232
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
233 /* System dependent: setup the vterm and start the job in it. */
11729
1c8ec1029233 patch 8.0.0747: :terminal without an argument doesn't work
Christian Brabandt <cb@256bit.org>
parents: 11727
diff changeset
234 if (term_and_job_init(term, term->tl_rows, term->tl_cols, cmd) == OK)
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
235 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
236 /* store the size we ended up with */
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
237 vterm_get_size(term->tl_vterm, &term->tl_rows, &term->tl_cols);
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
238 }
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
239 else
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
240 {
11727
cb1dc90d22cc patch 8.0.0746: when :term fails the job is not properly cleaned up
Christian Brabandt <cb@256bit.org>
parents: 11725
diff changeset
241 free_terminal(term);
cb1dc90d22cc patch 8.0.0746: when :term fails the job is not properly cleaned up
Christian Brabandt <cb@256bit.org>
parents: 11725
diff changeset
242 curbuf->b_term = NULL;
cb1dc90d22cc patch 8.0.0746: when :term fails the job is not properly cleaned up
Christian Brabandt <cb@256bit.org>
parents: 11725
diff changeset
243
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
244 /* Wiping out the buffer will also close the window and call
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
245 * free_terminal(). */
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
246 do_buffer(DOBUF_WIPE, DOBUF_CURRENT, FORWARD, 0, TRUE);
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
247 }
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
248
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
249 /* TODO: Setup pty, see mch_call_shell(). */
11670
3b2afa2b77b3 patch 8.0.0718: output of job in terminal is not displayed
Christian Brabandt <cb@256bit.org>
parents: 11668
diff changeset
250 }
3b2afa2b77b3 patch 8.0.0718: output of job in terminal is not displayed
Christian Brabandt <cb@256bit.org>
parents: 11668
diff changeset
251
3b2afa2b77b3 patch 8.0.0718: output of job in terminal is not displayed
Christian Brabandt <cb@256bit.org>
parents: 11668
diff changeset
252 /*
11690
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
253 * Free a terminal and everything it refers to.
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
254 * Kills the job if there is one.
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
255 * Called when wiping out a buffer.
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
256 */
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
257 void
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
258 free_terminal(term_T *term)
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
259 {
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
260 term_T *tp;
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
261
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
262 if (term == NULL)
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
263 return;
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
264 if (first_term == term)
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
265 first_term = term->tl_next;
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
266 else
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
267 for (tp = first_term; tp->tl_next != NULL; tp = tp->tl_next)
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
268 if (tp->tl_next == term)
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
269 {
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
270 tp->tl_next = term->tl_next;
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
271 break;
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
272 }
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
273
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
274 if (term->tl_job != NULL)
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
275 {
11727
cb1dc90d22cc patch 8.0.0746: when :term fails the job is not properly cleaned up
Christian Brabandt <cb@256bit.org>
parents: 11725
diff changeset
276 if (term->tl_job->jv_status != JOB_ENDED
cb1dc90d22cc patch 8.0.0746: when :term fails the job is not properly cleaned up
Christian Brabandt <cb@256bit.org>
parents: 11725
diff changeset
277 && term->tl_job->jv_status != JOB_FAILED)
11690
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
278 job_stop(term->tl_job, NULL, "kill");
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
279 job_unref(term->tl_job);
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
280 }
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
281
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
282 term_free(term);
11772
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
283 vim_free(term->tl_title);
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
284 vim_free(term->tl_status_text);
11690
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
285 vim_free(term);
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
286 }
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
287
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
288 /*
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
289 * Write job output "msg[len]" to the vterm.
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
290 */
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
291 static void
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
292 term_write_job_output(term_T *term, char_u *msg, size_t len)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
293 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
294 VTerm *vterm = term->tl_vterm;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
295 char_u *p;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
296 size_t done;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
297 size_t len_now;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
298
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
299 for (done = 0; done < len; done += len_now)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
300 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
301 for (p = msg + done; p < msg + len; )
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
302 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
303 if (*p == NL)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
304 break;
11790
4dfebc1b2674 patch 8.0.0777: compiler warnings with 64 bit compiler
Christian Brabandt <cb@256bit.org>
parents: 11786
diff changeset
305 p += utf_ptr2len_len(p, (int)(len - (p - msg)));
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
306 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
307 len_now = p - msg - done;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
308 vterm_input_write(vterm, (char *)msg + done, len_now);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
309 if (p < msg + len && *p == NL)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
310 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
311 /* Convert NL to CR-NL, that appears to work best. */
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
312 vterm_input_write(vterm, "\r\n", 2);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
313 ++len_now;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
314 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
315 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
316
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
317 /* this invokes the damage callbacks */
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
318 vterm_screen_flush_damage(vterm_obtain_screen(vterm));
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
319 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
320
11778
e8005055f845 patch 8.0.0771: cursor in terminal window not always updated in GUI
Christian Brabandt <cb@256bit.org>
parents: 11774
diff changeset
321 static void
11786
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
322 update_cursor(term_T *term, int redraw)
11778
e8005055f845 patch 8.0.0771: cursor in terminal window not always updated in GUI
Christian Brabandt <cb@256bit.org>
parents: 11774
diff changeset
323 {
e8005055f845 patch 8.0.0771: cursor in terminal window not always updated in GUI
Christian Brabandt <cb@256bit.org>
parents: 11774
diff changeset
324 setcursor();
11792
4bc1f94afc34 patch 8.0.0778: in a terminal the cursor may be hidden
Christian Brabandt <cb@256bit.org>
parents: 11790
diff changeset
325 if (redraw && term->tl_buffer == curbuf)
11786
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
326 {
11792
4bc1f94afc34 patch 8.0.0778: in a terminal the cursor may be hidden
Christian Brabandt <cb@256bit.org>
parents: 11790
diff changeset
327 if (term->tl_cursor_visible)
4bc1f94afc34 patch 8.0.0778: in a terminal the cursor may be hidden
Christian Brabandt <cb@256bit.org>
parents: 11790
diff changeset
328 cursor_on();
11786
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
329 out_flush();
11778
e8005055f845 patch 8.0.0771: cursor in terminal window not always updated in GUI
Christian Brabandt <cb@256bit.org>
parents: 11774
diff changeset
330 #ifdef FEAT_GUI
11792
4bc1f94afc34 patch 8.0.0778: in a terminal the cursor may be hidden
Christian Brabandt <cb@256bit.org>
parents: 11790
diff changeset
331 if (gui.in_use && term->tl_cursor_visible)
11786
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
332 gui_update_cursor(FALSE, FALSE);
11778
e8005055f845 patch 8.0.0771: cursor in terminal window not always updated in GUI
Christian Brabandt <cb@256bit.org>
parents: 11774
diff changeset
333 #endif
11786
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
334 }
11778
e8005055f845 patch 8.0.0771: cursor in terminal window not always updated in GUI
Christian Brabandt <cb@256bit.org>
parents: 11774
diff changeset
335 }
e8005055f845 patch 8.0.0771: cursor in terminal window not always updated in GUI
Christian Brabandt <cb@256bit.org>
parents: 11774
diff changeset
336
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
337 /*
11670
3b2afa2b77b3 patch 8.0.0718: output of job in terminal is not displayed
Christian Brabandt <cb@256bit.org>
parents: 11668
diff changeset
338 * Invoked when "msg" output from a job was received. Write it to the terminal
3b2afa2b77b3 patch 8.0.0718: output of job in terminal is not displayed
Christian Brabandt <cb@256bit.org>
parents: 11668
diff changeset
339 * of "buffer".
3b2afa2b77b3 patch 8.0.0718: output of job in terminal is not displayed
Christian Brabandt <cb@256bit.org>
parents: 11668
diff changeset
340 */
3b2afa2b77b3 patch 8.0.0718: output of job in terminal is not displayed
Christian Brabandt <cb@256bit.org>
parents: 11668
diff changeset
341 void
3b2afa2b77b3 patch 8.0.0718: output of job in terminal is not displayed
Christian Brabandt <cb@256bit.org>
parents: 11668
diff changeset
342 write_to_term(buf_T *buffer, char_u *msg, channel_T *channel)
3b2afa2b77b3 patch 8.0.0718: output of job in terminal is not displayed
Christian Brabandt <cb@256bit.org>
parents: 11668
diff changeset
343 {
3b2afa2b77b3 patch 8.0.0718: output of job in terminal is not displayed
Christian Brabandt <cb@256bit.org>
parents: 11668
diff changeset
344 size_t len = STRLEN(msg);
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
345 term_T *term = buffer->b_term;
11670
3b2afa2b77b3 patch 8.0.0718: output of job in terminal is not displayed
Christian Brabandt <cb@256bit.org>
parents: 11668
diff changeset
346
3b2afa2b77b3 patch 8.0.0718: output of job in terminal is not displayed
Christian Brabandt <cb@256bit.org>
parents: 11668
diff changeset
347 ch_logn(channel, "writing %d bytes to terminal", (int)len);
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
348 term_write_job_output(term, msg, len);
11670
3b2afa2b77b3 patch 8.0.0718: output of job in terminal is not displayed
Christian Brabandt <cb@256bit.org>
parents: 11668
diff changeset
349
3b2afa2b77b3 patch 8.0.0718: output of job in terminal is not displayed
Christian Brabandt <cb@256bit.org>
parents: 11668
diff changeset
350 /* TODO: only update once in a while. */
3b2afa2b77b3 patch 8.0.0718: output of job in terminal is not displayed
Christian Brabandt <cb@256bit.org>
parents: 11668
diff changeset
351 update_screen(0);
11786
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
352 update_cursor(term, TRUE);
11670
3b2afa2b77b3 patch 8.0.0718: output of job in terminal is not displayed
Christian Brabandt <cb@256bit.org>
parents: 11668
diff changeset
353 }
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
354
11670
3b2afa2b77b3 patch 8.0.0718: output of job in terminal is not displayed
Christian Brabandt <cb@256bit.org>
parents: 11668
diff changeset
355 /*
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
356 * Convert typed key "c" into bytes to send to the job.
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
357 * Return the number of bytes in "buf".
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
358 */
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
359 static int
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
360 term_convert_key(int c, char *buf)
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
361 {
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
362 VTerm *vterm = curbuf->b_term->tl_vterm;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
363 VTermKey key = VTERM_KEY_NONE;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
364 VTermModifier mod = VTERM_MOD_NONE;
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
365
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
366 switch (c)
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
367 {
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
368 case CAR: key = VTERM_KEY_ENTER; break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
369 case ESC: key = VTERM_KEY_ESCAPE; break;
11715
d7430b56c9ed patch 8.0.0740: cannot resize a terminal window by the command
Christian Brabandt <cb@256bit.org>
parents: 11713
diff changeset
370 /* VTERM_KEY_BACKSPACE becomes 0x7f DEL */
d7430b56c9ed patch 8.0.0740: cannot resize a terminal window by the command
Christian Brabandt <cb@256bit.org>
parents: 11713
diff changeset
371 case K_BS: c = BS; break;
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
372 case K_DEL: key = VTERM_KEY_DEL; break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
373 case K_DOWN: key = VTERM_KEY_DOWN; break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
374 case K_END: key = VTERM_KEY_END; break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
375 case K_F10: key = VTERM_KEY_FUNCTION(10); break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
376 case K_F11: key = VTERM_KEY_FUNCTION(11); break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
377 case K_F12: key = VTERM_KEY_FUNCTION(12); break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
378 case K_F1: key = VTERM_KEY_FUNCTION(1); break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
379 case K_F2: key = VTERM_KEY_FUNCTION(2); break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
380 case K_F3: key = VTERM_KEY_FUNCTION(3); break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
381 case K_F4: key = VTERM_KEY_FUNCTION(4); break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
382 case K_F5: key = VTERM_KEY_FUNCTION(5); break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
383 case K_F6: key = VTERM_KEY_FUNCTION(6); break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
384 case K_F7: key = VTERM_KEY_FUNCTION(7); break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
385 case K_F8: key = VTERM_KEY_FUNCTION(8); break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
386 case K_F9: key = VTERM_KEY_FUNCTION(9); break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
387 case K_HOME: key = VTERM_KEY_HOME; break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
388 case K_INS: key = VTERM_KEY_INS; break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
389 case K_K0: key = VTERM_KEY_KP_0; break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
390 case K_K1: key = VTERM_KEY_KP_1; break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
391 case K_K2: key = VTERM_KEY_KP_2; break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
392 case K_K3: key = VTERM_KEY_KP_3; break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
393 case K_K4: key = VTERM_KEY_KP_4; break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
394 case K_K5: key = VTERM_KEY_KP_5; break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
395 case K_K6: key = VTERM_KEY_KP_6; break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
396 case K_K7: key = VTERM_KEY_KP_7; break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
397 case K_K8: key = VTERM_KEY_KP_8; break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
398 case K_K9: key = VTERM_KEY_KP_9; break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
399 case K_KDEL: key = VTERM_KEY_DEL; break; /* TODO */
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
400 case K_KDIVIDE: key = VTERM_KEY_KP_DIVIDE; break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
401 case K_KEND: key = VTERM_KEY_KP_1; break; /* TODO */
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
402 case K_KENTER: key = VTERM_KEY_KP_ENTER; break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
403 case K_KHOME: key = VTERM_KEY_KP_7; break; /* TODO */
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
404 case K_KINS: key = VTERM_KEY_KP_0; break; /* TODO */
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
405 case K_KMINUS: key = VTERM_KEY_KP_MINUS; break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
406 case K_KMULTIPLY: key = VTERM_KEY_KP_MULT; break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
407 case K_KPAGEDOWN: key = VTERM_KEY_KP_3; break; /* TODO */
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
408 case K_KPAGEUP: key = VTERM_KEY_KP_9; break; /* TODO */
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
409 case K_KPLUS: key = VTERM_KEY_KP_PLUS; break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
410 case K_KPOINT: key = VTERM_KEY_KP_PERIOD; break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
411 case K_LEFT: key = VTERM_KEY_LEFT; break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
412 case K_PAGEDOWN: key = VTERM_KEY_PAGEDOWN; break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
413 case K_PAGEUP: key = VTERM_KEY_PAGEUP; break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
414 case K_RIGHT: key = VTERM_KEY_RIGHT; break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
415 case K_UP: key = VTERM_KEY_UP; break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
416 case TAB: key = VTERM_KEY_TAB; break;
11711
dac96f8800be patch 8.0.0738: cannot use the mouse to resize a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11694
diff changeset
417
dac96f8800be patch 8.0.0738: cannot use the mouse to resize a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11694
diff changeset
418 case K_MOUSEUP: /* TODO */ break;
dac96f8800be patch 8.0.0738: cannot use the mouse to resize a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11694
diff changeset
419 case K_MOUSEDOWN: /* TODO */ break;
dac96f8800be patch 8.0.0738: cannot use the mouse to resize a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11694
diff changeset
420 case K_MOUSELEFT: /* TODO */ break;
dac96f8800be patch 8.0.0738: cannot use the mouse to resize a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11694
diff changeset
421 case K_MOUSERIGHT: /* TODO */ break;
dac96f8800be patch 8.0.0738: cannot use the mouse to resize a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11694
diff changeset
422
dac96f8800be patch 8.0.0738: cannot use the mouse to resize a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11694
diff changeset
423 case K_LEFTMOUSE: /* TODO */ break;
dac96f8800be patch 8.0.0738: cannot use the mouse to resize a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11694
diff changeset
424 case K_LEFTMOUSE_NM: /* TODO */ break;
dac96f8800be patch 8.0.0738: cannot use the mouse to resize a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11694
diff changeset
425 case K_LEFTDRAG: /* TODO */ break;
dac96f8800be patch 8.0.0738: cannot use the mouse to resize a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11694
diff changeset
426 case K_LEFTRELEASE: /* TODO */ break;
dac96f8800be patch 8.0.0738: cannot use the mouse to resize a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11694
diff changeset
427 case K_LEFTRELEASE_NM: /* TODO */ break;
dac96f8800be patch 8.0.0738: cannot use the mouse to resize a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11694
diff changeset
428 case K_MIDDLEMOUSE: /* TODO */ break;
dac96f8800be patch 8.0.0738: cannot use the mouse to resize a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11694
diff changeset
429 case K_MIDDLEDRAG: /* TODO */ break;
dac96f8800be patch 8.0.0738: cannot use the mouse to resize a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11694
diff changeset
430 case K_MIDDLERELEASE: /* TODO */ break;
dac96f8800be patch 8.0.0738: cannot use the mouse to resize a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11694
diff changeset
431 case K_RIGHTMOUSE: /* TODO */ break;
dac96f8800be patch 8.0.0738: cannot use the mouse to resize a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11694
diff changeset
432 case K_RIGHTDRAG: /* TODO */ break;
dac96f8800be patch 8.0.0738: cannot use the mouse to resize a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11694
diff changeset
433 case K_RIGHTRELEASE: /* TODO */ break;
dac96f8800be patch 8.0.0738: cannot use the mouse to resize a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11694
diff changeset
434 case K_X1MOUSE: /* TODO */ break;
dac96f8800be patch 8.0.0738: cannot use the mouse to resize a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11694
diff changeset
435 case K_X1DRAG: /* TODO */ break;
dac96f8800be patch 8.0.0738: cannot use the mouse to resize a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11694
diff changeset
436 case K_X1RELEASE: /* TODO */ break;
dac96f8800be patch 8.0.0738: cannot use the mouse to resize a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11694
diff changeset
437 case K_X2MOUSE: /* TODO */ break;
dac96f8800be patch 8.0.0738: cannot use the mouse to resize a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11694
diff changeset
438 case K_X2DRAG: /* TODO */ break;
dac96f8800be patch 8.0.0738: cannot use the mouse to resize a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11694
diff changeset
439 case K_X2RELEASE: /* TODO */ break;
dac96f8800be patch 8.0.0738: cannot use the mouse to resize a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11694
diff changeset
440
dac96f8800be patch 8.0.0738: cannot use the mouse to resize a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11694
diff changeset
441 /* TODO: handle all special keys and modifiers that terminal_loop()
dac96f8800be patch 8.0.0738: cannot use the mouse to resize a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11694
diff changeset
442 * does not handle. */
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
443 }
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
444
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
445 /*
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
446 * Convert special keys to vterm keys:
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
447 * - Write keys to vterm: vterm_keyboard_key()
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
448 * - Write output to channel.
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
449 */
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
450 if (key != VTERM_KEY_NONE)
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
451 /* Special key, let vterm convert it. */
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
452 vterm_keyboard_key(vterm, key, mod);
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
453 else
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
454 /* Normal character, let vterm convert it. */
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
455 vterm_keyboard_unichar(vterm, c, mod);
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
456
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
457 /* Read back the converted escape sequence. */
11790
4dfebc1b2674 patch 8.0.0777: compiler warnings with 64 bit compiler
Christian Brabandt <cb@256bit.org>
parents: 11786
diff changeset
458 return (int)vterm_output_read(vterm, buf, KEY_BUF_LEN);
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
459 }
11684
1ce1376fbbf8 patch 8.0.0725: a terminal window does not handle keyboard input
Christian Brabandt <cb@256bit.org>
parents: 11670
diff changeset
460
1ce1376fbbf8 patch 8.0.0725: a terminal window does not handle keyboard input
Christian Brabandt <cb@256bit.org>
parents: 11670
diff changeset
461 /*
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
462 * Wait for input and send it to the job.
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
463 * Return when the start of a CTRL-W command is typed or anything else that
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
464 * should be handled as a Normal mode command.
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
465 */
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
466 void
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
467 terminal_loop(void)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
468 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
469 char buf[KEY_BUF_LEN];
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
470 int c;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
471 size_t len;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
472 static int mouse_was_outside = FALSE;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
473 int dragging_outside = FALSE;
11764
b82dad3fa176 patch 8.0.0764: 'termkey' does not work yet
Christian Brabandt <cb@256bit.org>
parents: 11757
diff changeset
474 int termkey = 0;
b82dad3fa176 patch 8.0.0764: 'termkey' does not work yet
Christian Brabandt <cb@256bit.org>
parents: 11757
diff changeset
475
b82dad3fa176 patch 8.0.0764: 'termkey' does not work yet
Christian Brabandt <cb@256bit.org>
parents: 11757
diff changeset
476 if (*curwin->w_p_tk != NUL)
b82dad3fa176 patch 8.0.0764: 'termkey' does not work yet
Christian Brabandt <cb@256bit.org>
parents: 11757
diff changeset
477 termkey = string_to_key(curwin->w_p_tk, TRUE);
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
478
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
479 for (;;)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
480 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
481 /* TODO: skip screen update when handling a sequence of keys. */
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
482 update_screen(0);
11786
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
483 update_cursor(curbuf->b_term, FALSE);
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
484 ++no_mapping;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
485 ++allow_keys;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
486 got_int = FALSE;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
487 c = vgetc();
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
488 --no_mapping;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
489 --allow_keys;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
490
11764
b82dad3fa176 patch 8.0.0764: 'termkey' does not work yet
Christian Brabandt <cb@256bit.org>
parents: 11757
diff changeset
491 if (c == (termkey == 0 ? Ctrl_W : termkey))
b82dad3fa176 patch 8.0.0764: 'termkey' does not work yet
Christian Brabandt <cb@256bit.org>
parents: 11757
diff changeset
492 {
b82dad3fa176 patch 8.0.0764: 'termkey' does not work yet
Christian Brabandt <cb@256bit.org>
parents: 11757
diff changeset
493 stuffcharReadbuff(Ctrl_W);
b82dad3fa176 patch 8.0.0764: 'termkey' does not work yet
Christian Brabandt <cb@256bit.org>
parents: 11757
diff changeset
494 return;
b82dad3fa176 patch 8.0.0764: 'termkey' does not work yet
Christian Brabandt <cb@256bit.org>
parents: 11757
diff changeset
495 }
b82dad3fa176 patch 8.0.0764: 'termkey' does not work yet
Christian Brabandt <cb@256bit.org>
parents: 11757
diff changeset
496
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
497 /* Catch keys that need to be handled as in Normal mode. */
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
498 switch (c)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
499 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
500 case NUL:
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
501 case K_ZERO:
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
502 stuffcharReadbuff(c);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
503 return;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
504
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
505 case K_IGNORE: continue;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
506
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
507 case K_LEFTDRAG:
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
508 case K_MIDDLEDRAG:
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
509 case K_RIGHTDRAG:
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
510 case K_X1DRAG:
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
511 case K_X2DRAG:
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
512 dragging_outside = mouse_was_outside;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
513 /* FALLTHROUGH */
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
514 case K_LEFTMOUSE:
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
515 case K_LEFTMOUSE_NM:
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
516 case K_LEFTRELEASE:
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
517 case K_LEFTRELEASE_NM:
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
518 case K_MIDDLEMOUSE:
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
519 case K_MIDDLERELEASE:
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
520 case K_RIGHTMOUSE:
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
521 case K_RIGHTRELEASE:
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
522 case K_X1MOUSE:
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
523 case K_X1RELEASE:
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
524 case K_X2MOUSE:
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
525 case K_X2RELEASE:
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
526 if (mouse_row < W_WINROW(curwin)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
527 || mouse_row >= (W_WINROW(curwin) + curwin->w_height)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
528 || mouse_col < W_WINCOL(curwin)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
529 || mouse_col >= W_ENDCOL(curwin)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
530 || dragging_outside)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
531 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
532 /* click outside the current window */
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
533 stuffcharReadbuff(c);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
534 mouse_was_outside = TRUE;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
535 return;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
536 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
537 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
538 mouse_was_outside = FALSE;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
539
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
540 /* Convert the typed key to a sequence of bytes for the job. */
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
541 len = term_convert_key(c, buf);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
542 if (len > 0)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
543 /* TODO: if FAIL is returned, stop? */
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
544 channel_send(curbuf->b_term->tl_job->jv_channel, PART_IN,
11790
4dfebc1b2674 patch 8.0.0777: compiler warnings with 64 bit compiler
Christian Brabandt <cb@256bit.org>
parents: 11786
diff changeset
545 (char_u *)buf, (int)len, NULL);
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
546 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
547 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
548
11757
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
549 /*
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
550 * Called when a job has finished.
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
551 */
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
552 void
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
553 term_job_ended(job_T *job)
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
554 {
11772
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
555 term_T *term;
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
556 int did_one = FALSE;
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
557
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
558 for (term = first_term; term != NULL; term = term->tl_next)
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
559 if (term->tl_job == job)
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
560 {
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
561 vim_free(term->tl_title);
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
562 term->tl_title = NULL;
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
563 vim_free(term->tl_status_text);
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
564 term->tl_status_text = NULL;
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
565 redraw_buf_and_status_later(term->tl_buffer, VALID);
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
566 did_one = TRUE;
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
567 }
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
568 if (did_one)
11786
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
569 redraw_statuslines();
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
570 if (curbuf->b_term != NULL)
11772
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
571 {
11786
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
572 if (curbuf->b_term->tl_job == job)
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
573 maketitle();
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
574 update_cursor(curbuf->b_term, TRUE);
11772
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
575 }
11757
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
576 }
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
577
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
578 /*
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
579 * Return TRUE if the job for "buf" is still running.
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
580 */
11772
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
581 static int
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
582 term_job_running(term_T *term)
11757
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
583 {
11772
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
584 return term->tl_job != NULL && term->tl_job->jv_status == JOB_STARTED;
11757
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
585 }
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
586
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
587 static void
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
588 position_cursor(win_T *wp, VTermPos *pos)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
589 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
590 wp->w_wrow = MIN(pos->row, MAX(0, wp->w_height - 1));
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
591 wp->w_wcol = MIN(pos->col, MAX(0, wp->w_width - 1));
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
592 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
593
11786
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
594 static void
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
595 may_toggle_cursor(term_T *term)
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
596 {
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
597 if (curbuf == term->tl_buffer)
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
598 {
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
599 if (term->tl_cursor_visible)
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
600 cursor_on();
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
601 else
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
602 cursor_off();
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
603 }
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
604 }
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
605
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
606 static int
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
607 handle_damage(VTermRect rect, void *user)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
608 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
609 term_T *term = (term_T *)user;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
610
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
611 term->tl_dirty_row_start = MIN(term->tl_dirty_row_start, rect.start_row);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
612 term->tl_dirty_row_end = MAX(term->tl_dirty_row_end, rect.end_row);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
613 redraw_buf_later(term->tl_buffer, NOT_VALID);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
614 return 1;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
615 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
616
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
617 static int
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
618 handle_moverect(VTermRect dest UNUSED, VTermRect src UNUSED, void *user)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
619 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
620 term_T *term = (term_T *)user;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
621
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
622 /* TODO */
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
623 redraw_buf_later(term->tl_buffer, NOT_VALID);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
624 return 1;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
625 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
626
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
627 static int
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
628 handle_movecursor(
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
629 VTermPos pos,
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
630 VTermPos oldpos UNUSED,
11786
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
631 int visible,
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
632 void *user)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
633 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
634 term_T *term = (term_T *)user;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
635 win_T *wp;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
636 int is_current = FALSE;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
637
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
638 FOR_ALL_WINDOWS(wp)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
639 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
640 if (wp->w_buffer == term->tl_buffer)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
641 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
642 position_cursor(wp, &pos);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
643 if (wp == curwin)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
644 is_current = TRUE;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
645 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
646 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
647
11786
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
648 term->tl_cursor_visible = visible;
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
649 if (is_current)
11786
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
650 {
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
651 may_toggle_cursor(term);
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
652 update_cursor(term, TRUE);
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
653 }
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
654
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
655 return 1;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
656 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
657
11772
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
658 static int
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
659 handle_settermprop(
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
660 VTermProp prop,
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
661 VTermValue *value,
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
662 void *user)
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
663 {
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
664 term_T *term = (term_T *)user;
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
665
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
666 switch (prop)
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
667 {
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
668 case VTERM_PROP_TITLE:
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
669 vim_free(term->tl_title);
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
670 term->tl_title = vim_strsave((char_u *)value->string);
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
671 vim_free(term->tl_status_text);
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
672 term->tl_status_text = NULL;
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
673 if (term == curbuf->b_term)
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
674 maketitle();
11786
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
675 break;
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
676
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
677 case VTERM_PROP_CURSORVISIBLE:
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
678 term->tl_cursor_visible = value->boolean;
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
679 may_toggle_cursor(term);
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
680 out_flush();
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
681 break;
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
682
11772
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
683 default:
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
684 break;
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
685 }
11786
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
686 /* Always return 1, otherwise vterm doesn't store the value internally. */
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
687 return 1;
11772
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
688 }
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
689
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
690 /*
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
691 * The job running in the terminal resized the terminal.
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
692 */
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
693 static int
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
694 handle_resize(int rows, int cols, void *user)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
695 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
696 term_T *term = (term_T *)user;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
697 win_T *wp;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
698
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
699 term->tl_rows = rows;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
700 term->tl_cols = cols;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
701 FOR_ALL_WINDOWS(wp)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
702 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
703 if (wp->w_buffer == term->tl_buffer)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
704 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
705 win_setheight_win(rows, wp);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
706 win_setwidth_win(cols, wp);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
707 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
708 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
709
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
710 redraw_buf_later(term->tl_buffer, NOT_VALID);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
711 return 1;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
712 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
713
11772
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
714 static VTermScreenCallbacks screen_callbacks = {
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
715 handle_damage, /* damage */
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
716 handle_moverect, /* moverect */
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
717 handle_movecursor, /* movecursor */
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
718 handle_settermprop, /* settermprop */
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
719 NULL, /* bell */
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
720 handle_resize, /* resize */
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
721 NULL, /* sb_pushline */
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
722 NULL /* sb_popline */
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
723 };
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
724
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
725 /*
11743
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
726 * Reverse engineer the RGB value into a cterm color index.
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
727 * First color is 1. Return 0 if no match found.
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
728 */
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
729 static int
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
730 color2index(VTermColor *color)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
731 {
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
732 int red = color->red;
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
733 int blue = color->blue;
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
734 int green = color->green;
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
735
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
736 if (red == 0)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
737 {
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
738 if (green == 0)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
739 {
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
740 if (blue == 0)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
741 return 1; /* black */
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
742 if (blue == 224)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
743 return 5; /* blue */
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
744 }
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
745 else if (green == 224)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
746 {
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
747 if (blue == 0)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
748 return 3; /* green */
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
749 if (blue == 224)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
750 return 7; /* cyan */
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
751 }
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
752 }
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
753 else if (red == 224)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
754 {
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
755 if (green == 0)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
756 {
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
757 if (blue == 0)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
758 return 2; /* red */
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
759 if (blue == 224)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
760 return 6; /* magenta */
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
761 }
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
762 else if (green == 224)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
763 {
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
764 if (blue == 0)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
765 return 4; /* yellow */
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
766 if (blue == 224)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
767 return 8; /* white */
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
768 }
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
769 }
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
770 else if (red == 128)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
771 {
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
772 if (green == 128 && blue == 128)
11774
edf1a2a247fa patch 8.0.0769: build problems with terminal on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11772
diff changeset
773 return 9; /* high intensity black */
11743
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
774 }
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
775 else if (red == 255)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
776 {
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
777 if (green == 64)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
778 {
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
779 if (blue == 64)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
780 return 10; /* high intensity red */
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
781 if (blue == 255)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
782 return 14; /* high intensity magenta */
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
783 }
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
784 else if (green == 255)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
785 {
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
786 if (blue == 64)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
787 return 12; /* high intensity yellow */
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
788 if (blue == 255)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
789 return 16; /* high intensity white */
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
790 }
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
791 }
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
792 else if (red == 64)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
793 {
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
794 if (green == 64)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
795 {
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
796 if (blue == 255)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
797 return 13; /* high intensity blue */
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
798 }
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
799 else if (green == 255)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
800 {
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
801 if (blue == 64)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
802 return 11; /* high intensity green */
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
803 if (blue == 255)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
804 return 15; /* high intensity cyan */
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
805 }
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
806 }
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
807 if (t_colors >= 256)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
808 {
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
809 if (red == blue && red == green)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
810 {
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
811 /* 24-color greyscale */
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
812 static int cutoff[23] = {
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
813 0x05, 0x10, 0x1B, 0x26, 0x31, 0x3C, 0x47, 0x52,
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
814 0x5D, 0x68, 0x73, 0x7F, 0x8A, 0x95, 0xA0, 0xAB,
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
815 0xB6, 0xC1, 0xCC, 0xD7, 0xE2, 0xED, 0xF9};
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
816 int i;
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
817
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
818 for (i = 0; i < 23; ++i)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
819 if (red < cutoff[i])
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
820 return i + 233;
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
821 return 256;
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
822 }
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
823
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
824 /* 216-color cube */
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
825 return 17 + ((red + 25) / 0x33) * 36
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
826 + ((green + 25) / 0x33) * 6
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
827 + (blue + 25) / 0x33;
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
828 }
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
829 return 0;
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
830 }
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
831
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
832 /*
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
833 * Convert the attributes of a vterm cell into an attribute index.
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
834 */
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
835 static int
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
836 cell2attr(VTermScreenCell *cell)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
837 {
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
838 int attr = 0;
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
839
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
840 if (cell->attrs.bold)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
841 attr |= HL_BOLD;
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
842 if (cell->attrs.underline)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
843 attr |= HL_UNDERLINE;
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
844 if (cell->attrs.italic)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
845 attr |= HL_ITALIC;
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
846 if (cell->attrs.strike)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
847 attr |= HL_STANDOUT;
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
848 if (cell->attrs.reverse)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
849 attr |= HL_INVERSE;
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
850 if (cell->attrs.strike)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
851 attr |= HL_UNDERLINE;
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
852
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
853 #ifdef FEAT_GUI
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
854 if (gui.in_use)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
855 {
11745
5a5709918a98 patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents: 11743
diff changeset
856 guicolor_T fg, bg;
5a5709918a98 patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents: 11743
diff changeset
857
5a5709918a98 patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents: 11743
diff changeset
858 fg = gui_mch_get_rgb_color(cell->fg.red, cell->fg.green, cell->fg.blue);
5a5709918a98 patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents: 11743
diff changeset
859 bg = gui_mch_get_rgb_color(cell->bg.red, cell->bg.green, cell->bg.blue);
5a5709918a98 patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents: 11743
diff changeset
860 return get_gui_attr_idx(attr, fg, bg);
11743
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
861 }
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
862 else
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
863 #endif
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
864 #ifdef FEAT_TERMGUICOLORS
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
865 if (p_tgc)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
866 {
11755
12fa6072977a patch 8.0.0760: terminal window colors wrong with 'termguicolors'
Christian Brabandt <cb@256bit.org>
parents: 11753
diff changeset
867 guicolor_T fg, bg;
12fa6072977a patch 8.0.0760: terminal window colors wrong with 'termguicolors'
Christian Brabandt <cb@256bit.org>
parents: 11753
diff changeset
868
12fa6072977a patch 8.0.0760: terminal window colors wrong with 'termguicolors'
Christian Brabandt <cb@256bit.org>
parents: 11753
diff changeset
869 fg = gui_get_rgb_color_cmn(cell->fg.red, cell->fg.green, cell->fg.blue);
12fa6072977a patch 8.0.0760: terminal window colors wrong with 'termguicolors'
Christian Brabandt <cb@256bit.org>
parents: 11753
diff changeset
870 bg = gui_get_rgb_color_cmn(cell->bg.red, cell->bg.green, cell->bg.blue);
12fa6072977a patch 8.0.0760: terminal window colors wrong with 'termguicolors'
Christian Brabandt <cb@256bit.org>
parents: 11753
diff changeset
871
12fa6072977a patch 8.0.0760: terminal window colors wrong with 'termguicolors'
Christian Brabandt <cb@256bit.org>
parents: 11753
diff changeset
872 return get_tgc_attr_idx(attr, fg, bg);
11743
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
873 }
11755
12fa6072977a patch 8.0.0760: terminal window colors wrong with 'termguicolors'
Christian Brabandt <cb@256bit.org>
parents: 11753
diff changeset
874 else
11743
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
875 #endif
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
876 {
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
877 return get_cterm_attr_idx(attr, color2index(&cell->fg),
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
878 color2index(&cell->bg));
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
879 }
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
880 return 0;
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
881 }
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
882
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
883 /*
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
884 * Called to update the window that contains the terminal.
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
885 */
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
886 void
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
887 term_update_window(win_T *wp)
11684
1ce1376fbbf8 patch 8.0.0725: a terminal window does not handle keyboard input
Christian Brabandt <cb@256bit.org>
parents: 11670
diff changeset
888 {
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
889 term_T *term = wp->w_buffer->b_term;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
890 VTerm *vterm = term->tl_vterm;
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
891 VTermScreen *screen = vterm_obtain_screen(vterm);
11713
2ec27561dd76 patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents: 11711
diff changeset
892 VTermState *state = vterm_obtain_state(vterm);
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
893 VTermPos pos;
11684
1ce1376fbbf8 patch 8.0.0725: a terminal window does not handle keyboard input
Christian Brabandt <cb@256bit.org>
parents: 11670
diff changeset
894
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
895 /*
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
896 * If the window was resized a redraw will be triggered and we get here.
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
897 * Adjust the size of the vterm unless 'termsize' specifies a fixed size.
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
898 */
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
899 if ((!term->tl_rows_fixed && term->tl_rows != wp->w_height)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
900 || (!term->tl_cols_fixed && term->tl_cols != wp->w_width))
11741
b4d8f956eb18 patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents: 11729
diff changeset
901 {
b4d8f956eb18 patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents: 11729
diff changeset
902 int rows = term->tl_rows_fixed ? term->tl_rows : wp->w_height;
b4d8f956eb18 patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents: 11729
diff changeset
903 int cols = term->tl_cols_fixed ? term->tl_cols : wp->w_width;
b4d8f956eb18 patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents: 11729
diff changeset
904
b4d8f956eb18 patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents: 11729
diff changeset
905 vterm_set_size(vterm, rows, cols);
b4d8f956eb18 patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents: 11729
diff changeset
906 ch_logn(term->tl_job->jv_channel, "Resizing terminal to %d lines",
b4d8f956eb18 patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents: 11729
diff changeset
907 rows);
11753
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
908 term_report_winsize(term, rows, cols);
11741
b4d8f956eb18 patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents: 11729
diff changeset
909 }
11713
2ec27561dd76 patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents: 11711
diff changeset
910
2ec27561dd76 patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents: 11711
diff changeset
911 /* The cursor may have been moved when resizing. */
2ec27561dd76 patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents: 11711
diff changeset
912 vterm_state_get_cursorpos(state, &pos);
2ec27561dd76 patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents: 11711
diff changeset
913 position_cursor(wp, &pos);
2ec27561dd76 patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents: 11711
diff changeset
914
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
915 /* TODO: Only redraw what changed. */
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
916 for (pos.row = 0; pos.row < wp->w_height; ++pos.row)
11684
1ce1376fbbf8 patch 8.0.0725: a terminal window does not handle keyboard input
Christian Brabandt <cb@256bit.org>
parents: 11670
diff changeset
917 {
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
918 int off = screen_get_current_line_off();
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
919 int max_col = MIN(wp->w_width, term->tl_cols);
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
920
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
921 if (pos.row < term->tl_rows)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
922 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
923 for (pos.col = 0; pos.col < max_col; )
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
924 {
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
925 VTermScreenCell cell;
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
926 int c;
11684
1ce1376fbbf8 patch 8.0.0725: a terminal window does not handle keyboard input
Christian Brabandt <cb@256bit.org>
parents: 11670
diff changeset
927
11743
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
928 if (vterm_screen_get_cell(screen, pos, &cell) == 0)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
929 vim_memset(&cell, 0, sizeof(cell));
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
930
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
931 /* TODO: composing chars */
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
932 c = cell.chars[0];
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
933 if (c == NUL)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
934 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
935 ScreenLines[off] = ' ';
11774
edf1a2a247fa patch 8.0.0769: build problems with terminal on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11772
diff changeset
936 #if defined(FEAT_MBYTE)
edf1a2a247fa patch 8.0.0769: build problems with terminal on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11772
diff changeset
937 if (enc_utf8)
edf1a2a247fa patch 8.0.0769: build problems with terminal on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11772
diff changeset
938 ScreenLinesUC[off] = NUL;
edf1a2a247fa patch 8.0.0769: build problems with terminal on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11772
diff changeset
939 #endif
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
940 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
941 else
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
942 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
943 #if defined(FEAT_MBYTE)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
944 if (enc_utf8 && c >= 0x80)
11725
22cef8face93 patch 8.0.0745: multi-byte characters in a terminal don't display well
Christian Brabandt <cb@256bit.org>
parents: 11723
diff changeset
945 {
22cef8face93 patch 8.0.0745: multi-byte characters in a terminal don't display well
Christian Brabandt <cb@256bit.org>
parents: 11723
diff changeset
946 ScreenLines[off] = ' ';
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
947 ScreenLinesUC[off] = c;
11725
22cef8face93 patch 8.0.0745: multi-byte characters in a terminal don't display well
Christian Brabandt <cb@256bit.org>
parents: 11723
diff changeset
948 }
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
949 else
11725
22cef8face93 patch 8.0.0745: multi-byte characters in a terminal don't display well
Christian Brabandt <cb@256bit.org>
parents: 11723
diff changeset
950 {
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
951 ScreenLines[off] = c;
11774
edf1a2a247fa patch 8.0.0769: build problems with terminal on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11772
diff changeset
952 if (enc_utf8)
edf1a2a247fa patch 8.0.0769: build problems with terminal on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11772
diff changeset
953 ScreenLinesUC[off] = NUL;
11725
22cef8face93 patch 8.0.0745: multi-byte characters in a terminal don't display well
Christian Brabandt <cb@256bit.org>
parents: 11723
diff changeset
954 }
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
955 #else
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
956 ScreenLines[off] = c;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
957 #endif
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
958 }
11743
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
959 ScreenAttrs[off] = cell2attr(&cell);
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
960
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
961 ++pos.col;
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
962 ++off;
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
963 if (cell.width == 2)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
964 {
11725
22cef8face93 patch 8.0.0745: multi-byte characters in a terminal don't display well
Christian Brabandt <cb@256bit.org>
parents: 11723
diff changeset
965 ScreenLines[off] = NUL;
11774
edf1a2a247fa patch 8.0.0769: build problems with terminal on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11772
diff changeset
966 #if defined(FEAT_MBYTE)
edf1a2a247fa patch 8.0.0769: build problems with terminal on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11772
diff changeset
967 if (enc_utf8)
edf1a2a247fa patch 8.0.0769: build problems with terminal on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11772
diff changeset
968 ScreenLinesUC[off] = NUL;
edf1a2a247fa patch 8.0.0769: build problems with terminal on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11772
diff changeset
969 #endif
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
970 ++pos.col;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
971 ++off;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
972 }
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
973 }
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
974 }
11711
dac96f8800be patch 8.0.0738: cannot use the mouse to resize a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11694
diff changeset
975 else
dac96f8800be patch 8.0.0738: cannot use the mouse to resize a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11694
diff changeset
976 pos.col = 0;
11684
1ce1376fbbf8 patch 8.0.0725: a terminal window does not handle keyboard input
Christian Brabandt <cb@256bit.org>
parents: 11670
diff changeset
977
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
978 screen_line(wp->w_winrow + pos.row, wp->w_wincol,
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
979 pos.col, wp->w_width, FALSE);
11684
1ce1376fbbf8 patch 8.0.0725: a terminal window does not handle keyboard input
Christian Brabandt <cb@256bit.org>
parents: 11670
diff changeset
980 }
1ce1376fbbf8 patch 8.0.0725: a terminal window does not handle keyboard input
Christian Brabandt <cb@256bit.org>
parents: 11670
diff changeset
981 }
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
982
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
983 /*
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
984 * Set job options common for Unix and MS-Windows.
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
985 */
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
986 static void
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
987 setup_job_options(jobopt_T *opt, int rows, int cols)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
988 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
989 clear_job_options(opt);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
990 opt->jo_mode = MODE_RAW;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
991 opt->jo_out_mode = MODE_RAW;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
992 opt->jo_err_mode = MODE_RAW;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
993 opt->jo_set = JO_MODE | JO_OUT_MODE | JO_ERR_MODE;
11757
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
994
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
995 opt->jo_io[PART_OUT] = JIO_BUFFER;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
996 opt->jo_io[PART_ERR] = JIO_BUFFER;
11757
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
997 opt->jo_set |= JO_OUT_IO + JO_ERR_IO;
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
998
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
999 opt->jo_modifiable[PART_OUT] = 0;
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
1000 opt->jo_modifiable[PART_ERR] = 0;
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
1001 opt->jo_set |= JO_OUT_MODIFIABLE + JO_ERR_MODIFIABLE;
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
1002
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1003 opt->jo_io_buf[PART_OUT] = curbuf->b_fnum;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1004 opt->jo_io_buf[PART_ERR] = curbuf->b_fnum;
11723
1922710ee8fa patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents: 11719
diff changeset
1005 opt->jo_pty = TRUE;
11757
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
1006 opt->jo_set |= JO_OUT_BUF + JO_ERR_BUF;
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
1007
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1008 opt->jo_term_rows = rows;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1009 opt->jo_term_cols = cols;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1010 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1011
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1012 /*
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1013 * Create a new vterm and initialize it.
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1014 */
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1015 static void
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1016 create_vterm(term_T *term, int rows, int cols)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1017 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1018 VTerm *vterm;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1019 VTermScreen *screen;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1020
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1021 vterm = vterm_new(rows, cols);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1022 term->tl_vterm = vterm;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1023 screen = vterm_obtain_screen(vterm);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1024 vterm_screen_set_callbacks(screen, &screen_callbacks, term);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1025 /* TODO: depends on 'encoding'. */
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1026 vterm_set_utf8(vterm, 1);
11743
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1027
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1028 /* Vterm uses a default black background. Set it to white when
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1029 * 'background' is "light". */
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1030 if (*p_bg == 'l')
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1031 {
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1032 VTermColor fg, bg;
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1033
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1034 fg.red = fg.green = fg.blue = 0;
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1035 bg.red = bg.green = bg.blue = 255;
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1036 vterm_state_set_default_colors(vterm_obtain_state(vterm), &fg, &bg);
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1037 }
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1038
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1039 /* Required to initialize most things. */
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1040 vterm_screen_reset(screen, 1 /* hard */);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1041 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1042
11772
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1043 /*
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1044 * Return the text to show for the buffer name and status.
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1045 */
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1046 char_u *
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1047 term_get_status_text(term_T *term)
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1048 {
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1049 if (term->tl_status_text == NULL)
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1050 {
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1051 char_u *txt;
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1052 size_t len;
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1053
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1054 if (term->tl_title != NULL)
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1055 txt = term->tl_title;
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1056 else if (term_job_running(term))
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1057 txt = (char_u *)_("running");
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1058 else
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1059 txt = (char_u *)_("finished");
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1060 len = 9 + STRLEN(term->tl_buffer->b_fname) + STRLEN(txt);
11790
4dfebc1b2674 patch 8.0.0777: compiler warnings with 64 bit compiler
Christian Brabandt <cb@256bit.org>
parents: 11786
diff changeset
1061 term->tl_status_text = alloc((int)len);
11772
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1062 if (term->tl_status_text != NULL)
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1063 vim_snprintf((char *)term->tl_status_text, len, "%s [%s]",
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1064 term->tl_buffer->b_fname, txt);
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1065 }
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1066 return term->tl_status_text;
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1067 }
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1068
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1069 # ifdef WIN3264
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1070
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1071 #define WINPTY_SPAWN_FLAG_AUTO_SHUTDOWN 1ul
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1072 #define WINPTY_SPAWN_FLAG_EXIT_AFTER_SHUTDOWN 2ull
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1073
11774
edf1a2a247fa patch 8.0.0769: build problems with terminal on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11772
diff changeset
1074 void* (*winpty_config_new)(UINT64, void*);
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1075 void* (*winpty_open)(void*, void*);
11774
edf1a2a247fa patch 8.0.0769: build problems with terminal on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11772
diff changeset
1076 void* (*winpty_spawn_config_new)(UINT64, void*, LPCWSTR, void*, void*, void*);
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1077 BOOL (*winpty_spawn)(void*, void*, HANDLE*, HANDLE*, DWORD*, void*);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1078 void (*winpty_config_set_initial_size)(void*, int, int);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1079 LPCWSTR (*winpty_conin_name)(void*);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1080 LPCWSTR (*winpty_conout_name)(void*);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1081 LPCWSTR (*winpty_conerr_name)(void*);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1082 void (*winpty_free)(void*);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1083 void (*winpty_config_free)(void*);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1084 void (*winpty_spawn_config_free)(void*);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1085 void (*winpty_error_free)(void*);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1086 LPCWSTR (*winpty_error_msg)(void*);
11753
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
1087 BOOL (*winpty_set_size)(void*, int, int, void*);
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1088
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1089 /**************************************
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1090 * 2. MS-Windows implementation.
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1091 */
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1092
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1093 #define WINPTY_DLL "winpty.dll"
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1094
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1095 static HINSTANCE hWinPtyDLL = NULL;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1096
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1097 int
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1098 dyn_winpty_init(void)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1099 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1100 int i;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1101 static struct
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1102 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1103 char *name;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1104 FARPROC *ptr;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1105 } winpty_entry[] =
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1106 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1107 {"winpty_conerr_name", (FARPROC*)&winpty_conerr_name},
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1108 {"winpty_config_free", (FARPROC*)&winpty_config_free},
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1109 {"winpty_config_new", (FARPROC*)&winpty_config_new},
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1110 {"winpty_config_set_initial_size", (FARPROC*)&winpty_config_set_initial_size},
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1111 {"winpty_conin_name", (FARPROC*)&winpty_conin_name},
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1112 {"winpty_conout_name", (FARPROC*)&winpty_conout_name},
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1113 {"winpty_error_free", (FARPROC*)&winpty_error_free},
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1114 {"winpty_free", (FARPROC*)&winpty_free},
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1115 {"winpty_open", (FARPROC*)&winpty_open},
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1116 {"winpty_spawn", (FARPROC*)&winpty_spawn},
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1117 {"winpty_spawn_config_free", (FARPROC*)&winpty_spawn_config_free},
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1118 {"winpty_spawn_config_new", (FARPROC*)&winpty_spawn_config_new},
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1119 {"winpty_error_msg", (FARPROC*)&winpty_error_msg},
11753
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
1120 {"winpty_set_size", (FARPROC*)&winpty_set_size},
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1121 {NULL, NULL}
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1122 };
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1123
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1124 /* No need to initialize twice. */
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1125 if (hWinPtyDLL)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1126 return 1;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1127 /* Load winpty.dll */
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1128 hWinPtyDLL = vimLoadLib(WINPTY_DLL);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1129 if (!hWinPtyDLL)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1130 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1131 EMSG2(_(e_loadlib), WINPTY_DLL);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1132 return 0;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1133 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1134 for (i = 0; winpty_entry[i].name != NULL
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1135 && winpty_entry[i].ptr != NULL; ++i)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1136 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1137 if ((*winpty_entry[i].ptr = (FARPROC)GetProcAddress(hWinPtyDLL,
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1138 winpty_entry[i].name)) == NULL)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1139 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1140 EMSG2(_(e_loadfunc), winpty_entry[i].name);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1141 return 0;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1142 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1143 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1144
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1145 return 1;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1146 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1147
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1148 /*
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1149 * Create a new terminal of "rows" by "cols" cells.
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1150 * Store a reference in "term".
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1151 * Return OK or FAIL.
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1152 */
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1153 static int
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1154 term_and_job_init(term_T *term, int rows, int cols, char_u *cmd)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1155 {
11798
4d545cd33f0a patch 8.0.0781: MS-Windows: memory leak when using :terminal
Christian Brabandt <cb@256bit.org>
parents: 11794
diff changeset
1156 WCHAR *p;
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1157 channel_T *channel = NULL;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1158 job_T *job = NULL;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1159 jobopt_T opt;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1160 DWORD error;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1161 HANDLE jo = NULL, child_process_handle, child_thread_handle;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1162 void *winpty_err;
11798
4d545cd33f0a patch 8.0.0781: MS-Windows: memory leak when using :terminal
Christian Brabandt <cb@256bit.org>
parents: 11794
diff changeset
1163 void *spawn_config = NULL;
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1164
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1165 if (!dyn_winpty_init())
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1166 return FAIL;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1167
11798
4d545cd33f0a patch 8.0.0781: MS-Windows: memory leak when using :terminal
Christian Brabandt <cb@256bit.org>
parents: 11794
diff changeset
1168 p = enc_to_utf16(cmd, NULL);
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1169 if (p == NULL)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1170 return FAIL;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1171
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1172 job = job_alloc();
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1173 if (job == NULL)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1174 goto failed;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1175
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1176 channel = add_channel();
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1177 if (channel == NULL)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1178 goto failed;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1179
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1180 term->tl_winpty_config = winpty_config_new(0, &winpty_err);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1181 if (term->tl_winpty_config == NULL)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1182 goto failed;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1183
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1184 winpty_config_set_initial_size(term->tl_winpty_config, cols, rows);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1185 term->tl_winpty = winpty_open(term->tl_winpty_config, &winpty_err);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1186 if (term->tl_winpty == NULL)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1187 goto failed;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1188
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1189 spawn_config = winpty_spawn_config_new(
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1190 WINPTY_SPAWN_FLAG_AUTO_SHUTDOWN |
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1191 WINPTY_SPAWN_FLAG_EXIT_AFTER_SHUTDOWN,
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1192 NULL,
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1193 p,
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1194 NULL,
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1195 NULL,
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1196 &winpty_err);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1197 if (spawn_config == NULL)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1198 goto failed;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1199
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1200 channel = add_channel();
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1201 if (channel == NULL)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1202 goto failed;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1203
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1204 job = job_alloc();
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1205 if (job == NULL)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1206 goto failed;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1207
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1208 if (!winpty_spawn(term->tl_winpty, spawn_config, &child_process_handle,
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1209 &child_thread_handle, &error, &winpty_err))
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1210 goto failed;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1211
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1212 channel_set_pipes(channel,
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1213 (sock_T) CreateFileW(
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1214 winpty_conin_name(term->tl_winpty),
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1215 GENERIC_WRITE, 0, NULL,
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1216 OPEN_EXISTING, 0, NULL),
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1217 (sock_T) CreateFileW(
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1218 winpty_conout_name(term->tl_winpty),
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1219 GENERIC_READ, 0, NULL,
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1220 OPEN_EXISTING, 0, NULL),
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1221 (sock_T) CreateFileW(
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1222 winpty_conerr_name(term->tl_winpty),
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1223 GENERIC_READ, 0, NULL,
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1224 OPEN_EXISTING, 0, NULL));
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1225
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1226 jo = CreateJobObject(NULL, NULL);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1227 if (jo == NULL)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1228 goto failed;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1229
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1230 if (!AssignProcessToJobObject(jo, child_process_handle))
11798
4d545cd33f0a patch 8.0.0781: MS-Windows: memory leak when using :terminal
Christian Brabandt <cb@256bit.org>
parents: 11794
diff changeset
1231 {
4d545cd33f0a patch 8.0.0781: MS-Windows: memory leak when using :terminal
Christian Brabandt <cb@256bit.org>
parents: 11794
diff changeset
1232 /* Failed, switch the way to terminate process with TerminateProcess. */
4d545cd33f0a patch 8.0.0781: MS-Windows: memory leak when using :terminal
Christian Brabandt <cb@256bit.org>
parents: 11794
diff changeset
1233 CloseHandle(jo);
4d545cd33f0a patch 8.0.0781: MS-Windows: memory leak when using :terminal
Christian Brabandt <cb@256bit.org>
parents: 11794
diff changeset
1234 jo = NULL;
4d545cd33f0a patch 8.0.0781: MS-Windows: memory leak when using :terminal
Christian Brabandt <cb@256bit.org>
parents: 11794
diff changeset
1235 }
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1236
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1237 winpty_spawn_config_free(spawn_config);
11798
4d545cd33f0a patch 8.0.0781: MS-Windows: memory leak when using :terminal
Christian Brabandt <cb@256bit.org>
parents: 11794
diff changeset
1238 vim_free(p);
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1239
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1240 create_vterm(term, rows, cols);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1241
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1242 setup_job_options(&opt, rows, cols);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1243 channel_set_job(channel, job, &opt);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1244
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1245 job->jv_channel = channel;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1246 job->jv_proc_info.hProcess = child_process_handle;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1247 job->jv_proc_info.dwProcessId = GetProcessId(child_process_handle);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1248 job->jv_job_object = jo;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1249 job->jv_status = JOB_STARTED;
11802
b1fd49b4eea7 patch 8.0.0783: job of terminal may be freed too early
Christian Brabandt <cb@256bit.org>
parents: 11798
diff changeset
1250 ++job->jv_refcount;
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1251 term->tl_job = job;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1252
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1253 return OK;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1254
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1255 failed:
11798
4d545cd33f0a patch 8.0.0781: MS-Windows: memory leak when using :terminal
Christian Brabandt <cb@256bit.org>
parents: 11794
diff changeset
1256 if (spawn_config != NULL)
4d545cd33f0a patch 8.0.0781: MS-Windows: memory leak when using :terminal
Christian Brabandt <cb@256bit.org>
parents: 11794
diff changeset
1257 winpty_spawn_config_free(spawn_config);
4d545cd33f0a patch 8.0.0781: MS-Windows: memory leak when using :terminal
Christian Brabandt <cb@256bit.org>
parents: 11794
diff changeset
1258 vim_free(p);
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1259 if (channel != NULL)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1260 channel_clear(channel);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1261 if (job != NULL)
11751
a1815c4f8b70 patch 8.0.0758: possible crash when using a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11745
diff changeset
1262 {
a1815c4f8b70 patch 8.0.0758: possible crash when using a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11745
diff changeset
1263 job->jv_channel = NULL;
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1264 job_cleanup(job);
11751
a1815c4f8b70 patch 8.0.0758: possible crash when using a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11745
diff changeset
1265 }
a1815c4f8b70 patch 8.0.0758: possible crash when using a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11745
diff changeset
1266 term->tl_job = NULL;
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1267 if (jo != NULL)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1268 CloseHandle(jo);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1269 if (term->tl_winpty != NULL)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1270 winpty_free(term->tl_winpty);
11751
a1815c4f8b70 patch 8.0.0758: possible crash when using a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11745
diff changeset
1271 term->tl_winpty = NULL;
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1272 if (term->tl_winpty_config != NULL)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1273 winpty_config_free(term->tl_winpty_config);
11751
a1815c4f8b70 patch 8.0.0758: possible crash when using a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11745
diff changeset
1274 term->tl_winpty_config = NULL;
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1275 if (winpty_err != NULL)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1276 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1277 char_u *msg = utf16_to_enc(
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1278 (short_u *)winpty_error_msg(winpty_err), NULL);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1279
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1280 EMSG(msg);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1281 winpty_error_free(winpty_err);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1282 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1283 return FAIL;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1284 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1285
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1286 /*
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1287 * Free the terminal emulator part of "term".
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1288 */
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1289 static void
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1290 term_free(term_T *term)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1291 {
11751
a1815c4f8b70 patch 8.0.0758: possible crash when using a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11745
diff changeset
1292 if (term->tl_winpty != NULL)
a1815c4f8b70 patch 8.0.0758: possible crash when using a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11745
diff changeset
1293 winpty_free(term->tl_winpty);
a1815c4f8b70 patch 8.0.0758: possible crash when using a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11745
diff changeset
1294 if (term->tl_winpty_config != NULL)
a1815c4f8b70 patch 8.0.0758: possible crash when using a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11745
diff changeset
1295 winpty_config_free(term->tl_winpty_config);
a1815c4f8b70 patch 8.0.0758: possible crash when using a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11745
diff changeset
1296 if (term->tl_vterm != NULL)
a1815c4f8b70 patch 8.0.0758: possible crash when using a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11745
diff changeset
1297 vterm_free(term->tl_vterm);
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1298 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1299
11753
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
1300 /*
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
1301 * Request size to terminal.
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
1302 */
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
1303 static void
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
1304 term_report_winsize(term_T *term, int rows, int cols)
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
1305 {
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
1306 winpty_set_size(term->tl_winpty, cols, rows, NULL);
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
1307 }
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
1308
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1309 # else
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1310
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1311 /**************************************
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1312 * 3. Unix-like implementation.
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1313 */
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1314
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1315 /*
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1316 * Create a new terminal of "rows" by "cols" cells.
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1317 * Start job for "cmd".
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1318 * Store the pointers in "term".
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1319 * Return OK or FAIL.
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1320 */
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1321 static int
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1322 term_and_job_init(term_T *term, int rows, int cols, char_u *cmd)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1323 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1324 typval_T argvars[2];
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1325 jobopt_T opt;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1326
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1327 create_vterm(term, rows, cols);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1328
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1329 argvars[0].v_type = VAR_STRING;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1330 argvars[0].vval.v_string = cmd;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1331 setup_job_options(&opt, rows, cols);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1332 term->tl_job = job_start(argvars, &opt);
11802
b1fd49b4eea7 patch 8.0.0783: job of terminal may be freed too early
Christian Brabandt <cb@256bit.org>
parents: 11798
diff changeset
1333 if (term->tl_job != NULL)
b1fd49b4eea7 patch 8.0.0783: job of terminal may be freed too early
Christian Brabandt <cb@256bit.org>
parents: 11798
diff changeset
1334 ++term->tl_job->jv_refcount;
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1335
11727
cb1dc90d22cc patch 8.0.0746: when :term fails the job is not properly cleaned up
Christian Brabandt <cb@256bit.org>
parents: 11725
diff changeset
1336 return term->tl_job != NULL
cb1dc90d22cc patch 8.0.0746: when :term fails the job is not properly cleaned up
Christian Brabandt <cb@256bit.org>
parents: 11725
diff changeset
1337 && term->tl_job->jv_channel != NULL
cb1dc90d22cc patch 8.0.0746: when :term fails the job is not properly cleaned up
Christian Brabandt <cb@256bit.org>
parents: 11725
diff changeset
1338 && term->tl_job->jv_status != JOB_FAILED ? OK : FAIL;
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1339 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1340
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1341 /*
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1342 * Free the terminal emulator part of "term".
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1343 */
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1344 static void
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1345 term_free(term_T *term)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1346 {
11751
a1815c4f8b70 patch 8.0.0758: possible crash when using a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11745
diff changeset
1347 if (term->tl_vterm != NULL)
a1815c4f8b70 patch 8.0.0758: possible crash when using a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11745
diff changeset
1348 vterm_free(term->tl_vterm);
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1349 }
11753
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
1350
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
1351 /*
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
1352 * Request size to terminal.
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
1353 */
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
1354 static void
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
1355 term_report_winsize(term_T *term, int rows, int cols)
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
1356 {
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
1357 /* Use an ioctl() to report the new window size to the job. */
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
1358 if (term->tl_job != NULL && term->tl_job->jv_channel != NULL)
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
1359 {
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
1360 int fd = -1;
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
1361 int part;
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
1362
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
1363 for (part = PART_OUT; part < PART_COUNT; ++part)
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
1364 {
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
1365 fd = term->tl_job->jv_channel->ch_part[part].ch_fd;
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
1366 if (isatty(fd))
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
1367 break;
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
1368 }
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
1369 if (part < PART_COUNT && mch_report_winsize(fd, rows, cols) == OK)
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
1370 mch_stop_job(term->tl_job, (char_u *)"winch");
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
1371 }
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
1372 }
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
1373
11804
5630978ae089 patch 8.0.0784: job of terminal may be garbage collected
Christian Brabandt <cb@256bit.org>
parents: 11802
diff changeset
1374 /*
5630978ae089 patch 8.0.0784: job of terminal may be garbage collected
Christian Brabandt <cb@256bit.org>
parents: 11802
diff changeset
1375 * Mark references in jobs of terminals.
5630978ae089 patch 8.0.0784: job of terminal may be garbage collected
Christian Brabandt <cb@256bit.org>
parents: 11802
diff changeset
1376 */
5630978ae089 patch 8.0.0784: job of terminal may be garbage collected
Christian Brabandt <cb@256bit.org>
parents: 11802
diff changeset
1377 int
5630978ae089 patch 8.0.0784: job of terminal may be garbage collected
Christian Brabandt <cb@256bit.org>
parents: 11802
diff changeset
1378 set_ref_in_term(int copyID)
5630978ae089 patch 8.0.0784: job of terminal may be garbage collected
Christian Brabandt <cb@256bit.org>
parents: 11802
diff changeset
1379 {
5630978ae089 patch 8.0.0784: job of terminal may be garbage collected
Christian Brabandt <cb@256bit.org>
parents: 11802
diff changeset
1380 int abort = FALSE;
5630978ae089 patch 8.0.0784: job of terminal may be garbage collected
Christian Brabandt <cb@256bit.org>
parents: 11802
diff changeset
1381 term_T *term;
5630978ae089 patch 8.0.0784: job of terminal may be garbage collected
Christian Brabandt <cb@256bit.org>
parents: 11802
diff changeset
1382 typval_T tv;
5630978ae089 patch 8.0.0784: job of terminal may be garbage collected
Christian Brabandt <cb@256bit.org>
parents: 11802
diff changeset
1383
5630978ae089 patch 8.0.0784: job of terminal may be garbage collected
Christian Brabandt <cb@256bit.org>
parents: 11802
diff changeset
1384 for (term = first_term; term != NULL; term = term->tl_next)
5630978ae089 patch 8.0.0784: job of terminal may be garbage collected
Christian Brabandt <cb@256bit.org>
parents: 11802
diff changeset
1385 if (term->tl_job != NULL)
5630978ae089 patch 8.0.0784: job of terminal may be garbage collected
Christian Brabandt <cb@256bit.org>
parents: 11802
diff changeset
1386 {
5630978ae089 patch 8.0.0784: job of terminal may be garbage collected
Christian Brabandt <cb@256bit.org>
parents: 11802
diff changeset
1387 tv.v_type = VAR_JOB;
5630978ae089 patch 8.0.0784: job of terminal may be garbage collected
Christian Brabandt <cb@256bit.org>
parents: 11802
diff changeset
1388 tv.vval.v_job = term->tl_job;
5630978ae089 patch 8.0.0784: job of terminal may be garbage collected
Christian Brabandt <cb@256bit.org>
parents: 11802
diff changeset
1389 abort = abort || set_ref_in_item(&tv, copyID, NULL, NULL);
5630978ae089 patch 8.0.0784: job of terminal may be garbage collected
Christian Brabandt <cb@256bit.org>
parents: 11802
diff changeset
1390 }
5630978ae089 patch 8.0.0784: job of terminal may be garbage collected
Christian Brabandt <cb@256bit.org>
parents: 11802
diff changeset
1391 return abort;
5630978ae089 patch 8.0.0784: job of terminal may be garbage collected
Christian Brabandt <cb@256bit.org>
parents: 11802
diff changeset
1392 }
5630978ae089 patch 8.0.0784: job of terminal may be garbage collected
Christian Brabandt <cb@256bit.org>
parents: 11802
diff changeset
1393
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1394 # endif
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
1395
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1396 #endif /* FEAT_TERMINAL */