mirror of
https://github.com/neovim/neovim.git
synced 2024-09-17 20:58:20 -04:00
refactor(terminal): only remove const qualifier when necessary (#26386)
This commit is contained in:
parent
cf612c64b0
commit
66f1563c7a
@ -1017,18 +1017,19 @@ Integer nvim_open_term(Buffer buffer, DictionaryOf(LuaRef) opts, Error *err)
|
||||
}
|
||||
}
|
||||
|
||||
TerminalOptions topts;
|
||||
Channel *chan = channel_alloc(kChannelStreamInternal);
|
||||
chan->stream.internal.cb = cb;
|
||||
chan->stream.internal.closed = false;
|
||||
topts.data = chan;
|
||||
// NB: overridden in terminal_check_size if a window is already
|
||||
// displaying the buffer
|
||||
topts.width = (uint16_t)MAX(curwin->w_width_inner - win_col_off(curwin), 0);
|
||||
topts.height = (uint16_t)curwin->w_height_inner;
|
||||
topts.write_cb = term_write;
|
||||
topts.resize_cb = term_resize;
|
||||
topts.close_cb = term_close;
|
||||
TerminalOptions topts = {
|
||||
.data = chan,
|
||||
// NB: overridden in terminal_check_size if a window is already
|
||||
// displaying the buffer
|
||||
.width = (uint16_t)MAX(curwin->w_width_inner - win_col_off(curwin), 0),
|
||||
.height = (uint16_t)curwin->w_height_inner,
|
||||
.write_cb = term_write,
|
||||
.resize_cb = term_resize,
|
||||
.close_cb = term_close,
|
||||
};
|
||||
channel_incref(chan);
|
||||
terminal_open(&chan->term, buf, topts);
|
||||
if (chan->term != NULL) {
|
||||
@ -1038,7 +1039,7 @@ Integer nvim_open_term(Buffer buffer, DictionaryOf(LuaRef) opts, Error *err)
|
||||
return (Integer)chan->id;
|
||||
}
|
||||
|
||||
static void term_write(char *buf, size_t size, void *data) // NOLINT(readability-non-const-parameter)
|
||||
static void term_write(const char *buf, size_t size, void *data)
|
||||
{
|
||||
Channel *chan = data;
|
||||
LuaRef cb = chan->stream.internal.cb;
|
||||
@ -1048,7 +1049,7 @@ static void term_write(char *buf, size_t size, void *data) // NOLINT(readabilit
|
||||
MAXSIZE_TEMP_ARRAY(args, 3);
|
||||
ADD_C(args, INTEGER_OBJ((Integer)chan->id));
|
||||
ADD_C(args, BUFFER_OBJ(terminal_buf(chan->term)));
|
||||
ADD_C(args, STRING_OBJ(((String){ .data = buf, .size = size })));
|
||||
ADD_C(args, STRING_OBJ(((String){ .data = (char *)buf, .size = size })));
|
||||
textlock++;
|
||||
nlua_call_ref(cb, "input", args, false, NULL);
|
||||
textlock--;
|
||||
|
@ -794,19 +794,20 @@ static void channel_callback_call(Channel *chan, CallbackReader *reader)
|
||||
/// and `buf` is assumed to be a new, unmodified buffer.
|
||||
void channel_terminal_open(buf_T *buf, Channel *chan)
|
||||
{
|
||||
TerminalOptions topts;
|
||||
topts.data = chan;
|
||||
topts.width = chan->stream.pty.width;
|
||||
topts.height = chan->stream.pty.height;
|
||||
topts.write_cb = term_write;
|
||||
topts.resize_cb = term_resize;
|
||||
topts.close_cb = term_close;
|
||||
TerminalOptions topts = {
|
||||
.data = chan,
|
||||
.width = chan->stream.pty.width,
|
||||
.height = chan->stream.pty.height,
|
||||
.write_cb = term_write,
|
||||
.resize_cb = term_resize,
|
||||
.close_cb = term_close,
|
||||
};
|
||||
buf->b_p_channel = (OptInt)chan->id; // 'channel' option
|
||||
channel_incref(chan);
|
||||
terminal_open(&chan->term, buf, topts);
|
||||
}
|
||||
|
||||
static void term_write(char *buf, size_t size, void *data)
|
||||
static void term_write(const char *buf, size_t size, void *data)
|
||||
{
|
||||
Channel *chan = data;
|
||||
if (chan->stream.proc.in.closed) {
|
||||
|
@ -188,7 +188,7 @@ void terminal_teardown(void)
|
||||
|
||||
static void term_output_callback(const char *s, size_t len, void *user_data)
|
||||
{
|
||||
terminal_send((Terminal *)user_data, (char *)s, len);
|
||||
terminal_send((Terminal *)user_data, s, len);
|
||||
}
|
||||
|
||||
// public API {{{
|
||||
@ -680,7 +680,7 @@ void terminal_destroy(Terminal **termpp)
|
||||
}
|
||||
}
|
||||
|
||||
void terminal_send(Terminal *term, char *data, size_t size)
|
||||
static void terminal_send(Terminal *term, const char *data, size_t size)
|
||||
{
|
||||
if (term->closed) {
|
||||
return;
|
||||
@ -762,7 +762,7 @@ void terminal_paste(int count, char **y_array, size_t y_size)
|
||||
vterm_keyboard_end_paste(curbuf->terminal->vt);
|
||||
}
|
||||
|
||||
void terminal_send_key(Terminal *term, int c)
|
||||
static void terminal_send_key(Terminal *term, int c)
|
||||
{
|
||||
VTermModifier mod = VTERM_MOD_NONE;
|
||||
|
||||
@ -780,7 +780,7 @@ void terminal_send_key(Terminal *term, int c)
|
||||
}
|
||||
}
|
||||
|
||||
void terminal_receive(Terminal *term, char *data, size_t len)
|
||||
void terminal_receive(Terminal *term, const char *data, size_t len)
|
||||
{
|
||||
if (!data) {
|
||||
return;
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct terminal Terminal;
|
||||
typedef void (*terminal_write_cb)(char *buffer, size_t size, void *data);
|
||||
typedef void (*terminal_write_cb)(const char *buffer, size_t size, void *data);
|
||||
typedef void (*terminal_resize_cb)(uint16_t width, uint16_t height, void *data);
|
||||
typedef void (*terminal_close_cb)(void *data);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user