mirror of
https://github.com/neovim/neovim.git
synced 2024-12-20 11:15:14 -07:00
nvim__screenshot
This commit is contained in:
parent
7b1b271f43
commit
a1508c9f6d
@ -36,6 +36,8 @@ void set_title(String title)
|
||||
FUNC_API_SINCE(3);
|
||||
void set_icon(String icon)
|
||||
FUNC_API_SINCE(3);
|
||||
void screenshot(String path)
|
||||
FUNC_API_SINCE(7) FUNC_API_REMOTE_IMPL;
|
||||
void option_set(String name, Object value)
|
||||
FUNC_API_SINCE(4) FUNC_API_BRIDGE_IMPL;
|
||||
// Stop event is not exported as such, represented by EOF in the msgpack stream.
|
||||
|
@ -2627,3 +2627,9 @@ void nvim__put_attr(Integer id, Integer start_row, Integer start_col,
|
||||
decorations_add_luahl_attr(attr, (int)start_row, (colnr_T)start_col,
|
||||
(int)end_row, (colnr_T)end_col);
|
||||
}
|
||||
|
||||
void nvim__screenshot(String path)
|
||||
FUNC_API_FAST
|
||||
{
|
||||
ui_call_screenshot(path);
|
||||
}
|
||||
|
@ -108,6 +108,7 @@ typedef struct {
|
||||
bool cork, overflow;
|
||||
bool cursor_color_changed;
|
||||
bool is_starting;
|
||||
FILE *screenshot;
|
||||
cursorentry_T cursor_shapes[SHAPE_IDX_COUNT];
|
||||
HlAttrs clear_attrs;
|
||||
kvec_t(HlAttrs) attrs;
|
||||
@ -167,6 +168,7 @@ UI *tui_start(void)
|
||||
ui->suspend = tui_suspend;
|
||||
ui->set_title = tui_set_title;
|
||||
ui->set_icon = tui_set_icon;
|
||||
ui->screenshot = tui_screenshot;
|
||||
ui->option_set= tui_option_set;
|
||||
ui->raw_line = tui_raw_line;
|
||||
|
||||
@ -412,6 +414,7 @@ static void tui_main(UIBridgeData *bridge, UI *ui)
|
||||
data->bridge = bridge;
|
||||
data->loop = &tui_loop;
|
||||
data->is_starting = true;
|
||||
data->screenshot = NULL;
|
||||
kv_init(data->invalid_regions);
|
||||
signal_watcher_init(data->loop, &data->winch_handle, ui);
|
||||
signal_watcher_init(data->loop, &data->cont_handle, data);
|
||||
@ -1317,6 +1320,31 @@ static void tui_set_icon(UI *ui, String icon)
|
||||
{
|
||||
}
|
||||
|
||||
static void tui_screenshot(UI *ui, String path)
|
||||
{
|
||||
TUIData *data = ui->data;
|
||||
UGrid *grid = &data->grid;
|
||||
flush_buf(ui);
|
||||
grid->row = 0;
|
||||
grid->col = 0;
|
||||
|
||||
FILE *f = fopen(path.data, "w");
|
||||
data->screenshot = f;
|
||||
fprintf(f, "%d,%d\n", grid->height, grid->width);
|
||||
unibi_out(ui, unibi_clear_screen);
|
||||
for (int i = 0; i < grid->height; i++) {
|
||||
cursor_goto(ui, i, 0);
|
||||
for (int j = 0; j < grid->width; j++) {
|
||||
print_cell(ui, &grid->cells[i][j]);
|
||||
}
|
||||
}
|
||||
flush_buf(ui);
|
||||
data->screenshot = NULL;
|
||||
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
|
||||
static void tui_option_set(UI *ui, String name, Object value)
|
||||
{
|
||||
TUIData *data = ui->data;
|
||||
@ -2054,9 +2082,15 @@ static void flush_buf(UI *ui)
|
||||
}
|
||||
}
|
||||
|
||||
uv_write(&req, STRUCT_CAST(uv_stream_t, &data->output_handle),
|
||||
bufs, (unsigned)(bufp - bufs), NULL);
|
||||
uv_run(&data->write_loop, UV_RUN_DEFAULT);
|
||||
if (data->screenshot) {
|
||||
for (size_t i = 0; i < (size_t)(bufp - bufs); i++) {
|
||||
fwrite(bufs[i].base, bufs[i].len, 1, data->screenshot);
|
||||
}
|
||||
} else {
|
||||
uv_write(&req, STRUCT_CAST(uv_stream_t, &data->output_handle),
|
||||
bufs, (unsigned)(bufp - bufs), NULL);
|
||||
uv_run(&data->write_loop, UV_RUN_DEFAULT);
|
||||
}
|
||||
data->bufpos = 0;
|
||||
data->overflow = false;
|
||||
}
|
||||
|
@ -61,6 +61,7 @@ UI *ui_bridge_attach(UI *ui, ui_main_fn ui_main, event_scheduler scheduler)
|
||||
rv->bridge.suspend = ui_bridge_suspend;
|
||||
rv->bridge.set_title = ui_bridge_set_title;
|
||||
rv->bridge.set_icon = ui_bridge_set_icon;
|
||||
rv->bridge.screenshot = ui_bridge_screenshot;
|
||||
rv->bridge.option_set = ui_bridge_option_set;
|
||||
rv->bridge.raw_line = ui_bridge_raw_line;
|
||||
rv->bridge.inspect = ui_bridge_inspect;
|
||||
|
Loading…
Reference in New Issue
Block a user