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
) {
33 if (reg
->buf
.len
> 0 && reg
->buf
.data
[reg
->buf
.len
-1] != '\0')
34 buffer_append(®
->buf
, "\0", 1);
36 *len
= reg
->buf
.len
> 0 ? reg
->buf
.len
- 1 : 0;
38 case REGISTER_CLIPBOARD
:
42 buffer_clear(®
->buf
);
43 Clipboard clipboard
= {
48 int status
= vis_pipe(vis
, &clipboard
,
49 &(Filerange
){ .start
= 0, .end
= 0 },
50 (const char*[]){ "vis-paste", "vis-paste", NULL
},
51 read_stdout
, read_stderr
);
53 vis_info_show(vis
, "Command failed %s", stderr
.len
> 0 ? stderr
.data
: "");
57 case REGISTER_BLACKHOLE
:
64 bool register_put(Vis
*vis
, Register
*reg
, const char *data
, size_t len
) {
65 return reg
->type
== REGISTER_NORMAL
&& buffer_put(®
->buf
, data
, len
);
68 bool register_put0(Vis
*vis
, Register
*reg
, const char *data
) {
69 return register_put(vis
, reg
, data
, strlen(data
)+1);
72 bool register_put_range(Vis
*vis
, Register
*reg
, Text
*txt
, Filerange
*range
) {
74 return register_append_range(reg
, txt
, range
);
78 size_t len
= text_range_size(range
);
79 if (!buffer_grow(®
->buf
, len
))
81 reg
->buf
.len
= text_bytes_get(txt
, range
->start
, len
, reg
->buf
.data
);
84 case REGISTER_CLIPBOARD
:
88 Clipboard clipboard
= {
92 int status
= vis_pipe(vis
, &clipboard
, range
,
93 (const char*[]){ "vis-copy", "vis-copy", NULL
},
97 vis_info_show(vis
, "Command failed %s", stderr
.len
> 0 ? stderr
.data
: "");
100 case REGISTER_BLACKHOLE
:
107 bool register_append_range(Register
*reg
, Text
*txt
, Filerange
*range
) {
109 case REGISTER_NORMAL
:
111 size_t len
= text_range_size(range
);
112 if (!buffer_grow(®
->buf
, reg
->buf
.len
+ len
))
114 reg
->buf
.len
+= text_bytes_get(txt
, range
->start
, len
, reg
->buf
.data
+ reg
->buf
.len
);