14 static ssize_t
read_stdout(void *context
, char *data
, size_t len
) {
15 Buffer
*buf
= ((Clipboard
*)context
)->stdout
;
16 buffer_append(buf
, data
, len
);
20 static ssize_t
read_stderr(void *context
, char *data
, size_t len
) {
21 Buffer
*buf
= ((Clipboard
*)context
)->stderr
;
22 buffer_append(buf
, data
, len
);
26 void register_release(Register
*reg
) {
27 buffer_release(®
->buf
);
30 const char *register_get(Vis
*vis
, Register
*reg
, size_t *len
) {
35 case REGISTER_CLIPBOARD
:
39 buffer_clear(®
->buf
);
40 Clipboard clipboard
= {
45 int status
= vis_pipe(vis
, &clipboard
,
46 &(Filerange
){ .start
= 0, .end
= 0 },
47 (const char*[]){ "vis-paste", "vis-paste", NULL
},
48 read_stdout
, read_stderr
);
50 vis_info_show(vis
, "Command failed %s", stderr
.len
> 0 ? stderr
.data
: "");
54 case REGISTER_BLACKHOLE
:
61 bool register_put(Vis
*vis
, Register
*reg
, Text
*txt
, Filerange
*range
) {
63 return register_append(reg
, txt
, range
);
67 size_t len
= text_range_size(range
);
68 if (!buffer_grow(®
->buf
, len
))
70 reg
->buf
.len
= text_bytes_get(txt
, range
->start
, len
, reg
->buf
.data
);
73 case REGISTER_CLIPBOARD
:
77 Clipboard clipboard
= {
81 int status
= vis_pipe(vis
, &clipboard
, range
,
82 (const char*[]){ "vis-copy", "vis-copy", NULL
},
86 vis_info_show(vis
, "Command failed %s", stderr
.len
> 0 ? stderr
.data
: "");
89 case REGISTER_BLACKHOLE
:
96 bool register_append(Register
*reg
, Text
*txt
, Filerange
*range
) {
100 size_t len
= text_range_size(range
);
101 if (!buffer_grow(®
->buf
, reg
->buf
.len
+ len
))
103 reg
->buf
.len
+= text_bytes_get(txt
, range
->start
, len
, reg
->buf
.data
+ reg
->buf
.len
);