annotate src/terminal.c @ 32669:448aef880252

normalize line endings
author Christian Brabandt <cb@256bit.org>
date Mon, 26 Jun 2023 09:54:34 +0200
parents a1e1527d1cb8
children 695b50472e85
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
32669
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7 * See README.txt for an overview of the Vim source code.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
8 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
9
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
10 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
11 * Terminal window support, see ":help :terminal".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
12 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
13 * There are three parts:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
14 * 1. Generic code for all systems.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
15 * Uses libvterm for the terminal emulator.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
16 * 2. The MS-Windows implementation.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
17 * Uses winpty.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
18 * 3. The Unix-like implementation.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
19 * Uses pseudo-tty's (pty's).
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
20 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
21 * For each terminal one VTerm is constructed. This uses libvterm. A copy of
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
22 * this library is in the libvterm directory.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
23 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
24 * When a terminal window is opened, a job is started that will be connected to
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
25 * the terminal emulator.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
26 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
27 * If the terminal window has keyboard focus, typed keys are converted to the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
28 * terminal encoding and writing to the job over a channel.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
29 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
30 * If the job produces output, it is written to the terminal emulator. The
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
31 * terminal emulator invokes callbacks when its screen content changes. The
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
32 * line range is stored in tl_dirty_row_start and tl_dirty_row_end. Once in a
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
33 * while, if the terminal window is visible, the screen contents is drawn.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
34 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
35 * When the job ends the text is put in a buffer. Redrawing then happens from
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
36 * that buffer, attributes come from the scrollback buffer tl_scrollback.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
37 * When the buffer is changed it is turned into a normal buffer, the attributes
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
38 * in tl_scrollback are no longer used.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
39 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
40
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
41 #include "vim.h"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
42
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
43 #if defined(FEAT_TERMINAL) || defined(PROTO)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
44
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
45 #ifndef MIN
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
46 # define MIN(x,y) ((x) < (y) ? (x) : (y))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
47 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
48 #ifndef MAX
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
49 # define MAX(x,y) ((x) > (y) ? (x) : (y))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
50 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
51
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
52 #include "libvterm/include/vterm.h"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
53
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
54 // This is VTermScreenCell without the characters, thus much smaller.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
55 typedef struct {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
56 VTermScreenCellAttrs attrs;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
57 char width;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
58 VTermColor fg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
59 VTermColor bg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
60 } cellattr_T;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
61
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
62 typedef struct sb_line_S {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
63 int sb_cols; // can differ per line
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
64 cellattr_T *sb_cells; // allocated
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
65 cellattr_T sb_fill_attr; // for short line
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
66 char_u *sb_text; // for tl_scrollback_postponed
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
67 } sb_line_T;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
68
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
69 #ifdef MSWIN
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
70 # ifndef HPCON
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
71 # define HPCON VOID*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
72 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
73 # ifndef EXTENDED_STARTUPINFO_PRESENT
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
74 # define EXTENDED_STARTUPINFO_PRESENT 0x00080000
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
75 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
76 # ifndef PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
77 # define PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE 0x00020016
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
78 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
79 typedef struct _DYN_STARTUPINFOEXW
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
80 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
81 STARTUPINFOW StartupInfo;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
82 LPPROC_THREAD_ATTRIBUTE_LIST lpAttributeList;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
83 } DYN_STARTUPINFOEXW, *PDYN_STARTUPINFOEXW;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
84 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
85
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
86 // typedef term_T in structs.h
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
87 struct terminal_S {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
88 term_T *tl_next;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
89
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
90 VTerm *tl_vterm;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
91 job_T *tl_job;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
92 buf_T *tl_buffer;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
93 #if defined(FEAT_GUI)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
94 int tl_system; // when non-zero used for :!cmd output
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
95 int tl_toprow; // row with first line of system terminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
96 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
97
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
98 // Set when setting the size of a vterm, reset after redrawing.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
99 int tl_vterm_size_changed;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
100
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
101 int tl_normal_mode; // TRUE: Terminal-Normal mode
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
102 int tl_channel_closing;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
103 int tl_channel_closed;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
104 int tl_channel_recently_closed; // still need to handle tl_finish
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
105
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
106 int tl_finish;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
107 #define TL_FINISH_UNSET NUL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
108 #define TL_FINISH_CLOSE 'c' // ++close or :terminal without argument
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
109 #define TL_FINISH_NOCLOSE 'n' // ++noclose
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
110 #define TL_FINISH_OPEN 'o' // ++open
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
111 char_u *tl_opencmd;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
112 char_u *tl_eof_chars;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
113 char_u *tl_api; // prefix for terminal API function
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
114
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
115 char_u *tl_arg0_cmd; // To format the status bar
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
116
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
117 #ifdef MSWIN
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
118 void *tl_winpty_config;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
119 void *tl_winpty;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
120
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
121 HPCON tl_conpty;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
122 DYN_STARTUPINFOEXW tl_siex; // Structure that always needs to be hold
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
123
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
124 FILE *tl_out_fd;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
125 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
126 #if defined(FEAT_SESSION)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
127 char_u *tl_command;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
128 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
129 char_u *tl_kill;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
130
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
131 // last known vterm size
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
132 int tl_rows;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
133 int tl_cols;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
134
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
135 char_u *tl_title; // NULL or allocated
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
136 char_u *tl_status_text; // NULL or allocated
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
137
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
138 // Range of screen rows to update. Zero based.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
139 int tl_dirty_row_start; // MAX_ROW if nothing dirty
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
140 int tl_dirty_row_end; // row below last one to update
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
141 int tl_dirty_snapshot; // text updated after making snapshot
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
142 #ifdef FEAT_TIMERS
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
143 int tl_timer_set;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
144 proftime_T tl_timer_due;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
145 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
146 int tl_postponed_scroll; // to be scrolled up
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
147
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
148 garray_T tl_scrollback;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
149 int tl_scrollback_scrolled;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
150 garray_T tl_scrollback_postponed;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
151
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
152 char_u *tl_highlight_name; // replaces "Terminal"; allocated
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
153
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
154 cellattr_T tl_default_color;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
155
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
156 linenr_T tl_top_diff_rows; // rows of top diff file or zero
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
157 linenr_T tl_bot_diff_rows; // rows of bottom diff file
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
158
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
159 VTermPos tl_cursor_pos;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
160 int tl_cursor_visible;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
161 int tl_cursor_blink;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
162 int tl_cursor_shape; // 1: block, 2: underline, 3: bar
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
163 char_u *tl_cursor_color; // NULL or allocated
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
164
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
165 long_u *tl_palette; // array of 16 colors specified by term_start, can
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
166 // be NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
167 int tl_using_altscreen;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
168 garray_T tl_osc_buf; // incomplete OSC string
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
169 };
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
170
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
171 #define TMODE_ONCE 1 // CTRL-\ CTRL-N used
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
172 #define TMODE_LOOP 2 // CTRL-W N used
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
173
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
174 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
175 * List of all active terminals.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
176 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
177 static term_T *first_term = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
178
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
179 // Terminal active in terminal_loop().
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
180 static term_T *in_terminal_loop = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
181
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
182 #ifdef MSWIN
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
183 static BOOL has_winpty = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
184 static BOOL has_conpty = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
185 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
186
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
187 #define MAX_ROW 999999 // used for tl_dirty_row_end to update all rows
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
188 #define KEY_BUF_LEN 200
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
189
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
190 #define FOR_ALL_TERMS(term) \
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
191 for ((term) = first_term; (term) != NULL; (term) = (term)->tl_next)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
192
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
193 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
194 * Functions with separate implementation for MS-Windows and Unix-like systems.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
195 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
196 static int term_and_job_init(term_T *term, typval_T *argvar, char **argv, jobopt_T *opt, jobopt_T *orig_opt);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
197 static int create_pty_only(term_T *term, jobopt_T *opt);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
198 static void term_report_winsize(term_T *term, int rows, int cols);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
199 static void term_free_vterm(term_T *term);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
200 #ifdef FEAT_GUI
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
201 static void update_system_term(term_T *term);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
202 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
203
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
204 static void handle_postponed_scrollback(term_T *term);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
205
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
206 // The character that we know (or assume) that the terminal expects for the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
207 // backspace key.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
208 static int term_backspace_char = BS;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
209
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
210 // Store the last set and the desired cursor properties, so that we only update
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
211 // them when needed. Doing it unnecessary may result in flicker.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
212 static char_u *last_set_cursor_color = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
213 static char_u *desired_cursor_color = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
214 static int last_set_cursor_shape = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
215 static int desired_cursor_shape = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
216 static int last_set_cursor_blink = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
217 static int desired_cursor_blink = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
218
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
219
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
220 ///////////////////////////////////////
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
221 // 1. Generic code for all systems.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
222
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
223 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
224 cursor_color_equal(char_u *lhs_color, char_u *rhs_color)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
225 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
226 if (lhs_color != NULL && rhs_color != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
227 return STRCMP(lhs_color, rhs_color) == 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
228 return lhs_color == NULL && rhs_color == NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
229 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
230
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
231 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
232 cursor_color_copy(char_u **to_color, char_u *from_color)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
233 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
234 // Avoid a free & alloc if the value is already right.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
235 if (cursor_color_equal(*to_color, from_color))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
236 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
237 vim_free(*to_color);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
238 *to_color = (from_color == NULL) ? NULL : vim_strsave(from_color);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
239 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
240
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
241 static char_u *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
242 cursor_color_get(char_u *color)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
243 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
244 return (color == NULL) ? (char_u *)"" : color;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
245 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
246
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
247
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
248 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
249 * Parse 'termwinsize' and set "rows" and "cols" for the terminal size in the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
250 * current window.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
251 * Sets "rows" and/or "cols" to zero when it should follow the window size.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
252 * Return TRUE if the size is the minimum size: "24*80".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
253 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
254 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
255 parse_termwinsize(win_T *wp, int *rows, int *cols)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
256 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
257 int minsize = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
258
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
259 *rows = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
260 *cols = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
261
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
262 if (*wp->w_p_tws == NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
263 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
264
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
265 char_u *p = vim_strchr(wp->w_p_tws, 'x');
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
266
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
267 // Syntax of value was already checked when it's set.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
268 if (p == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
269 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
270 minsize = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
271 p = vim_strchr(wp->w_p_tws, '*');
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
272 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
273 *rows = atoi((char *)wp->w_p_tws);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
274 *cols = atoi((char *)p + 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
275 return minsize;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
276 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
277
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
278 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
279 * Determine the terminal size from 'termwinsize' and the current window.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
280 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
281 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
282 set_term_and_win_size(term_T *term, jobopt_T *opt)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
283 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
284 int rows, cols;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
285 int minsize;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
286
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
287 #ifdef FEAT_GUI
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
288 if (term->tl_system)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
289 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
290 // Use the whole screen for the system command. However, it will start
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
291 // at the command line and scroll up as needed, using tl_toprow.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
292 term->tl_rows = Rows;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
293 term->tl_cols = Columns;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
294 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
295 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
296 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
297 term->tl_rows = curwin->w_height;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
298 term->tl_cols = curwin->w_width;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
299
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
300 minsize = parse_termwinsize(curwin, &rows, &cols);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
301 if (minsize)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
302 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
303 if (term->tl_rows < rows)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
304 term->tl_rows = rows;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
305 if (term->tl_cols < cols)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
306 term->tl_cols = cols;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
307 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
308 if ((opt->jo_set2 & JO2_TERM_ROWS))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
309 term->tl_rows = opt->jo_term_rows;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
310 else if (rows != 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
311 term->tl_rows = rows;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
312 if ((opt->jo_set2 & JO2_TERM_COLS))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
313 term->tl_cols = opt->jo_term_cols;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
314 else if (cols != 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
315 term->tl_cols = cols;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
316
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
317 if (!opt->jo_hidden)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
318 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
319 if (term->tl_rows != curwin->w_height)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
320 win_setheight_win(term->tl_rows, curwin);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
321 if (term->tl_cols != curwin->w_width)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
322 win_setwidth_win(term->tl_cols, curwin);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
323
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
324 // Set 'winsize' now to avoid a resize at the next redraw.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
325 if (!minsize && *curwin->w_p_tws != NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
326 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
327 char_u buf[100];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
328
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
329 vim_snprintf((char *)buf, 100, "%dx%d",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
330 term->tl_rows, term->tl_cols);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
331 set_option_value_give_err((char_u *)"termwinsize",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
332 0L, buf, OPT_LOCAL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
333 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
334 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
335 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
336
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
337 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
338 * Initialize job options for a terminal job.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
339 * Caller may overrule some of them.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
340 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
341 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
342 init_job_options(jobopt_T *opt)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
343 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
344 clear_job_options(opt);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
345
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
346 opt->jo_mode = CH_MODE_RAW;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
347 opt->jo_out_mode = CH_MODE_RAW;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
348 opt->jo_err_mode = CH_MODE_RAW;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
349 opt->jo_set = JO_MODE | JO_OUT_MODE | JO_ERR_MODE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
350 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
351
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
352 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
353 * Set job options mandatory for a terminal job.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
354 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
355 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
356 setup_job_options(jobopt_T *opt, int rows, int cols)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
357 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
358 #ifndef MSWIN
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
359 // Win32: Redirecting the job output won't work, thus always connect stdout
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
360 // here.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
361 if (!(opt->jo_set & JO_OUT_IO))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
362 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
363 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
364 // Connect stdout to the terminal.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
365 opt->jo_io[PART_OUT] = JIO_BUFFER;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
366 opt->jo_io_buf[PART_OUT] = curbuf->b_fnum;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
367 opt->jo_modifiable[PART_OUT] = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
368 opt->jo_set |= JO_OUT_IO + JO_OUT_BUF + JO_OUT_MODIFIABLE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
369 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
370
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
371 #ifndef MSWIN
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
372 // Win32: Redirecting the job output won't work, thus always connect stderr
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
373 // here.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
374 if (!(opt->jo_set & JO_ERR_IO))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
375 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
376 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
377 // Connect stderr to the terminal.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
378 opt->jo_io[PART_ERR] = JIO_BUFFER;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
379 opt->jo_io_buf[PART_ERR] = curbuf->b_fnum;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
380 opt->jo_modifiable[PART_ERR] = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
381 opt->jo_set |= JO_ERR_IO + JO_ERR_BUF + JO_ERR_MODIFIABLE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
382 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
383
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
384 opt->jo_pty = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
385 if ((opt->jo_set2 & JO2_TERM_ROWS) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
386 opt->jo_term_rows = rows;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
387 if ((opt->jo_set2 & JO2_TERM_COLS) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
388 opt->jo_term_cols = cols;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
389 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
390
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
391 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
392 * Flush messages on channels.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
393 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
394 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
395 term_flush_messages(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
396 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
397 mch_check_messages();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
398 parse_queued_messages();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
399 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
400
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
401 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
402 * Close a terminal buffer (and its window). Used when creating the terminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
403 * fails.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
404 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
405 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
406 term_close_buffer(buf_T *buf, buf_T *old_curbuf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
407 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
408 free_terminal(buf);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
409 if (old_curbuf != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
410 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
411 --curbuf->b_nwindows;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
412 curbuf = old_curbuf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
413 curwin->w_buffer = curbuf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
414 ++curbuf->b_nwindows;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
415 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
416 CHECK_CURBUF;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
417
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
418 // Wiping out the buffer will also close the window and call
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
419 // free_terminal().
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
420 do_buffer(DOBUF_WIPE, DOBUF_FIRST, FORWARD, buf->b_fnum, TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
421 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
422
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
423 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
424 * Start a terminal window and return its buffer.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
425 * Use either "argvar" or "argv", the other must be NULL.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
426 * When "flags" has TERM_START_NOJOB only create the buffer, b_term and open
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
427 * the window.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
428 * Returns NULL when failed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
429 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
430 buf_T *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
431 term_start(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
432 typval_T *argvar,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
433 char **argv,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
434 jobopt_T *opt,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
435 int flags)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
436 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
437 exarg_T split_ea;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
438 win_T *old_curwin = curwin;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
439 term_T *term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
440 buf_T *old_curbuf = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
441 int res;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
442 buf_T *newbuf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
443 int vertical = opt->jo_vertical || (cmdmod.cmod_split & WSP_VERT);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
444 jobopt_T orig_opt; // only partly filled
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
445
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
446 if (check_restricted() || check_secure())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
447 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
448 if (cmdwin_type != 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
449 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
450 emsg(_(e_cannot_open_terminal_from_command_line_window));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
451 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
452 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
453
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
454 if ((opt->jo_set & (JO_IN_IO + JO_OUT_IO + JO_ERR_IO))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
455 == (JO_IN_IO + JO_OUT_IO + JO_ERR_IO)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
456 || (!(opt->jo_set & JO_OUT_IO) && (opt->jo_set & JO_OUT_BUF))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
457 || (!(opt->jo_set & JO_ERR_IO) && (opt->jo_set & JO_ERR_BUF))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
458 || (argvar != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
459 && argvar->v_type == VAR_LIST
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
460 && argvar->vval.v_list != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
461 && argvar->vval.v_list->lv_first == &range_list_item))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
462 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
463 emsg(_(e_invalid_argument));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
464 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
465 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
466
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
467 term = ALLOC_CLEAR_ONE(term_T);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
468 if (term == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
469 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
470 term->tl_dirty_row_end = MAX_ROW;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
471 term->tl_cursor_visible = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
472 term->tl_cursor_shape = VTERM_PROP_CURSORSHAPE_BLOCK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
473 term->tl_finish = opt->jo_term_finish;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
474 #ifdef FEAT_GUI
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
475 term->tl_system = (flags & TERM_START_SYSTEM);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
476 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
477 ga_init2(&term->tl_scrollback, sizeof(sb_line_T), 300);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
478 ga_init2(&term->tl_scrollback_postponed, sizeof(sb_line_T), 300);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
479 ga_init2(&term->tl_osc_buf, sizeof(char), 300);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
480
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
481 setpcmark();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
482 CLEAR_FIELD(split_ea);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
483 if (opt->jo_curwin)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
484 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
485 // Create a new buffer in the current window.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
486 if (!can_abandon(curbuf, flags & TERM_START_FORCEIT))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
487 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
488 no_write_message();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
489 vim_free(term);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
490 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
491 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
492 if (do_ecmd(0, NULL, NULL, &split_ea, ECMD_ONE,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
493 (buf_hide(curwin->w_buffer) ? ECMD_HIDE : 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
494 + ((flags & TERM_START_FORCEIT) ? ECMD_FORCEIT : 0),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
495 curwin) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
496 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
497 vim_free(term);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
498 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
499 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
500 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
501 else if (opt->jo_hidden || (flags & TERM_START_SYSTEM))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
502 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
503 buf_T *buf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
504
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
505 // Create a new buffer without a window. Make it the current buffer for
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
506 // a moment to be able to do the initializations.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
507 buf = buflist_new((char_u *)"", NULL, (linenr_T)0,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
508 BLN_NEW | BLN_LISTED);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
509 if (buf == NULL || ml_open(buf) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
510 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
511 vim_free(term);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
512 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
513 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
514 old_curbuf = curbuf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
515 --curbuf->b_nwindows;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
516 curbuf = buf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
517 curwin->w_buffer = buf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
518 ++curbuf->b_nwindows;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
519 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
520 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
521 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
522 // Open a new window or tab.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
523 split_ea.cmdidx = CMD_new;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
524 split_ea.cmd = (char_u *)"new";
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
525 split_ea.arg = (char_u *)"";
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
526 if (opt->jo_term_rows > 0 && !vertical)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
527 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
528 split_ea.line2 = opt->jo_term_rows;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
529 split_ea.addr_count = 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
530 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
531 if (opt->jo_term_cols > 0 && vertical)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
532 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
533 split_ea.line2 = opt->jo_term_cols;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
534 split_ea.addr_count = 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
535 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
536
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
537 if (vertical)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
538 cmdmod.cmod_split |= WSP_VERT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
539 ex_splitview(&split_ea);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
540 if (curwin == old_curwin)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
541 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
542 // split failed
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
543 vim_free(term);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
544 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
545 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
546 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
547 term->tl_buffer = curbuf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
548 curbuf->b_term = term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
549
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
550 if (!opt->jo_hidden)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
551 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
552 // Only one size was taken care of with :new, do the other one. With
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
553 // "curwin" both need to be done.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
554 if (opt->jo_term_rows > 0 && (opt->jo_curwin || vertical))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
555 win_setheight(opt->jo_term_rows);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
556 if (opt->jo_term_cols > 0 && (opt->jo_curwin || !vertical))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
557 win_setwidth(opt->jo_term_cols);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
558 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
559
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
560 // Link the new terminal in the list of active terminals.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
561 term->tl_next = first_term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
562 first_term = term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
563
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
564 apply_autocmds(EVENT_BUFFILEPRE, NULL, NULL, FALSE, curbuf);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
565
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
566 if (opt->jo_term_name != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
567 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
568 vim_free(curbuf->b_ffname);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
569 curbuf->b_ffname = vim_strsave(opt->jo_term_name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
570 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
571 else if (argv != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
572 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
573 vim_free(curbuf->b_ffname);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
574 curbuf->b_ffname = vim_strsave((char_u *)"!system");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
575 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
576 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
577 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
578 int i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
579 size_t len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
580 char_u *cmd, *p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
581
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
582 if (argvar->v_type == VAR_STRING)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
583 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
584 cmd = argvar->vval.v_string;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
585 if (cmd == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
586 cmd = (char_u *)"";
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
587 else if (STRCMP(cmd, "NONE") == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
588 cmd = (char_u *)"pty";
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
589 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
590 else if (argvar->v_type != VAR_LIST
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
591 || argvar->vval.v_list == NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
592 || argvar->vval.v_list->lv_len == 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
593 || (cmd = tv_get_string_chk(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
594 &argvar->vval.v_list->lv_first->li_tv)) == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
595 cmd = (char_u*)"";
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
596
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
597 len = STRLEN(cmd) + 10;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
598 p = alloc(len);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
599
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
600 for (i = 0; p != NULL; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
601 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
602 // Prepend a ! to the command name to avoid the buffer name equals
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
603 // the executable, otherwise ":w!" would overwrite it.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
604 if (i == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
605 vim_snprintf((char *)p, len, "!%s", cmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
606 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
607 vim_snprintf((char *)p, len, "!%s (%d)", cmd, i);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
608 if (buflist_findname(p) == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
609 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
610 vim_free(curbuf->b_ffname);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
611 curbuf->b_ffname = p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
612 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
613 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
614 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
615 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
616 vim_free(curbuf->b_sfname);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
617 curbuf->b_sfname = vim_strsave(curbuf->b_ffname);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
618 curbuf->b_fname = curbuf->b_ffname;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
619
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
620 apply_autocmds(EVENT_BUFFILEPOST, NULL, NULL, FALSE, curbuf);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
621
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
622 if (opt->jo_term_opencmd != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
623 term->tl_opencmd = vim_strsave(opt->jo_term_opencmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
624
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
625 if (opt->jo_eof_chars != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
626 term->tl_eof_chars = vim_strsave(opt->jo_eof_chars);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
627
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
628 set_string_option_direct((char_u *)"buftype", -1,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
629 (char_u *)"terminal", OPT_FREE|OPT_LOCAL, 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
630 // Avoid that 'buftype' is reset when this buffer is entered.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
631 curbuf->b_p_initialized = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
632
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
633 // Mark the buffer as not modifiable. It can only be made modifiable after
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
634 // the job finished.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
635 curbuf->b_p_ma = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
636
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
637 set_term_and_win_size(term, opt);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
638 #ifdef MSWIN
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
639 mch_memmove(orig_opt.jo_io, opt->jo_io, sizeof(orig_opt.jo_io));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
640 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
641 setup_job_options(opt, term->tl_rows, term->tl_cols);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
642
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
643 if (flags & TERM_START_NOJOB)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
644 return curbuf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
645
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
646 #if defined(FEAT_SESSION)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
647 // Remember the command for the session file.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
648 if (opt->jo_term_norestore || argv != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
649 term->tl_command = vim_strsave((char_u *)"NONE");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
650 else if (argvar->v_type == VAR_STRING)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
651 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
652 char_u *cmd = argvar->vval.v_string;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
653
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
654 if (cmd != NULL && STRCMP(cmd, p_sh) != 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
655 term->tl_command = vim_strsave(cmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
656 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
657 else if (argvar->v_type == VAR_LIST
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
658 && argvar->vval.v_list != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
659 && argvar->vval.v_list->lv_len > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
660 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
661 garray_T ga;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
662 listitem_T *item;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
663
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
664 ga_init2(&ga, 1, 100);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
665 FOR_ALL_LIST_ITEMS(argvar->vval.v_list, item)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
666 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
667 char_u *s = tv_get_string_chk(&item->li_tv);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
668 char_u *p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
669
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
670 if (s == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
671 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
672 p = vim_strsave_fnameescape(s, VSE_NONE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
673 if (p == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
674 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
675 ga_concat(&ga, p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
676 vim_free(p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
677 ga_append(&ga, ' ');
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
678 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
679 if (item == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
680 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
681 ga_append(&ga, NUL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
682 term->tl_command = ga.ga_data;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
683 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
684 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
685 ga_clear(&ga);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
686 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
687 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
688
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
689 if (opt->jo_term_kill != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
690 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
691 char_u *p = skiptowhite(opt->jo_term_kill);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
692
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
693 term->tl_kill = vim_strnsave(opt->jo_term_kill, p - opt->jo_term_kill);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
694 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
695
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
696 if (opt->jo_term_api != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
697 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
698 char_u *p = skiptowhite(opt->jo_term_api);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
699
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
700 term->tl_api = vim_strnsave(opt->jo_term_api, p - opt->jo_term_api);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
701 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
702 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
703 term->tl_api = vim_strsave((char_u *)"Tapi_");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
704
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
705 if (opt->jo_set2 & JO2_TERM_HIGHLIGHT)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
706 term->tl_highlight_name = vim_strsave(opt->jo_term_highlight);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
707
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
708 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
709 // Save the user-defined palette, it is only used in GUI (or 'tgc' is on).
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
710 if (opt->jo_set2 & JO2_ANSI_COLORS)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
711 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
712 term->tl_palette = ALLOC_MULT(long_u, 16);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
713 if (term->tl_palette == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
714 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
715 vim_free(term);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
716 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
717 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
718 memcpy(term->tl_palette, opt->jo_ansi_colors, sizeof(long_u) * 16);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
719 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
720 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
721
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
722 // System dependent: setup the vterm and maybe start the job in it.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
723 if (argv == NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
724 && argvar->v_type == VAR_STRING
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
725 && argvar->vval.v_string != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
726 && STRCMP(argvar->vval.v_string, "NONE") == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
727 res = create_pty_only(term, opt);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
728 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
729 res = term_and_job_init(term, argvar, argv, opt, &orig_opt);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
730
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
731 newbuf = curbuf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
732 if (res == OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
733 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
734 // Get and remember the size we ended up with. Update the pty.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
735 vterm_get_size(term->tl_vterm, &term->tl_rows, &term->tl_cols);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
736 term_report_winsize(term, term->tl_rows, term->tl_cols);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
737 #ifdef FEAT_GUI
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
738 if (term->tl_system)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
739 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
740 // display first line below typed command
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
741 term->tl_toprow = msg_row + 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
742 term->tl_dirty_row_end = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
743 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
744 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
745
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
746 // Make sure we don't get stuck on sending keys to the job, it leads to
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
747 // a deadlock if the job is waiting for Vim to read.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
748 channel_set_nonblock(term->tl_job->jv_channel, PART_IN);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
749
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
750 if (old_curbuf != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
751 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
752 --curbuf->b_nwindows;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
753 curbuf = old_curbuf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
754 curwin->w_buffer = curbuf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
755 ++curbuf->b_nwindows;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
756 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
757 else if (vgetc_busy
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
758 #ifdef FEAT_TIMERS
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
759 || timer_busy
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
760 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
761 || input_busy)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
762 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
763 char_u ignore[4];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
764
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
765 // When waiting for input need to return and possibly end up in
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
766 // terminal_loop() instead.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
767 ignore[0] = K_SPECIAL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
768 ignore[1] = KS_EXTRA;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
769 ignore[2] = KE_IGNORE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
770 ignore[3] = NUL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
771 ins_typebuf(ignore, REMAP_NONE, 0, TRUE, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
772 typebuf_was_filled = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
773 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
774 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
775 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
776 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
777 term_close_buffer(curbuf, old_curbuf);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
778 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
779 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
780
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
781 apply_autocmds(EVENT_TERMINALOPEN, NULL, NULL, FALSE, newbuf);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
782 if (!opt->jo_hidden && !(flags & TERM_START_SYSTEM))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
783 apply_autocmds(EVENT_TERMINALWINOPEN, NULL, NULL, FALSE, newbuf);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
784 return newbuf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
785 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
786
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
787 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
788 * ":terminal": open a terminal window and execute a job in it.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
789 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
790 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
791 ex_terminal(exarg_T *eap)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
792 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
793 typval_T argvar[2];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
794 jobopt_T opt;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
795 int opt_shell = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
796 char_u *cmd;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
797 char_u *tofree = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
798
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
799 init_job_options(&opt);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
800
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
801 cmd = eap->arg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
802 while (*cmd == '+' && *(cmd + 1) == '+')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
803 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
804 char_u *p, *ep;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
805
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
806 cmd += 2;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
807 p = skiptowhite(cmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
808 ep = vim_strchr(cmd, '=');
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
809 if (ep != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
810 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
811 if (ep < p)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
812 p = ep;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
813 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
814 ep = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
815 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
816
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
817 # define OPTARG_HAS(name) ((int)(p - cmd) == sizeof(name) - 1 \
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
818 && STRNICMP(cmd, name, sizeof(name) - 1) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
819 if (OPTARG_HAS("close"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
820 opt.jo_term_finish = 'c';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
821 else if (OPTARG_HAS("noclose"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
822 opt.jo_term_finish = 'n';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
823 else if (OPTARG_HAS("open"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
824 opt.jo_term_finish = 'o';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
825 else if (OPTARG_HAS("curwin"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
826 opt.jo_curwin = 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
827 else if (OPTARG_HAS("hidden"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
828 opt.jo_hidden = 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
829 else if (OPTARG_HAS("norestore"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
830 opt.jo_term_norestore = 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
831 else if (OPTARG_HAS("shell"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
832 opt_shell = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
833 else if (OPTARG_HAS("kill") && ep != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
834 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
835 opt.jo_set2 |= JO2_TERM_KILL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
836 opt.jo_term_kill = ep + 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
837 p = skiptowhite(cmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
838 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
839 else if (OPTARG_HAS("api"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
840 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
841 opt.jo_set2 |= JO2_TERM_API;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
842 if (ep != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
843 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
844 opt.jo_term_api = ep + 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
845 p = skiptowhite(cmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
846 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
847 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
848 opt.jo_term_api = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
849 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
850 else if (OPTARG_HAS("rows") && ep != NULL && isdigit(ep[1]))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
851 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
852 opt.jo_set2 |= JO2_TERM_ROWS;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
853 opt.jo_term_rows = atoi((char *)ep + 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
854 p = skiptowhite(cmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
855 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
856 else if (OPTARG_HAS("cols") && ep != NULL && isdigit(ep[1]))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
857 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
858 opt.jo_set2 |= JO2_TERM_COLS;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
859 opt.jo_term_cols = atoi((char *)ep + 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
860 p = skiptowhite(cmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
861 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
862 else if (OPTARG_HAS("eof") && ep != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
863 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
864 char_u *buf = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
865 char_u *keys;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
866
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
867 vim_free(opt.jo_eof_chars);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
868 p = skiptowhite(cmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
869 *p = NUL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
870 keys = replace_termcodes(ep + 1, &buf,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
871 REPTERM_FROM_PART | REPTERM_DO_LT | REPTERM_SPECIAL, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
872 opt.jo_set2 |= JO2_EOF_CHARS;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
873 opt.jo_eof_chars = vim_strsave(keys);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
874 vim_free(buf);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
875 *p = ' ';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
876 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
877 #ifdef MSWIN
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
878 else if ((int)(p - cmd) == 4 && STRNICMP(cmd, "type", 4) == 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
879 && ep != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
880 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
881 int tty_type = NUL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
882
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
883 p = skiptowhite(cmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
884 if (STRNICMP(ep + 1, "winpty", p - (ep + 1)) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
885 tty_type = 'w';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
886 else if (STRNICMP(ep + 1, "conpty", p - (ep + 1)) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
887 tty_type = 'c';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
888 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
889 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
890 semsg(_(e_invalid_value_for_argument_str), "type");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
891 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
892 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
893 opt.jo_set2 |= JO2_TTY_TYPE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
894 opt.jo_tty_type = tty_type;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
895 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
896 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
897 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
898 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
899 if (*p)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
900 *p = NUL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
901 semsg(_(e_invalid_attribute_str), cmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
902 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
903 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
904 # undef OPTARG_HAS
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
905 cmd = skipwhite(p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
906 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
907 if (*cmd == NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
908 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
909 // Make a copy of 'shell', an autocommand may change the option.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
910 tofree = cmd = vim_strsave(p_sh);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
911
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
912 // default to close when the shell exits
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
913 if (opt.jo_term_finish == NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
914 opt.jo_term_finish = TL_FINISH_CLOSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
915 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
916
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
917 if (eap->addr_count > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
918 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
919 // Write lines from current buffer to the job.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
920 opt.jo_set |= JO_IN_IO | JO_IN_BUF | JO_IN_TOP | JO_IN_BOT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
921 opt.jo_io[PART_IN] = JIO_BUFFER;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
922 opt.jo_io_buf[PART_IN] = curbuf->b_fnum;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
923 opt.jo_in_top = eap->line1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
924 opt.jo_in_bot = eap->line2;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
925 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
926
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
927 if (opt_shell && tofree == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
928 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
929 #ifdef UNIX
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
930 char **argv = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
931 char_u *tofree1 = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
932 char_u *tofree2 = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
933
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
934 // :term ++shell command
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
935 if (unix_build_argv(cmd, &argv, &tofree1, &tofree2) == OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
936 term_start(NULL, argv, &opt, eap->forceit ? TERM_START_FORCEIT : 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
937 vim_free(argv);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
938 vim_free(tofree1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
939 vim_free(tofree2);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
940 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
941 #else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
942 # ifdef MSWIN
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
943 long_u cmdlen = STRLEN(p_sh) + STRLEN(p_shcf) + STRLEN(cmd) + 10;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
944 char_u *newcmd;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
945
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
946 newcmd = alloc(cmdlen);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
947 if (newcmd == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
948 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
949 tofree = newcmd;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
950 vim_snprintf((char *)newcmd, cmdlen, "%s %s %s", p_sh, p_shcf, cmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
951 cmd = newcmd;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
952 # else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
953 emsg(_(e_sorry_plusplusshell_not_supported_on_this_system));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
954 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
955 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
956 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
957 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
958 argvar[0].v_type = VAR_STRING;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
959 argvar[0].vval.v_string = cmd;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
960 argvar[1].v_type = VAR_UNKNOWN;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
961 term_start(argvar, NULL, &opt, eap->forceit ? TERM_START_FORCEIT : 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
962
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
963 theend:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
964 vim_free(tofree);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
965 vim_free(opt.jo_eof_chars);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
966 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
967
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
968 #if defined(FEAT_SESSION) || defined(PROTO)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
969 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
970 * Write a :terminal command to the session file to restore the terminal in
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
971 * window "wp".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
972 * Return FAIL if writing fails.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
973 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
974 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
975 term_write_session(FILE *fd, win_T *wp, hashtab_T *terminal_bufs)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
976 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
977 const int bufnr = wp->w_buffer->b_fnum;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
978 term_T *term = wp->w_buffer->b_term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
979
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
980 if (terminal_bufs != NULL && wp->w_buffer->b_nwindows > 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
981 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
982 // There are multiple views into this terminal buffer. We don't want to
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
983 // create the terminal multiple times. If it's the first time, create,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
984 // otherwise link to the first buffer.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
985 char id_as_str[NUMBUFLEN];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
986 hashitem_T *entry;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
987
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
988 vim_snprintf(id_as_str, sizeof(id_as_str), "%d", bufnr);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
989
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
990 entry = hash_find(terminal_bufs, (char_u *)id_as_str);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
991 if (!HASHITEM_EMPTY(entry))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
992 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
993 // we've already opened this terminal buffer
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
994 if (fprintf(fd, "execute 'buffer ' . s:term_buf_%d", bufnr) < 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
995 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
996 return put_eol(fd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
997 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
998 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
999
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1000 // Create the terminal and run the command. This is not without
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1001 // risk, but let's assume the user only creates a session when this
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1002 // will be OK.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1003 if (fprintf(fd, "terminal ++curwin ++cols=%d ++rows=%d ",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1004 term->tl_cols, term->tl_rows) < 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1005 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1006 #ifdef MSWIN
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1007 if (fprintf(fd, "++type=%s ", term->tl_job->jv_tty_type) < 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1008 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1009 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1010 if (term->tl_command != NULL && fputs((char *)term->tl_command, fd) < 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1011 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1012 if (put_eol(fd) != OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1013 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1014
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1015 if (fprintf(fd, "let s:term_buf_%d = bufnr()", bufnr) < 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1016 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1017
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1018 if (terminal_bufs != NULL && wp->w_buffer->b_nwindows > 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1019 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1020 char *hash_key = alloc(NUMBUFLEN);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1021
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1022 vim_snprintf(hash_key, NUMBUFLEN, "%d", bufnr);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1023 hash_add(terminal_bufs, (char_u *)hash_key, "terminal session");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1024 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1025
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1026 return put_eol(fd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1027 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1028
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1029 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1030 * Return TRUE if "buf" has a terminal that should be restored.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1031 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1032 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1033 term_should_restore(buf_T *buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1034 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1035 term_T *term = buf->b_term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1036
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1037 return term != NULL && (term->tl_command == NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1038 || STRCMP(term->tl_command, "NONE") != 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1039 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1040 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1041
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1042 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1043 * Free the scrollback buffer for "term".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1044 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1045 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1046 free_scrollback(term_T *term)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1047 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1048 int i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1049
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1050 for (i = 0; i < term->tl_scrollback.ga_len; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1051 vim_free(((sb_line_T *)term->tl_scrollback.ga_data + i)->sb_cells);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1052 ga_clear(&term->tl_scrollback);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1053 for (i = 0; i < term->tl_scrollback_postponed.ga_len; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1054 vim_free(((sb_line_T *)term->tl_scrollback_postponed.ga_data + i)->sb_cells);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1055 ga_clear(&term->tl_scrollback_postponed);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1056 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1057
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1058
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1059 // Terminals that need to be freed soon.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1060 static term_T *terminals_to_free = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1061
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1062 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1063 * Free a terminal and everything it refers to.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1064 * Kills the job if there is one.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1065 * Called when wiping out a buffer.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1066 * The actual terminal structure is freed later in free_unused_terminals(),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1067 * because callbacks may wipe out a buffer while the terminal is still
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1068 * referenced.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1069 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1070 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1071 free_terminal(buf_T *buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1072 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1073 term_T *term = buf->b_term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1074 term_T *tp;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1075
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1076 if (term == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1077 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1078
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1079 // Unlink the terminal form the list of terminals.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1080 if (first_term == term)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1081 first_term = term->tl_next;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1082 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1083 for (tp = first_term; tp->tl_next != NULL; tp = tp->tl_next)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1084 if (tp->tl_next == term)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1085 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1086 tp->tl_next = term->tl_next;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1087 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1088 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1089
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1090 if (term->tl_job != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1091 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1092 if (term->tl_job->jv_status != JOB_ENDED
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1093 && term->tl_job->jv_status != JOB_FINISHED
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1094 && term->tl_job->jv_status != JOB_FAILED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1095 job_stop(term->tl_job, NULL, "kill");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1096 job_unref(term->tl_job);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1097 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1098 term->tl_next = terminals_to_free;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1099 terminals_to_free = term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1100
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1101 buf->b_term = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1102 if (in_terminal_loop == term)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1103 in_terminal_loop = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1104 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1105
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1106 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1107 free_unused_terminals(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1108 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1109 while (terminals_to_free != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1110 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1111 term_T *term = terminals_to_free;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1112
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1113 terminals_to_free = term->tl_next;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1114
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1115 free_scrollback(term);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1116 ga_clear(&term->tl_osc_buf);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1117
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1118 term_free_vterm(term);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1119 vim_free(term->tl_api);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1120 vim_free(term->tl_title);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1121 #ifdef FEAT_SESSION
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1122 vim_free(term->tl_command);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1123 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1124 vim_free(term->tl_kill);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1125 vim_free(term->tl_status_text);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1126 vim_free(term->tl_opencmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1127 vim_free(term->tl_eof_chars);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1128 vim_free(term->tl_arg0_cmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1129 #ifdef MSWIN
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1130 if (term->tl_out_fd != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1131 fclose(term->tl_out_fd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1132 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1133 vim_free(term->tl_highlight_name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1134 vim_free(term->tl_cursor_color);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1135 vim_free(term->tl_palette);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1136 vim_free(term);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1137 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1138 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1139
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1140 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1141 * Get the part that is connected to the tty. Normally this is PART_IN, but
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1142 * when writing buffer lines to the job it can be another. This makes it
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1143 * possible to do "1,5term vim -".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1144 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1145 static ch_part_T
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1146 get_tty_part(term_T *term UNUSED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1147 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1148 #ifdef UNIX
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1149 ch_part_T parts[3] = {PART_IN, PART_OUT, PART_ERR};
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1150 int i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1151
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1152 for (i = 0; i < 3; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1153 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1154 int fd = term->tl_job->jv_channel->ch_part[parts[i]].ch_fd;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1155
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1156 if (mch_isatty(fd))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1157 return parts[i];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1158 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1159 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1160 return PART_IN;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1161 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1162
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1163 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1164 * Read any vterm output and send it on the channel.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1165 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1166 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1167 term_forward_output(term_T *term)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1168 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1169 VTerm *vterm = term->tl_vterm;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1170 char buf[KEY_BUF_LEN];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1171 size_t curlen = vterm_output_read(vterm, buf, KEY_BUF_LEN);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1172
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1173 if (curlen > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1174 channel_send(term->tl_job->jv_channel, get_tty_part(term),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1175 (char_u *)buf, (int)curlen, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1176 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1177
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1178 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1179 * Write job output "msg[len]" to the vterm.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1180 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1181 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1182 term_write_job_output(term_T *term, char_u *msg_arg, size_t len_arg)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1183 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1184 char_u *msg = msg_arg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1185 size_t len = len_arg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1186 VTerm *vterm = term->tl_vterm;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1187 size_t prevlen = vterm_output_get_buffer_current(vterm);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1188 size_t limit = term->tl_buffer->b_p_twsl * term->tl_cols * 3;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1189
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1190 // Limit the length to 'termwinscroll' * cols * 3 bytes. Keep the text at
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1191 // the end.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1192 if (len > limit)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1193 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1194 char_u *p = msg + len - limit;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1195
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1196 p -= (*mb_head_off)(msg, p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1197 len -= p - msg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1198 msg = p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1199 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1200
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1201 vterm_input_write(vterm, (char *)msg, len);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1202
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1203 // flush vterm buffer when vterm responded to control sequence
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1204 if (prevlen != vterm_output_get_buffer_current(vterm))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1205 term_forward_output(term);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1206
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1207 // this invokes the damage callbacks
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1208 vterm_screen_flush_damage(vterm_obtain_screen(vterm));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1209 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1210
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1211 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1212 position_cursor(win_T *wp, VTermPos *pos)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1213 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1214 wp->w_wrow = MIN(pos->row, MAX(0, wp->w_height - 1));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1215 wp->w_wcol = MIN(pos->col, MAX(0, wp->w_width - 1));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1216 #ifdef FEAT_PROP_POPUP
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1217 if (popup_is_popup(wp))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1218 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1219 wp->w_wrow += popup_top_extra(wp);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1220 wp->w_wcol += popup_left_extra(wp);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1221 wp->w_flags |= WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1222 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1223 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1224 wp->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1225 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1226 wp->w_valid |= (VALID_WCOL|VALID_WROW);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1227 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1228
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1229 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1230 update_cursor(term_T *term, int redraw)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1231 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1232 if (term->tl_normal_mode)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1233 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1234 #ifdef FEAT_GUI
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1235 if (term->tl_system)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1236 windgoto(term->tl_cursor_pos.row + term->tl_toprow,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1237 term->tl_cursor_pos.col);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1238 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1239 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1240 if (!term_job_running(term))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1241 // avoid the cursor positioned below the last used line
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1242 setcursor();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1243 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1244 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1245 // do not use the window cursor position
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1246 position_cursor(curwin, &curbuf->b_term->tl_cursor_pos);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1247 windgoto(W_WINROW(curwin) + curwin->w_wrow,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1248 curwin->w_wincol + curwin->w_wcol);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1249 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1250 if (redraw)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1251 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1252 aco_save_T aco;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1253
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1254 if (term->tl_buffer == curbuf && term->tl_cursor_visible)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1255 cursor_on();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1256 out_flush();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1257 #ifdef FEAT_GUI
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1258 if (gui.in_use)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1259 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1260 gui_update_cursor(FALSE, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1261 gui_mch_flush();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1262 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1263 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1264 // Make sure an invoked autocmd doesn't delete the buffer (and the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1265 // terminal) under our fingers.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1266 ++term->tl_buffer->b_locked;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1267
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1268 // save and restore curwin and curbuf, in case the autocmd changes them
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1269 aucmd_prepbuf(&aco, curbuf);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1270 apply_autocmds(EVENT_TEXTCHANGEDT, NULL, NULL, FALSE, term->tl_buffer);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1271 aucmd_restbuf(&aco);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1272
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1273 --term->tl_buffer->b_locked;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1274 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1275 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1276
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1277 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1278 * Invoked when "msg" output from a job was received. Write it to the terminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1279 * of "buffer".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1280 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1281 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1282 write_to_term(buf_T *buffer, char_u *msg, channel_T *channel)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1283 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1284 size_t len = STRLEN(msg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1285 term_T *term = buffer->b_term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1286
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1287 #ifdef MSWIN
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1288 // Win32: Cannot redirect output of the job, intercept it here and write to
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1289 // the file.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1290 if (term->tl_out_fd != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1291 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1292 ch_log(channel, "Writing %d bytes to output file", (int)len);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1293 fwrite(msg, len, 1, term->tl_out_fd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1294 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1295 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1296 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1297
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1298 if (term->tl_vterm == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1299 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1300 ch_log(channel, "NOT writing %d bytes to terminal", (int)len);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1301 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1302 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1303 ch_log(channel, "writing %d bytes to terminal", (int)len);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1304 cursor_off();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1305 term_write_job_output(term, msg, len);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1306
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1307 #ifdef FEAT_GUI
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1308 if (term->tl_system)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1309 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1310 // show system output, scrolling up the screen as needed
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1311 update_system_term(term);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1312 update_cursor(term, TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1313 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1314 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1315 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1316 // In Terminal-Normal mode we are displaying the buffer, not the terminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1317 // contents, thus no screen update is needed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1318 if (!term->tl_normal_mode)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1319 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1320 // Don't use update_screen() when editing the command line, it gets
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1321 // cleared.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1322 // TODO: only update once in a while.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1323 ch_log(term->tl_job->jv_channel, "updating screen");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1324 if (buffer == curbuf && (State & MODE_CMDLINE) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1325 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1326 update_screen(UPD_VALID_NO_UPDATE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1327 // update_screen() can be slow, check the terminal wasn't closed
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1328 // already
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1329 if (buffer == curbuf && curbuf->b_term != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1330 update_cursor(curbuf->b_term, TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1331 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1332 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1333 redraw_after_callback(TRUE, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1334 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1335 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1336
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1337 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1338 * Send a mouse position and click to the vterm
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1339 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1340 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1341 term_send_mouse(VTerm *vterm, int button, int pressed)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1342 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1343 VTermModifier mod = VTERM_MOD_NONE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1344 int row = mouse_row - W_WINROW(curwin);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1345 int col = mouse_col - curwin->w_wincol;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1346
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1347 #ifdef FEAT_PROP_POPUP
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1348 if (popup_is_popup(curwin))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1349 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1350 row -= popup_top_extra(curwin);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1351 col -= popup_left_extra(curwin);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1352 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1353 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1354 vterm_mouse_move(vterm, row, col, mod);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1355 if (button != 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1356 vterm_mouse_button(vterm, button, pressed, mod);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1357 return TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1358 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1359
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1360 static int enter_mouse_col = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1361 static int enter_mouse_row = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1362
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1363 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1364 * Handle a mouse click, drag or release.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1365 * Return TRUE when a mouse event is sent to the terminal.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1366 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1367 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1368 term_mouse_click(VTerm *vterm, int key)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1369 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1370 #if defined(FEAT_CLIPBOARD)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1371 // For modeless selection mouse drag and release events are ignored, unless
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1372 // they are preceded with a mouse down event
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1373 static int ignore_drag_release = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1374 VTermMouseState mouse_state;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1375
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1376 vterm_state_get_mousestate(vterm_obtain_state(vterm), &mouse_state);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1377 if (mouse_state.flags == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1378 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1379 // Terminal is not using the mouse, use modeless selection.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1380 switch (key)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1381 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1382 case K_LEFTDRAG:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1383 case K_LEFTRELEASE:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1384 case K_RIGHTDRAG:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1385 case K_RIGHTRELEASE:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1386 // Ignore drag and release events when the button-down wasn't
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1387 // seen before.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1388 if (ignore_drag_release)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1389 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1390 int save_mouse_col, save_mouse_row;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1391
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1392 if (enter_mouse_col < 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1393 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1394
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1395 // mouse click in the window gave us focus, handle that
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1396 // click now
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1397 save_mouse_col = mouse_col;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1398 save_mouse_row = mouse_row;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1399 mouse_col = enter_mouse_col;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1400 mouse_row = enter_mouse_row;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1401 clip_modeless(MOUSE_LEFT, TRUE, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1402 mouse_col = save_mouse_col;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1403 mouse_row = save_mouse_row;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1404 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1405 // FALLTHROUGH
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1406 case K_LEFTMOUSE:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1407 case K_RIGHTMOUSE:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1408 if (key == K_LEFTRELEASE || key == K_RIGHTRELEASE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1409 ignore_drag_release = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1410 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1411 ignore_drag_release = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1412 // Should we call mouse_has() here?
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1413 if (clip_star.available)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1414 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1415 int button, is_click, is_drag;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1416
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1417 button = get_mouse_button(KEY2TERMCAP1(key),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1418 &is_click, &is_drag);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1419 if (mouse_model_popup() && button == MOUSE_LEFT
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1420 && (mod_mask & MOD_MASK_SHIFT))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1421 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1422 // Translate shift-left to right button.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1423 button = MOUSE_RIGHT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1424 mod_mask &= ~MOD_MASK_SHIFT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1425 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1426 clip_modeless(button, is_click, is_drag);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1427 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1428 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1429
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1430 case K_MIDDLEMOUSE:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1431 if (clip_star.available)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1432 insert_reg('*', TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1433 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1434 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1435 enter_mouse_col = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1436 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1437 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1438 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1439 enter_mouse_col = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1440
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1441 switch (key)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1442 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1443 case K_LEFTMOUSE:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1444 case K_LEFTMOUSE_NM: term_send_mouse(vterm, 1, 1); break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1445 case K_LEFTDRAG: term_send_mouse(vterm, 1, 1); break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1446 case K_LEFTRELEASE:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1447 case K_LEFTRELEASE_NM: term_send_mouse(vterm, 1, 0); break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1448 case K_MOUSEMOVE: term_send_mouse(vterm, 0, 0); break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1449 case K_MIDDLEMOUSE: term_send_mouse(vterm, 2, 1); break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1450 case K_MIDDLEDRAG: term_send_mouse(vterm, 2, 1); break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1451 case K_MIDDLERELEASE: term_send_mouse(vterm, 2, 0); break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1452 case K_RIGHTMOUSE: term_send_mouse(vterm, 3, 1); break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1453 case K_RIGHTDRAG: term_send_mouse(vterm, 3, 1); break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1454 case K_RIGHTRELEASE: term_send_mouse(vterm, 3, 0); break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1455 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1456 return TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1457 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1458
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1459 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1460 * Convert typed key "c" with modifiers "modmask" into bytes to send to the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1461 * job.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1462 * Return the number of bytes in "buf".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1463 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1464 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1465 term_convert_key(term_T *term, int c, int modmask, char *buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1466 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1467 VTerm *vterm = term->tl_vterm;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1468 VTermKey key = VTERM_KEY_NONE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1469 VTermModifier mod = VTERM_MOD_NONE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1470 int other = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1471
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1472 switch (c)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1473 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1474 // don't use VTERM_KEY_ENTER, it may do an unwanted conversion
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1475
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1476 // don't use VTERM_KEY_BACKSPACE, it always
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1477 // becomes 0x7f DEL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1478 case K_BS: c = term_backspace_char; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1479
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1480 case ESC: key = VTERM_KEY_ESCAPE; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1481 case K_DEL: key = VTERM_KEY_DEL; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1482 case K_DOWN: key = VTERM_KEY_DOWN; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1483 case K_S_DOWN: mod = VTERM_MOD_SHIFT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1484 key = VTERM_KEY_DOWN; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1485 case K_END: key = VTERM_KEY_END; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1486 case K_S_END: mod = VTERM_MOD_SHIFT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1487 key = VTERM_KEY_END; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1488 case K_C_END: mod = VTERM_MOD_CTRL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1489 key = VTERM_KEY_END; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1490 case K_F10: key = VTERM_KEY_FUNCTION(10); break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1491 case K_F11: key = VTERM_KEY_FUNCTION(11); break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1492 case K_F12: key = VTERM_KEY_FUNCTION(12); break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1493 case K_F1: key = VTERM_KEY_FUNCTION(1); break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1494 case K_F2: key = VTERM_KEY_FUNCTION(2); break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1495 case K_F3: key = VTERM_KEY_FUNCTION(3); break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1496 case K_F4: key = VTERM_KEY_FUNCTION(4); break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1497 case K_F5: key = VTERM_KEY_FUNCTION(5); break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1498 case K_F6: key = VTERM_KEY_FUNCTION(6); break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1499 case K_F7: key = VTERM_KEY_FUNCTION(7); break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1500 case K_F8: key = VTERM_KEY_FUNCTION(8); break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1501 case K_F9: key = VTERM_KEY_FUNCTION(9); break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1502 case K_HOME: key = VTERM_KEY_HOME; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1503 case K_S_HOME: mod = VTERM_MOD_SHIFT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1504 key = VTERM_KEY_HOME; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1505 case K_C_HOME: mod = VTERM_MOD_CTRL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1506 key = VTERM_KEY_HOME; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1507 case K_INS: key = VTERM_KEY_INS; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1508 case K_K0: key = VTERM_KEY_KP_0; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1509 case K_K1: key = VTERM_KEY_KP_1; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1510 case K_K2: key = VTERM_KEY_KP_2; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1511 case K_K3: key = VTERM_KEY_KP_3; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1512 case K_K4: key = VTERM_KEY_KP_4; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1513 case K_K5: key = VTERM_KEY_KP_5; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1514 case K_K6: key = VTERM_KEY_KP_6; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1515 case K_K7: key = VTERM_KEY_KP_7; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1516 case K_K8: key = VTERM_KEY_KP_8; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1517 case K_K9: key = VTERM_KEY_KP_9; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1518 case K_KDEL: key = VTERM_KEY_DEL; break; // TODO
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1519 case K_KDIVIDE: key = VTERM_KEY_KP_DIVIDE; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1520 case K_KEND: key = VTERM_KEY_KP_1; break; // TODO
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1521 case K_KENTER: key = VTERM_KEY_KP_ENTER; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1522 case K_KHOME: key = VTERM_KEY_KP_7; break; // TODO
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1523 case K_KINS: key = VTERM_KEY_KP_0; break; // TODO
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1524 case K_KMINUS: key = VTERM_KEY_KP_MINUS; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1525 case K_KMULTIPLY: key = VTERM_KEY_KP_MULT; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1526 case K_KPAGEDOWN: key = VTERM_KEY_KP_3; break; // TODO
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1527 case K_KPAGEUP: key = VTERM_KEY_KP_9; break; // TODO
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1528 case K_KPLUS: key = VTERM_KEY_KP_PLUS; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1529 case K_KPOINT: key = VTERM_KEY_KP_PERIOD; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1530 case K_LEFT: key = VTERM_KEY_LEFT; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1531 case K_S_LEFT: mod = VTERM_MOD_SHIFT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1532 key = VTERM_KEY_LEFT; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1533 case K_C_LEFT: mod = VTERM_MOD_CTRL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1534 key = VTERM_KEY_LEFT; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1535 case K_PAGEDOWN: key = VTERM_KEY_PAGEDOWN; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1536 case K_PAGEUP: key = VTERM_KEY_PAGEUP; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1537 case K_RIGHT: key = VTERM_KEY_RIGHT; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1538 case K_S_RIGHT: mod = VTERM_MOD_SHIFT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1539 key = VTERM_KEY_RIGHT; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1540 case K_C_RIGHT: mod = VTERM_MOD_CTRL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1541 key = VTERM_KEY_RIGHT; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1542 case K_UP: key = VTERM_KEY_UP; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1543 case K_S_UP: mod = VTERM_MOD_SHIFT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1544 key = VTERM_KEY_UP; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1545 case TAB: key = VTERM_KEY_TAB; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1546 case K_S_TAB: mod = VTERM_MOD_SHIFT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1547 key = VTERM_KEY_TAB; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1548
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1549 case K_MOUSEUP: other = term_send_mouse(vterm, 5, 1); break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1550 case K_MOUSEDOWN: other = term_send_mouse(vterm, 4, 1); break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1551 case K_MOUSELEFT: other = term_send_mouse(vterm, 7, 1); break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1552 case K_MOUSERIGHT: other = term_send_mouse(vterm, 6, 1); break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1553
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1554 case K_LEFTMOUSE:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1555 case K_LEFTMOUSE_NM:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1556 case K_LEFTDRAG:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1557 case K_LEFTRELEASE:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1558 case K_LEFTRELEASE_NM:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1559 case K_MOUSEMOVE:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1560 case K_MIDDLEMOUSE:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1561 case K_MIDDLEDRAG:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1562 case K_MIDDLERELEASE:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1563 case K_RIGHTMOUSE:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1564 case K_RIGHTDRAG:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1565 case K_RIGHTRELEASE: if (!term_mouse_click(vterm, c))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1566 return 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1567 other = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1568 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1569
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1570 case K_X1MOUSE: /* TODO */ return 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1571 case K_X1DRAG: /* TODO */ return 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1572 case K_X1RELEASE: /* TODO */ return 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1573 case K_X2MOUSE: /* TODO */ return 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1574 case K_X2DRAG: /* TODO */ return 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1575 case K_X2RELEASE: /* TODO */ return 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1576
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1577 case K_IGNORE: return 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1578 case K_NOP: return 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1579 case K_UNDO: return 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1580 case K_HELP: return 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1581 case K_XF1: key = VTERM_KEY_FUNCTION(1); break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1582 case K_XF2: key = VTERM_KEY_FUNCTION(2); break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1583 case K_XF3: key = VTERM_KEY_FUNCTION(3); break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1584 case K_XF4: key = VTERM_KEY_FUNCTION(4); break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1585 case K_SELECT: return 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1586 #ifdef FEAT_GUI
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1587 case K_VER_SCROLLBAR: return 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1588 case K_HOR_SCROLLBAR: return 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1589 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1590 #ifdef FEAT_GUI_TABLINE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1591 case K_TABLINE: return 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1592 case K_TABMENU: return 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1593 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1594 #ifdef FEAT_NETBEANS_INTG
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1595 case K_F21: key = VTERM_KEY_FUNCTION(21); break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1596 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1597 #ifdef FEAT_DND
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1598 case K_DROP: return 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1599 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1600 case K_CURSORHOLD: return 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1601 case K_PS: vterm_keyboard_start_paste(vterm);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1602 other = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1603 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1604 case K_PE: vterm_keyboard_end_paste(vterm);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1605 other = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1606 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1607 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1608
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1609 // add modifiers for the typed key
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1610 if (modmask & MOD_MASK_SHIFT)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1611 mod |= VTERM_MOD_SHIFT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1612 if (modmask & MOD_MASK_CTRL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1613 mod |= VTERM_MOD_CTRL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1614 if (modmask & (MOD_MASK_ALT | MOD_MASK_META))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1615 mod |= VTERM_MOD_ALT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1616
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1617 // Ctrl-Shift-i may have the key "I" instead of "i", but for the kitty
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1618 // keyboard protocol should use "i". Applies to all ascii letters.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1619 if (ASCII_ISUPPER(c)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1620 && vterm_is_kitty_keyboard(vterm)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1621 && mod == (VTERM_MOD_CTRL | VTERM_MOD_SHIFT))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1622 c = TOLOWER_ASC(c);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1623
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1624 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1625 * Convert special keys to vterm keys:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1626 * - Write keys to vterm: vterm_keyboard_key()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1627 * - Write output to channel.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1628 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1629 if (key != VTERM_KEY_NONE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1630 // Special key, let vterm convert it.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1631 vterm_keyboard_key(vterm, key, mod);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1632 else if (!other)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1633 // Normal character, let vterm convert it.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1634 vterm_keyboard_unichar(vterm, c, mod);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1635
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1636 // Read back the converted escape sequence.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1637 return (int)vterm_output_read(vterm, buf, KEY_BUF_LEN);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1638 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1639
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1640 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1641 * Return TRUE if the job for "term" is still running.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1642 * If "check_job_status" is TRUE update the job status.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1643 * NOTE: "term" may be freed by callbacks.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1644 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1645 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1646 term_job_running_check(term_T *term, int check_job_status)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1647 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1648 // Also consider the job finished when the channel is closed, to avoid a
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1649 // race condition when updating the title.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1650 if (term == NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1651 || term->tl_job == NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1652 || !channel_is_open(term->tl_job->jv_channel))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1653 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1654
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1655 job_T *job = term->tl_job;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1656
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1657 // Careful: Checking the job status may invoke callbacks, which close
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1658 // the buffer and terminate "term". However, "job" will not be freed
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1659 // yet.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1660 if (check_job_status)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1661 job_status(job);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1662 return (job->jv_status == JOB_STARTED
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1663 || (job->jv_channel != NULL && job->jv_channel->ch_keep_open));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1664 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1665
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1666 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1667 * Return TRUE if the job for "term" is still running.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1668 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1669 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1670 term_job_running(term_T *term)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1671 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1672 return term_job_running_check(term, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1673 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1674
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1675 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1676 * Return TRUE if the job for "term" is still running, ignoring the job was
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1677 * "NONE".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1678 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1679 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1680 term_job_running_not_none(term_T *term)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1681 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1682 return term_job_running(term) && !term_none_open(term);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1683 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1684
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1685 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1686 * Return TRUE if "term" has an active channel and used ":term NONE".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1687 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1688 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1689 term_none_open(term_T *term)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1690 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1691 // Also consider the job finished when the channel is closed, to avoid a
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1692 // race condition when updating the title.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1693 return term != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1694 && term->tl_job != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1695 && channel_is_open(term->tl_job->jv_channel)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1696 && term->tl_job->jv_channel->ch_keep_open;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1697 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1698
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1699 //
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1700 // Used to confirm whether we would like to kill a terminal.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1701 // Return OK when the user confirms to kill it.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1702 // Return FAIL if the user selects otherwise.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1703 //
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1704 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1705 term_confirm_stop(buf_T *buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1706 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1707 char_u buff[DIALOG_MSG_SIZE];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1708 int ret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1709
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1710 dialog_msg(buff, _("Kill job in \"%s\"?"), buf_get_fname(buf));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1711 ret = vim_dialog_yesno(VIM_QUESTION, NULL, buff, 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1712 if (ret == VIM_YES)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1713 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1714 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1715 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1716 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1717
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1718 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1719 * Used when exiting: kill the job in "buf" if so desired.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1720 * Return OK when the job finished.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1721 * Return FAIL when the job is still running.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1722 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1723 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1724 term_try_stop_job(buf_T *buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1725 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1726 int count;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1727 char *how = (char *)buf->b_term->tl_kill;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1728
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1729 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1730 if ((how == NULL || *how == NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1731 && (p_confirm || (cmdmod.cmod_flags & CMOD_CONFIRM)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1732 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1733 if (term_confirm_stop(buf) == OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1734 how = "kill";
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1735 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1736 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1737 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1738 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1739 if (how == NULL || *how == NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1740 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1741
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1742 job_stop(buf->b_term->tl_job, NULL, how);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1743
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1744 // wait for up to a second for the job to die
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1745 for (count = 0; count < 100; ++count)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1746 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1747 job_T *job;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1748
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1749 // buffer, terminal and job may be cleaned up while waiting
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1750 if (!buf_valid(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1751 || buf->b_term == NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1752 || buf->b_term->tl_job == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1753 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1754 job = buf->b_term->tl_job;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1755
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1756 // Call job_status() to update jv_status. It may cause the job to be
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1757 // cleaned up but it won't be freed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1758 job_status(job);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1759 if (job->jv_status >= JOB_ENDED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1760 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1761
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1762 ui_delay(10L, TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1763 term_flush_messages();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1764 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1765 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1766 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1767
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1768 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1769 * Add the last line of the scrollback buffer to the buffer in the window.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1770 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1771 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1772 add_scrollback_line_to_buffer(term_T *term, char_u *text, int len)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1773 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1774 buf_T *buf = term->tl_buffer;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1775 int empty = (buf->b_ml.ml_flags & ML_EMPTY);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1776 linenr_T lnum = buf->b_ml.ml_line_count;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1777
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1778 #ifdef MSWIN
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1779 if (!enc_utf8 && enc_codepage > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1780 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1781 WCHAR *ret = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1782 int length = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1783
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1784 MultiByteToWideChar_alloc(CP_UTF8, 0, (char*)text, len + 1,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1785 &ret, &length);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1786 if (ret != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1787 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1788 WideCharToMultiByte_alloc(enc_codepage, 0,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1789 ret, length, (char **)&text, &len, 0, 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1790 vim_free(ret);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1791 ml_append_buf(term->tl_buffer, lnum, text, len, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1792 vim_free(text);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1793 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1794 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1795 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1796 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1797 ml_append_buf(term->tl_buffer, lnum, text, len + 1, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1798 if (empty)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1799 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1800 // Delete the empty line that was in the empty buffer.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1801 curbuf = buf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1802 ml_delete(1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1803 curbuf = curwin->w_buffer;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1804 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1805 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1806
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1807 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1808 cell2cellattr(const VTermScreenCell *cell, cellattr_T *attr)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1809 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1810 attr->width = cell->width;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1811 attr->attrs = cell->attrs;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1812 attr->fg = cell->fg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1813 attr->bg = cell->bg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1814 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1815
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1816 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1817 equal_celattr(cellattr_T *a, cellattr_T *b)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1818 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1819 // We only compare the RGB colors, ignoring the ANSI index and type.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1820 // Thus black set explicitly is equal the background black.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1821 return a->fg.red == b->fg.red
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1822 && a->fg.green == b->fg.green
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1823 && a->fg.blue == b->fg.blue
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1824 && a->bg.red == b->bg.red
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1825 && a->bg.green == b->bg.green
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1826 && a->bg.blue == b->bg.blue;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1827 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1828
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1829 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1830 * Add an empty scrollback line to "term". When "lnum" is not zero, add the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1831 * line at this position. Otherwise at the end.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1832 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1833 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1834 add_empty_scrollback(term_T *term, cellattr_T *fill_attr, int lnum)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1835 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1836 if (ga_grow(&term->tl_scrollback, 1) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1837 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1838
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1839 sb_line_T *line = (sb_line_T *)term->tl_scrollback.ga_data
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1840 + term->tl_scrollback.ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1841
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1842 if (lnum > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1843 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1844 int i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1845
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1846 for (i = 0; i < term->tl_scrollback.ga_len - lnum; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1847 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1848 *line = *(line - 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1849 --line;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1850 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1851 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1852 line->sb_cols = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1853 line->sb_cells = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1854 line->sb_fill_attr = *fill_attr;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1855 ++term->tl_scrollback.ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1856 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1857 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1858
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1859 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1860 * Remove the terminal contents from the scrollback and the buffer.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1861 * Used before adding a new scrollback line or updating the buffer for lines
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1862 * displayed in the terminal.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1863 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1864 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1865 cleanup_scrollback(term_T *term)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1866 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1867 sb_line_T *line;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1868 garray_T *gap;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1869
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1870 curbuf = term->tl_buffer;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1871 gap = &term->tl_scrollback;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1872 while (curbuf->b_ml.ml_line_count > term->tl_scrollback_scrolled
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1873 && gap->ga_len > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1874 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1875 ml_delete(curbuf->b_ml.ml_line_count);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1876 line = (sb_line_T *)gap->ga_data + gap->ga_len - 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1877 vim_free(line->sb_cells);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1878 --gap->ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1879 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1880 curbuf = curwin->w_buffer;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1881 if (curbuf == term->tl_buffer)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1882 check_cursor();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1883 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1884
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1885 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1886 * Add the current lines of the terminal to scrollback and to the buffer.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1887 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1888 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1889 update_snapshot(term_T *term)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1890 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1891 VTermScreen *screen;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1892 int len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1893 int lines_skipped = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1894 VTermPos pos;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1895 VTermScreenCell cell;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1896 cellattr_T fill_attr, new_fill_attr;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1897 cellattr_T *p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1898
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1899 ch_log(term->tl_job == NULL ? NULL : term->tl_job->jv_channel,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1900 "Adding terminal window snapshot to buffer");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1901
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1902 // First remove the lines that were appended before, they might be
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1903 // outdated.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1904 cleanup_scrollback(term);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1905
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1906 screen = vterm_obtain_screen(term->tl_vterm);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1907 fill_attr = new_fill_attr = term->tl_default_color;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1908 for (pos.row = 0; pos.row < term->tl_rows; ++pos.row)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1909 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1910 len = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1911 for (pos.col = 0; pos.col < term->tl_cols; ++pos.col)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1912 if (vterm_screen_get_cell(screen, pos, &cell) != 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1913 && cell.chars[0] != NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1914 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1915 len = pos.col + 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1916 new_fill_attr = term->tl_default_color;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1917 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1918 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1919 // Assume the last attr is the filler attr.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1920 cell2cellattr(&cell, &new_fill_attr);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1921
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1922 if (len == 0 && equal_celattr(&new_fill_attr, &fill_attr))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1923 ++lines_skipped;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1924 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1925 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1926 while (lines_skipped > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1927 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1928 // Line was skipped, add an empty line.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1929 --lines_skipped;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1930 if (add_empty_scrollback(term, &fill_attr, 0) == OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1931 add_scrollback_line_to_buffer(term, (char_u *)"", 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1932 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1933
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1934 if (len == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1935 p = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1936 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1937 p = ALLOC_MULT(cellattr_T, len);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1938 if ((p != NULL || len == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1939 && ga_grow(&term->tl_scrollback, 1) == OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1940 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1941 garray_T ga;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1942 int width;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1943 sb_line_T *line = (sb_line_T *)term->tl_scrollback.ga_data
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1944 + term->tl_scrollback.ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1945
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1946 ga_init2(&ga, 1, 100);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1947 for (pos.col = 0; pos.col < len; pos.col += width)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1948 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1949 if (vterm_screen_get_cell(screen, pos, &cell) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1950 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1951 width = 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1952 CLEAR_POINTER(p + pos.col);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1953 if (ga_grow(&ga, 1) == OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1954 ga.ga_len += utf_char2bytes(' ',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1955 (char_u *)ga.ga_data + ga.ga_len);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1956 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1957 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1958 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1959 width = cell.width;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1960
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1961 cell2cellattr(&cell, &p[pos.col]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1962 if (width == 2)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1963 // second cell of double-width character has the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1964 // same attributes.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1965 p[pos.col + 1] = p[pos.col];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1966
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1967 // Each character can be up to 6 bytes.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1968 if (ga_grow(&ga, VTERM_MAX_CHARS_PER_CELL * 6) == OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1969 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1970 int i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1971 int c;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1972
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1973 for (i = 0; (c = cell.chars[i]) > 0 || i == 0; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1974 ga.ga_len += utf_char2bytes(c == NUL ? ' ' : c,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1975 (char_u *)ga.ga_data + ga.ga_len);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1976 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1977 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1978 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1979 line->sb_cols = len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1980 line->sb_cells = p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1981 line->sb_fill_attr = new_fill_attr;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1982 fill_attr = new_fill_attr;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1983 ++term->tl_scrollback.ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1984
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1985 if (ga_grow(&ga, 1) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1986 add_scrollback_line_to_buffer(term, (char_u *)"", 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1987 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1988 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1989 *((char_u *)ga.ga_data + ga.ga_len) = NUL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1990 add_scrollback_line_to_buffer(term, ga.ga_data, ga.ga_len);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1991 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1992 ga_clear(&ga);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1993 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1994 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1995 vim_free(p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1996 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1997 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1998
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
1999 // Add trailing empty lines.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2000 for (pos.row = term->tl_scrollback.ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2001 pos.row < term->tl_scrollback_scrolled + term->tl_cursor_pos.row;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2002 ++pos.row)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2003 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2004 if (add_empty_scrollback(term, &fill_attr, 0) == OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2005 add_scrollback_line_to_buffer(term, (char_u *)"", 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2006 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2007
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2008 term->tl_dirty_snapshot = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2009 #ifdef FEAT_TIMERS
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2010 term->tl_timer_set = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2011 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2012 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2013
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2014 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2015 * Loop over all windows in the current tab, and also curwin, which is not
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2016 * encountered when using a terminal in a popup window.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2017 * Return TRUE if "*wp" was set to the next window.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2018 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2019 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2020 for_all_windows_and_curwin(win_T **wp, int *did_curwin)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2021 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2022 if (*wp == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2023 *wp = firstwin;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2024 else if ((*wp)->w_next != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2025 *wp = (*wp)->w_next;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2026 else if (!*did_curwin)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2027 *wp = curwin;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2028 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2029 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2030 if (*wp == curwin)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2031 *did_curwin = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2032 return TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2033 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2034
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2035 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2036 * If needed, add the current lines of the terminal to scrollback and to the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2037 * buffer. Called after the job has ended and when switching to
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2038 * Terminal-Normal mode.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2039 * When "redraw" is TRUE redraw the windows that show the terminal.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2040 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2041 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2042 may_move_terminal_to_buffer(term_T *term, int redraw)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2043 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2044 if (term->tl_vterm == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2045 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2046
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2047 // Update the snapshot only if something changes or the buffer does not
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2048 // have all the lines.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2049 if (term->tl_dirty_snapshot || term->tl_buffer->b_ml.ml_line_count
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2050 <= term->tl_scrollback_scrolled)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2051 update_snapshot(term);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2052
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2053 // Obtain the current background color.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2054 vterm_state_get_default_colors(vterm_obtain_state(term->tl_vterm),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2055 &term->tl_default_color.fg, &term->tl_default_color.bg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2056
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2057 if (redraw)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2058 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2059 win_T *wp = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2060 int did_curwin = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2061
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2062 while (for_all_windows_and_curwin(&wp, &did_curwin))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2063 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2064 if (wp->w_buffer == term->tl_buffer)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2065 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2066 wp->w_cursor.lnum = term->tl_buffer->b_ml.ml_line_count;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2067 wp->w_cursor.col = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2068 wp->w_valid = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2069 if (wp->w_cursor.lnum >= wp->w_height)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2070 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2071 linenr_T min_topline = wp->w_cursor.lnum - wp->w_height + 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2072
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2073 if (wp->w_topline < min_topline)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2074 wp->w_topline = min_topline;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2075 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2076 redraw_win_later(wp, UPD_NOT_VALID);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2077 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2078 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2079 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2080 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2081
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2082 #if defined(FEAT_TIMERS) || defined(PROTO)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2083 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2084 * Check if any terminal timer expired. If so, copy text from the terminal to
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2085 * the buffer.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2086 * Return the time until the next timer will expire.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2087 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2088 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2089 term_check_timers(int next_due_arg, proftime_T *now)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2090 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2091 term_T *term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2092 int next_due = next_due_arg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2093
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2094 FOR_ALL_TERMS(term)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2095 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2096 if (term->tl_timer_set && !term->tl_normal_mode)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2097 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2098 long this_due = proftime_time_left(&term->tl_timer_due, now);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2099
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2100 if (this_due <= 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2101 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2102 term->tl_timer_set = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2103 may_move_terminal_to_buffer(term, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2104 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2105 else if (next_due == -1 || next_due > this_due)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2106 next_due = this_due;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2107 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2108 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2109
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2110 return next_due;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2111 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2112 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2113
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2114 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2115 * When "normal_mode" is TRUE set the terminal to Terminal-Normal mode,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2116 * otherwise end it.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2117 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2118 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2119 set_terminal_mode(term_T *term, int normal_mode)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2120 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2121 term->tl_normal_mode = normal_mode;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2122 may_trigger_modechanged();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2123 if (!normal_mode)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2124 handle_postponed_scrollback(term);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2125 VIM_CLEAR(term->tl_status_text);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2126 if (term->tl_buffer == curbuf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2127 maketitle();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2128 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2129
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2130 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2131 * Called after the job is finished and Terminal mode is not active:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2132 * Move the vterm contents into the scrollback buffer and free the vterm.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2133 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2134 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2135 cleanup_vterm(term_T *term)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2136 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2137 set_terminal_mode(term, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2138 if (term->tl_finish != TL_FINISH_CLOSE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2139 may_move_terminal_to_buffer(term, TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2140 term_free_vterm(term);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2141 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2142
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2143 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2144 * Switch from Terminal-Job mode to Terminal-Normal mode.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2145 * Suspends updating the terminal window.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2146 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2147 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2148 term_enter_normal_mode(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2149 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2150 term_T *term = curbuf->b_term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2151
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2152 set_terminal_mode(term, TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2153
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2154 // Append the current terminal contents to the buffer.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2155 may_move_terminal_to_buffer(term, TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2156
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2157 // Move the window cursor to the position of the cursor in the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2158 // terminal.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2159 curwin->w_cursor.lnum = term->tl_scrollback_scrolled
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2160 + term->tl_cursor_pos.row + 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2161 check_cursor();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2162 if (coladvance(term->tl_cursor_pos.col) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2163 coladvance(MAXCOL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2164 curwin->w_set_curswant = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2165
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2166 // Display the same lines as in the terminal.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2167 curwin->w_topline = term->tl_scrollback_scrolled + 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2168 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2169
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2170 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2171 * Returns TRUE if the current window contains a terminal and we are in
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2172 * Terminal-Normal mode.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2173 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2174 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2175 term_in_normal_mode(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2176 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2177 term_T *term = curbuf->b_term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2178
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2179 return term != NULL && term->tl_normal_mode;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2180 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2181
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2182 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2183 * Switch from Terminal-Normal mode to Terminal-Job mode.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2184 * Restores updating the terminal window.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2185 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2186 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2187 term_enter_job_mode(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2188 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2189 term_T *term = curbuf->b_term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2190
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2191 set_terminal_mode(term, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2192
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2193 if (term->tl_channel_closed)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2194 cleanup_vterm(term);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2195 redraw_buf_and_status_later(curbuf, UPD_NOT_VALID);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2196 #ifdef FEAT_PROP_POPUP
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2197 if (WIN_IS_POPUP(curwin))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2198 redraw_later(UPD_NOT_VALID);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2199 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2200 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2201
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2202 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2203 * When "modify_other_keys" is set then vgetc() should not reduce a key with
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2204 * modifiers into a basic key. However, we may only find out after calling
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2205 * vgetc(). Therefore vgetorpeek() will call check_no_reduce_keys() to update
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2206 * "no_reduce_keys" before using it.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2207 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2208 typedef enum {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2209 NRKS_NONE, // initial value
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2210 NRKS_CHECK, // modify_other_keys was off before calling vgetc()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2211 NRKS_SET, // no_reduce_keys was incremented in term_vgetc() or
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2212 // check_no_reduce_keys(), must be decremented.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2213 } reduce_key_state_T;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2214
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2215 static reduce_key_state_T no_reduce_key_state = NRKS_NONE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2216
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2217 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2218 * Return TRUE if the term is using modifyOtherKeys level 2 or the kitty
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2219 * keyboard protocol.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2220 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2221 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2222 vterm_using_key_protocol(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2223 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2224 return curbuf->b_term != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2225 && curbuf->b_term->tl_vterm != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2226 && (vterm_is_modify_other_keys(curbuf->b_term->tl_vterm)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2227 || vterm_is_kitty_keyboard(curbuf->b_term->tl_vterm));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2228 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2229
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2230 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2231 check_no_reduce_keys(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2232 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2233 if (no_reduce_key_state != NRKS_CHECK
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2234 || no_reduce_keys >= 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2235 || curbuf->b_term == NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2236 || curbuf->b_term->tl_vterm == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2237 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2238
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2239 if (vterm_using_key_protocol())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2240 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2241 // "modify_other_keys" or kitty keyboard protocol was enabled while
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2242 // waiting.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2243 no_reduce_key_state = NRKS_SET;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2244 ++no_reduce_keys;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2245 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2246 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2247
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2248 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2249 * Get a key from the user with terminal mode mappings.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2250 * Note: while waiting a terminal may be closed and freed if the channel is
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2251 * closed and ++close was used. This may even happen before we get here.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2252 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2253 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2254 term_vgetc(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2255 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2256 int c;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2257 int save_State = State;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2258
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2259 State = MODE_TERMINAL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2260 got_int = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2261 #ifdef MSWIN
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2262 ctrl_break_was_pressed = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2263 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2264
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2265 if (vterm_using_key_protocol())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2266 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2267 ++no_reduce_keys;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2268 no_reduce_key_state = NRKS_SET;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2269 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2270 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2271 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2272 no_reduce_key_state = NRKS_CHECK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2273 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2274
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2275 c = vgetc();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2276 got_int = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2277 State = save_State;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2278
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2279 if (no_reduce_key_state == NRKS_SET)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2280 --no_reduce_keys;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2281 no_reduce_key_state = NRKS_NONE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2282
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2283 return c;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2284 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2285
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2286 static int mouse_was_outside = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2287
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2288 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2289 * Send key "c" with modifiers "modmask" to terminal.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2290 * Return FAIL when the key needs to be handled in Normal mode.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2291 * Return OK when the key was dropped or sent to the terminal.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2292 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2293 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2294 send_keys_to_term(term_T *term, int c, int modmask, int typed)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2295 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2296 char msg[KEY_BUF_LEN];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2297 size_t len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2298 int dragging_outside = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2299
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2300 // Catch keys that need to be handled as in Normal mode.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2301 switch (c)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2302 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2303 case NUL:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2304 case K_ZERO:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2305 if (typed)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2306 stuffcharReadbuff(c);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2307 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2308
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2309 case K_TABLINE:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2310 stuffcharReadbuff(c);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2311 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2312
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2313 case K_IGNORE:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2314 case K_CANCEL: // used for :normal when running out of chars
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2315 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2316
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2317 case K_LEFTDRAG:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2318 case K_MIDDLEDRAG:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2319 case K_RIGHTDRAG:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2320 case K_X1DRAG:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2321 case K_X2DRAG:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2322 dragging_outside = mouse_was_outside;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2323 // FALLTHROUGH
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2324 case K_LEFTMOUSE:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2325 case K_LEFTMOUSE_NM:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2326 case K_LEFTRELEASE:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2327 case K_LEFTRELEASE_NM:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2328 case K_MOUSEMOVE:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2329 case K_MIDDLEMOUSE:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2330 case K_MIDDLERELEASE:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2331 case K_RIGHTMOUSE:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2332 case K_RIGHTRELEASE:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2333 case K_X1MOUSE:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2334 case K_X1RELEASE:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2335 case K_X2MOUSE:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2336 case K_X2RELEASE:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2337
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2338 case K_MOUSEUP:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2339 case K_MOUSEDOWN:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2340 case K_MOUSELEFT:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2341 case K_MOUSERIGHT:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2342 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2343 int row = mouse_row;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2344 int col = mouse_col;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2345
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2346 #ifdef FEAT_PROP_POPUP
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2347 if (popup_is_popup(curwin))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2348 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2349 row -= popup_top_extra(curwin);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2350 col -= popup_left_extra(curwin);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2351 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2352 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2353 if (row < W_WINROW(curwin)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2354 || row >= (W_WINROW(curwin) + curwin->w_height)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2355 || col < curwin->w_wincol
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2356 || col >= W_ENDCOL(curwin)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2357 || dragging_outside)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2358 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2359 // click or scroll outside the current window or on status
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2360 // line or vertical separator
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2361 if (typed)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2362 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2363 stuffcharReadbuff(c);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2364 mouse_was_outside = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2365 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2366 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2367 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2368 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2369 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2370
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2371 case K_COMMAND:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2372 case K_SCRIPT_COMMAND:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2373 return do_cmdkey_command(c, 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2374 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2375 if (typed)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2376 mouse_was_outside = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2377
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2378 // Convert the typed key to a sequence of bytes for the job.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2379 len = term_convert_key(term, c, modmask, msg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2380 if (len > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2381 // TODO: if FAIL is returned, stop?
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2382 channel_send(term->tl_job->jv_channel, get_tty_part(term),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2383 (char_u *)msg, (int)len, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2384
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2385 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2386 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2387
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2388 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2389 * Handle CTRL-W "": send register contents to the job.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2390 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2391 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2392 term_paste_register(int prev_c UNUSED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2393 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2394 int c;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2395 list_T *l;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2396 listitem_T *item;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2397 long reglen = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2398 int type;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2399
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2400 if (add_to_showcmd(prev_c))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2401 if (add_to_showcmd('"'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2402 out_flush();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2403
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2404 c = term_vgetc();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2405 clear_showcmd();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2406
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2407 if (!term_use_loop())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2408 // job finished while waiting for a character
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2409 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2410
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2411 // CTRL-W "= prompt for expression to evaluate.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2412 if (c == '=' && get_expr_register() != '=')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2413 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2414 if (!term_use_loop())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2415 // job finished while waiting for a character
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2416 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2417
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2418 l = (list_T *)get_reg_contents(c, GREG_LIST);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2419 if (l == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2420 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2421
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2422 type = get_reg_type(c, &reglen);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2423 FOR_ALL_LIST_ITEMS(l, item)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2424 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2425 char_u *s = tv_get_string(&item->li_tv);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2426 #ifdef MSWIN
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2427 char_u *tmp = s;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2428
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2429 if (!enc_utf8 && enc_codepage > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2430 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2431 WCHAR *ret = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2432 int length = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2433
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2434 MultiByteToWideChar_alloc(enc_codepage, 0, (char *)s,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2435 (int)STRLEN(s), &ret, &length);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2436 if (ret != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2437 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2438 WideCharToMultiByte_alloc(CP_UTF8, 0,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2439 ret, length, (char **)&s, &length, 0, 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2440 vim_free(ret);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2441 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2442 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2443 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2444 channel_send(curbuf->b_term->tl_job->jv_channel, PART_IN,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2445 s, (int)STRLEN(s), NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2446 #ifdef MSWIN
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2447 if (tmp != s)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2448 vim_free(s);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2449 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2450
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2451 if (item->li_next != NULL || type == MLINE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2452 channel_send(curbuf->b_term->tl_job->jv_channel, PART_IN,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2453 (char_u *)"\r", 1, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2454 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2455 list_free(l);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2456 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2457
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2458 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2459 * Return TRUE when waiting for a character in the terminal, the cursor of the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2460 * terminal should be displayed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2461 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2462 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2463 terminal_is_active(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2464 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2465 return in_terminal_loop != NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2466 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2467
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2468 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2469 * Return the highlight group ID for the terminal and the window.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2470 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2471 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2472 term_get_highlight_id(term_T *term, win_T *wp)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2473 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2474 char_u *name;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2475
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2476 if (wp != NULL && *wp->w_p_wcr != NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2477 name = wp->w_p_wcr;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2478 else if (term->tl_highlight_name != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2479 name = term->tl_highlight_name;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2480 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2481 name = (char_u*)"Terminal";
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2482
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2483 return syn_name2id(name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2484 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2485
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2486 #if defined(FEAT_GUI) || defined(PROTO)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2487 cursorentry_T *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2488 term_get_cursor_shape(guicolor_T *fg, guicolor_T *bg)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2489 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2490 term_T *term = in_terminal_loop;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2491 static cursorentry_T entry;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2492 int id;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2493 guicolor_T term_fg = INVALCOLOR;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2494 guicolor_T term_bg = INVALCOLOR;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2495
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2496 CLEAR_FIELD(entry);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2497 entry.shape = entry.mshape =
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2498 term->tl_cursor_shape == VTERM_PROP_CURSORSHAPE_UNDERLINE ? SHAPE_HOR :
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2499 term->tl_cursor_shape == VTERM_PROP_CURSORSHAPE_BAR_LEFT ? SHAPE_VER :
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2500 SHAPE_BLOCK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2501 entry.percentage = 20;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2502 if (term->tl_cursor_blink)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2503 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2504 entry.blinkwait = 700;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2505 entry.blinkon = 400;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2506 entry.blinkoff = 250;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2507 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2508
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2509 // The highlight group overrules the defaults.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2510 id = term_get_highlight_id(term, curwin);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2511 if (id != 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2512 syn_id2colors(id, &term_fg, &term_bg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2513 if (term_bg != INVALCOLOR)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2514 *fg = term_bg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2515 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2516 *fg = gui.back_pixel;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2517
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2518 if (term->tl_cursor_color == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2519 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2520 if (term_fg != INVALCOLOR)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2521 *bg = term_fg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2522 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2523 *bg = gui.norm_pixel;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2524 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2525 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2526 *bg = color_name2handle(term->tl_cursor_color);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2527 entry.name = "n";
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2528 entry.used_for = SHAPE_CURSOR;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2529
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2530 return &entry;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2531 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2532 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2533
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2534 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2535 may_output_cursor_props(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2536 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2537 if (!cursor_color_equal(last_set_cursor_color, desired_cursor_color)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2538 || last_set_cursor_shape != desired_cursor_shape
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2539 || last_set_cursor_blink != desired_cursor_blink)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2540 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2541 cursor_color_copy(&last_set_cursor_color, desired_cursor_color);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2542 last_set_cursor_shape = desired_cursor_shape;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2543 last_set_cursor_blink = desired_cursor_blink;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2544 term_cursor_color(cursor_color_get(desired_cursor_color));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2545 if (desired_cursor_shape == -1 || desired_cursor_blink == -1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2546 // this will restore the initial cursor style, if possible
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2547 ui_cursor_shape_forced(TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2548 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2549 term_cursor_shape(desired_cursor_shape, desired_cursor_blink);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2550 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2551 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2552
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2553 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2554 * Set the cursor color and shape, if not last set to these.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2555 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2556 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2557 may_set_cursor_props(term_T *term)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2558 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2559 #ifdef FEAT_GUI
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2560 // For the GUI the cursor properties are obtained with
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2561 // term_get_cursor_shape().
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2562 if (gui.in_use)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2563 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2564 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2565 if (in_terminal_loop == term)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2566 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2567 cursor_color_copy(&desired_cursor_color, term->tl_cursor_color);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2568 desired_cursor_shape = term->tl_cursor_shape;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2569 desired_cursor_blink = term->tl_cursor_blink;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2570 may_output_cursor_props();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2571 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2572 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2573
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2574 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2575 * Reset the desired cursor properties and restore them when needed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2576 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2577 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2578 prepare_restore_cursor_props(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2579 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2580 #ifdef FEAT_GUI
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2581 if (gui.in_use)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2582 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2583 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2584 cursor_color_copy(&desired_cursor_color, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2585 desired_cursor_shape = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2586 desired_cursor_blink = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2587 may_output_cursor_props();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2588 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2589
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2590 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2591 * Returns TRUE if the current window contains a terminal and we are sending
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2592 * keys to the job.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2593 * If "check_job_status" is TRUE update the job status.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2594 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2595 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2596 term_use_loop_check(int check_job_status)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2597 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2598 term_T *term = curbuf->b_term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2599
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2600 return term != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2601 && !term->tl_normal_mode
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2602 && term->tl_vterm != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2603 && term_job_running_check(term, check_job_status);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2604 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2605
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2606 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2607 * Returns TRUE if the current window contains a terminal and we are sending
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2608 * keys to the job.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2609 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2610 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2611 term_use_loop(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2612 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2613 return term_use_loop_check(FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2614 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2615
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2616 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2617 * Called when entering a window with the mouse. If this is a terminal window
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2618 * we may want to change state.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2619 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2620 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2621 term_win_entered(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2622 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2623 term_T *term = curbuf->b_term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2624
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2625 if (term == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2626 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2627
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2628 if (term_use_loop_check(TRUE))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2629 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2630 reset_VIsual_and_resel();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2631 if (State & MODE_INSERT)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2632 stop_insert_mode = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2633 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2634 mouse_was_outside = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2635 enter_mouse_col = mouse_col;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2636 enter_mouse_row = mouse_row;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2637 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2638
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2639 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2640 term_focus_change(int in_focus)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2641 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2642 term_T *term = curbuf->b_term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2643
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2644 if (term == NULL || term->tl_vterm == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2645 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2646
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2647 VTermState *state = vterm_obtain_state(term->tl_vterm);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2648
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2649 if (in_focus)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2650 vterm_state_focus_in(state);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2651 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2652 vterm_state_focus_out(state);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2653 term_forward_output(term);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2654 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2655
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2656 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2657 * vgetc() may not include CTRL in the key when modify_other_keys is set.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2658 * Return the Ctrl-key value in that case.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2659 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2660 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2661 raw_c_to_ctrl(int c)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2662 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2663 if ((mod_mask & MOD_MASK_CTRL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2664 && ((c >= '`' && c <= 0x7f) || (c >= '@' && c <= '_')))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2665 return c & 0x1f;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2666 return c;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2667 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2668
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2669 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2670 * When modify_other_keys is set then do the reverse of raw_c_to_ctrl().
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2671 * Also when the Kitty keyboard protocol is used.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2672 * May set "mod_mask".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2673 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2674 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2675 ctrl_to_raw_c(int c)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2676 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2677 if (c < 0x20 && vterm_using_key_protocol())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2678 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2679 mod_mask |= MOD_MASK_CTRL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2680 return c + '@';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2681 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2682 return c;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2683 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2684
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2685 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2686 * Wait for input and send it to the job.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2687 * When "blocking" is TRUE wait for a character to be typed. Otherwise return
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2688 * when there is no more typahead.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2689 * Return when the start of a CTRL-W command is typed or anything else that
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2690 * should be handled as a Normal mode command.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2691 * Returns OK if a typed character is to be handled in Normal mode, FAIL if
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2692 * the terminal was closed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2693 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2694 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2695 terminal_loop(int blocking)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2696 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2697 int c;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2698 int raw_c;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2699 int termwinkey = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2700 int ret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2701 #ifdef UNIX
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2702 int tty_fd = curbuf->b_term->tl_job->jv_channel
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2703 ->ch_part[get_tty_part(curbuf->b_term)].ch_fd;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2704 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2705 int restore_cursor = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2706
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2707 // Remember the terminal we are sending keys to. However, the terminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2708 // might be closed while waiting for a character, e.g. typing "exit" in a
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2709 // shell and ++close was used. Therefore use curbuf->b_term instead of a
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2710 // stored reference.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2711 in_terminal_loop = curbuf->b_term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2712
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2713 if (*curwin->w_p_twk != NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2714 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2715 termwinkey = string_to_key(curwin->w_p_twk, TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2716 if (termwinkey == Ctrl_W)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2717 termwinkey = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2718 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2719 position_cursor(curwin, &curbuf->b_term->tl_cursor_pos);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2720 may_set_cursor_props(curbuf->b_term);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2721
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2722 while (blocking || vpeekc_nomap() != NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2723 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2724 #ifdef FEAT_GUI
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2725 if (curbuf->b_term != NULL && !curbuf->b_term->tl_system)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2726 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2727 // TODO: skip screen update when handling a sequence of keys.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2728 // Repeat redrawing in case a message is received while redrawing.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2729 while (must_redraw != 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2730 if (update_screen(0) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2731 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2732 if (!term_use_loop_check(TRUE) || in_terminal_loop != curbuf->b_term)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2733 // job finished while redrawing
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2734 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2735
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2736 update_cursor(curbuf->b_term, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2737 restore_cursor = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2738
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2739 raw_c = term_vgetc();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2740 if (!term_use_loop_check(TRUE) || in_terminal_loop != curbuf->b_term)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2741 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2742 // Job finished while waiting for a character. Push back the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2743 // received character.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2744 if (raw_c != K_IGNORE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2745 vungetc(raw_c);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2746 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2747 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2748 if (raw_c == K_IGNORE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2749 continue;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2750 c = raw_c_to_ctrl(raw_c);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2751
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2752 #ifdef UNIX
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2753 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2754 * The shell or another program may change the tty settings. Getting
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2755 * them for every typed character is a bit of overhead, but it's needed
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2756 * for the first character typed, e.g. when Vim starts in a shell.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2757 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2758 if (mch_isatty(tty_fd))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2759 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2760 ttyinfo_T info;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2761
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2762 // Get the current backspace character of the pty.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2763 if (get_tty_info(tty_fd, &info) == OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2764 term_backspace_char = info.backspace;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2765 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2766 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2767
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2768 #ifdef MSWIN
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2769 // On Windows winpty handles CTRL-C, don't send a CTRL_C_EVENT.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2770 // Use CTRL-BREAK to kill the job.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2771 if (ctrl_break_was_pressed)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2772 mch_signal_job(curbuf->b_term->tl_job, (char_u *)"kill");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2773 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2774 // Was either CTRL-W (termwinkey) or CTRL-\ pressed?
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2775 // Not in a system terminal.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2776 if ((c == (termwinkey == 0 ? Ctrl_W : termwinkey) || c == Ctrl_BSL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2777 #ifdef FEAT_GUI
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2778 && !curbuf->b_term->tl_system
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2779 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2780 )
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2781 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2782 int prev_c = c;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2783 int prev_raw_c = raw_c;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2784 int prev_mod_mask = mod_mask;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2785
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2786 if (add_to_showcmd(c))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2787 out_flush();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2788
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2789 raw_c = term_vgetc();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2790 c = raw_c_to_ctrl(raw_c);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2791
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2792 clear_showcmd();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2793
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2794 if (!term_use_loop_check(TRUE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2795 || in_terminal_loop != curbuf->b_term)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2796 // job finished while waiting for a character
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2797 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2798
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2799 if (prev_c == Ctrl_BSL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2800 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2801 if (c == Ctrl_N)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2802 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2803 // CTRL-\ CTRL-N : go to Terminal-Normal mode.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2804 term_enter_normal_mode();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2805 ret = FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2806 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2807 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2808 // Send both keys to the terminal, first one here, second one
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2809 // below.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2810 send_keys_to_term(curbuf->b_term, prev_raw_c, prev_mod_mask,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2811 TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2812 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2813 else if (c == Ctrl_C)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2814 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2815 // "CTRL-W CTRL-C" or 'termwinkey' CTRL-C: end the job
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2816 mch_signal_job(curbuf->b_term->tl_job, (char_u *)"kill");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2817 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2818 else if (c == '.')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2819 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2820 // "CTRL-W .": send CTRL-W to the job
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2821 // "'termwinkey' .": send 'termwinkey' to the job
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2822 raw_c = ctrl_to_raw_c(termwinkey == 0 ? Ctrl_W : termwinkey);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2823 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2824 else if (c == Ctrl_BSL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2825 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2826 // "CTRL-W CTRL-\": send CTRL-\ to the job
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2827 raw_c = ctrl_to_raw_c(Ctrl_BSL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2828 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2829 else if (c == 'N')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2830 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2831 // CTRL-W N : go to Terminal-Normal mode.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2832 term_enter_normal_mode();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2833 ret = FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2834 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2835 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2836 else if (c == '"')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2837 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2838 term_paste_register(prev_c);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2839 continue;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2840 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2841 else if (termwinkey == 0 || c != termwinkey)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2842 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2843 // space for CTRL-W, modifier, multi-byte char and NUL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2844 char_u buf[1 + 3 + MB_MAXBYTES + 1];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2845
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2846 // Put the command into the typeahead buffer, when using the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2847 // stuff buffer KeyStuffed is set and 'langmap' won't be used.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2848 buf[0] = Ctrl_W;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2849 buf[special_to_buf(c, mod_mask, FALSE, buf + 1) + 1] = NUL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2850 ins_typebuf(buf, REMAP_NONE, 0, TRUE, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2851 ret = OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2852 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2853 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2854 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2855 # ifdef MSWIN
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2856 if (!enc_utf8 && has_mbyte && raw_c >= 0x80)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2857 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2858 WCHAR wc;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2859 char_u mb[3];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2860
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2861 mb[0] = (unsigned)raw_c >> 8;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2862 mb[1] = raw_c;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2863 if (MultiByteToWideChar(GetACP(), 0, (char*)mb, 2, &wc, 1) > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2864 raw_c = wc;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2865 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2866 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2867 if (send_keys_to_term(curbuf->b_term, raw_c, mod_mask, TRUE) != OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2868 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2869 if (raw_c == K_MOUSEMOVE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2870 // We are sure to come back here, don't reset the cursor color
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2871 // and shape to avoid flickering.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2872 restore_cursor = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2873
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2874 ret = OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2875 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2876 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2877 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2878 ret = FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2879
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2880 theend:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2881 in_terminal_loop = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2882 if (restore_cursor)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2883 prepare_restore_cursor_props();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2884
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2885 // Move a snapshot of the screen contents to the buffer, so that completion
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2886 // works in other buffers.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2887 if (curbuf->b_term != NULL && !curbuf->b_term->tl_normal_mode)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2888 may_move_terminal_to_buffer(curbuf->b_term, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2889
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2890 return ret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2891 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2892
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2893 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2894 may_toggle_cursor(term_T *term)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2895 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2896 if (in_terminal_loop != term)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2897 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2898
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2899 if (term->tl_cursor_visible)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2900 cursor_on();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2901 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2902 cursor_off();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2903 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2904
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2905 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2906 * Reverse engineer the RGB value into a cterm color index.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2907 * First color is 1. Return 0 if no match found (default color).
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2908 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2909 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2910 color2index(VTermColor *color, int fg, int *boldp)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2911 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2912 int red = color->red;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2913 int blue = color->blue;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2914 int green = color->green;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2915
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2916 *boldp = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2917
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2918 if (VTERM_COLOR_IS_INVALID(color))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2919 return 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2920
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2921 if (VTERM_COLOR_IS_INDEXED(color))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2922 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2923 // Use the color as-is if possible, give up otherwise.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2924 if (color->index < t_colors)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2925 return color->index + 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2926 // 8-color terminals can actually display twice as many colors by
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2927 // setting the high-intensity/bold bit.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2928 else if (t_colors == 8 && fg && color->index < 16)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2929 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2930 *boldp = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2931 return (color->index & 7) + 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2932 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2933 return 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2934 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2935
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2936 if (t_colors >= 256)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2937 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2938 if (red == blue && red == green)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2939 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2940 // 24-color greyscale plus white and black
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2941 static int cutoff[23] = {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2942 0x0D, 0x17, 0x21, 0x2B, 0x35, 0x3F, 0x49, 0x53, 0x5D, 0x67,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2943 0x71, 0x7B, 0x85, 0x8F, 0x99, 0xA3, 0xAD, 0xB7, 0xC1, 0xCB,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2944 0xD5, 0xDF, 0xE9};
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2945 int i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2946
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2947 if (red < 5)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2948 return 17; // 00/00/00
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2949 if (red > 245) // ff/ff/ff
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2950 return 232;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2951 for (i = 0; i < 23; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2952 if (red < cutoff[i])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2953 return i + 233;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2954 return 256;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2955 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2956 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2957 static int cutoff[5] = {0x2F, 0x73, 0x9B, 0xC3, 0xEB};
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2958 int ri, gi, bi;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2959
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2960 // 216-color cube
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2961 for (ri = 0; ri < 5; ++ri)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2962 if (red < cutoff[ri])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2963 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2964 for (gi = 0; gi < 5; ++gi)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2965 if (green < cutoff[gi])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2966 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2967 for (bi = 0; bi < 5; ++bi)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2968 if (blue < cutoff[bi])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2969 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2970 return 17 + ri * 36 + gi * 6 + bi;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2971 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2972 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2973 return 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2974 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2975
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2976 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2977 * Convert Vterm attributes to highlight flags.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2978 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2979 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2980 vtermAttr2hl(VTermScreenCellAttrs *cellattrs)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2981 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2982 int attr = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2983
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2984 if (cellattrs->bold)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2985 attr |= HL_BOLD;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2986 if (cellattrs->underline)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2987 attr |= HL_UNDERLINE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2988 if (cellattrs->italic)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2989 attr |= HL_ITALIC;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2990 if (cellattrs->strike)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2991 attr |= HL_STRIKETHROUGH;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2992 if (cellattrs->reverse)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2993 attr |= HL_INVERSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2994 return attr;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2995 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2996
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2997 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2998 * Store Vterm attributes in "cell" from highlight flags.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
2999 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3000 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3001 hl2vtermAttr(int attr, cellattr_T *cell)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3002 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3003 CLEAR_FIELD(cell->attrs);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3004 if (attr & HL_BOLD)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3005 cell->attrs.bold = 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3006 if (attr & HL_UNDERLINE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3007 cell->attrs.underline = 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3008 if (attr & HL_ITALIC)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3009 cell->attrs.italic = 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3010 if (attr & HL_STRIKETHROUGH)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3011 cell->attrs.strike = 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3012 if (attr & HL_INVERSE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3013 cell->attrs.reverse = 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3014 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3015
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3016 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3017 * Convert the attributes of a vterm cell into an attribute index.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3018 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3019 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3020 cell2attr(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3021 term_T *term,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3022 win_T *wp,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3023 VTermScreenCellAttrs *cellattrs,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3024 VTermColor *cellfg,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3025 VTermColor *cellbg)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3026 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3027 int attr = vtermAttr2hl(cellattrs);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3028 VTermColor *fg = cellfg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3029 VTermColor *bg = cellbg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3030 int is_default_fg = VTERM_COLOR_IS_DEFAULT_FG(fg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3031 int is_default_bg = VTERM_COLOR_IS_DEFAULT_BG(bg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3032
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3033 if (is_default_fg || is_default_bg)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3034 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3035 if (wp != NULL && *wp->w_p_wcr != NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3036 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3037 if (is_default_fg)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3038 fg = &wp->w_term_wincolor.fg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3039 if (is_default_bg)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3040 bg = &wp->w_term_wincolor.bg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3041 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3042 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3043 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3044 if (is_default_fg)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3045 fg = &term->tl_default_color.fg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3046 if (is_default_bg)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3047 bg = &term->tl_default_color.bg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3048 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3049 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3050
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3051 #ifdef FEAT_GUI
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3052 if (gui.in_use)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3053 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3054 guicolor_T guifg = gui_mch_get_rgb_color(fg->red, fg->green, fg->blue);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3055 guicolor_T guibg = gui_mch_get_rgb_color(bg->red, bg->green, bg->blue);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3056 return get_gui_attr_idx(attr, guifg, guibg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3057 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3058 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3059 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3060 #ifdef FEAT_TERMGUICOLORS
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3061 if (p_tgc)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3062 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3063 guicolor_T tgcfg = VTERM_COLOR_IS_INVALID(fg)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3064 ? INVALCOLOR
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3065 : gui_get_rgb_color_cmn(fg->red, fg->green, fg->blue);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3066 guicolor_T tgcbg = VTERM_COLOR_IS_INVALID(bg)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3067 ? INVALCOLOR
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3068 : gui_get_rgb_color_cmn(bg->red, bg->green, bg->blue);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3069 return get_tgc_attr_idx(attr, tgcfg, tgcbg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3070 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3071 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3072 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3073 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3074 int bold = MAYBE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3075 int ctermfg = color2index(fg, TRUE, &bold);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3076 int ctermbg = color2index(bg, FALSE, &bold);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3077
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3078 // with 8 colors set the bold attribute to get a bright foreground
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3079 if (bold == TRUE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3080 attr |= HL_BOLD;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3081
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3082 return get_cterm_attr_idx(attr, ctermfg, ctermbg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3083 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3084 return 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3085 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3086
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3087 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3088 set_dirty_snapshot(term_T *term)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3089 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3090 term->tl_dirty_snapshot = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3091 #ifdef FEAT_TIMERS
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3092 if (!term->tl_normal_mode)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3093 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3094 // Update the snapshot after 100 msec of not getting updates.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3095 profile_setlimit(100L, &term->tl_timer_due);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3096 term->tl_timer_set = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3097 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3098 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3099 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3100
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3101 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3102 handle_damage(VTermRect rect, void *user)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3103 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3104 term_T *term = (term_T *)user;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3105
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3106 term->tl_dirty_row_start = MIN(term->tl_dirty_row_start, rect.start_row);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3107 term->tl_dirty_row_end = MAX(term->tl_dirty_row_end, rect.end_row);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3108 set_dirty_snapshot(term);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3109 redraw_buf_later(term->tl_buffer, UPD_SOME_VALID);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3110 return 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3111 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3112
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3113 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3114 term_scroll_up(term_T *term, int start_row, int count)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3115 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3116 win_T *wp = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3117 int did_curwin = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3118 VTermColor fg, bg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3119 VTermScreenCellAttrs attr;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3120 int clear_attr;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3121
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3122 CLEAR_FIELD(attr);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3123
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3124 while (for_all_windows_and_curwin(&wp, &did_curwin))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3125 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3126 if (wp->w_buffer == term->tl_buffer)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3127 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3128 // Set the color to clear lines with.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3129 vterm_state_get_default_colors(vterm_obtain_state(term->tl_vterm),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3130 &fg, &bg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3131 clear_attr = cell2attr(term, wp, &attr, &fg, &bg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3132 win_del_lines(wp, start_row, count, FALSE, FALSE, clear_attr);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3133 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3134 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3135 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3136
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3137 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3138 handle_moverect(VTermRect dest, VTermRect src, void *user)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3139 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3140 term_T *term = (term_T *)user;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3141 int count = src.start_row - dest.start_row;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3142
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3143 // Scrolling up is done much more efficiently by deleting lines instead of
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3144 // redrawing the text. But avoid doing this multiple times, postpone until
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3145 // the redraw happens.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3146 if (dest.start_col == src.start_col
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3147 && dest.end_col == src.end_col
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3148 && dest.start_row < src.start_row)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3149 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3150 if (dest.start_row == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3151 term->tl_postponed_scroll += count;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3152 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3153 term_scroll_up(term, dest.start_row, count);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3154 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3155
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3156 term->tl_dirty_row_start = MIN(term->tl_dirty_row_start, dest.start_row);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3157 term->tl_dirty_row_end = MIN(term->tl_dirty_row_end, dest.end_row);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3158 set_dirty_snapshot(term);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3159
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3160 // Note sure if the scrolling will work correctly, let's do a complete
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3161 // redraw later.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3162 redraw_buf_later(term->tl_buffer, UPD_NOT_VALID);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3163 return 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3164 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3165
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3166 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3167 handle_movecursor(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3168 VTermPos pos,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3169 VTermPos oldpos UNUSED,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3170 int visible,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3171 void *user)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3172 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3173 term_T *term = (term_T *)user;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3174 win_T *wp = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3175 int did_curwin = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3176
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3177 term->tl_cursor_pos = pos;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3178 term->tl_cursor_visible = visible;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3179
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3180 while (for_all_windows_and_curwin(&wp, &did_curwin))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3181 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3182 if (wp->w_buffer == term->tl_buffer)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3183 position_cursor(wp, &pos);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3184 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3185 if (term->tl_buffer == curbuf && !term->tl_normal_mode)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3186 update_cursor(term, term->tl_cursor_visible);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3187
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3188 return 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3189 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3190
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3191 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3192 handle_settermprop(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3193 VTermProp prop,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3194 VTermValue *value,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3195 void *user)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3196 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3197 term_T *term = (term_T *)user;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3198 char_u *strval = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3199
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3200 switch (prop)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3201 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3202 case VTERM_PROP_TITLE:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3203 if (disable_vterm_title_for_testing)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3204 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3205 strval = vim_strnsave((char_u *)value->string.str,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3206 value->string.len);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3207 if (strval == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3208 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3209 vim_free(term->tl_title);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3210 // a blank title isn't useful, make it empty, so that "running" is
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3211 // displayed
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3212 if (*skipwhite(strval) == NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3213 term->tl_title = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3214 // Same as blank
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3215 else if (term->tl_arg0_cmd != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3216 && STRNCMP(term->tl_arg0_cmd, strval,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3217 (int)STRLEN(term->tl_arg0_cmd)) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3218 term->tl_title = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3219 // Empty corrupted data of winpty
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3220 else if (STRNCMP(" - ", strval, 4) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3221 term->tl_title = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3222 #ifdef MSWIN
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3223 else if (!enc_utf8 && enc_codepage > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3224 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3225 WCHAR *ret = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3226 int length = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3227
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3228 MultiByteToWideChar_alloc(CP_UTF8, 0,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3229 (char*)value->string.str,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3230 (int)value->string.len, &ret, &length);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3231 if (ret != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3232 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3233 WideCharToMultiByte_alloc(enc_codepage, 0,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3234 ret, length, (char**)&term->tl_title,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3235 &length, 0, 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3236 vim_free(ret);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3237 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3238 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3239 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3240 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3241 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3242 term->tl_title = strval;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3243 strval = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3244 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3245 VIM_CLEAR(term->tl_status_text);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3246 if (term == curbuf->b_term)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3247 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3248 maketitle();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3249 curwin->w_redr_status = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3250 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3251 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3252
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3253 case VTERM_PROP_CURSORVISIBLE:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3254 term->tl_cursor_visible = value->boolean;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3255 may_toggle_cursor(term);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3256 out_flush();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3257 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3258
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3259 case VTERM_PROP_CURSORBLINK:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3260 term->tl_cursor_blink = value->boolean;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3261 may_set_cursor_props(term);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3262 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3263
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3264 case VTERM_PROP_CURSORSHAPE:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3265 term->tl_cursor_shape = value->number;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3266 may_set_cursor_props(term);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3267 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3268
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3269 case VTERM_PROP_CURSORCOLOR:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3270 strval = vim_strnsave((char_u *)value->string.str,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3271 value->string.len);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3272 if (strval == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3273 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3274 cursor_color_copy(&term->tl_cursor_color, strval);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3275 may_set_cursor_props(term);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3276 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3277
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3278 case VTERM_PROP_ALTSCREEN:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3279 // TODO: do anything else?
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3280 term->tl_using_altscreen = value->boolean;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3281 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3282
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3283 default:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3284 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3285 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3286 vim_free(strval);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3287
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3288 // Always return 1, otherwise vterm doesn't store the value internally.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3289 return 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3290 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3291
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3292 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3293 * The job running in the terminal resized the terminal.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3294 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3295 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3296 handle_resize(int rows, int cols, void *user)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3297 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3298 term_T *term = (term_T *)user;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3299 win_T *wp;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3300
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3301 term->tl_rows = rows;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3302 term->tl_cols = cols;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3303 if (term->tl_vterm_size_changed)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3304 // Size was set by vterm_set_size(), don't set the window size.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3305 term->tl_vterm_size_changed = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3306 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3307 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3308 FOR_ALL_WINDOWS(wp)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3309 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3310 if (wp->w_buffer == term->tl_buffer)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3311 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3312 win_setheight_win(rows, wp);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3313 win_setwidth_win(cols, wp);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3314 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3315 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3316 redraw_buf_later(term->tl_buffer, UPD_NOT_VALID);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3317 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3318 return 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3319 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3320
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3321 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3322 * If the number of lines that are stored goes over 'termwinscroll' then
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3323 * delete the first 10%.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3324 * "gap" points to tl_scrollback or tl_scrollback_postponed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3325 * "update_buffer" is TRUE when the buffer should be updated.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3326 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3327 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3328 limit_scrollback(term_T *term, garray_T *gap, int update_buffer)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3329 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3330 if (gap->ga_len < term->tl_buffer->b_p_twsl)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3331 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3332
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3333 int todo = term->tl_buffer->b_p_twsl / 10;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3334 int i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3335
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3336 curbuf = term->tl_buffer;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3337 for (i = 0; i < todo; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3338 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3339 vim_free(((sb_line_T *)gap->ga_data + i)->sb_cells);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3340 if (update_buffer)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3341 ml_delete(1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3342 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3343 curbuf = curwin->w_buffer;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3344
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3345 gap->ga_len -= todo;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3346 mch_memmove(gap->ga_data,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3347 (sb_line_T *)gap->ga_data + todo,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3348 sizeof(sb_line_T) * gap->ga_len);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3349 if (update_buffer)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3350 term->tl_scrollback_scrolled -= todo;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3351 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3352
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3353 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3354 * Handle a line that is pushed off the top of the screen.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3355 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3356 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3357 handle_pushline(int cols, const VTermScreenCell *cells, void *user)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3358 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3359 term_T *term = (term_T *)user;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3360 garray_T *gap;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3361 int update_buffer;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3362
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3363 if (term->tl_normal_mode)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3364 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3365 // In Terminal-Normal mode the user interacts with the buffer, thus we
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3366 // must not change it. Postpone adding the scrollback lines.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3367 gap = &term->tl_scrollback_postponed;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3368 update_buffer = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3369 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3370 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3371 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3372 // First remove the lines that were appended before, the pushed line
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3373 // goes above it.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3374 cleanup_scrollback(term);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3375 gap = &term->tl_scrollback;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3376 update_buffer = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3377 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3378
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3379 limit_scrollback(term, gap, update_buffer);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3380
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3381 if (ga_grow(gap, 1) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3382 return 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3383
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3384 cellattr_T *p = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3385 int len = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3386 int i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3387 int c;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3388 int col;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3389 int text_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3390 char_u *text;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3391 sb_line_T *line;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3392 garray_T ga;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3393 cellattr_T fill_attr = term->tl_default_color;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3394
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3395 // do not store empty cells at the end
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3396 for (i = 0; i < cols; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3397 if (cells[i].chars[0] != 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3398 len = i + 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3399 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3400 cell2cellattr(&cells[i], &fill_attr);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3401
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3402 ga_init2(&ga, 1, 100);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3403 if (len > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3404 p = ALLOC_MULT(cellattr_T, len);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3405 if (p != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3406 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3407 for (col = 0; col < len; col += cells[col].width)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3408 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3409 if (ga_grow(&ga, MB_MAXBYTES) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3410 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3411 ga.ga_len = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3412 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3413 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3414 for (i = 0; (c = cells[col].chars[i]) > 0 || i == 0; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3415 ga.ga_len += utf_char2bytes(c == NUL ? ' ' : c,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3416 (char_u *)ga.ga_data + ga.ga_len);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3417 cell2cellattr(&cells[col], &p[col]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3418 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3419 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3420 if (ga_grow(&ga, 1) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3421 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3422 if (update_buffer)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3423 text = (char_u *)"";
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3424 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3425 text = vim_strsave((char_u *)"");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3426 text_len = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3427 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3428 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3429 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3430 text = ga.ga_data;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3431 text_len = ga.ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3432 *(text + text_len) = NUL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3433 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3434 if (update_buffer)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3435 add_scrollback_line_to_buffer(term, text, text_len);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3436
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3437 line = (sb_line_T *)gap->ga_data + gap->ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3438 line->sb_cols = len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3439 line->sb_cells = p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3440 line->sb_fill_attr = fill_attr;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3441 if (update_buffer)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3442 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3443 line->sb_text = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3444 ++term->tl_scrollback_scrolled;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3445 ga_clear(&ga); // free the text
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3446 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3447 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3448 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3449 line->sb_text = text;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3450 ga_init(&ga); // text is kept in tl_scrollback_postponed
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3451 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3452 ++gap->ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3453 return 0; // ignored
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3454 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3455
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3456 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3457 * Called when leaving Terminal-Normal mode: deal with any scrollback that was
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3458 * received and stored in tl_scrollback_postponed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3459 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3460 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3461 handle_postponed_scrollback(term_T *term)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3462 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3463 int i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3464
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3465 if (term->tl_scrollback_postponed.ga_len == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3466 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3467 ch_log(NULL, "Moving postponed scrollback to scrollback");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3468
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3469 // First remove the lines that were appended before, the pushed lines go
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3470 // above it.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3471 cleanup_scrollback(term);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3472
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3473 for (i = 0; i < term->tl_scrollback_postponed.ga_len; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3474 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3475 char_u *text;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3476 sb_line_T *pp_line;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3477 sb_line_T *line;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3478
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3479 if (ga_grow(&term->tl_scrollback, 1) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3480 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3481 pp_line = (sb_line_T *)term->tl_scrollback_postponed.ga_data + i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3482
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3483 text = pp_line->sb_text;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3484 if (text == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3485 text = (char_u *)"";
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3486 add_scrollback_line_to_buffer(term, text, (int)STRLEN(text));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3487 vim_free(pp_line->sb_text);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3488
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3489 line = (sb_line_T *)term->tl_scrollback.ga_data
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3490 + term->tl_scrollback.ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3491 line->sb_cols = pp_line->sb_cols;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3492 line->sb_cells = pp_line->sb_cells;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3493 line->sb_fill_attr = pp_line->sb_fill_attr;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3494 line->sb_text = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3495 ++term->tl_scrollback_scrolled;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3496 ++term->tl_scrollback.ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3497 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3498
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3499 ga_clear(&term->tl_scrollback_postponed);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3500 limit_scrollback(term, &term->tl_scrollback, TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3501 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3502
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3503 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3504 * Called when the terminal wants to ring the system bell.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3505 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3506 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3507 handle_bell(void *user UNUSED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3508 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3509 vim_beep(BO_TERM);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3510 return 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3511 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3512
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3513 static VTermScreenCallbacks screen_callbacks = {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3514 handle_damage, // damage
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3515 handle_moverect, // moverect
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3516 handle_movecursor, // movecursor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3517 handle_settermprop, // settermprop
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3518 handle_bell, // bell
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3519 handle_resize, // resize
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3520 handle_pushline, // sb_pushline
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3521 NULL, // sb_popline
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3522 NULL // sb_clear
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3523 };
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3524
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3525 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3526 * Do the work after the channel of a terminal was closed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3527 * Must be called only when updating_screen is FALSE.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3528 * Returns TRUE when a buffer was closed (list of terminals may have changed).
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3529 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3530 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3531 term_after_channel_closed(term_T *term)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3532 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3533 // Unless in Terminal-Normal mode: clear the vterm.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3534 if (!term->tl_normal_mode)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3535 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3536 int fnum = term->tl_buffer->b_fnum;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3537
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3538 cleanup_vterm(term);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3539
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3540 if (term->tl_finish == TL_FINISH_CLOSE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3541 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3542 aco_save_T aco;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3543 int do_set_w_closing = term->tl_buffer->b_nwindows == 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3544 #ifdef FEAT_PROP_POPUP
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3545 win_T *pwin = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3546
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3547 // If this was a terminal in a popup window, go back to the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3548 // previous window.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3549 if (popup_is_popup(curwin) && curbuf == term->tl_buffer)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3550 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3551 pwin = curwin;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3552 if (win_valid(prevwin))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3553 win_enter(prevwin, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3554 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3555 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3556 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3557 // If this is the last normal window: exit Vim.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3558 if (term->tl_buffer->b_nwindows > 0 && only_one_window())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3559 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3560 exarg_T ea;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3561
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3562 CLEAR_FIELD(ea);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3563 ex_quit(&ea);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3564 return TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3565 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3566
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3567 // ++close or term_finish == "close"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3568 ch_log(NULL, "terminal job finished, closing window");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3569 aucmd_prepbuf(&aco, term->tl_buffer);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3570 if (curbuf == term->tl_buffer)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3571 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3572 // Avoid closing the window if we temporarily use it.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3573 if (is_aucmd_win(curwin))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3574 do_set_w_closing = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3575 if (do_set_w_closing)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3576 curwin->w_closing = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3577 do_bufdel(DOBUF_WIPE, (char_u *)"", 1, fnum, fnum, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3578 if (do_set_w_closing)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3579 curwin->w_closing = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3580 aucmd_restbuf(&aco);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3581 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3582 #ifdef FEAT_PROP_POPUP
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3583 if (pwin != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3584 popup_close_with_retval(pwin, 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3585 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3586 return TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3587 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3588 if (term->tl_finish == TL_FINISH_OPEN
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3589 && term->tl_buffer->b_nwindows == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3590 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3591 char *cmd = term->tl_opencmd == NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3592 ? "botright sbuf %d"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3593 : (char *)term->tl_opencmd;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3594 size_t len = strlen(cmd) + 50;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3595 char *buf = alloc(len);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3596
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3597 if (buf != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3598 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3599 ch_log(NULL, "terminal job finished, opening window");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3600 vim_snprintf(buf, len, cmd, fnum);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3601 do_cmdline_cmd((char_u *)buf);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3602 vim_free(buf);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3603 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3604 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3605 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3606 ch_log(NULL, "terminal job finished");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3607 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3608
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3609 redraw_buf_and_status_later(term->tl_buffer, UPD_NOT_VALID);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3610 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3611 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3612
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3613 #if defined(FEAT_PROP_POPUP) || defined(PROTO)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3614 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3615 * If the current window is a terminal in a popup window and the job has
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3616 * finished, close the popup window and to back to the previous window.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3617 * Otherwise return FAIL.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3618 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3619 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3620 may_close_term_popup(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3621 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3622 if (!popup_is_popup(curwin) || curbuf->b_term == NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3623 || term_job_running_not_none(curbuf->b_term))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3624 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3625
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3626 win_T *pwin = curwin;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3627
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3628 if (win_valid(prevwin))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3629 win_enter(prevwin, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3630 popup_close_with_retval(pwin, 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3631 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3632 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3633 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3634
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3635 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3636 * Called when a channel is going to be closed, before invoking the close
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3637 * callback.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3638 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3639 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3640 term_channel_closing(channel_T *ch)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3641 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3642 term_T *term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3643
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3644 for (term = first_term; term != NULL; term = term->tl_next)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3645 if (term->tl_job == ch->ch_job && !term->tl_channel_closed)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3646 term->tl_channel_closing = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3647 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3648
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3649 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3650 * Called when a channel has been closed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3651 * If this was a channel for a terminal window then finish it up.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3652 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3653 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3654 term_channel_closed(channel_T *ch)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3655 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3656 term_T *term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3657 term_T *next_term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3658 int did_one = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3659
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3660 for (term = first_term; term != NULL; term = next_term)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3661 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3662 next_term = term->tl_next;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3663 if (term->tl_job == ch->ch_job && !term->tl_channel_closed)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3664 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3665 term->tl_channel_closed = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3666 did_one = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3667
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3668 VIM_CLEAR(term->tl_title);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3669 VIM_CLEAR(term->tl_status_text);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3670 #ifdef MSWIN
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3671 if (term->tl_out_fd != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3672 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3673 fclose(term->tl_out_fd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3674 term->tl_out_fd = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3675 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3676 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3677
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3678 if (updating_screen)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3679 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3680 // Cannot open or close windows now. Can happen when
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3681 // 'lazyredraw' is set.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3682 term->tl_channel_recently_closed = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3683 continue;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3684 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3685
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3686 if (term_after_channel_closed(term))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3687 next_term = first_term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3688 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3689 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3690
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3691 if (did_one)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3692 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3693 redraw_statuslines();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3694
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3695 // Need to break out of vgetc().
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3696 ins_char_typebuf(K_IGNORE, 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3697 typebuf_was_filled = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3698
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3699 term = curbuf->b_term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3700 if (term != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3701 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3702 if (term->tl_job == ch->ch_job)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3703 maketitle();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3704 update_cursor(term, term->tl_cursor_visible);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3705 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3706 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3707 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3708
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3709 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3710 * To be called after resetting updating_screen: handle any terminal where the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3711 * channel was closed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3712 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3713 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3714 term_check_channel_closed_recently(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3715 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3716 term_T *term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3717 term_T *next_term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3718
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3719 for (term = first_term; term != NULL; term = next_term)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3720 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3721 next_term = term->tl_next;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3722 if (term->tl_channel_recently_closed)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3723 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3724 term->tl_channel_recently_closed = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3725 if (term_after_channel_closed(term))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3726 // start over, the list may have changed
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3727 next_term = first_term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3728 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3729 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3730 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3731
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3732 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3733 * Fill one screen line from a line of the terminal.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3734 * Advances "pos" to past the last column.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3735 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3736 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3737 term_line2screenline(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3738 term_T *term,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3739 win_T *wp,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3740 VTermScreen *screen,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3741 VTermPos *pos,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3742 int max_col)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3743 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3744 int off = screen_get_current_line_off();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3745
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3746 for (pos->col = 0; pos->col < max_col; )
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3747 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3748 VTermScreenCell cell;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3749 int c;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3750
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3751 if (vterm_screen_get_cell(screen, *pos, &cell) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3752 CLEAR_FIELD(cell);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3753
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3754 c = cell.chars[0];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3755 if (c == NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3756 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3757 ScreenLines[off] = ' ';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3758 if (enc_utf8)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3759 ScreenLinesUC[off] = NUL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3760 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3761 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3762 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3763 if (enc_utf8)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3764 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3765 int i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3766
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3767 // composing chars
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3768 for (i = 0; i < Screen_mco
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3769 && i + 1 < VTERM_MAX_CHARS_PER_CELL; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3770 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3771 ScreenLinesC[i][off] = cell.chars[i + 1];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3772 if (cell.chars[i + 1] == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3773 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3774 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3775 if (c >= 0x80 || (Screen_mco > 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3776 && ScreenLinesC[0][off] != 0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3777 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3778 ScreenLines[off] = ' ';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3779 ScreenLinesUC[off] = c;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3780 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3781 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3782 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3783 ScreenLines[off] = c;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3784 ScreenLinesUC[off] = NUL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3785 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3786 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3787 #ifdef MSWIN
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3788 else if (has_mbyte && c >= 0x80)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3789 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3790 char_u mb[MB_MAXBYTES+1];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3791 WCHAR wc = c;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3792
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3793 if (WideCharToMultiByte(GetACP(), 0, &wc, 1,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3794 (char*)mb, 2, 0, 0) > 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3795 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3796 ScreenLines[off] = mb[0];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3797 ScreenLines[off + 1] = mb[1];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3798 cell.width = mb_ptr2cells(mb);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3799 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3800 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3801 ScreenLines[off] = c;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3802 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3803 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3804 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3805 // This will only store the lower byte of "c".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3806 ScreenLines[off] = c;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3807 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3808 ScreenAttrs[off] = cell2attr(term, wp, &cell.attrs, &cell.fg,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3809 &cell.bg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3810
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3811 ++pos->col;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3812 ++off;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3813 if (cell.width == 2)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3814 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3815 // don't set the second byte to NUL for a DBCS encoding, it
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3816 // has been set above
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3817 if (enc_utf8)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3818 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3819 ScreenLinesUC[off] = NUL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3820 ScreenLines[off] = NUL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3821 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3822 else if (!has_mbyte)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3823 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3824 // Can't show a double-width character with a single-byte
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3825 // 'encoding', just use a space.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3826 ScreenLines[off] = ' ';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3827 ScreenAttrs[off] = ScreenAttrs[off - 1];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3828 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3829
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3830 ++pos->col;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3831 ++off;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3832 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3833 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3834 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3835
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3836 #if defined(FEAT_GUI)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3837 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3838 update_system_term(term_T *term)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3839 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3840 VTermPos pos;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3841 VTermScreen *screen;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3842
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3843 if (term->tl_vterm == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3844 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3845 screen = vterm_obtain_screen(term->tl_vterm);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3846
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3847 // Scroll up to make more room for terminal lines if needed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3848 while (term->tl_toprow > 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3849 && (Rows - term->tl_toprow) < term->tl_dirty_row_end)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3850 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3851 int save_p_more = p_more;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3852
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3853 p_more = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3854 msg_row = Rows - 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3855 msg_puts("\n");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3856 p_more = save_p_more;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3857 --term->tl_toprow;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3858 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3859
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3860 for (pos.row = term->tl_dirty_row_start; pos.row < term->tl_dirty_row_end
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3861 && pos.row < Rows; ++pos.row)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3862 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3863 if (pos.row < term->tl_rows)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3864 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3865 int max_col = MIN(Columns, term->tl_cols);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3866
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3867 term_line2screenline(term, NULL, screen, &pos, max_col);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3868 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3869 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3870 pos.col = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3871
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3872 screen_line(curwin, term->tl_toprow + pos.row, 0, pos.col, Columns, 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3873 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3874
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3875 term->tl_dirty_row_start = MAX_ROW;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3876 term->tl_dirty_row_end = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3877 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3878 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3879
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3880 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3881 * Return TRUE if window "wp" is to be redrawn with term_update_window().
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3882 * Returns FALSE when there is no terminal running in this window or it is in
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3883 * Terminal-Normal mode.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3884 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3885 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3886 term_do_update_window(win_T *wp)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3887 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3888 term_T *term = wp->w_buffer->b_term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3889
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3890 return term != NULL && term->tl_vterm != NULL && !term->tl_normal_mode;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3891 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3892
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3893 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3894 * Called to update a window that contains an active terminal.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3895 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3896 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3897 term_update_window(win_T *wp)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3898 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3899 term_T *term = wp->w_buffer->b_term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3900 VTerm *vterm;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3901 VTermScreen *screen;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3902 VTermState *state;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3903 VTermPos pos;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3904 int rows, cols;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3905 int newrows, newcols;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3906 int minsize;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3907 win_T *twp;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3908
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3909 vterm = term->tl_vterm;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3910 screen = vterm_obtain_screen(vterm);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3911 state = vterm_obtain_state(vterm);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3912
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3913 // We use UPD_NOT_VALID on a resize or scroll, redraw everything then.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3914 // With UPD_SOME_VALID only redraw what was marked dirty.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3915 if (wp->w_redr_type > UPD_SOME_VALID)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3916 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3917 term->tl_dirty_row_start = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3918 term->tl_dirty_row_end = MAX_ROW;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3919
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3920 if (term->tl_postponed_scroll > 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3921 && term->tl_postponed_scroll < term->tl_rows / 3)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3922 // Scrolling is usually faster than redrawing, when there are only
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3923 // a few lines to scroll.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3924 term_scroll_up(term, 0, term->tl_postponed_scroll);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3925 term->tl_postponed_scroll = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3926 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3927
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3928 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3929 * If the window was resized a redraw will be triggered and we get here.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3930 * Adjust the size of the vterm unless 'termwinsize' specifies a fixed size.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3931 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3932 minsize = parse_termwinsize(wp, &rows, &cols);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3933
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3934 newrows = 99999;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3935 newcols = 99999;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3936 for (twp = firstwin; ; twp = twp->w_next)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3937 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3938 // Always use curwin, it may be a popup window.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3939 win_T *wwp = twp == NULL ? curwin : twp;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3940
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3941 // When more than one window shows the same terminal, use the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3942 // smallest size.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3943 if (wwp->w_buffer == term->tl_buffer)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3944 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3945 newrows = MIN(newrows, wwp->w_height);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3946 newcols = MIN(newcols, wwp->w_width);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3947 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3948 if (twp == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3949 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3950 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3951 if (newrows == 99999 || newcols == 99999)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3952 return; // safety exit
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3953 newrows = rows == 0 ? newrows : minsize ? MAX(rows, newrows) : rows;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3954 newcols = cols == 0 ? newcols : minsize ? MAX(cols, newcols) : cols;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3955
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3956 // If no cell is visible there is no point in resizing. Also, vterm can't
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3957 // handle a zero height.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3958 if (newrows == 0 || newcols == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3959 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3960
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3961 if (term->tl_rows != newrows || term->tl_cols != newcols)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3962 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3963 term->tl_vterm_size_changed = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3964 vterm_set_size(vterm, newrows, newcols);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3965 ch_log(term->tl_job->jv_channel, "Resizing terminal to %d lines",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3966 newrows);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3967 term_report_winsize(term, newrows, newcols);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3968
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3969 // Updating the terminal size will cause the snapshot to be cleared.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3970 // When not in terminal_loop() we need to restore it.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3971 if (term != in_terminal_loop)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3972 may_move_terminal_to_buffer(term, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3973 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3974
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3975 // The cursor may have been moved when resizing.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3976 vterm_state_get_cursorpos(state, &pos);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3977 position_cursor(wp, &pos);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3978
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3979 for (pos.row = term->tl_dirty_row_start; pos.row < term->tl_dirty_row_end
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3980 && pos.row < wp->w_height; ++pos.row)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3981 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3982 if (pos.row < term->tl_rows)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3983 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3984 int max_col = MIN(wp->w_width, term->tl_cols);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3985
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3986 term_line2screenline(term, wp, screen, &pos, max_col);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3987 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3988 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3989 pos.col = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3990
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3991 screen_line(wp, wp->w_winrow + pos.row
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3992 #ifdef FEAT_MENU
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3993 + winbar_height(wp)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3994 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3995 , wp->w_wincol, pos.col, wp->w_width,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3996 #ifdef FEAT_PROP_POPUP
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3997 popup_is_popup(wp) ? SLF_POPUP :
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3998 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
3999 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4000 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4001 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4002
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4003 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4004 * Called after updating all windows: may reset dirty rows.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4005 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4006 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4007 term_did_update_window(win_T *wp)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4008 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4009 term_T *term = wp->w_buffer->b_term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4010
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4011 if (term == NULL || term->tl_vterm == NULL || term->tl_normal_mode
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4012 || wp->w_redr_type != 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4013 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4014
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4015 term->tl_dirty_row_start = MAX_ROW;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4016 term->tl_dirty_row_end = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4017 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4018
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4019 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4020 * Return TRUE if "wp" is a terminal window where the job has finished.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4021 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4022 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4023 term_is_finished(buf_T *buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4024 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4025 return buf->b_term != NULL && buf->b_term->tl_vterm == NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4026 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4027
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4028 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4029 * Return TRUE if "wp" is a terminal window where the job has finished or we
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4030 * are in Terminal-Normal mode, thus we show the buffer contents.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4031 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4032 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4033 term_show_buffer(buf_T *buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4034 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4035 term_T *term = buf->b_term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4036
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4037 return term != NULL && (term->tl_vterm == NULL || term->tl_normal_mode);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4038 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4039
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4040 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4041 * The current buffer is going to be changed. If there is terminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4042 * highlighting remove it now.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4043 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4044 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4045 term_change_in_curbuf(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4046 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4047 term_T *term = curbuf->b_term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4048
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4049 if (!term_is_finished(curbuf) || term->tl_scrollback.ga_len <= 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4050 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4051
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4052 free_scrollback(term);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4053 redraw_buf_later(term->tl_buffer, UPD_NOT_VALID);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4054
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4055 // The buffer is now like a normal buffer, it cannot be easily
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4056 // abandoned when changed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4057 set_string_option_direct((char_u *)"buftype", -1,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4058 (char_u *)"", OPT_FREE|OPT_LOCAL, 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4059 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4060
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4061 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4062 * Get the screen attribute for a position in the buffer.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4063 * Use a negative "col" to get the filler background color.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4064 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4065 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4066 term_get_attr(win_T *wp, linenr_T lnum, int col)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4067 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4068 buf_T *buf = wp->w_buffer;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4069 term_T *term = buf->b_term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4070 sb_line_T *line;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4071 cellattr_T *cellattr;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4072
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4073 if (lnum > term->tl_scrollback.ga_len)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4074 cellattr = &term->tl_default_color;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4075 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4076 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4077 line = (sb_line_T *)term->tl_scrollback.ga_data + lnum - 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4078 if (col < 0 || col >= line->sb_cols)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4079 cellattr = &line->sb_fill_attr;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4080 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4081 cellattr = line->sb_cells + col;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4082 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4083 return cell2attr(term, wp, &cellattr->attrs, &cellattr->fg, &cellattr->bg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4084 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4085
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4086 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4087 * Convert a cterm color number 0 - 255 to RGB.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4088 * This is compatible with xterm.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4089 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4090 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4091 cterm_color2vterm(int nr, VTermColor *rgb)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4092 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4093 cterm_color2rgb(nr, &rgb->red, &rgb->green, &rgb->blue, &rgb->index);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4094 if (rgb->index == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4095 rgb->type = VTERM_COLOR_RGB;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4096 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4097 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4098 rgb->type = VTERM_COLOR_INDEXED;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4099 --rgb->index;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4100 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4101 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4102
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4103 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4104 * Initialize vterm color from the synID.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4105 * Returns TRUE if color is set to "fg" and "bg".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4106 * Otherwise returns FALSE.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4107 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4108 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4109 get_vterm_color_from_synid(int id, VTermColor *fg, VTermColor *bg)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4110 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4111 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4112 // Use the actual color for the GUI and when 'termguicolors' is set.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4113 if (0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4114 # ifdef FEAT_GUI
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4115 || gui.in_use
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4116 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4117 # ifdef FEAT_TERMGUICOLORS
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4118 || p_tgc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4119 # ifdef FEAT_VTP
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4120 // Finally get INVALCOLOR on this execution path
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4121 || (!p_tgc && t_colors >= 256)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4122 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4123 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4124 )
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4125 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4126 guicolor_T fg_rgb = INVALCOLOR;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4127 guicolor_T bg_rgb = INVALCOLOR;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4128
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4129 if (id > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4130 syn_id2colors(id, &fg_rgb, &bg_rgb);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4131
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4132 if (fg_rgb != INVALCOLOR)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4133 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4134 long_u rgb = GUI_MCH_GET_RGB(fg_rgb);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4135 fg->red = (unsigned)(rgb >> 16);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4136 fg->green = (unsigned)(rgb >> 8) & 255;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4137 fg->blue = (unsigned)rgb & 255;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4138 fg->type = VTERM_COLOR_RGB | VTERM_COLOR_DEFAULT_FG;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4139 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4140 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4141 fg->type = VTERM_COLOR_INVALID | VTERM_COLOR_DEFAULT_FG;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4142
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4143 if (bg_rgb != INVALCOLOR)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4144 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4145 long_u rgb = GUI_MCH_GET_RGB(bg_rgb);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4146 bg->red = (unsigned)(rgb >> 16);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4147 bg->green = (unsigned)(rgb >> 8) & 255;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4148 bg->blue = (unsigned)rgb & 255;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4149 bg->type = VTERM_COLOR_RGB | VTERM_COLOR_DEFAULT_BG;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4150 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4151 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4152 bg->type = VTERM_COLOR_INVALID | VTERM_COLOR_DEFAULT_BG;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4153
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4154 return TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4155 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4156 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4157 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4158 if (t_colors >= 16)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4159 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4160 int cterm_fg = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4161 int cterm_bg = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4162
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4163 if (id > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4164 syn_id2cterm_bg(id, &cterm_fg, &cterm_bg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4165
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4166 if (cterm_fg >= 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4167 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4168 cterm_color2vterm(cterm_fg, fg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4169 fg->type |= VTERM_COLOR_DEFAULT_FG;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4170 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4171 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4172 fg->type = VTERM_COLOR_INVALID | VTERM_COLOR_DEFAULT_FG;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4173
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4174 if (cterm_bg >= 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4175 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4176 cterm_color2vterm(cterm_bg, bg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4177 bg->type |= VTERM_COLOR_DEFAULT_BG;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4178 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4179 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4180 bg->type = VTERM_COLOR_INVALID | VTERM_COLOR_DEFAULT_BG;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4181
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4182 return TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4183 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4184
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4185 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4186 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4187
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4188 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4189 term_reset_wincolor(win_T *wp)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4190 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4191 wp->w_term_wincolor.fg.type = VTERM_COLOR_INVALID | VTERM_COLOR_DEFAULT_FG;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4192 wp->w_term_wincolor.bg.type = VTERM_COLOR_INVALID | VTERM_COLOR_DEFAULT_BG;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4193 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4194
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4195 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4196 * Cache the color of 'wincolor'.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4197 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4198 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4199 term_update_wincolor(win_T *wp)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4200 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4201 int id = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4202
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4203 if (*wp->w_p_wcr != NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4204 id = syn_name2id(wp->w_p_wcr);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4205 if (id == 0 || !get_vterm_color_from_synid(id, &wp->w_term_wincolor.fg,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4206 &wp->w_term_wincolor.bg))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4207 term_reset_wincolor(wp);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4208 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4209
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4210 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4211 * Called when option 'termguicolors' was set,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4212 * or when any highlight is changed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4213 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4214 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4215 term_update_wincolor_all(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4216 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4217 win_T *wp = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4218 int did_curwin = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4219
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4220 while (for_all_windows_and_curwin(&wp, &did_curwin))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4221 term_update_wincolor(wp);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4222 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4223
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4224 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4225 * Initialize term->tl_default_color from the environment.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4226 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4227 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4228 init_default_colors(term_T *term)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4229 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4230 VTermColor *fg, *bg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4231 int fgval, bgval;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4232 int id;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4233
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4234 CLEAR_FIELD(term->tl_default_color.attrs);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4235 term->tl_default_color.width = 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4236 fg = &term->tl_default_color.fg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4237 bg = &term->tl_default_color.bg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4238
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4239 // Vterm uses a default black background. Set it to white when
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4240 // 'background' is "light".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4241 if (*p_bg == 'l')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4242 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4243 fgval = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4244 bgval = 255;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4245 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4246 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4247 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4248 fgval = 255;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4249 bgval = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4250 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4251 fg->red = fg->green = fg->blue = fgval;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4252 bg->red = bg->green = bg->blue = bgval;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4253 fg->type = VTERM_COLOR_RGB | VTERM_COLOR_DEFAULT_FG;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4254 bg->type = VTERM_COLOR_RGB | VTERM_COLOR_DEFAULT_BG;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4255
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4256 // The highlight group overrules the defaults.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4257 id = term_get_highlight_id(term, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4258
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4259 if (!get_vterm_color_from_synid(id, fg, bg))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4260 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4261 #if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4262 int tmp;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4263 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4264
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4265 // In an MS-Windows console we know the normal colors.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4266 if (cterm_normal_fg_color > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4267 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4268 cterm_color2vterm(cterm_normal_fg_color - 1, fg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4269 # if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4270 # ifdef VIMDLL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4271 if (!gui.in_use)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4272 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4273 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4274 tmp = fg->red;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4275 fg->red = fg->blue;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4276 fg->blue = tmp;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4277 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4278 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4279 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4280 # ifdef FEAT_TERMRESPONSE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4281 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4282 term_get_fg_color(&fg->red, &fg->green, &fg->blue);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4283 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4284
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4285 if (cterm_normal_bg_color > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4286 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4287 cterm_color2vterm(cterm_normal_bg_color - 1, bg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4288 # if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4289 # ifdef VIMDLL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4290 if (!gui.in_use)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4291 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4292 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4293 tmp = fg->red;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4294 fg->red = fg->blue;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4295 fg->blue = tmp;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4296 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4297 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4298 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4299 # ifdef FEAT_TERMRESPONSE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4300 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4301 term_get_bg_color(&bg->red, &bg->green, &bg->blue);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4302 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4303 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4304 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4305
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4306 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4307 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4308 * Return TRUE if the user-defined palette (either g:terminal_ansi_colors or the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4309 * "ansi_colors" argument in term_start()) shall be applied.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4310 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4311 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4312 term_use_palette(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4313 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4314 if (0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4315 #ifdef FEAT_GUI
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4316 || gui.in_use
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4317 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4318 #ifdef FEAT_TERMGUICOLORS
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4319 || p_tgc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4320 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4321 )
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4322 return TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4323 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4324 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4325
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4326 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4327 * Set the 16 ANSI colors from array of RGB values
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4328 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4329 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4330 set_vterm_palette(VTerm *vterm, long_u *rgb)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4331 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4332 int index = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4333 VTermState *state = vterm_obtain_state(vterm);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4334
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4335 for (; index < 16; index++)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4336 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4337 VTermColor color;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4338
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4339 color.type = VTERM_COLOR_RGB;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4340 color.red = (unsigned)(rgb[index] >> 16);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4341 color.green = (unsigned)(rgb[index] >> 8) & 255;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4342 color.blue = (unsigned)rgb[index] & 255;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4343 color.index = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4344 vterm_state_set_palette_color(state, index, &color);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4345 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4346 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4347
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4348 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4349 * Set the ANSI color palette from a list of colors
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4350 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4351 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4352 set_ansi_colors_list(VTerm *vterm, list_T *list)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4353 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4354 int n = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4355 long_u rgb[16];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4356 listitem_T *li;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4357
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4358 for (li = list->lv_first; li != NULL && n < 16; li = li->li_next, n++)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4359 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4360 char_u *color_name;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4361 guicolor_T guicolor;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4362
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4363 color_name = tv_get_string_chk(&li->li_tv);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4364 if (color_name == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4365 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4366
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4367 guicolor = GUI_GET_COLOR(color_name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4368 if (guicolor == INVALCOLOR)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4369 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4370
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4371 rgb[n] = GUI_MCH_GET_RGB(guicolor);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4372 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4373
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4374 if (n != 16 || li != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4375 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4376
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4377 set_vterm_palette(vterm, rgb);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4378
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4379 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4380 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4381
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4382 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4383 * Initialize the ANSI color palette from g:terminal_ansi_colors[0:15]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4384 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4385 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4386 init_vterm_ansi_colors(VTerm *vterm)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4387 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4388 dictitem_T *var = find_var((char_u *)"g:terminal_ansi_colors", NULL, TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4389
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4390 if (var == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4391 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4392
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4393 if (var->di_tv.v_type != VAR_LIST
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4394 || var->di_tv.vval.v_list == NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4395 || var->di_tv.vval.v_list->lv_first == &range_list_item
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4396 || set_ansi_colors_list(vterm, var->di_tv.vval.v_list) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4397 semsg(_(e_invalid_argument_str), "g:terminal_ansi_colors");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4398 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4399 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4400
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4401 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4402 * Handles a "drop" command from the job in the terminal.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4403 * "item" is the file name, "item->li_next" may have options.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4404 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4405 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4406 handle_drop_command(listitem_T *item)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4407 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4408 char_u *fname = tv_get_string(&item->li_tv);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4409 listitem_T *opt_item = item->li_next;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4410 int bufnr;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4411 win_T *wp;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4412 tabpage_T *tp;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4413 exarg_T ea;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4414 char_u *tofree = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4415
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4416 bufnr = buflist_add(fname, BLN_LISTED | BLN_NOOPT);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4417 FOR_ALL_TAB_WINDOWS(tp, wp)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4418 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4419 if (wp->w_buffer->b_fnum == bufnr)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4420 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4421 // buffer is in a window already, go there
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4422 goto_tabpage_win(tp, wp);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4423 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4424 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4425 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4426
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4427 CLEAR_FIELD(ea);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4428
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4429 if (opt_item != NULL && opt_item->li_tv.v_type == VAR_DICT
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4430 && opt_item->li_tv.vval.v_dict != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4431 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4432 dict_T *dict = opt_item->li_tv.vval.v_dict;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4433 char_u *p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4434
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4435 p = dict_get_string(dict, "ff", FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4436 if (p == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4437 p = dict_get_string(dict, "fileformat", FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4438 if (p != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4439 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4440 if (check_ff_value(p) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4441 ch_log(NULL, "Invalid ff argument to drop: %s", p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4442 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4443 ea.force_ff = *p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4444 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4445 p = dict_get_string(dict, "enc", FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4446 if (p == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4447 p = dict_get_string(dict, "encoding", FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4448 if (p != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4449 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4450 ea.cmd = alloc(STRLEN(p) + 12);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4451 if (ea.cmd != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4452 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4453 sprintf((char *)ea.cmd, "sbuf ++enc=%s", p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4454 ea.force_enc = 11;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4455 tofree = ea.cmd;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4456 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4457 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4458
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4459 p = dict_get_string(dict, "bad", FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4460 if (p != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4461 get_bad_opt(p, &ea);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4462
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4463 if (dict_has_key(dict, "bin"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4464 ea.force_bin = FORCE_BIN;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4465 if (dict_has_key(dict, "binary"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4466 ea.force_bin = FORCE_BIN;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4467 if (dict_has_key(dict, "nobin"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4468 ea.force_bin = FORCE_NOBIN;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4469 if (dict_has_key(dict, "nobinary"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4470 ea.force_bin = FORCE_NOBIN;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4471 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4472
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4473 // open in new window, like ":split fname"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4474 if (ea.cmd == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4475 ea.cmd = (char_u *)"split";
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4476 ea.arg = fname;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4477 ea.cmdidx = CMD_split;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4478 ex_splitview(&ea);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4479
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4480 vim_free(tofree);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4481 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4482
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4483 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4484 * Return TRUE if "func" starts with "pat" and "pat" isn't empty.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4485 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4486 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4487 is_permitted_term_api(char_u *func, char_u *pat)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4488 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4489 return pat != NULL && *pat != NUL && STRNICMP(func, pat, STRLEN(pat)) == 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4490 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4491
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4492 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4493 * Handles a function call from the job running in a terminal.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4494 * "item" is the function name, "item->li_next" has the arguments.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4495 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4496 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4497 handle_call_command(term_T *term, channel_T *channel, listitem_T *item)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4498 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4499 char_u *func;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4500 typval_T argvars[2];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4501 typval_T rettv;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4502 funcexe_T funcexe;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4503
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4504 if (item->li_next == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4505 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4506 ch_log(channel, "Missing function arguments for call");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4507 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4508 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4509 func = tv_get_string(&item->li_tv);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4510
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4511 if (!is_permitted_term_api(func, term->tl_api))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4512 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4513 ch_log(channel, "Unpermitted function: %s", func);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4514 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4515 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4516
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4517 argvars[0].v_type = VAR_NUMBER;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4518 argvars[0].vval.v_number = term->tl_buffer->b_fnum;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4519 argvars[1] = item->li_next->li_tv;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4520 CLEAR_FIELD(funcexe);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4521 funcexe.fe_firstline = 1L;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4522 funcexe.fe_lastline = 1L;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4523 funcexe.fe_evaluate = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4524 if (call_func(func, -1, &rettv, 2, argvars, &funcexe) == OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4525 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4526 clear_tv(&rettv);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4527 ch_log(channel, "Function %s called", func);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4528 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4529 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4530 ch_log(channel, "Calling function %s failed", func);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4531 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4532
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4533 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4534 * URL decoding (also know as Percent-encoding).
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4535 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4536 * Note this function currently is only used for decoding shell's
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4537 * OSC 7 escape sequence which we can assume all bytes are valid
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4538 * UTF-8 bytes. Thus we don't need to deal with invalid UTF-8
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4539 * encoding bytes like 0xfe, 0xff.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4540 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4541 static size_t
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4542 url_decode(const char *src, const size_t len, char_u *dst)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4543 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4544 size_t i = 0, j = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4545
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4546 while (i < len)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4547 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4548 if (src[i] == '%' && i + 2 < len)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4549 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4550 dst[j] = hexhex2nr((char_u *)&src[i + 1]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4551 j++;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4552 i += 3;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4553 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4554 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4555 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4556 dst[j] = src[i];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4557 i++;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4558 j++;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4559 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4560 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4561 dst[j] = '\0';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4562 return j;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4563 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4564
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4565 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4566 * Sync terminal buffer's cwd with shell's pwd with the help of OSC 7.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4567 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4568 * The OSC 7 sequence has the format of
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4569 * "\033]7;file://HOSTNAME/CURRENT/DIR\033\\"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4570 * and what VTerm provides via VTermStringFragment is
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4571 * "file://HOSTNAME/CURRENT/DIR"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4572 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4573 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4574 sync_shell_dir(garray_T *gap)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4575 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4576 int offset = 7; // len of "file://" is 7
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4577 char *pos = (char *)gap->ga_data + offset;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4578 char_u *new_dir;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4579
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4580 // remove HOSTNAME to get PWD
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4581 while (offset < (int)gap->ga_len && *pos != '/' )
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4582 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4583 ++offset;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4584 ++pos;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4585 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4586
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4587 if (offset >= (int)gap->ga_len)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4588 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4589 semsg(_(e_failed_to_extract_pwd_from_str_check_your_shell_config),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4590 gap->ga_data);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4591 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4592 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4593
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4594 new_dir = alloc(gap->ga_len - offset + 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4595 url_decode(pos, gap->ga_len-offset, new_dir);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4596 changedir_func(new_dir, TRUE, CDSCOPE_WINDOW);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4597 vim_free(new_dir);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4598 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4599
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4600 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4601 * Called by libvterm when it cannot recognize an OSC sequence.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4602 * We recognize a terminal API command.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4603 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4604 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4605 parse_osc(int command, VTermStringFragment frag, void *user)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4606 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4607 term_T *term = (term_T *)user;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4608 js_read_T reader;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4609 typval_T tv;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4610 channel_T *channel = term->tl_job == NULL ? NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4611 : term->tl_job->jv_channel;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4612 garray_T *gap = &term->tl_osc_buf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4613
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4614 // We recognize only OSC 5 1 ; {command} and OSC 7 ; {command}
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4615 if (command != 51 && (command != 7 || !p_asd))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4616 return 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4617
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4618 // Concatenate what was received until the final piece is found.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4619 if (ga_grow(gap, (int)frag.len + 1) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4620 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4621 ga_clear(gap);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4622 return 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4623 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4624 mch_memmove((char *)gap->ga_data + gap->ga_len, frag.str, frag.len);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4625 gap->ga_len += (int)frag.len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4626 if (!frag.final)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4627 return 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4628
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4629 ((char *)gap->ga_data)[gap->ga_len] = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4630
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4631 if (command == 7)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4632 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4633 sync_shell_dir(gap);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4634 ga_clear(gap);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4635 return 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4636 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4637
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4638 reader.js_buf = gap->ga_data;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4639 reader.js_fill = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4640 reader.js_used = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4641 if (json_decode(&reader, &tv, 0) == OK
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4642 && tv.v_type == VAR_LIST
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4643 && tv.vval.v_list != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4644 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4645 listitem_T *item = tv.vval.v_list->lv_first;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4646
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4647 if (item == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4648 ch_log(channel, "Missing command");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4649 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4650 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4651 char_u *cmd = tv_get_string(&item->li_tv);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4652
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4653 // Make sure an invoked command doesn't delete the buffer (and the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4654 // terminal) under our fingers.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4655 ++term->tl_buffer->b_locked;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4656
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4657 item = item->li_next;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4658 if (item == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4659 ch_log(channel, "Missing argument for %s", cmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4660 else if (STRCMP(cmd, "drop") == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4661 handle_drop_command(item);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4662 else if (STRCMP(cmd, "call") == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4663 handle_call_command(term, channel, item);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4664 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4665 ch_log(channel, "Invalid command received: %s", cmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4666 --term->tl_buffer->b_locked;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4667 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4668 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4669 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4670 ch_log(channel, "Invalid JSON received");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4671
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4672 ga_clear(gap);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4673 clear_tv(&tv);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4674 return 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4675 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4676
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4677 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4678 * Called by libvterm when it cannot recognize a CSI sequence.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4679 * We recognize the window position report.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4680 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4681 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4682 parse_csi(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4683 const char *leader UNUSED,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4684 const long args[],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4685 int argcount,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4686 const char *intermed UNUSED,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4687 char command,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4688 void *user)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4689 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4690 term_T *term = (term_T *)user;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4691 char buf[100];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4692 int len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4693 int x = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4694 int y = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4695 win_T *wp;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4696
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4697 // We recognize only CSI 13 t
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4698 if (command != 't' || argcount != 1 || args[0] != 13)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4699 return 0; // not handled
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4700
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4701 // When getting the window position is not possible or it fails it results
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4702 // in zero/zero.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4703 #if defined(FEAT_GUI) \
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4704 || (defined(HAVE_TGETENT) && defined(FEAT_TERMRESPONSE)) \
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4705 || defined(MSWIN)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4706 (void)ui_get_winpos(&x, &y, (varnumber_T)100);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4707 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4708
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4709 FOR_ALL_WINDOWS(wp)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4710 if (wp->w_buffer == term->tl_buffer)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4711 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4712 if (wp != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4713 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4714 #ifdef FEAT_GUI
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4715 if (gui.in_use)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4716 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4717 x += wp->w_wincol * gui.char_width;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4718 y += W_WINROW(wp) * gui.char_height;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4719 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4720 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4721 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4722 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4723 // We roughly estimate the position of the terminal window inside
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4724 // the Vim window by assuming a 10 x 7 character cell.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4725 x += wp->w_wincol * 7;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4726 y += W_WINROW(wp) * 10;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4727 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4728 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4729
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4730 len = vim_snprintf(buf, 100, "\x1b[3;%d;%dt", x, y);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4731 channel_send(term->tl_job->jv_channel, get_tty_part(term),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4732 (char_u *)buf, len, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4733 return 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4734 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4735
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4736 static VTermStateFallbacks state_fallbacks = {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4737 NULL, // control
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4738 parse_csi, // csi
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4739 parse_osc, // osc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4740 NULL, // dcs
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4741 NULL, // apc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4742 NULL, // pm
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4743 NULL // sos
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4744 };
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4745
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4746 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4747 * Use Vim's allocation functions for vterm so profiling works.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4748 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4749 static void *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4750 vterm_malloc(size_t size, void *data UNUSED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4751 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4752 // make sure that the length is not zero
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4753 return alloc_clear(size == 0 ? 1L : size);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4754 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4755
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4756 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4757 vterm_memfree(void *ptr, void *data UNUSED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4758 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4759 vim_free(ptr);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4760 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4761
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4762 static VTermAllocatorFunctions vterm_allocator = {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4763 &vterm_malloc,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4764 &vterm_memfree
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4765 };
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4766
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4767 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4768 * Create a new vterm and initialize it.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4769 * Return FAIL when out of memory.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4770 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4771 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4772 create_vterm(term_T *term, int rows, int cols)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4773 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4774 VTerm *vterm;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4775 VTermScreen *screen;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4776 VTermState *state;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4777 VTermValue value;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4778
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4779 vterm = vterm_new_with_allocator(rows, cols, &vterm_allocator, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4780 term->tl_vterm = vterm;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4781 if (vterm == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4782 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4783
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4784 // Allocate screen and state here, so we can bail out if that fails.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4785 state = vterm_obtain_state(vterm);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4786 screen = vterm_obtain_screen(vterm);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4787 if (state == NULL || screen == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4788 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4789 vterm_free(vterm);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4790 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4791 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4792
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4793 vterm_screen_set_callbacks(screen, &screen_callbacks, term);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4794 // TODO: depends on 'encoding'.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4795 vterm_set_utf8(vterm, 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4796
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4797 init_default_colors(term);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4798
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4799 vterm_state_set_default_colors(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4800 state,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4801 &term->tl_default_color.fg,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4802 &term->tl_default_color.bg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4803
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4804 if (t_colors < 16)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4805 // Less than 16 colors: assume that bold means using a bright color for
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4806 // the foreground color.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4807 vterm_state_set_bold_highbright(vterm_obtain_state(vterm), 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4808
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4809 // Required to initialize most things.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4810 vterm_screen_reset(screen, 1 /* hard */);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4811
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4812 // Allow using alternate screen.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4813 vterm_screen_enable_altscreen(screen, 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4814
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4815 // For unix do not use a blinking cursor. In an xterm this causes the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4816 // cursor to blink if it's blinking in the xterm.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4817 // For Windows we respect the system wide setting.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4818 #ifdef MSWIN
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4819 if (GetCaretBlinkTime() == INFINITE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4820 value.boolean = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4821 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4822 value.boolean = 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4823 #else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4824 value.boolean = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4825 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4826 vterm_state_set_termprop(state, VTERM_PROP_CURSORBLINK, &value);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4827 vterm_state_set_unrecognised_fallbacks(state, &state_fallbacks, term);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4828
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4829 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4830 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4831
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4832 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4833 * Reset the terminal palette to its default value.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4834 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4835 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4836 term_reset_palette(VTerm *vterm)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4837 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4838 VTermState *state = vterm_obtain_state(vterm);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4839 int index;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4840
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4841 for (index = 0; index < 16; index++)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4842 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4843 VTermColor color;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4844
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4845 color.type = VTERM_COLOR_INDEXED;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4846 ansi_color2rgb(index, &color.red, &color.green, &color.blue,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4847 &color.index);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4848 // The first valid index starts at 1.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4849 color.index -= 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4850
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4851 vterm_state_set_palette_color(state, index, &color);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4852 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4853 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4854
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4855 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4856 term_update_palette(term_T *term)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4857 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4858 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4859 if (term_use_palette()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4860 && (term->tl_palette != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4861 || find_var((char_u *)"g:terminal_ansi_colors", NULL, TRUE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4862 != NULL))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4863 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4864 if (term->tl_palette != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4865 set_vterm_palette(term->tl_vterm, term->tl_palette);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4866 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4867 init_vterm_ansi_colors(term->tl_vterm);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4868 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4869 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4870 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4871 term_reset_palette(term->tl_vterm);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4872 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4873
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4874 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4875 * Called when option 'termguicolors' is changed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4876 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4877 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4878 term_update_palette_all(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4879 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4880 term_T *term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4881
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4882 FOR_ALL_TERMS(term)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4883 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4884 if (term->tl_vterm == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4885 continue;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4886 term_update_palette(term);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4887 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4888 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4889
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4890 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4891 * Called when option 'background' or 'termguicolors' was set,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4892 * or when any highlight is changed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4893 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4894 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4895 term_update_colors_all(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4896 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4897 term_T *term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4898
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4899 FOR_ALL_TERMS(term)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4900 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4901 if (term->tl_vterm == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4902 continue;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4903 init_default_colors(term);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4904 vterm_state_set_default_colors(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4905 vterm_obtain_state(term->tl_vterm),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4906 &term->tl_default_color.fg,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4907 &term->tl_default_color.bg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4908 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4909 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4910
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4911 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4912 * Return the text to show for the buffer name and status.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4913 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4914 char_u *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4915 term_get_status_text(term_T *term)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4916 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4917 if (term->tl_status_text != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4918 return term->tl_status_text;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4919
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4920 char_u *txt;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4921 size_t len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4922 char_u *fname;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4923
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4924 if (term->tl_normal_mode)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4925 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4926 if (term_job_running(term))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4927 txt = (char_u *)_("Terminal");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4928 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4929 txt = (char_u *)_("Terminal-finished");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4930 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4931 else if (term->tl_title != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4932 txt = term->tl_title;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4933 else if (term_none_open(term))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4934 txt = (char_u *)_("active");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4935 else if (term_job_running(term))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4936 txt = (char_u *)_("running");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4937 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4938 txt = (char_u *)_("finished");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4939 fname = buf_get_fname(term->tl_buffer);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4940 len = 9 + STRLEN(fname) + STRLEN(txt);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4941 term->tl_status_text = alloc(len);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4942 if (term->tl_status_text != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4943 vim_snprintf((char *)term->tl_status_text, len, "%s [%s]",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4944 fname, txt);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4945 return term->tl_status_text;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4946 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4947
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4948 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4949 * Clear the cached value of the status text.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4950 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4951 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4952 term_clear_status_text(term_T *term)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4953 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4954 VIM_CLEAR(term->tl_status_text);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4955 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4956
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4957 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4958 * Mark references in jobs of terminals.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4959 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4960 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4961 set_ref_in_term(int copyID)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4962 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4963 int abort = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4964 term_T *term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4965 typval_T tv;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4966
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4967 for (term = first_term; !abort && term != NULL; term = term->tl_next)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4968 if (term->tl_job != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4969 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4970 tv.v_type = VAR_JOB;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4971 tv.vval.v_job = term->tl_job;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4972 abort = abort || set_ref_in_item(&tv, copyID, NULL, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4973 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4974 return abort;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4975 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4976
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4977 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4978 * Get the buffer from the first argument in "argvars".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4979 * Returns NULL when the buffer is not for a terminal window and logs a message
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4980 * with "where".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4981 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4982 static buf_T *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4983 term_get_buf(typval_T *argvars, char *where)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4984 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4985 buf_T *buf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4986
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4987 ++emsg_off;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4988 buf = tv_get_buf(&argvars[0], FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4989 --emsg_off;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4990 if (buf == NULL || buf->b_term == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4991 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4992 (void)tv_get_number(&argvars[0]); // issue errmsg if type error
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4993 ch_log(NULL, "%s: invalid buffer argument", where);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4994 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4995 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4996 return buf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4997 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4998
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
4999 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5000 clear_cell(VTermScreenCell *cell)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5001 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5002 CLEAR_FIELD(*cell);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5003 cell->fg.type = VTERM_COLOR_INVALID | VTERM_COLOR_DEFAULT_FG;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5004 cell->bg.type = VTERM_COLOR_INVALID | VTERM_COLOR_DEFAULT_BG;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5005 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5006
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5007 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5008 dump_term_color(FILE *fd, VTermColor *color)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5009 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5010 int index;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5011
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5012 if (VTERM_COLOR_IS_INDEXED(color))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5013 index = color->index + 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5014 else if (color->type == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5015 // use RGB values
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5016 index = 255;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5017 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5018 // default color
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5019 index = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5020 fprintf(fd, "%02x%02x%02x%d",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5021 (int)color->red, (int)color->green, (int)color->blue,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5022 index);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5023 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5024
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5025 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5026 * "term_dumpwrite(buf, filename, options)" function
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5027 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5028 * Each screen cell in full is:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5029 * |{characters}+{attributes}#{fg-color}{color-idx}#{bg-color}{color-idx}
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5030 * {characters} is a space for an empty cell
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5031 * For a double-width character "+" is changed to "*" and the next cell is
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5032 * skipped.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5033 * {attributes} is the decimal value of HL_BOLD + HL_UNDERLINE, etc.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5034 * when "&" use the same as the previous cell.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5035 * {fg-color} is hex RGB, when "&" use the same as the previous cell.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5036 * {bg-color} is hex RGB, when "&" use the same as the previous cell.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5037 * {color-idx} is a number from 0 to 255
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5038 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5039 * Screen cell with same width, attributes and color as the previous one:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5040 * |{characters}
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5041 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5042 * To use the color of the previous cell, use "&" instead of {color}-{idx}.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5043 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5044 * Repeating the previous screen cell:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5045 * @{count}
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5046 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5047 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5048 f_term_dumpwrite(typval_T *argvars, typval_T *rettv UNUSED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5049 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5050 buf_T *buf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5051 term_T *term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5052 char_u *fname;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5053 int max_height = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5054 int max_width = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5055 stat_T st;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5056 FILE *fd;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5057 VTermPos pos;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5058 VTermScreen *screen;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5059 VTermScreenCell prev_cell;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5060 VTermState *state;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5061 VTermPos cursor_pos;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5062
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5063 if (check_restricted() || check_secure())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5064 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5065
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5066 if (in_vim9script()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5067 && (check_for_buffer_arg(argvars, 0) == FAIL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5068 || check_for_string_arg(argvars, 1) == FAIL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5069 || check_for_opt_dict_arg(argvars, 2) == FAIL))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5070 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5071
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5072 buf = term_get_buf(argvars, "term_dumpwrite()");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5073 if (buf == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5074 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5075 term = buf->b_term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5076 if (term->tl_vterm == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5077 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5078 emsg(_(e_job_already_finished));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5079 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5080 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5081
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5082 if (argvars[2].v_type != VAR_UNKNOWN)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5083 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5084 dict_T *d;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5085
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5086 if (check_for_dict_arg(argvars, 2) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5087 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5088 d = argvars[2].vval.v_dict;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5089 if (d != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5090 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5091 max_height = dict_get_number(d, "rows");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5092 max_width = dict_get_number(d, "columns");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5093 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5094 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5095
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5096 fname = tv_get_string_chk(&argvars[1]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5097 if (fname == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5098 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5099 if (mch_stat((char *)fname, &st) >= 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5100 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5101 semsg(_(e_file_exists_str), fname);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5102 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5103 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5104
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5105 if (*fname == NUL || (fd = mch_fopen((char *)fname, WRITEBIN)) == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5106 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5107 semsg(_(e_cant_create_file_str), *fname == NUL ? (char_u *)_("<empty>") : fname);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5108 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5109 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5110
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5111 clear_cell(&prev_cell);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5112
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5113 screen = vterm_obtain_screen(term->tl_vterm);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5114 state = vterm_obtain_state(term->tl_vterm);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5115 vterm_state_get_cursorpos(state, &cursor_pos);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5116
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5117 for (pos.row = 0; (max_height == 0 || pos.row < max_height)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5118 && pos.row < term->tl_rows; ++pos.row)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5119 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5120 int repeat = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5121
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5122 for (pos.col = 0; (max_width == 0 || pos.col < max_width)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5123 && pos.col < term->tl_cols; ++pos.col)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5124 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5125 VTermScreenCell cell;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5126 int same_attr;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5127 int same_chars = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5128 int i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5129 int is_cursor_pos = (pos.col == cursor_pos.col
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5130 && pos.row == cursor_pos.row);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5131
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5132 if (vterm_screen_get_cell(screen, pos, &cell) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5133 clear_cell(&cell);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5134
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5135 for (i = 0; i < VTERM_MAX_CHARS_PER_CELL; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5136 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5137 int c = cell.chars[i];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5138 int pc = prev_cell.chars[i];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5139 int should_break = c == NUL || pc == NUL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5140
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5141 // For the first character NUL is the same as space.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5142 if (i == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5143 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5144 c = (c == NUL) ? ' ' : c;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5145 pc = (pc == NUL) ? ' ' : pc;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5146 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5147 if (c != pc)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5148 same_chars = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5149 if (should_break)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5150 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5151 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5152 same_attr = vtermAttr2hl(&cell.attrs)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5153 == vtermAttr2hl(&prev_cell.attrs)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5154 && vterm_color_is_equal(&cell.fg, &prev_cell.fg)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5155 && vterm_color_is_equal(&cell.bg, &prev_cell.bg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5156 if (same_chars && cell.width == prev_cell.width && same_attr
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5157 && !is_cursor_pos)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5158 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5159 ++repeat;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5160 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5161 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5162 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5163 if (repeat > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5164 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5165 fprintf(fd, "@%d", repeat);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5166 repeat = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5167 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5168 fputs(is_cursor_pos ? ">" : "|", fd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5169
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5170 if (cell.chars[0] == NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5171 fputs(" ", fd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5172 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5173 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5174 char_u charbuf[10];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5175 int len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5176
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5177 for (i = 0; i < VTERM_MAX_CHARS_PER_CELL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5178 && cell.chars[i] != NUL; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5179 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5180 len = utf_char2bytes(cell.chars[i], charbuf);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5181 fwrite(charbuf, len, 1, fd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5182 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5183 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5184
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5185 // When only the characters differ we don't write anything, the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5186 // following "|", "@" or NL will indicate using the same
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5187 // attributes.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5188 if (cell.width != prev_cell.width || !same_attr)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5189 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5190 if (cell.width == 2)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5191 fputs("*", fd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5192 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5193 fputs("+", fd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5194
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5195 if (same_attr)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5196 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5197 fputs("&", fd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5198 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5199 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5200 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5201 fprintf(fd, "%d", vtermAttr2hl(&cell.attrs));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5202 if (vterm_color_is_equal(&cell.fg, &prev_cell.fg))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5203 fputs("&", fd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5204 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5205 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5206 fputs("#", fd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5207 dump_term_color(fd, &cell.fg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5208 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5209 if (vterm_color_is_equal(&cell.bg, &prev_cell.bg))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5210 fputs("&", fd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5211 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5212 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5213 fputs("#", fd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5214 dump_term_color(fd, &cell.bg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5215 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5216 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5217 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5218
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5219 prev_cell = cell;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5220 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5221
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5222 if (cell.width == 2)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5223 ++pos.col;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5224 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5225 if (repeat > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5226 fprintf(fd, "@%d", repeat);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5227 fputs("\n", fd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5228 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5229
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5230 fclose(fd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5231 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5232
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5233 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5234 * Called when a dump is corrupted. Put a breakpoint here when debugging.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5235 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5236 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5237 dump_is_corrupt(garray_T *gap)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5238 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5239 ga_concat(gap, (char_u *)"CORRUPT");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5240 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5241
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5242 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5243 append_cell(garray_T *gap, cellattr_T *cell)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5244 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5245 if (ga_grow(gap, 1) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5246 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5247
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5248 *(((cellattr_T *)gap->ga_data) + gap->ga_len) = *cell;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5249 ++gap->ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5250 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5251
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5252 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5253 clear_cellattr(cellattr_T *cell)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5254 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5255 CLEAR_FIELD(*cell);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5256 cell->fg.type = VTERM_COLOR_DEFAULT_FG;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5257 cell->bg.type = VTERM_COLOR_DEFAULT_BG;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5258 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5259
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5260 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5261 * Read the dump file from "fd" and append lines to the current buffer.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5262 * Return the cell width of the longest line.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5263 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5264 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5265 read_dump_file(FILE *fd, VTermPos *cursor_pos)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5266 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5267 int c;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5268 garray_T ga_text;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5269 garray_T ga_cell;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5270 char_u *prev_char = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5271 int attr = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5272 cellattr_T cell;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5273 cellattr_T empty_cell;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5274 term_T *term = curbuf->b_term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5275 int max_cells = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5276 int start_row = term->tl_scrollback.ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5277
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5278 ga_init2(&ga_text, 1, 90);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5279 ga_init2(&ga_cell, sizeof(cellattr_T), 90);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5280 clear_cellattr(&cell);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5281 clear_cellattr(&empty_cell);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5282 cursor_pos->row = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5283 cursor_pos->col = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5284
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5285 c = fgetc(fd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5286 for (;;)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5287 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5288 if (c == EOF)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5289 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5290 if (c == '\r')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5291 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5292 // DOS line endings? Ignore.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5293 c = fgetc(fd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5294 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5295 else if (c == '\n')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5296 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5297 // End of a line: append it to the buffer.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5298 if (ga_text.ga_data == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5299 dump_is_corrupt(&ga_text);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5300 if (ga_grow(&term->tl_scrollback, 1) == OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5301 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5302 sb_line_T *line = (sb_line_T *)term->tl_scrollback.ga_data
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5303 + term->tl_scrollback.ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5304
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5305 if (max_cells < ga_cell.ga_len)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5306 max_cells = ga_cell.ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5307 line->sb_cols = ga_cell.ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5308 line->sb_cells = ga_cell.ga_data;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5309 line->sb_fill_attr = term->tl_default_color;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5310 ++term->tl_scrollback.ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5311 ga_init(&ga_cell);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5312
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5313 ga_append(&ga_text, NUL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5314 ml_append(curbuf->b_ml.ml_line_count, ga_text.ga_data,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5315 ga_text.ga_len, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5316 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5317 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5318 ga_clear(&ga_cell);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5319 ga_text.ga_len = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5320
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5321 c = fgetc(fd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5322 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5323 else if (c == '|' || c == '>')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5324 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5325 int prev_len = ga_text.ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5326
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5327 if (c == '>')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5328 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5329 if (cursor_pos->row != -1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5330 dump_is_corrupt(&ga_text); // duplicate cursor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5331 cursor_pos->row = term->tl_scrollback.ga_len - start_row;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5332 cursor_pos->col = ga_cell.ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5333 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5334
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5335 // normal character(s) followed by "+", "*", "|", "@" or NL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5336 c = fgetc(fd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5337 if (c != EOF)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5338 ga_append(&ga_text, c);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5339 for (;;)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5340 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5341 c = fgetc(fd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5342 if (c == '+' || c == '*' || c == '|' || c == '>' || c == '@'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5343 || c == EOF || c == '\n')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5344 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5345 ga_append(&ga_text, c);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5346 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5347
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5348 // save the character for repeating it
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5349 vim_free(prev_char);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5350 if (ga_text.ga_data != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5351 prev_char = vim_strnsave(((char_u *)ga_text.ga_data) + prev_len,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5352 ga_text.ga_len - prev_len);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5353
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5354 if (c == '@' || c == '|' || c == '>' || c == '\n')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5355 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5356 // use all attributes from previous cell
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5357 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5358 else if (c == '+' || c == '*')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5359 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5360 int is_bg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5361
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5362 cell.width = c == '+' ? 1 : 2;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5363
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5364 c = fgetc(fd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5365 if (c == '&')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5366 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5367 // use same attr as previous cell
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5368 c = fgetc(fd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5369 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5370 else if (isdigit(c))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5371 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5372 // get the decimal attribute
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5373 attr = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5374 while (isdigit(c))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5375 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5376 attr = attr * 10 + (c - '0');
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5377 c = fgetc(fd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5378 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5379 hl2vtermAttr(attr, &cell);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5380
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5381 // is_bg == 0: fg, is_bg == 1: bg
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5382 for (is_bg = 0; is_bg <= 1; ++is_bg)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5383 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5384 if (c == '&')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5385 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5386 // use same color as previous cell
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5387 c = fgetc(fd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5388 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5389 else if (c == '#')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5390 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5391 int red, green, blue, index = 0, type;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5392
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5393 c = fgetc(fd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5394 red = hex2nr(c);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5395 c = fgetc(fd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5396 red = (red << 4) + hex2nr(c);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5397 c = fgetc(fd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5398 green = hex2nr(c);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5399 c = fgetc(fd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5400 green = (green << 4) + hex2nr(c);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5401 c = fgetc(fd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5402 blue = hex2nr(c);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5403 c = fgetc(fd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5404 blue = (blue << 4) + hex2nr(c);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5405 c = fgetc(fd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5406 if (!isdigit(c))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5407 dump_is_corrupt(&ga_text);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5408 while (isdigit(c))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5409 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5410 index = index * 10 + (c - '0');
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5411 c = fgetc(fd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5412 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5413 if (index == 0 || index == 255)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5414 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5415 type = VTERM_COLOR_RGB;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5416 if (index == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5417 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5418 if (is_bg)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5419 type |= VTERM_COLOR_DEFAULT_BG;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5420 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5421 type |= VTERM_COLOR_DEFAULT_FG;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5422 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5423 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5424 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5425 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5426 type = VTERM_COLOR_INDEXED;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5427 index -= 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5428 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5429 if (is_bg)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5430 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5431 cell.bg.type = type;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5432 cell.bg.red = red;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5433 cell.bg.green = green;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5434 cell.bg.blue = blue;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5435 cell.bg.index = index;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5436 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5437 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5438 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5439 cell.fg.type = type;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5440 cell.fg.red = red;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5441 cell.fg.green = green;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5442 cell.fg.blue = blue;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5443 cell.fg.index = index;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5444 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5445 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5446 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5447 dump_is_corrupt(&ga_text);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5448 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5449 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5450 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5451 dump_is_corrupt(&ga_text);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5452 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5453 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5454 dump_is_corrupt(&ga_text);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5455
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5456 append_cell(&ga_cell, &cell);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5457 if (cell.width == 2)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5458 append_cell(&ga_cell, &empty_cell);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5459 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5460 else if (c == '@')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5461 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5462 if (prev_char == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5463 dump_is_corrupt(&ga_text);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5464 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5465 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5466 int count = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5467
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5468 // repeat previous character, get the count
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5469 for (;;)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5470 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5471 c = fgetc(fd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5472 if (!isdigit(c))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5473 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5474 count = count * 10 + (c - '0');
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5475 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5476
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5477 while (count-- > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5478 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5479 ga_concat(&ga_text, prev_char);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5480 append_cell(&ga_cell, &cell);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5481 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5482 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5483 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5484 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5485 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5486 dump_is_corrupt(&ga_text);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5487 c = fgetc(fd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5488 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5489 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5490
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5491 if (ga_text.ga_len > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5492 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5493 // trailing characters after last NL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5494 dump_is_corrupt(&ga_text);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5495 ga_append(&ga_text, NUL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5496 ml_append(curbuf->b_ml.ml_line_count, ga_text.ga_data,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5497 ga_text.ga_len, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5498 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5499
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5500 ga_clear(&ga_text);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5501 ga_clear(&ga_cell);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5502 vim_free(prev_char);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5503
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5504 return max_cells;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5505 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5506
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5507 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5508 * Return an allocated string with at least "text_width" "=" characters and
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5509 * "fname" inserted in the middle.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5510 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5511 static char_u *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5512 get_separator(int text_width, char_u *fname)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5513 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5514 int width = MAX(text_width, curwin->w_width);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5515 char_u *textline;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5516 int fname_size;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5517 char_u *p = fname;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5518 int i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5519 size_t off;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5520
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5521 textline = alloc(width + (int)STRLEN(fname) + 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5522 if (textline == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5523 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5524
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5525 fname_size = vim_strsize(fname);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5526 if (fname_size < width - 8)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5527 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5528 // enough room, don't use the full window width
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5529 width = MAX(text_width, fname_size + 8);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5530 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5531 else if (fname_size > width - 8)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5532 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5533 // full name doesn't fit, use only the tail
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5534 p = gettail(fname);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5535 fname_size = vim_strsize(p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5536 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5537 // skip characters until the name fits
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5538 while (fname_size > width - 8)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5539 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5540 p += (*mb_ptr2len)(p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5541 fname_size = vim_strsize(p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5542 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5543
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5544 for (i = 0; i < (width - fname_size) / 2 - 1; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5545 textline[i] = '=';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5546 textline[i++] = ' ';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5547
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5548 STRCPY(textline + i, p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5549 off = STRLEN(textline);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5550 textline[off] = ' ';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5551 for (i = 1; i < (width - fname_size) / 2; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5552 textline[off + i] = '=';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5553 textline[off + i] = NUL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5554
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5555 return textline;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5556 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5557
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5558 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5559 * Common for "term_dumpdiff()" and "term_dumpload()".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5560 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5561 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5562 term_load_dump(typval_T *argvars, typval_T *rettv, int do_diff)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5563 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5564 jobopt_T opt;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5565 buf_T *buf = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5566 char_u buf1[NUMBUFLEN];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5567 char_u buf2[NUMBUFLEN];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5568 char_u *fname1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5569 char_u *fname2 = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5570 char_u *fname_tofree = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5571 FILE *fd1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5572 FILE *fd2 = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5573 char_u *textline = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5574
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5575 // First open the files. If this fails bail out.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5576 fname1 = tv_get_string_buf_chk(&argvars[0], buf1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5577 if (do_diff)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5578 fname2 = tv_get_string_buf_chk(&argvars[1], buf2);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5579 if (fname1 == NULL || (do_diff && fname2 == NULL))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5580 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5581 emsg(_(e_invalid_argument));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5582 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5583 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5584 fd1 = mch_fopen((char *)fname1, READBIN);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5585 if (fd1 == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5586 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5587 semsg(_(e_cant_read_file_str), fname1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5588 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5589 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5590 if (do_diff)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5591 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5592 fd2 = mch_fopen((char *)fname2, READBIN);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5593 if (fd2 == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5594 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5595 fclose(fd1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5596 semsg(_(e_cant_read_file_str), fname2);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5597 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5598 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5599 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5600
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5601 init_job_options(&opt);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5602 if (argvars[do_diff ? 2 : 1].v_type != VAR_UNKNOWN
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5603 && get_job_options(&argvars[do_diff ? 2 : 1], &opt, 0,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5604 JO2_TERM_NAME + JO2_TERM_COLS + JO2_TERM_ROWS
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5605 + JO2_VERTICAL + JO2_CURWIN + JO2_NORESTORE) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5606 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5607
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5608 if (opt.jo_term_name == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5609 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5610 size_t len = STRLEN(fname1) + 12;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5611
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5612 fname_tofree = alloc(len);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5613 if (fname_tofree != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5614 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5615 vim_snprintf((char *)fname_tofree, len, "dump diff %s", fname1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5616 opt.jo_term_name = fname_tofree;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5617 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5618 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5619
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5620 if (opt.jo_bufnr_buf != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5621 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5622 win_T *wp = buf_jump_open_win(opt.jo_bufnr_buf);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5623
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5624 // With "bufnr" argument: enter the window with this buffer and make it
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5625 // empty.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5626 if (wp == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5627 semsg(_(e_invalid_argument_str), "bufnr");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5628 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5629 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5630 buf = curbuf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5631 while (!(curbuf->b_ml.ml_flags & ML_EMPTY))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5632 ml_delete((linenr_T)1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5633 free_scrollback(curbuf->b_term);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5634 redraw_later(UPD_NOT_VALID);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5635 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5636 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5637 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5638 // Create a new terminal window.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5639 buf = term_start(&argvars[0], NULL, &opt, TERM_START_NOJOB);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5640
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5641 if (buf != NULL && buf->b_term != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5642 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5643 int i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5644 linenr_T bot_lnum;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5645 linenr_T lnum;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5646 term_T *term = buf->b_term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5647 int width;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5648 int width2;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5649 VTermPos cursor_pos1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5650 VTermPos cursor_pos2;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5651
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5652 init_default_colors(term);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5653
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5654 rettv->vval.v_number = buf->b_fnum;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5655
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5656 // read the files, fill the buffer with the diff
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5657 width = read_dump_file(fd1, &cursor_pos1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5658
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5659 // position the cursor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5660 if (cursor_pos1.row >= 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5661 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5662 curwin->w_cursor.lnum = cursor_pos1.row + 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5663 coladvance(cursor_pos1.col);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5664 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5665
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5666 // Delete the empty line that was in the empty buffer.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5667 ml_delete(1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5668
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5669 // For term_dumpload() we are done here.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5670 if (!do_diff)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5671 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5672
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5673 term->tl_top_diff_rows = curbuf->b_ml.ml_line_count;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5674
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5675 textline = get_separator(width, fname1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5676 if (textline == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5677 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5678 if (add_empty_scrollback(term, &term->tl_default_color, 0) == OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5679 ml_append(curbuf->b_ml.ml_line_count, textline, 0, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5680 vim_free(textline);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5681
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5682 textline = get_separator(width, fname2);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5683 if (textline == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5684 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5685 if (add_empty_scrollback(term, &term->tl_default_color, 0) == OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5686 ml_append(curbuf->b_ml.ml_line_count, textline, 0, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5687 textline[width] = NUL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5688
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5689 bot_lnum = curbuf->b_ml.ml_line_count;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5690 width2 = read_dump_file(fd2, &cursor_pos2);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5691 if (width2 > width)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5692 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5693 vim_free(textline);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5694 textline = alloc(width2 + 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5695 if (textline == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5696 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5697 width = width2;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5698 textline[width] = NUL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5699 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5700 term->tl_bot_diff_rows = curbuf->b_ml.ml_line_count - bot_lnum;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5701
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5702 for (lnum = 1; lnum <= term->tl_top_diff_rows; ++lnum)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5703 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5704 if (lnum + bot_lnum > curbuf->b_ml.ml_line_count)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5705 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5706 // bottom part has fewer rows, fill with "-"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5707 for (i = 0; i < width; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5708 textline[i] = '-';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5709 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5710 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5711 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5712 char_u *line1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5713 char_u *line2;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5714 char_u *p1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5715 char_u *p2;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5716 int col;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5717 sb_line_T *sb_line = (sb_line_T *)term->tl_scrollback.ga_data;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5718 cellattr_T *cellattr1 = (sb_line + lnum - 1)->sb_cells;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5719 cellattr_T *cellattr2 = (sb_line + lnum + bot_lnum - 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5720 ->sb_cells;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5721
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5722 // Make a copy, getting the second line will invalidate it.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5723 line1 = vim_strsave(ml_get(lnum));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5724 if (line1 == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5725 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5726 p1 = line1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5727
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5728 line2 = ml_get(lnum + bot_lnum);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5729 p2 = line2;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5730 for (col = 0; col < width && *p1 != NUL && *p2 != NUL; ++col)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5731 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5732 int len1 = utfc_ptr2len(p1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5733 int len2 = utfc_ptr2len(p2);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5734
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5735 textline[col] = ' ';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5736 if (len1 != len2 || STRNCMP(p1, p2, len1) != 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5737 // text differs
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5738 textline[col] = 'X';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5739 else if (lnum == cursor_pos1.row + 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5740 && col == cursor_pos1.col
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5741 && (cursor_pos1.row != cursor_pos2.row
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5742 || cursor_pos1.col != cursor_pos2.col))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5743 // cursor in first but not in second
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5744 textline[col] = '>';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5745 else if (lnum == cursor_pos2.row + 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5746 && col == cursor_pos2.col
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5747 && (cursor_pos1.row != cursor_pos2.row
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5748 || cursor_pos1.col != cursor_pos2.col))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5749 // cursor in second but not in first
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5750 textline[col] = '<';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5751 else if (cellattr1 != NULL && cellattr2 != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5752 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5753 if ((cellattr1 + col)->width
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5754 != (cellattr2 + col)->width)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5755 textline[col] = 'w';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5756 else if (!vterm_color_is_equal(&(cellattr1 + col)->fg,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5757 &(cellattr2 + col)->fg))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5758 textline[col] = 'f';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5759 else if (!vterm_color_is_equal(&(cellattr1 + col)->bg,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5760 &(cellattr2 + col)->bg))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5761 textline[col] = 'b';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5762 else if (vtermAttr2hl(&(cellattr1 + col)->attrs)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5763 != vtermAttr2hl(&((cellattr2 + col)->attrs)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5764 textline[col] = 'a';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5765 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5766 p1 += len1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5767 p2 += len2;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5768 // TODO: handle different width
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5769 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5770
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5771 while (col < width)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5772 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5773 if (*p1 == NUL && *p2 == NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5774 textline[col] = '?';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5775 else if (*p1 == NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5776 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5777 textline[col] = '+';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5778 p2 += utfc_ptr2len(p2);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5779 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5780 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5781 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5782 textline[col] = '-';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5783 p1 += utfc_ptr2len(p1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5784 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5785 ++col;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5786 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5787
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5788 vim_free(line1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5789 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5790 if (add_empty_scrollback(term, &term->tl_default_color,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5791 term->tl_top_diff_rows) == OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5792 ml_append(term->tl_top_diff_rows + lnum, textline, 0, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5793 ++bot_lnum;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5794 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5795
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5796 while (lnum + bot_lnum <= curbuf->b_ml.ml_line_count)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5797 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5798 // bottom part has more rows, fill with "+"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5799 for (i = 0; i < width; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5800 textline[i] = '+';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5801 if (add_empty_scrollback(term, &term->tl_default_color,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5802 term->tl_top_diff_rows) == OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5803 ml_append(term->tl_top_diff_rows + lnum, textline, 0, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5804 ++lnum;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5805 ++bot_lnum;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5806 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5807
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5808 term->tl_cols = width;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5809
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5810 // looks better without wrapping
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5811 curwin->w_p_wrap = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5812 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5813
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5814 theend:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5815 vim_free(textline);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5816 vim_free(fname_tofree);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5817 fclose(fd1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5818 if (fd2 != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5819 fclose(fd2);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5820 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5821
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5822 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5823 * If the current buffer shows the output of term_dumpdiff(), swap the top and
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5824 * bottom files.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5825 * Return FAIL when this is not possible.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5826 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5827 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5828 term_swap_diff(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5829 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5830 term_T *term = curbuf->b_term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5831 linenr_T line_count;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5832 linenr_T top_rows;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5833 linenr_T bot_rows;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5834 linenr_T bot_start;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5835 linenr_T lnum;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5836 char_u *p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5837 sb_line_T *sb_line;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5838
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5839 if (term == NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5840 || !term_is_finished(curbuf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5841 || term->tl_top_diff_rows == 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5842 || term->tl_scrollback.ga_len == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5843 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5844
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5845 line_count = curbuf->b_ml.ml_line_count;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5846 top_rows = term->tl_top_diff_rows;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5847 bot_rows = term->tl_bot_diff_rows;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5848 bot_start = line_count - bot_rows;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5849 sb_line = (sb_line_T *)term->tl_scrollback.ga_data;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5850
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5851 // move lines from top to above the bottom part
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5852 for (lnum = 1; lnum <= top_rows; ++lnum)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5853 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5854 p = vim_strsave(ml_get(1));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5855 if (p == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5856 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5857 ml_append(bot_start, p, 0, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5858 ml_delete(1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5859 vim_free(p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5860 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5861
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5862 // move lines from bottom to the top
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5863 for (lnum = 1; lnum <= bot_rows; ++lnum)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5864 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5865 p = vim_strsave(ml_get(bot_start + lnum));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5866 if (p == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5867 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5868 ml_delete(bot_start + lnum);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5869 ml_append(lnum - 1, p, 0, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5870 vim_free(p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5871 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5872
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5873 // move top title to bottom
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5874 p = vim_strsave(ml_get(bot_rows + 1));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5875 if (p == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5876 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5877 ml_append(line_count - top_rows - 1, p, 0, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5878 ml_delete(bot_rows + 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5879 vim_free(p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5880
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5881 // move bottom title to top
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5882 p = vim_strsave(ml_get(line_count - top_rows));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5883 if (p == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5884 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5885 ml_delete(line_count - top_rows);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5886 ml_append(bot_rows, p, 0, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5887 vim_free(p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5888
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5889 if (top_rows == bot_rows)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5890 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5891 // rows counts are equal, can swap cell properties
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5892 for (lnum = 0; lnum < top_rows; ++lnum)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5893 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5894 sb_line_T temp;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5895
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5896 temp = *(sb_line + lnum);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5897 *(sb_line + lnum) = *(sb_line + bot_start + lnum);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5898 *(sb_line + bot_start + lnum) = temp;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5899 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5900 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5901 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5902 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5903 size_t size = sizeof(sb_line_T) * term->tl_scrollback.ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5904 sb_line_T *temp = alloc(size);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5905
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5906 // need to copy cell properties into temp memory
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5907 if (temp != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5908 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5909 mch_memmove(temp, term->tl_scrollback.ga_data, size);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5910 mch_memmove(term->tl_scrollback.ga_data,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5911 temp + bot_start,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5912 sizeof(sb_line_T) * bot_rows);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5913 mch_memmove((sb_line_T *)term->tl_scrollback.ga_data + bot_rows,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5914 temp + top_rows,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5915 sizeof(sb_line_T) * (line_count - top_rows - bot_rows));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5916 mch_memmove((sb_line_T *)term->tl_scrollback.ga_data
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5917 + line_count - top_rows,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5918 temp,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5919 sizeof(sb_line_T) * top_rows);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5920 vim_free(temp);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5921 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5922 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5923
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5924 term->tl_top_diff_rows = bot_rows;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5925 term->tl_bot_diff_rows = top_rows;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5926
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5927 update_screen(UPD_NOT_VALID);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5928 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5929 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5930
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5931 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5932 * "term_dumpdiff(filename, filename, options)" function
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5933 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5934 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5935 f_term_dumpdiff(typval_T *argvars, typval_T *rettv)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5936 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5937 if (in_vim9script()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5938 && (check_for_string_arg(argvars, 0) == FAIL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5939 || check_for_string_arg(argvars, 1) == FAIL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5940 || check_for_opt_dict_arg(argvars, 2) == FAIL))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5941 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5942
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5943 term_load_dump(argvars, rettv, TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5944 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5945
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5946 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5947 * "term_dumpload(filename, options)" function
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5948 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5949 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5950 f_term_dumpload(typval_T *argvars, typval_T *rettv)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5951 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5952 if (in_vim9script()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5953 && (check_for_string_arg(argvars, 0) == FAIL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5954 || check_for_opt_dict_arg(argvars, 1) == FAIL))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5955 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5956
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5957 term_load_dump(argvars, rettv, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5958 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5959
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5960 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5961 * "term_getaltscreen(buf)" function
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5962 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5963 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5964 f_term_getaltscreen(typval_T *argvars, typval_T *rettv)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5965 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5966 buf_T *buf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5967
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5968 if (in_vim9script() && check_for_buffer_arg(argvars, 0) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5969 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5970
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5971 buf = term_get_buf(argvars, "term_getaltscreen()");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5972 if (buf == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5973 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5974 rettv->vval.v_number = buf->b_term->tl_using_altscreen;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5975 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5976
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5977 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5978 * "term_getattr(attr, name)" function
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5979 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5980 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5981 f_term_getattr(typval_T *argvars, typval_T *rettv)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5982 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5983 int attr;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5984 size_t i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5985 char_u *name;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5986
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5987 static struct {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5988 char *name;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5989 int attr;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5990 } attrs[] = {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5991 {"bold", HL_BOLD},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5992 {"italic", HL_ITALIC},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5993 {"underline", HL_UNDERLINE},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5994 {"strike", HL_STRIKETHROUGH},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5995 {"reverse", HL_INVERSE},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5996 };
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5997
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5998 if (in_vim9script()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
5999 && (check_for_number_arg(argvars, 0) == FAIL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6000 || check_for_string_arg(argvars, 1) == FAIL))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6001 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6002
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6003 attr = tv_get_number(&argvars[0]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6004 name = tv_get_string_chk(&argvars[1]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6005 if (name == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6006 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6007
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6008 if (attr > HL_ALL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6009 attr = syn_attr2attr(attr);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6010 for (i = 0; i < ARRAY_LENGTH(attrs); ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6011 if (STRCMP(name, attrs[i].name) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6012 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6013 rettv->vval.v_number = (attr & attrs[i].attr) != 0 ? 1 : 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6014 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6015 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6016 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6017
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6018 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6019 * "term_getcursor(buf)" function
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6020 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6021 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6022 f_term_getcursor(typval_T *argvars, typval_T *rettv)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6023 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6024 buf_T *buf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6025 term_T *term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6026 list_T *l;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6027 dict_T *d;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6028
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6029 if (rettv_list_alloc(rettv) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6030 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6031
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6032 if (in_vim9script() && check_for_buffer_arg(argvars, 0) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6033 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6034
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6035 buf = term_get_buf(argvars, "term_getcursor()");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6036 if (buf == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6037 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6038 term = buf->b_term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6039
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6040 l = rettv->vval.v_list;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6041 list_append_number(l, term->tl_cursor_pos.row + 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6042 list_append_number(l, term->tl_cursor_pos.col + 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6043
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6044 d = dict_alloc();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6045 if (d == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6046 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6047
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6048 dict_add_number(d, "visible", term->tl_cursor_visible);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6049 dict_add_number(d, "blink", blink_state_is_inverted()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6050 ? !term->tl_cursor_blink : term->tl_cursor_blink);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6051 dict_add_number(d, "shape", term->tl_cursor_shape);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6052 dict_add_string(d, "color", cursor_color_get(term->tl_cursor_color));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6053 list_append_dict(l, d);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6054 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6055
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6056 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6057 * "term_getjob(buf)" function
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6058 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6059 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6060 f_term_getjob(typval_T *argvars, typval_T *rettv)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6061 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6062 buf_T *buf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6063
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6064 if (in_vim9script() && check_for_buffer_arg(argvars, 0) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6065 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6066
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6067 buf = term_get_buf(argvars, "term_getjob()");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6068 if (buf == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6069 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6070 rettv->v_type = VAR_SPECIAL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6071 rettv->vval.v_number = VVAL_NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6072 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6073 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6074
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6075 rettv->v_type = VAR_JOB;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6076 rettv->vval.v_job = buf->b_term->tl_job;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6077 if (rettv->vval.v_job != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6078 ++rettv->vval.v_job->jv_refcount;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6079 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6080
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6081 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6082 get_row_number(typval_T *tv, term_T *term)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6083 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6084 if (tv->v_type == VAR_STRING
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6085 && tv->vval.v_string != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6086 && STRCMP(tv->vval.v_string, ".") == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6087 return term->tl_cursor_pos.row;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6088 return (int)tv_get_number(tv) - 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6089 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6090
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6091 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6092 * "term_getline(buf, row)" function
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6093 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6094 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6095 f_term_getline(typval_T *argvars, typval_T *rettv)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6096 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6097 buf_T *buf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6098 term_T *term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6099 int row;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6100
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6101 rettv->v_type = VAR_STRING;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6102
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6103 if (in_vim9script()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6104 && (check_for_buffer_arg(argvars, 0) == FAIL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6105 || check_for_lnum_arg(argvars, 1) == FAIL))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6106 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6107
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6108 buf = term_get_buf(argvars, "term_getline()");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6109 if (buf == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6110 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6111 term = buf->b_term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6112 row = get_row_number(&argvars[1], term);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6113
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6114 if (term->tl_vterm == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6115 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6116 linenr_T lnum = row + term->tl_scrollback_scrolled + 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6117
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6118 // vterm is finished, get the text from the buffer
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6119 if (lnum > 0 && lnum <= buf->b_ml.ml_line_count)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6120 rettv->vval.v_string = vim_strsave(ml_get_buf(buf, lnum, FALSE));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6121 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6122 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6123 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6124 VTermScreen *screen = vterm_obtain_screen(term->tl_vterm);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6125 VTermRect rect;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6126 int len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6127 char_u *p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6128
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6129 if (row < 0 || row >= term->tl_rows)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6130 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6131 len = term->tl_cols * MB_MAXBYTES + 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6132 p = alloc(len);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6133 if (p == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6134 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6135 rettv->vval.v_string = p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6136
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6137 rect.start_col = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6138 rect.end_col = term->tl_cols;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6139 rect.start_row = row;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6140 rect.end_row = row + 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6141 p[vterm_screen_get_text(screen, (char *)p, len, rect)] = NUL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6142 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6143 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6144
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6145 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6146 * "term_getscrolled(buf)" function
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6147 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6148 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6149 f_term_getscrolled(typval_T *argvars, typval_T *rettv)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6150 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6151 buf_T *buf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6152
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6153 if (in_vim9script() && check_for_buffer_arg(argvars, 0) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6154 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6155
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6156 buf = term_get_buf(argvars, "term_getscrolled()");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6157 if (buf == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6158 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6159 rettv->vval.v_number = buf->b_term->tl_scrollback_scrolled;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6160 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6161
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6162 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6163 * "term_getsize(buf)" function
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6164 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6165 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6166 f_term_getsize(typval_T *argvars, typval_T *rettv)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6167 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6168 buf_T *buf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6169 list_T *l;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6170
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6171 if (rettv_list_alloc(rettv) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6172 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6173
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6174 if (in_vim9script() && check_for_buffer_arg(argvars, 0) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6175 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6176
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6177 buf = term_get_buf(argvars, "term_getsize()");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6178 if (buf == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6179 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6180
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6181 l = rettv->vval.v_list;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6182 list_append_number(l, buf->b_term->tl_rows);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6183 list_append_number(l, buf->b_term->tl_cols);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6184 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6185
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6186 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6187 * "term_setsize(buf, rows, cols)" function
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6188 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6189 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6190 f_term_setsize(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6191 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6192 buf_T *buf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6193 term_T *term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6194 varnumber_T rows, cols;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6195
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6196 if (in_vim9script()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6197 && (check_for_buffer_arg(argvars, 0) == FAIL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6198 || check_for_number_arg(argvars, 1) == FAIL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6199 || check_for_number_arg(argvars, 2) == FAIL))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6200 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6201
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6202 buf = term_get_buf(argvars, "term_setsize()");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6203 if (buf == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6204 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6205 emsg(_(e_not_terminal_buffer));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6206 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6207 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6208 if (buf->b_term->tl_vterm == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6209 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6210 term = buf->b_term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6211 rows = tv_get_number(&argvars[1]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6212 rows = rows <= 0 ? term->tl_rows : rows;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6213 cols = tv_get_number(&argvars[2]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6214 cols = cols <= 0 ? term->tl_cols : cols;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6215 vterm_set_size(term->tl_vterm, rows, cols);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6216 // handle_resize() will resize the windows
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6217
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6218 // Get and remember the size we ended up with. Update the pty.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6219 vterm_get_size(term->tl_vterm, &term->tl_rows, &term->tl_cols);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6220 term_report_winsize(term, term->tl_rows, term->tl_cols);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6221 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6222
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6223 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6224 * "term_getstatus(buf)" function
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6225 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6226 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6227 f_term_getstatus(typval_T *argvars, typval_T *rettv)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6228 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6229 buf_T *buf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6230 term_T *term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6231 char_u val[100];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6232
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6233 rettv->v_type = VAR_STRING;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6234
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6235 if (in_vim9script() && check_for_buffer_arg(argvars, 0) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6236 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6237
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6238 buf = term_get_buf(argvars, "term_getstatus()");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6239 if (buf == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6240 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6241 term = buf->b_term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6242
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6243 if (term_job_running(term))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6244 STRCPY(val, "running");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6245 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6246 STRCPY(val, "finished");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6247 if (term->tl_normal_mode)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6248 STRCAT(val, ",normal");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6249 rettv->vval.v_string = vim_strsave(val);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6250 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6251
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6252 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6253 * "term_gettitle(buf)" function
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6254 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6255 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6256 f_term_gettitle(typval_T *argvars, typval_T *rettv)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6257 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6258 buf_T *buf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6259
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6260 rettv->v_type = VAR_STRING;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6261
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6262 if (in_vim9script() && check_for_buffer_arg(argvars, 0) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6263 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6264
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6265 buf = term_get_buf(argvars, "term_gettitle()");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6266 if (buf == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6267 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6268
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6269 if (buf->b_term->tl_title != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6270 rettv->vval.v_string = vim_strsave(buf->b_term->tl_title);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6271 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6272
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6273 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6274 * "term_gettty(buf)" function
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6275 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6276 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6277 f_term_gettty(typval_T *argvars, typval_T *rettv)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6278 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6279 buf_T *buf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6280 char_u *p = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6281 int num = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6282
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6283 if (in_vim9script()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6284 && (check_for_buffer_arg(argvars, 0) == FAIL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6285 || check_for_opt_bool_arg(argvars, 1) == FAIL))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6286 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6287
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6288 rettv->v_type = VAR_STRING;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6289 buf = term_get_buf(argvars, "term_gettty()");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6290 if (buf == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6291 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6292 if (argvars[1].v_type != VAR_UNKNOWN)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6293 num = tv_get_bool(&argvars[1]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6294
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6295 switch (num)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6296 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6297 case 0:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6298 if (buf->b_term->tl_job != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6299 p = buf->b_term->tl_job->jv_tty_out;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6300 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6301 case 1:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6302 if (buf->b_term->tl_job != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6303 p = buf->b_term->tl_job->jv_tty_in;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6304 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6305 default:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6306 semsg(_(e_invalid_argument_str), tv_get_string(&argvars[1]));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6307 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6308 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6309 if (p != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6310 rettv->vval.v_string = vim_strsave(p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6311 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6312
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6313 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6314 * "term_list()" function
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6315 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6316 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6317 f_term_list(typval_T *argvars UNUSED, typval_T *rettv)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6318 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6319 term_T *tp;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6320 list_T *l;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6321
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6322 if (rettv_list_alloc(rettv) == FAIL || first_term == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6323 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6324
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6325 l = rettv->vval.v_list;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6326 FOR_ALL_TERMS(tp)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6327 if (tp->tl_buffer != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6328 if (list_append_number(l,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6329 (varnumber_T)tp->tl_buffer->b_fnum) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6330 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6331 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6332
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6333 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6334 * "term_scrape(buf, row)" function
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6335 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6336 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6337 f_term_scrape(typval_T *argvars, typval_T *rettv)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6338 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6339 buf_T *buf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6340 VTermScreen *screen = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6341 VTermPos pos;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6342 list_T *l;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6343 term_T *term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6344 char_u *p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6345 sb_line_T *line;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6346
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6347 if (rettv_list_alloc(rettv) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6348 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6349
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6350 if (in_vim9script()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6351 && (check_for_buffer_arg(argvars, 0) == FAIL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6352 || check_for_lnum_arg(argvars, 1) == FAIL))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6353 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6354
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6355 buf = term_get_buf(argvars, "term_scrape()");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6356 if (buf == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6357 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6358 term = buf->b_term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6359
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6360 l = rettv->vval.v_list;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6361 pos.row = get_row_number(&argvars[1], term);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6362
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6363 if (term->tl_vterm != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6364 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6365 screen = vterm_obtain_screen(term->tl_vterm);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6366 if (screen == NULL) // can't really happen
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6367 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6368 p = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6369 line = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6370 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6371 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6372 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6373 linenr_T lnum = pos.row + term->tl_scrollback_scrolled;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6374
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6375 if (lnum < 0 || lnum >= term->tl_scrollback.ga_len)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6376 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6377 p = ml_get_buf(buf, lnum + 1, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6378 line = (sb_line_T *)term->tl_scrollback.ga_data + lnum;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6379 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6380
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6381 for (pos.col = 0; pos.col < term->tl_cols; )
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6382 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6383 dict_T *dcell;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6384 int width;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6385 VTermScreenCellAttrs attrs;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6386 VTermColor fg, bg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6387 char_u rgb[8];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6388 char_u mbs[MB_MAXBYTES * VTERM_MAX_CHARS_PER_CELL + 1];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6389 int off = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6390 int i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6391
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6392 if (screen == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6393 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6394 cellattr_T *cellattr;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6395 int len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6396
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6397 // vterm has finished, get the cell from scrollback
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6398 if (pos.col >= line->sb_cols)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6399 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6400 cellattr = line->sb_cells + pos.col;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6401 width = cellattr->width;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6402 attrs = cellattr->attrs;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6403 fg = cellattr->fg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6404 bg = cellattr->bg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6405 len = mb_ptr2len(p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6406 mch_memmove(mbs, p, len);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6407 mbs[len] = NUL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6408 p += len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6409 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6410 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6411 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6412 VTermScreenCell cell;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6413
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6414 if (vterm_screen_get_cell(screen, pos, &cell) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6415 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6416 for (i = 0; i < VTERM_MAX_CHARS_PER_CELL; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6417 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6418 if (cell.chars[i] == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6419 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6420 off += (*utf_char2bytes)((int)cell.chars[i], mbs + off);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6421 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6422 mbs[off] = NUL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6423 width = cell.width;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6424 attrs = cell.attrs;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6425 fg = cell.fg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6426 bg = cell.bg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6427 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6428 dcell = dict_alloc();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6429 if (dcell == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6430 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6431 list_append_dict(l, dcell);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6432
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6433 dict_add_string(dcell, "chars", mbs);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6434
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6435 vim_snprintf((char *)rgb, 8, "#%02x%02x%02x",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6436 fg.red, fg.green, fg.blue);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6437 dict_add_string(dcell, "fg", rgb);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6438 vim_snprintf((char *)rgb, 8, "#%02x%02x%02x",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6439 bg.red, bg.green, bg.blue);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6440 dict_add_string(dcell, "bg", rgb);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6441
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6442 dict_add_number(dcell, "attr",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6443 cell2attr(term, NULL, &attrs, &fg, &bg));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6444 dict_add_number(dcell, "width", width);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6445
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6446 ++pos.col;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6447 if (width == 2)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6448 ++pos.col;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6449 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6450 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6451
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6452 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6453 * "term_sendkeys(buf, keys)" function
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6454 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6455 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6456 f_term_sendkeys(typval_T *argvars, typval_T *rettv UNUSED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6457 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6458 buf_T *buf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6459 char_u *msg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6460 term_T *term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6461
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6462 if (in_vim9script()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6463 && (check_for_buffer_arg(argvars, 0) == FAIL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6464 || check_for_string_arg(argvars, 1) == FAIL))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6465 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6466
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6467 buf = term_get_buf(argvars, "term_sendkeys()");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6468 if (buf == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6469 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6470
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6471 msg = tv_get_string_chk(&argvars[1]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6472 if (msg == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6473 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6474 term = buf->b_term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6475 if (term->tl_vterm == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6476 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6477
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6478 while (*msg != NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6479 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6480 int c;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6481
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6482 if (*msg == K_SPECIAL && msg[1] != NUL && msg[2] != NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6483 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6484 c = TO_SPECIAL(msg[1], msg[2]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6485 msg += 3;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6486 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6487 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6488 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6489 c = PTR2CHAR(msg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6490 msg += MB_CPTR2LEN(msg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6491 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6492 send_keys_to_term(term, c, 0, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6493 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6494 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6495
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6496 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) || defined(PROTO)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6497 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6498 * "term_getansicolors(buf)" function
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6499 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6500 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6501 f_term_getansicolors(typval_T *argvars, typval_T *rettv)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6502 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6503 buf_T *buf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6504 term_T *term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6505 VTermState *state;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6506 VTermColor color;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6507 char_u hexbuf[10];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6508 int index;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6509 list_T *list;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6510
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6511 if (rettv_list_alloc(rettv) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6512 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6513
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6514 if (in_vim9script() && check_for_buffer_arg(argvars, 0) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6515 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6516
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6517 buf = term_get_buf(argvars, "term_getansicolors()");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6518 if (buf == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6519 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6520 term = buf->b_term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6521 if (term->tl_vterm == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6522 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6523
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6524 list = rettv->vval.v_list;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6525 state = vterm_obtain_state(term->tl_vterm);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6526 for (index = 0; index < 16; index++)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6527 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6528 vterm_state_get_palette_color(state, index, &color);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6529 sprintf((char *)hexbuf, "#%02x%02x%02x",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6530 color.red, color.green, color.blue);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6531 if (list_append_string(list, hexbuf, 7) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6532 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6533 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6534 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6535
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6536 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6537 * "term_setansicolors(buf, list)" function
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6538 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6539 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6540 f_term_setansicolors(typval_T *argvars, typval_T *rettv UNUSED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6541 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6542 buf_T *buf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6543 term_T *term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6544 listitem_T *li;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6545 int n = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6546
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6547 if (in_vim9script()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6548 && (check_for_buffer_arg(argvars, 0) == FAIL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6549 || check_for_list_arg(argvars, 1) == FAIL))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6550 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6551
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6552 buf = term_get_buf(argvars, "term_setansicolors()");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6553 if (buf == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6554 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6555 term = buf->b_term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6556 if (term->tl_vterm == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6557 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6558
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6559 if (check_for_nonnull_list_arg(argvars, 1) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6560 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6561
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6562 if (argvars[1].vval.v_list->lv_first == &range_list_item
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6563 || argvars[1].vval.v_list->lv_len != 16)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6564 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6565 semsg(_(e_invalid_value_for_argument_str), "\"colors\"");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6566 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6567 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6568
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6569 if (term->tl_palette == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6570 term->tl_palette = ALLOC_MULT(long_u, 16);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6571 if (term->tl_palette == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6572 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6573
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6574 FOR_ALL_LIST_ITEMS(argvars[1].vval.v_list, li)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6575 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6576 char_u *color_name;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6577 guicolor_T guicolor;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6578
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6579 color_name = tv_get_string_chk(&li->li_tv);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6580 if (color_name == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6581 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6582
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6583 guicolor = GUI_GET_COLOR(color_name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6584 if (guicolor == INVALCOLOR)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6585 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6586 semsg(_(e_cannot_allocate_color_str), color_name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6587 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6588 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6589
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6590 term->tl_palette[n++] = GUI_MCH_GET_RGB(guicolor);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6591 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6592
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6593 term_update_palette(term);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6594 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6595 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6596
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6597 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6598 * "term_setapi(buf, api)" function
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6599 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6600 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6601 f_term_setapi(typval_T *argvars, typval_T *rettv UNUSED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6602 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6603 buf_T *buf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6604 term_T *term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6605 char_u *api;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6606
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6607 if (in_vim9script()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6608 && (check_for_buffer_arg(argvars, 0) == FAIL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6609 || check_for_string_arg(argvars, 1) == FAIL))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6610 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6611
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6612 buf = term_get_buf(argvars, "term_setapi()");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6613 if (buf == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6614 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6615 term = buf->b_term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6616 vim_free(term->tl_api);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6617 api = tv_get_string_chk(&argvars[1]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6618 if (api != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6619 term->tl_api = vim_strsave(api);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6620 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6621 term->tl_api = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6622 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6623
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6624 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6625 * "term_setrestore(buf, command)" function
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6626 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6627 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6628 f_term_setrestore(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6629 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6630 #if defined(FEAT_SESSION)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6631 buf_T *buf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6632 term_T *term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6633 char_u *cmd;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6634
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6635 if (in_vim9script()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6636 && (check_for_buffer_arg(argvars, 0) == FAIL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6637 || check_for_string_arg(argvars, 1) == FAIL))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6638 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6639
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6640 buf = term_get_buf(argvars, "term_setrestore()");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6641 if (buf == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6642 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6643 term = buf->b_term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6644 vim_free(term->tl_command);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6645 cmd = tv_get_string_chk(&argvars[1]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6646 if (cmd != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6647 term->tl_command = vim_strsave(cmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6648 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6649 term->tl_command = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6650 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6651 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6652
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6653 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6654 * "term_setkill(buf, how)" function
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6655 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6656 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6657 f_term_setkill(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6658 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6659 buf_T *buf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6660 term_T *term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6661 char_u *how;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6662
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6663 if (in_vim9script()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6664 && (check_for_buffer_arg(argvars, 0) == FAIL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6665 || check_for_string_arg(argvars, 1) == FAIL))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6666 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6667
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6668 buf = term_get_buf(argvars, "term_setkill()");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6669 if (buf == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6670 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6671 term = buf->b_term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6672 vim_free(term->tl_kill);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6673 how = tv_get_string_chk(&argvars[1]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6674 if (how != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6675 term->tl_kill = vim_strsave(how);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6676 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6677 term->tl_kill = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6678 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6679
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6680 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6681 * "term_start(command, options)" function
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6682 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6683 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6684 f_term_start(typval_T *argvars, typval_T *rettv)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6685 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6686 jobopt_T opt;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6687 buf_T *buf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6688
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6689 if (in_vim9script()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6690 && (check_for_string_or_list_arg(argvars, 0) == FAIL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6691 || check_for_opt_dict_arg(argvars, 1) == FAIL))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6692 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6693
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6694 init_job_options(&opt);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6695 if (argvars[1].v_type != VAR_UNKNOWN
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6696 && get_job_options(&argvars[1], &opt,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6697 JO_TIMEOUT_ALL + JO_STOPONEXIT
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6698 + JO_CALLBACK + JO_OUT_CALLBACK + JO_ERR_CALLBACK
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6699 + JO_EXIT_CB + JO_CLOSE_CALLBACK + JO_OUT_IO,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6700 JO2_TERM_NAME + JO2_TERM_FINISH + JO2_HIDDEN + JO2_TERM_OPENCMD
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6701 + JO2_TERM_COLS + JO2_TERM_ROWS + JO2_VERTICAL + JO2_CURWIN
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6702 + JO2_CWD + JO2_ENV + JO2_EOF_CHARS
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6703 + JO2_NORESTORE + JO2_TERM_KILL + JO2_TERM_HIGHLIGHT
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6704 + JO2_ANSI_COLORS + JO2_TTY_TYPE + JO2_TERM_API) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6705 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6706
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6707 buf = term_start(&argvars[0], NULL, &opt, 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6708
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6709 if (buf != NULL && buf->b_term != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6710 rettv->vval.v_number = buf->b_fnum;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6711 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6712
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6713 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6714 * "term_wait" function
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6715 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6716 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6717 f_term_wait(typval_T *argvars, typval_T *rettv UNUSED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6718 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6719 buf_T *buf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6720
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6721 if (in_vim9script()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6722 && (check_for_buffer_arg(argvars, 0) == FAIL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6723 || check_for_opt_number_arg(argvars, 1) == FAIL))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6724 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6725
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6726 buf = term_get_buf(argvars, "term_wait()");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6727 if (buf == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6728 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6729 if (buf->b_term->tl_job == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6730 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6731 ch_log(NULL, "term_wait(): no job to wait for");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6732 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6733 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6734 if (buf->b_term->tl_job->jv_channel == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6735 // channel is closed, nothing to do
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6736 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6737
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6738 // Get the job status, this will detect a job that finished.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6739 if (!buf->b_term->tl_job->jv_channel->ch_keep_open
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6740 && STRCMP(job_status(buf->b_term->tl_job), "dead") == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6741 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6742 // The job is dead, keep reading channel I/O until the channel is
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6743 // closed. buf->b_term may become NULL if the terminal was closed while
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6744 // waiting.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6745 ch_log(NULL, "term_wait(): waiting for channel to close");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6746 while (buf->b_term != NULL && !buf->b_term->tl_channel_closed)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6747 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6748 term_flush_messages();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6749
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6750 ui_delay(10L, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6751 if (!buf_valid(buf))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6752 // If the terminal is closed when the channel is closed the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6753 // buffer disappears.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6754 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6755 if (buf->b_term == NULL || buf->b_term->tl_channel_closing)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6756 // came here from a close callback, only wait one time
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6757 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6758 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6759
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6760 term_flush_messages();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6761 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6762 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6763 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6764 long wait = 10L;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6765
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6766 term_flush_messages();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6767
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6768 // Wait for some time for any channel I/O.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6769 if (argvars[1].v_type != VAR_UNKNOWN)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6770 wait = tv_get_number(&argvars[1]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6771 ui_delay(wait, TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6772
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6773 // Flushing messages on channels is hopefully sufficient.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6774 // TODO: is there a better way?
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6775 term_flush_messages();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6776 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6777 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6778
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6779 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6780 * Called when a channel has sent all the lines to a terminal.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6781 * Send a CTRL-D to mark the end of the text.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6782 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6783 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6784 term_send_eof(channel_T *ch)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6785 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6786 term_T *term;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6787
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6788 FOR_ALL_TERMS(term)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6789 if (term->tl_job == ch->ch_job)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6790 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6791 if (term->tl_eof_chars != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6792 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6793 channel_send(ch, PART_IN, term->tl_eof_chars,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6794 (int)STRLEN(term->tl_eof_chars), NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6795 channel_send(ch, PART_IN, (char_u *)"\r", 1, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6796 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6797 # ifdef MSWIN
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6798 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6799 // Default: CTRL-D
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6800 channel_send(ch, PART_IN, (char_u *)"\004\r", 2, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6801 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6802 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6803 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6804
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6805 #if defined(FEAT_GUI) || defined(PROTO)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6806 job_T *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6807 term_getjob(term_T *term)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6808 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6809 return term != NULL ? term->tl_job : NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6810 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6811 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6812
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6813 # if defined(MSWIN) || defined(PROTO)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6814
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6815 ///////////////////////////////////////
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6816 // 2. MS-Windows implementation.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6817 #ifdef PROTO
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6818 typedef int COORD;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6819 typedef int DWORD;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6820 typedef int HANDLE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6821 typedef int *DWORD_PTR;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6822 typedef int HPCON;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6823 typedef int HRESULT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6824 typedef int LPPROC_THREAD_ATTRIBUTE_LIST;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6825 typedef int SIZE_T;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6826 typedef int PSIZE_T;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6827 typedef int PVOID;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6828 typedef int BOOL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6829 # define WINAPI
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6830 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6831
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6832 HRESULT (WINAPI *pCreatePseudoConsole)(COORD, HANDLE, HANDLE, DWORD, HPCON*);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6833 HRESULT (WINAPI *pResizePseudoConsole)(HPCON, COORD);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6834 HRESULT (WINAPI *pClosePseudoConsole)(HPCON);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6835 BOOL (WINAPI *pInitializeProcThreadAttributeList)(LPPROC_THREAD_ATTRIBUTE_LIST, DWORD, DWORD, PSIZE_T);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6836 BOOL (WINAPI *pUpdateProcThreadAttribute)(LPPROC_THREAD_ATTRIBUTE_LIST, DWORD, DWORD_PTR, PVOID, SIZE_T, PVOID, PSIZE_T);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6837 void (WINAPI *pDeleteProcThreadAttributeList)(LPPROC_THREAD_ATTRIBUTE_LIST);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6838
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6839 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6840 dyn_conpty_init(int verbose)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6841 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6842 static HMODULE hKerneldll = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6843 int i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6844 static struct
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6845 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6846 char *name;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6847 FARPROC *ptr;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6848 } conpty_entry[] =
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6849 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6850 {"CreatePseudoConsole", (FARPROC*)&pCreatePseudoConsole},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6851 {"ResizePseudoConsole", (FARPROC*)&pResizePseudoConsole},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6852 {"ClosePseudoConsole", (FARPROC*)&pClosePseudoConsole},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6853 {"InitializeProcThreadAttributeList",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6854 (FARPROC*)&pInitializeProcThreadAttributeList},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6855 {"UpdateProcThreadAttribute",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6856 (FARPROC*)&pUpdateProcThreadAttribute},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6857 {"DeleteProcThreadAttributeList",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6858 (FARPROC*)&pDeleteProcThreadAttributeList},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6859 {NULL, NULL}
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6860 };
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6861
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6862 if (!has_conpty_working())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6863 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6864 if (verbose)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6865 emsg(_(e_conpty_is_not_available));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6866 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6867 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6868
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6869 // No need to initialize twice.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6870 if (hKerneldll)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6871 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6872
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6873 hKerneldll = vimLoadLib("kernel32.dll");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6874 for (i = 0; conpty_entry[i].name != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6875 && conpty_entry[i].ptr != NULL; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6876 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6877 if ((*conpty_entry[i].ptr = (FARPROC)GetProcAddress(hKerneldll,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6878 conpty_entry[i].name)) == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6879 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6880 if (verbose)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6881 semsg(_(e_could_not_load_library_function_str), conpty_entry[i].name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6882 hKerneldll = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6883 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6884 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6885 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6886
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6887 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6888 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6889
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6890 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6891 conpty_term_and_job_init(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6892 term_T *term,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6893 typval_T *argvar,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6894 char **argv UNUSED,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6895 jobopt_T *opt,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6896 jobopt_T *orig_opt)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6897 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6898 WCHAR *cmd_wchar = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6899 WCHAR *cmd_wchar_copy = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6900 WCHAR *cwd_wchar = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6901 WCHAR *env_wchar = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6902 channel_T *channel = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6903 job_T *job = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6904 HANDLE jo = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6905 garray_T ga_cmd, ga_env;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6906 char_u *cmd = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6907 HRESULT hr;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6908 COORD consize;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6909 SIZE_T breq;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6910 PROCESS_INFORMATION proc_info;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6911 HANDLE i_theirs = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6912 HANDLE o_theirs = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6913 HANDLE i_ours = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6914 HANDLE o_ours = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6915
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6916 ga_init2(&ga_cmd, sizeof(char*), 20);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6917 ga_init2(&ga_env, sizeof(char*), 20);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6918
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6919 if (argvar->v_type == VAR_STRING)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6920 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6921 cmd = argvar->vval.v_string;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6922 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6923 else if (argvar->v_type == VAR_LIST)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6924 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6925 if (win32_build_cmd(argvar->vval.v_list, &ga_cmd) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6926 goto failed;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6927 cmd = ga_cmd.ga_data;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6928 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6929 if (cmd == NULL || *cmd == NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6930 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6931 emsg(_(e_invalid_argument));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6932 goto failed;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6933 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6934
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6935 term->tl_arg0_cmd = vim_strsave(cmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6936
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6937 cmd_wchar = enc_to_utf16(cmd, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6938
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6939 if (cmd_wchar != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6940 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6941 // Request by CreateProcessW
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6942 breq = wcslen(cmd_wchar) + 1 + 1; // Addition of NUL by API
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6943 cmd_wchar_copy = ALLOC_MULT(WCHAR, breq);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6944 wcsncpy(cmd_wchar_copy, cmd_wchar, breq - 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6945 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6946
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6947 ga_clear(&ga_cmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6948 if (cmd_wchar == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6949 goto failed;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6950 if (opt->jo_cwd != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6951 cwd_wchar = enc_to_utf16(opt->jo_cwd, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6952
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6953 win32_build_env(opt->jo_env, &ga_env, TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6954 env_wchar = ga_env.ga_data;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6955
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6956 if (!CreatePipe(&i_theirs, &i_ours, NULL, 0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6957 goto failed;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6958 if (!CreatePipe(&o_ours, &o_theirs, NULL, 0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6959 goto failed;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6960
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6961 consize.X = term->tl_cols;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6962 consize.Y = term->tl_rows;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6963 hr = pCreatePseudoConsole(consize, i_theirs, o_theirs, 0,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6964 &term->tl_conpty);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6965 if (FAILED(hr))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6966 goto failed;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6967
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6968 term->tl_siex.StartupInfo.cb = sizeof(term->tl_siex);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6969
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6970 // Set up pipe inheritance safely: Vista or later.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6971 pInitializeProcThreadAttributeList(NULL, 1, 0, &breq);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6972 term->tl_siex.lpAttributeList = alloc(breq);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6973 if (!term->tl_siex.lpAttributeList)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6974 goto failed;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6975 if (!pInitializeProcThreadAttributeList(term->tl_siex.lpAttributeList, 1,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6976 0, &breq))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6977 goto failed;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6978 if (!pUpdateProcThreadAttribute(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6979 term->tl_siex.lpAttributeList, 0,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6980 PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE, term->tl_conpty,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6981 sizeof(HPCON), NULL, NULL))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6982 goto failed;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6983
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6984 channel = add_channel();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6985 if (channel == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6986 goto failed;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6987
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6988 job = job_alloc();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6989 if (job == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6990 goto failed;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6991 if (argvar->v_type == VAR_STRING)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6992 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6993 int argc;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6994
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6995 build_argv_from_string(cmd, &job->jv_argv, &argc);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6996 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6997 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6998 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
6999 int argc;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7000
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7001 build_argv_from_list(argvar->vval.v_list, &job->jv_argv, &argc);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7002 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7003
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7004 if (opt->jo_set & JO_IN_BUF)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7005 job->jv_in_buf = buflist_findnr(opt->jo_io_buf[PART_IN]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7006
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7007 if (!CreateProcessW(NULL, cmd_wchar_copy, NULL, NULL, FALSE,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7008 EXTENDED_STARTUPINFO_PRESENT | CREATE_UNICODE_ENVIRONMENT
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7009 | CREATE_SUSPENDED | CREATE_DEFAULT_ERROR_MODE,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7010 env_wchar, cwd_wchar,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7011 &term->tl_siex.StartupInfo, &proc_info))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7012 goto failed;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7013
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7014 CloseHandle(i_theirs);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7015 CloseHandle(o_theirs);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7016
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7017 channel_set_pipes(channel,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7018 (sock_T)i_ours,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7019 (sock_T)o_ours,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7020 (sock_T)o_ours);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7021
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7022 // Write lines with CR instead of NL.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7023 channel->ch_write_text_mode = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7024
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7025 // Use to explicitly delete anonymous pipe handle.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7026 channel->ch_anonymous_pipe = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7027
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7028 jo = CreateJobObject(NULL, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7029 if (jo == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7030 goto failed;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7031
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7032 if (!AssignProcessToJobObject(jo, proc_info.hProcess))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7033 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7034 // Failed, switch the way to terminate process with TerminateProcess.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7035 CloseHandle(jo);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7036 jo = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7037 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7038
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7039 ResumeThread(proc_info.hThread);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7040 CloseHandle(proc_info.hThread);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7041
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7042 vim_free(cmd_wchar);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7043 vim_free(cmd_wchar_copy);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7044 vim_free(cwd_wchar);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7045 vim_free(env_wchar);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7046
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7047 if (create_vterm(term, term->tl_rows, term->tl_cols) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7048 goto failed;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7049
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7050 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7051 if (term_use_palette())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7052 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7053 if (term->tl_palette != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7054 set_vterm_palette(term->tl_vterm, term->tl_palette);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7055 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7056 init_vterm_ansi_colors(term->tl_vterm);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7057 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7058 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7059
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7060 channel_set_job(channel, job, opt);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7061 job_set_options(job, opt);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7062
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7063 job->jv_channel = channel;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7064 job->jv_proc_info = proc_info;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7065 job->jv_job_object = jo;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7066 job->jv_status = JOB_STARTED;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7067 job->jv_tty_type = vim_strsave((char_u *)"conpty");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7068 ++job->jv_refcount;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7069 term->tl_job = job;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7070
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7071 // Redirecting stdout and stderr doesn't work at the job level. Instead
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7072 // open the file here and handle it in. opt->jo_io was changed in
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7073 // setup_job_options(), use the original flags here.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7074 if (orig_opt->jo_io[PART_OUT] == JIO_FILE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7075 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7076 char_u *fname = opt->jo_io_name[PART_OUT];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7077
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7078 ch_log(channel, "Opening output file %s", fname);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7079 term->tl_out_fd = mch_fopen((char *)fname, WRITEBIN);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7080 if (term->tl_out_fd == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7081 semsg(_(e_cant_open_file_str), fname);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7082 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7083
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7084 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7085
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7086 failed:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7087 ga_clear(&ga_cmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7088 ga_clear(&ga_env);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7089 vim_free(cmd_wchar);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7090 vim_free(cmd_wchar_copy);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7091 vim_free(cwd_wchar);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7092 if (channel != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7093 channel_clear(channel);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7094 if (job != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7095 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7096 job->jv_channel = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7097 job_cleanup(job);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7098 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7099 term->tl_job = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7100 if (jo != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7101 CloseHandle(jo);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7102
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7103 if (term->tl_siex.lpAttributeList != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7104 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7105 pDeleteProcThreadAttributeList(term->tl_siex.lpAttributeList);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7106 vim_free(term->tl_siex.lpAttributeList);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7107 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7108 term->tl_siex.lpAttributeList = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7109 if (o_theirs != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7110 CloseHandle(o_theirs);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7111 if (o_ours != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7112 CloseHandle(o_ours);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7113 if (i_ours != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7114 CloseHandle(i_ours);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7115 if (i_theirs != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7116 CloseHandle(i_theirs);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7117 if (term->tl_conpty != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7118 pClosePseudoConsole(term->tl_conpty);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7119 term->tl_conpty = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7120 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7121 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7122
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7123 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7124 conpty_term_report_winsize(term_T *term, int rows, int cols)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7125 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7126 COORD consize;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7127
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7128 consize.X = cols;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7129 consize.Y = rows;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7130 pResizePseudoConsole(term->tl_conpty, consize);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7131 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7132
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7133 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7134 term_free_conpty(term_T *term)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7135 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7136 if (term->tl_siex.lpAttributeList != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7137 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7138 pDeleteProcThreadAttributeList(term->tl_siex.lpAttributeList);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7139 vim_free(term->tl_siex.lpAttributeList);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7140 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7141 term->tl_siex.lpAttributeList = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7142 if (term->tl_conpty != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7143 pClosePseudoConsole(term->tl_conpty);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7144 term->tl_conpty = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7145 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7146
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7147 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7148 use_conpty(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7149 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7150 return has_conpty;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7151 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7152
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7153 # ifndef PROTO
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7154
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7155 #define WINPTY_SPAWN_FLAG_AUTO_SHUTDOWN 1ul
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7156 #define WINPTY_SPAWN_FLAG_EXIT_AFTER_SHUTDOWN 2ull
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7157 #define WINPTY_MOUSE_MODE_FORCE 2
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7158
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7159 void* (*winpty_config_new)(UINT64, void*);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7160 void* (*winpty_open)(void*, void*);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7161 void* (*winpty_spawn_config_new)(UINT64, void*, LPCWSTR, void*, void*, void*);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7162 BOOL (*winpty_spawn)(void*, void*, HANDLE*, HANDLE*, DWORD*, void*);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7163 void (*winpty_config_set_mouse_mode)(void*, int);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7164 void (*winpty_config_set_initial_size)(void*, int, int);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7165 LPCWSTR (*winpty_conin_name)(void*);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7166 LPCWSTR (*winpty_conout_name)(void*);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7167 LPCWSTR (*winpty_conerr_name)(void*);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7168 void (*winpty_free)(void*);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7169 void (*winpty_config_free)(void*);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7170 void (*winpty_spawn_config_free)(void*);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7171 void (*winpty_error_free)(void*);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7172 LPCWSTR (*winpty_error_msg)(void*);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7173 BOOL (*winpty_set_size)(void*, int, int, void*);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7174 HANDLE (*winpty_agent_process)(void*);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7175
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7176 #define WINPTY_DLL "winpty.dll"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7177
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7178 static HINSTANCE hWinPtyDLL = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7179 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7180
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7181 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7182 dyn_winpty_init(int verbose)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7183 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7184 int i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7185 static struct
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7186 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7187 char *name;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7188 FARPROC *ptr;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7189 } winpty_entry[] =
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7190 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7191 {"winpty_conerr_name", (FARPROC*)&winpty_conerr_name},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7192 {"winpty_config_free", (FARPROC*)&winpty_config_free},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7193 {"winpty_config_new", (FARPROC*)&winpty_config_new},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7194 {"winpty_config_set_mouse_mode",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7195 (FARPROC*)&winpty_config_set_mouse_mode},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7196 {"winpty_config_set_initial_size",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7197 (FARPROC*)&winpty_config_set_initial_size},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7198 {"winpty_conin_name", (FARPROC*)&winpty_conin_name},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7199 {"winpty_conout_name", (FARPROC*)&winpty_conout_name},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7200 {"winpty_error_free", (FARPROC*)&winpty_error_free},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7201 {"winpty_free", (FARPROC*)&winpty_free},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7202 {"winpty_open", (FARPROC*)&winpty_open},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7203 {"winpty_spawn", (FARPROC*)&winpty_spawn},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7204 {"winpty_spawn_config_free", (FARPROC*)&winpty_spawn_config_free},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7205 {"winpty_spawn_config_new", (FARPROC*)&winpty_spawn_config_new},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7206 {"winpty_error_msg", (FARPROC*)&winpty_error_msg},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7207 {"winpty_set_size", (FARPROC*)&winpty_set_size},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7208 {"winpty_agent_process", (FARPROC*)&winpty_agent_process},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7209 {NULL, NULL}
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7210 };
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7211
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7212 // No need to initialize twice.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7213 if (hWinPtyDLL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7214 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7215 // Load winpty.dll, prefer using the 'winptydll' option, fall back to just
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7216 // winpty.dll.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7217 if (*p_winptydll != NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7218 hWinPtyDLL = vimLoadLib((char *)p_winptydll);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7219 if (!hWinPtyDLL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7220 hWinPtyDLL = vimLoadLib(WINPTY_DLL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7221 if (!hWinPtyDLL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7222 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7223 if (verbose)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7224 semsg(_(e_could_not_load_library_str_str),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7225 (*p_winptydll != NUL ? p_winptydll : (char_u *)WINPTY_DLL),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7226 GetWin32Error());
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7227 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7228 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7229 for (i = 0; winpty_entry[i].name != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7230 && winpty_entry[i].ptr != NULL; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7231 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7232 if ((*winpty_entry[i].ptr = (FARPROC)GetProcAddress(hWinPtyDLL,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7233 winpty_entry[i].name)) == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7234 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7235 if (verbose)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7236 semsg(_(e_could_not_load_library_function_str), winpty_entry[i].name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7237 hWinPtyDLL = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7238 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7239 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7240 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7241
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7242 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7243 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7244
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7245 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7246 winpty_term_and_job_init(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7247 term_T *term,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7248 typval_T *argvar,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7249 char **argv UNUSED,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7250 jobopt_T *opt,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7251 jobopt_T *orig_opt)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7252 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7253 WCHAR *cmd_wchar = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7254 WCHAR *cwd_wchar = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7255 WCHAR *env_wchar = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7256 channel_T *channel = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7257 job_T *job = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7258 DWORD error;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7259 HANDLE jo = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7260 HANDLE child_process_handle;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7261 HANDLE child_thread_handle;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7262 void *winpty_err = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7263 void *spawn_config = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7264 garray_T ga_cmd, ga_env;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7265 char_u *cmd = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7266
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7267 ga_init2(&ga_cmd, sizeof(char*), 20);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7268 ga_init2(&ga_env, sizeof(char*), 20);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7269
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7270 if (argvar->v_type == VAR_STRING)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7271 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7272 cmd = argvar->vval.v_string;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7273 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7274 else if (argvar->v_type == VAR_LIST)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7275 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7276 if (win32_build_cmd(argvar->vval.v_list, &ga_cmd) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7277 goto failed;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7278 cmd = ga_cmd.ga_data;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7279 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7280 if (cmd == NULL || *cmd == NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7281 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7282 emsg(_(e_invalid_argument));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7283 goto failed;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7284 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7285
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7286 term->tl_arg0_cmd = vim_strsave(cmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7287
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7288 cmd_wchar = enc_to_utf16(cmd, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7289 ga_clear(&ga_cmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7290 if (cmd_wchar == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7291 goto failed;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7292 if (opt->jo_cwd != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7293 cwd_wchar = enc_to_utf16(opt->jo_cwd, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7294
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7295 win32_build_env(opt->jo_env, &ga_env, TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7296 env_wchar = ga_env.ga_data;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7297
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7298 term->tl_winpty_config = winpty_config_new(0, &winpty_err);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7299 if (term->tl_winpty_config == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7300 goto failed;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7301
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7302 winpty_config_set_mouse_mode(term->tl_winpty_config,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7303 WINPTY_MOUSE_MODE_FORCE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7304 winpty_config_set_initial_size(term->tl_winpty_config,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7305 term->tl_cols, term->tl_rows);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7306 term->tl_winpty = winpty_open(term->tl_winpty_config, &winpty_err);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7307 if (term->tl_winpty == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7308 goto failed;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7309
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7310 spawn_config = winpty_spawn_config_new(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7311 WINPTY_SPAWN_FLAG_AUTO_SHUTDOWN |
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7312 WINPTY_SPAWN_FLAG_EXIT_AFTER_SHUTDOWN,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7313 NULL,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7314 cmd_wchar,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7315 cwd_wchar,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7316 env_wchar,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7317 &winpty_err);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7318 if (spawn_config == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7319 goto failed;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7320
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7321 channel = add_channel();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7322 if (channel == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7323 goto failed;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7324
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7325 job = job_alloc();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7326 if (job == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7327 goto failed;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7328 if (argvar->v_type == VAR_STRING)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7329 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7330 int argc;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7331
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7332 build_argv_from_string(cmd, &job->jv_argv, &argc);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7333 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7334 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7335 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7336 int argc;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7337
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7338 build_argv_from_list(argvar->vval.v_list, &job->jv_argv, &argc);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7339 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7340
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7341 if (opt->jo_set & JO_IN_BUF)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7342 job->jv_in_buf = buflist_findnr(opt->jo_io_buf[PART_IN]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7343
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7344 if (!winpty_spawn(term->tl_winpty, spawn_config, &child_process_handle,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7345 &child_thread_handle, &error, &winpty_err))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7346 goto failed;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7347
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7348 channel_set_pipes(channel,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7349 (sock_T)CreateFileW(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7350 winpty_conin_name(term->tl_winpty),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7351 GENERIC_WRITE, 0, NULL,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7352 OPEN_EXISTING, 0, NULL),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7353 (sock_T)CreateFileW(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7354 winpty_conout_name(term->tl_winpty),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7355 GENERIC_READ, 0, NULL,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7356 OPEN_EXISTING, 0, NULL),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7357 (sock_T)CreateFileW(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7358 winpty_conerr_name(term->tl_winpty),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7359 GENERIC_READ, 0, NULL,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7360 OPEN_EXISTING, 0, NULL));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7361
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7362 // Write lines with CR instead of NL.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7363 channel->ch_write_text_mode = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7364
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7365 jo = CreateJobObject(NULL, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7366 if (jo == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7367 goto failed;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7368
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7369 if (!AssignProcessToJobObject(jo, child_process_handle))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7370 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7371 // Failed, switch the way to terminate process with TerminateProcess.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7372 CloseHandle(jo);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7373 jo = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7374 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7375
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7376 winpty_spawn_config_free(spawn_config);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7377 vim_free(cmd_wchar);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7378 vim_free(cwd_wchar);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7379 vim_free(env_wchar);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7380
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7381 if (create_vterm(term, term->tl_rows, term->tl_cols) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7382 goto failed;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7383
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7384 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7385 if (term_use_palette())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7386 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7387 if (term->tl_palette != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7388 set_vterm_palette(term->tl_vterm, term->tl_palette);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7389 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7390 init_vterm_ansi_colors(term->tl_vterm);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7391 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7392 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7393
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7394 channel_set_job(channel, job, opt);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7395 job_set_options(job, opt);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7396
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7397 job->jv_channel = channel;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7398 job->jv_proc_info.hProcess = child_process_handle;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7399 job->jv_proc_info.dwProcessId = GetProcessId(child_process_handle);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7400 job->jv_job_object = jo;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7401 job->jv_status = JOB_STARTED;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7402 job->jv_tty_in = utf16_to_enc(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7403 (short_u *)winpty_conin_name(term->tl_winpty), NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7404 job->jv_tty_out = utf16_to_enc(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7405 (short_u *)winpty_conout_name(term->tl_winpty), NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7406 job->jv_tty_type = vim_strsave((char_u *)"winpty");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7407 ++job->jv_refcount;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7408 term->tl_job = job;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7409
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7410 // Redirecting stdout and stderr doesn't work at the job level. Instead
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7411 // open the file here and handle it in. opt->jo_io was changed in
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7412 // setup_job_options(), use the original flags here.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7413 if (orig_opt->jo_io[PART_OUT] == JIO_FILE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7414 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7415 char_u *fname = opt->jo_io_name[PART_OUT];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7416
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7417 ch_log(channel, "Opening output file %s", fname);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7418 term->tl_out_fd = mch_fopen((char *)fname, WRITEBIN);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7419 if (term->tl_out_fd == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7420 semsg(_(e_cant_open_file_str), fname);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7421 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7422
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7423 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7424
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7425 failed:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7426 ga_clear(&ga_cmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7427 ga_clear(&ga_env);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7428 vim_free(cmd_wchar);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7429 vim_free(cwd_wchar);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7430 if (spawn_config != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7431 winpty_spawn_config_free(spawn_config);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7432 if (channel != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7433 channel_clear(channel);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7434 if (job != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7435 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7436 job->jv_channel = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7437 job_cleanup(job);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7438 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7439 term->tl_job = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7440 if (jo != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7441 CloseHandle(jo);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7442 if (term->tl_winpty != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7443 winpty_free(term->tl_winpty);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7444 term->tl_winpty = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7445 if (term->tl_winpty_config != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7446 winpty_config_free(term->tl_winpty_config);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7447 term->tl_winpty_config = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7448 if (winpty_err != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7449 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7450 char *msg = (char *)utf16_to_enc(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7451 (short_u *)winpty_error_msg(winpty_err), NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7452
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7453 emsg(msg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7454 winpty_error_free(winpty_err);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7455 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7456 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7457 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7458
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7459 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7460 * Create a new terminal of "rows" by "cols" cells.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7461 * Store a reference in "term".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7462 * Return OK or FAIL.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7463 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7464 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7465 term_and_job_init(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7466 term_T *term,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7467 typval_T *argvar,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7468 char **argv,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7469 jobopt_T *opt,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7470 jobopt_T *orig_opt)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7471 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7472 int use_winpty = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7473 int use_conpty = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7474 int tty_type = *p_twt;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7475
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7476 has_winpty = dyn_winpty_init(FALSE) != FAIL ? TRUE : FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7477 has_conpty = dyn_conpty_init(FALSE) != FAIL ? TRUE : FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7478
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7479 if (!has_winpty && !has_conpty)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7480 // If neither is available give the errors for winpty, since when
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7481 // conpty is not available it can't be installed either.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7482 return dyn_winpty_init(TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7483
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7484 if (opt->jo_tty_type != NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7485 tty_type = opt->jo_tty_type;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7486
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7487 if (tty_type == NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7488 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7489 if (has_conpty && (is_conpty_stable() || !has_winpty))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7490 use_conpty = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7491 else if (has_winpty)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7492 use_winpty = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7493 // else: error
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7494 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7495 else if (tty_type == 'w') // winpty
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7496 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7497 if (has_winpty)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7498 use_winpty = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7499 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7500 else if (tty_type == 'c') // conpty
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7501 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7502 if (has_conpty)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7503 use_conpty = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7504 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7505 return dyn_conpty_init(TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7506 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7507
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7508 if (use_conpty)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7509 return conpty_term_and_job_init(term, argvar, argv, opt, orig_opt);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7510
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7511 if (use_winpty)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7512 return winpty_term_and_job_init(term, argvar, argv, opt, orig_opt);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7513
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7514 // error
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7515 return dyn_winpty_init(TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7516 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7517
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7518 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7519 create_pty_only(term_T *term, jobopt_T *options)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7520 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7521 HANDLE hPipeIn = INVALID_HANDLE_VALUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7522 HANDLE hPipeOut = INVALID_HANDLE_VALUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7523 char in_name[80], out_name[80];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7524 channel_T *channel = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7525
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7526 if (create_vterm(term, term->tl_rows, term->tl_cols) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7527 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7528
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7529 vim_snprintf(in_name, sizeof(in_name), "\\\\.\\pipe\\vim-%d-in-%d",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7530 GetCurrentProcessId(),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7531 curbuf->b_fnum);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7532 hPipeIn = CreateNamedPipe(in_name, PIPE_ACCESS_OUTBOUND,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7533 PIPE_TYPE_MESSAGE | PIPE_NOWAIT,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7534 PIPE_UNLIMITED_INSTANCES,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7535 0, 0, NMPWAIT_NOWAIT, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7536 if (hPipeIn == INVALID_HANDLE_VALUE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7537 goto failed;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7538
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7539 vim_snprintf(out_name, sizeof(out_name), "\\\\.\\pipe\\vim-%d-out-%d",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7540 GetCurrentProcessId(),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7541 curbuf->b_fnum);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7542 hPipeOut = CreateNamedPipe(out_name, PIPE_ACCESS_INBOUND,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7543 PIPE_TYPE_MESSAGE | PIPE_NOWAIT,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7544 PIPE_UNLIMITED_INSTANCES,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7545 0, 0, 0, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7546 if (hPipeOut == INVALID_HANDLE_VALUE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7547 goto failed;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7548
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7549 ConnectNamedPipe(hPipeIn, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7550 ConnectNamedPipe(hPipeOut, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7551
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7552 term->tl_job = job_alloc();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7553 if (term->tl_job == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7554 goto failed;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7555 ++term->tl_job->jv_refcount;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7556
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7557 // behave like the job is already finished
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7558 term->tl_job->jv_status = JOB_FINISHED;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7559
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7560 channel = add_channel();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7561 if (channel == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7562 goto failed;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7563 term->tl_job->jv_channel = channel;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7564 channel->ch_keep_open = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7565 channel->ch_named_pipe = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7566
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7567 channel_set_pipes(channel,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7568 (sock_T)hPipeIn,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7569 (sock_T)hPipeOut,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7570 (sock_T)hPipeOut);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7571 channel_set_job(channel, term->tl_job, options);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7572 term->tl_job->jv_tty_in = vim_strsave((char_u*)in_name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7573 term->tl_job->jv_tty_out = vim_strsave((char_u*)out_name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7574
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7575 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7576
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7577 failed:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7578 if (hPipeIn != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7579 CloseHandle(hPipeIn);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7580 if (hPipeOut != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7581 CloseHandle(hPipeOut);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7582 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7583 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7584
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7585 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7586 * Free the terminal emulator part of "term".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7587 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7588 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7589 term_free_vterm(term_T *term)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7590 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7591 term_free_conpty(term);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7592 if (term->tl_winpty != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7593 winpty_free(term->tl_winpty);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7594 term->tl_winpty = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7595 if (term->tl_winpty_config != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7596 winpty_config_free(term->tl_winpty_config);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7597 term->tl_winpty_config = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7598 if (term->tl_vterm != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7599 vterm_free(term->tl_vterm);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7600 term->tl_vterm = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7601 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7602
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7603 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7604 * Report the size to the terminal.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7605 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7606 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7607 term_report_winsize(term_T *term, int rows, int cols)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7608 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7609 if (term->tl_conpty)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7610 conpty_term_report_winsize(term, rows, cols);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7611 if (term->tl_winpty)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7612 winpty_set_size(term->tl_winpty, cols, rows, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7613 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7614
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7615 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7616 terminal_enabled(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7617 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7618 return dyn_winpty_init(FALSE) == OK || dyn_conpty_init(FALSE) == OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7619 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7620
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7621 # else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7622
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7623 ///////////////////////////////////////
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7624 // 3. Unix-like implementation.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7625
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7626 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7627 * Create a new terminal of "rows" by "cols" cells.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7628 * Start job for "cmd".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7629 * Store the pointers in "term".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7630 * When "argv" is not NULL then "argvar" is not used.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7631 * Return OK or FAIL.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7632 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7633 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7634 term_and_job_init(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7635 term_T *term,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7636 typval_T *argvar,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7637 char **argv,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7638 jobopt_T *opt,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7639 jobopt_T *orig_opt UNUSED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7640 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7641 term->tl_arg0_cmd = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7642
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7643 if (create_vterm(term, term->tl_rows, term->tl_cols) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7644 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7645
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7646 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7647 if (term_use_palette())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7648 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7649 if (term->tl_palette != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7650 set_vterm_palette(term->tl_vterm, term->tl_palette);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7651 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7652 init_vterm_ansi_colors(term->tl_vterm);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7653 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7654 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7655
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7656 // This may change a string in "argvar".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7657 term->tl_job = job_start(argvar, argv, opt, &term->tl_job);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7658 if (term->tl_job != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7659 ++term->tl_job->jv_refcount;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7660
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7661 return term->tl_job != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7662 && term->tl_job->jv_channel != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7663 && term->tl_job->jv_status != JOB_FAILED ? OK : FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7664 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7665
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7666 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7667 create_pty_only(term_T *term, jobopt_T *opt)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7668 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7669 if (create_vterm(term, term->tl_rows, term->tl_cols) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7670 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7671
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7672 term->tl_job = job_alloc();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7673 if (term->tl_job == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7674 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7675 ++term->tl_job->jv_refcount;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7676
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7677 // behave like the job is already finished
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7678 term->tl_job->jv_status = JOB_FINISHED;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7679
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7680 return mch_create_pty_channel(term->tl_job, opt);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7681 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7682
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7683 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7684 * Free the terminal emulator part of "term".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7685 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7686 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7687 term_free_vterm(term_T *term)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7688 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7689 if (term->tl_vterm != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7690 vterm_free(term->tl_vterm);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7691 term->tl_vterm = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7692 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7693
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7694 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7695 * Report the size to the terminal.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7696 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7697 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7698 term_report_winsize(term_T *term, int rows, int cols)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7699 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7700 // Use an ioctl() to report the new window size to the job.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7701 if (term->tl_job == NULL || term->tl_job->jv_channel == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7702 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7703
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7704 int fd = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7705 int part;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7706
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7707 for (part = PART_OUT; part < PART_COUNT; ++part)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7708 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7709 fd = term->tl_job->jv_channel->ch_part[part].ch_fd;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7710 if (mch_isatty(fd))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7711 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7712 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7713 if (part < PART_COUNT && mch_report_winsize(fd, rows, cols) == OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7714 mch_signal_job(term->tl_job, (char_u *)"winch");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7715 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7716
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7717 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7718
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32481
diff changeset
7719 #endif // FEAT_TERMINAL