vte3 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,964 @@
1
+ /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * Copyright (C) 2006-2011 Ruby-GNOME2 Project Team
4
+ *
5
+ * This library is free software; you can redistribute it and/or
6
+ * modify it under the terms of the GNU Lesser General Public
7
+ * License as published by the Free Software Foundation; either
8
+ * version 2.1 of the License, or (at your option) any later version.
9
+ *
10
+ * This library is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ * Lesser General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU Lesser General Public
16
+ * License along with this library; if not, write to the Free Software
17
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18
+ * MA 02110-1301 USA
19
+ */
20
+
21
+ #include "rbvte3private.h"
22
+
23
+ #include <stdarg.h>
24
+ #include <pwd.h>
25
+
26
+ #define RG_TARGET_NAMESPACE cTerminal
27
+ #define _SELF(s) (RVAL2VTETERMINAL(s))
28
+
29
+ static ID id_new, id_call;
30
+
31
+ static char **
32
+ rval2cstrary(VALUE ary)
33
+ {
34
+ long i, len;
35
+ char **result;
36
+
37
+ if (NIL_P(ary))
38
+ return NULL;
39
+
40
+ len = RARRAY_LEN(ary);
41
+ result = ALLOC_N(char *, len + 1);
42
+ for (i = 0; i < len; i++) {
43
+ result[i] = g_strdup(RVAL2CSTR(RARRAY_PTR(ary)[i]));
44
+ }
45
+ result[i] = NULL;
46
+
47
+ return result;
48
+ }
49
+
50
+ static void
51
+ free_cstrary(char **ary)
52
+ {
53
+ long i;
54
+
55
+ if (!ary) return;
56
+
57
+ for (i = 0; ary[i] != NULL; i++) {
58
+ g_free(ary[i]);
59
+ }
60
+ g_free(ary);
61
+ }
62
+
63
+ static VALUE
64
+ attrary2rval(GArray *attrs)
65
+ {
66
+ long i, len;
67
+ VALUE rb_attrs, rb_class;
68
+
69
+ len = attrs->len;
70
+ rb_attrs = rb_ary_new2(len);
71
+ rb_class = rb_const_get(rb_const_get(rb_cObject, rb_intern("Vte")), rb_intern("CharAttributes"));
72
+
73
+ for (i = 0; i < len; i++) {
74
+ VteCharAttributes *attr;
75
+ attr = &g_array_index(attrs, VteCharAttributes, i);
76
+ rb_ary_push(rb_attrs, rb_funcall(rb_class, id_new, 6,
77
+ LONG2NUM(attr->row),
78
+ LONG2NUM(attr->column),
79
+ GDKCOLOR2RVAL(&(attr->fore)),
80
+ GDKCOLOR2RVAL(&(attr->back)),
81
+ CBOOL2RVAL(attr->underline),
82
+ CBOOL2RVAL(attr->strikethrough)));
83
+ }
84
+
85
+ return rb_attrs;
86
+ }
87
+
88
+ static VALUE
89
+ rg_initialize(VALUE self)
90
+ {
91
+ RBGTK_INITIALIZE(self, vte_terminal_new());
92
+ return Qnil;
93
+ }
94
+
95
+ static VALUE
96
+ fork_command_default_argv(void)
97
+ {
98
+ struct passwd *pwd;
99
+ const char *shell = NULL;
100
+
101
+ pwd = getpwuid(getuid());
102
+ if (pwd != NULL)
103
+ shell = pwd->pw_shell;
104
+ if (shell == NULL)
105
+ shell = g_getenv("SHELL") ? g_getenv("SHELL") : "/bin/sh";
106
+
107
+ return rb_ary_new3(1, CSTR2RVAL(shell));
108
+ }
109
+
110
+ static VALUE
111
+ rg_fork_command(int argc, VALUE *argv, VALUE self)
112
+ {
113
+ VALUE options, rb_pty_flags, rb_working_directory, rb_command_argv, rb_envv, rb_spawn_flags;
114
+ int pty_flags, spawn_flags;
115
+ char *working_directory;
116
+ char **command_argv;
117
+ char **envv;
118
+ GPid child_pid;
119
+ gboolean result;
120
+ GError *error = NULL;
121
+
122
+ rb_scan_args(argc, argv, "01", &options);
123
+ rbg_scan_options(options,
124
+ "pty_flags", &rb_pty_flags,
125
+ "working_directory", &rb_working_directory,
126
+ "argv", &rb_command_argv,
127
+ "envv", &rb_envv,
128
+ "spawn_flags", &rb_spawn_flags,
129
+ NULL);
130
+ pty_flags = NIL_P(rb_pty_flags) ?
131
+ VTE_PTY_DEFAULT :
132
+ RVAL2VTEPTYFLAGS(rb_pty_flags);
133
+ working_directory = RVAL2CSTR_ACCEPT_NIL(rb_working_directory);
134
+ command_argv = rval2cstrary(NIL_P(rb_command_argv) ? fork_command_default_argv() : rb_command_argv);
135
+ envv = rval2cstrary(rb_envv);
136
+ spawn_flags = NIL_P(rb_spawn_flags) ?
137
+ G_SPAWN_CHILD_INHERITS_STDIN | G_SPAWN_SEARCH_PATH :
138
+ NUM2INT(rb_spawn_flags);
139
+
140
+ result = vte_terminal_fork_command_full(_SELF(self),
141
+ pty_flags,
142
+ working_directory,
143
+ command_argv,
144
+ envv,
145
+ spawn_flags,
146
+ NULL,
147
+ NULL,
148
+ &child_pid,
149
+ &error);
150
+ free_cstrary(command_argv);
151
+ free_cstrary(envv);
152
+ if (error)
153
+ RAISE_GERROR(error);
154
+
155
+ return INT2NUM(child_pid);
156
+ }
157
+
158
+ static VALUE
159
+ rg_feed(VALUE self, VALUE data)
160
+ {
161
+ glong length;
162
+
163
+ length = RSTRING_LEN(data);
164
+
165
+ if (length > 0) {
166
+ vte_terminal_feed(_SELF(self), RSTRING_PTR(data), length);
167
+ }
168
+
169
+ return self;
170
+ }
171
+
172
+ static VALUE
173
+ rg_feed_child(VALUE self, VALUE data)
174
+ {
175
+ glong length;
176
+
177
+ length = RSTRING_LEN(data);
178
+
179
+ if (length > 0) {
180
+ vte_terminal_feed_child(_SELF(self), RSTRING_PTR(data), length);
181
+ }
182
+
183
+ return self;
184
+ }
185
+
186
+ static VALUE
187
+ rg_feed_child_binary(VALUE self, VALUE data)
188
+ {
189
+ glong length;
190
+
191
+ length = RSTRING_LEN(data);
192
+
193
+ if (length > 0) {
194
+ vte_terminal_feed_child_binary(_SELF(self),
195
+ RSTRING_PTR(data), length);
196
+ }
197
+
198
+ return self;
199
+ }
200
+
201
+ static VALUE
202
+ rg_copy_clipboard(VALUE self)
203
+ {
204
+ vte_terminal_copy_clipboard(_SELF(self));
205
+ return self;
206
+ }
207
+
208
+ static VALUE
209
+ rg_paste_clipboard(VALUE self)
210
+ {
211
+ vte_terminal_paste_clipboard(_SELF(self));
212
+ return self;
213
+ }
214
+
215
+ static VALUE
216
+ rg_copy_primary(VALUE self)
217
+ {
218
+ vte_terminal_copy_primary(_SELF(self));
219
+ return self;
220
+ }
221
+
222
+ static VALUE
223
+ rg_paste_primary(VALUE self)
224
+ {
225
+ vte_terminal_paste_primary(_SELF(self));
226
+ return self;
227
+ }
228
+
229
+ static VALUE
230
+ rg_set_size(VALUE self, VALUE columns, VALUE rows)
231
+ {
232
+ vte_terminal_set_size(_SELF(self), NUM2LONG(columns), NUM2LONG(rows));
233
+ return self;
234
+ }
235
+
236
+ static VALUE
237
+ rg_set_audible_bell(VALUE self, VALUE is_audible)
238
+ {
239
+ vte_terminal_set_audible_bell(_SELF(self), RVAL2CBOOL(is_audible));
240
+ return self;
241
+ }
242
+
243
+ static VALUE
244
+ rg_audible_bell_p(VALUE self)
245
+ {
246
+ return CBOOL2RVAL(vte_terminal_get_audible_bell(_SELF(self)));
247
+ }
248
+
249
+ static VALUE
250
+ rg_set_visible_bell(VALUE self, VALUE is_visible)
251
+ {
252
+ vte_terminal_set_visible_bell(_SELF(self), RVAL2CBOOL(is_visible));
253
+ return self;
254
+ }
255
+
256
+ static VALUE
257
+ rg_visible_bell_p(VALUE self)
258
+ {
259
+ return CBOOL2RVAL(vte_terminal_get_visible_bell(_SELF(self)));
260
+ }
261
+
262
+ static VALUE
263
+ rg_set_scroll_background(VALUE self, VALUE scroll)
264
+ {
265
+ vte_terminal_set_scroll_background(_SELF(self), RVAL2CBOOL(scroll));
266
+ return self;
267
+ }
268
+
269
+ static VALUE
270
+ rg_set_scroll_on_output(VALUE self, VALUE scroll)
271
+ {
272
+ vte_terminal_set_scroll_on_output(_SELF(self), RVAL2CBOOL(scroll));
273
+ return self;
274
+ }
275
+
276
+ static VALUE
277
+ rg_set_scroll_on_keystroke(VALUE self, VALUE scroll)
278
+ {
279
+ vte_terminal_set_scroll_on_keystroke(_SELF(self), RVAL2CBOOL(scroll));
280
+ return self;
281
+ }
282
+
283
+ static VALUE
284
+ rg_set_color_dim(VALUE self, VALUE dim)
285
+ {
286
+ vte_terminal_set_color_dim(_SELF(self), RVAL2GDKCOLOR(dim));
287
+ return self;
288
+ }
289
+
290
+ static VALUE
291
+ rg_set_color_bold(VALUE self, VALUE bold)
292
+ {
293
+ vte_terminal_set_color_bold(_SELF(self), RVAL2GDKCOLOR(bold));
294
+ return self;
295
+ }
296
+
297
+ static VALUE
298
+ rg_set_color_foreground(VALUE self, VALUE foreground)
299
+ {
300
+ vte_terminal_set_color_foreground(_SELF(self), RVAL2GDKCOLOR(foreground));
301
+ return self;
302
+ }
303
+
304
+ static VALUE
305
+ rg_set_color_background(VALUE self, VALUE background)
306
+ {
307
+ vte_terminal_set_color_background(_SELF(self), RVAL2GDKCOLOR(background));
308
+ return self;
309
+ }
310
+
311
+ static VALUE
312
+ rg_set_color_cursor(VALUE self, VALUE cursor)
313
+ {
314
+ vte_terminal_set_color_cursor(_SELF(self),
315
+ NIL_P(cursor) ? NULL : RVAL2GDKCOLOR(cursor));
316
+ return self;
317
+ }
318
+
319
+ static VALUE
320
+ rg_set_color_highlight(VALUE self, VALUE highlight)
321
+ {
322
+ vte_terminal_set_color_highlight(_SELF(self),
323
+ NIL_P(highlight) ?
324
+ NULL : RVAL2GDKCOLOR(highlight));
325
+ return self;
326
+ }
327
+
328
+ static VALUE
329
+ rg_set_colors(VALUE self, VALUE foreground, VALUE background,
330
+ VALUE rb_palette)
331
+ {
332
+ glong i, len;
333
+ GdkColor *palette;
334
+
335
+ len = RARRAY_LEN(rb_palette);
336
+
337
+ if (!(len == 0 || len == 8 || len == 16 || len == 24)) {
338
+ char *inspect;
339
+ inspect = RVAL2CSTR(rb_palette);
340
+ rb_raise(rb_eArgError, "palette size must be 0, 8, 16 or 24: %s",
341
+ inspect);
342
+ }
343
+
344
+ palette = ALLOCA_N(GdkColor, len);
345
+ for (i = 0; i < len; i++) {
346
+ GdkColor *color;
347
+ color = RVAL2GDKCOLOR(RARRAY_PTR(rb_palette)[i]);
348
+ palette[i] = *color;
349
+ }
350
+
351
+ vte_terminal_set_colors(_SELF(self), RVAL2GDKCOLOR(foreground),
352
+ RVAL2GDKCOLOR(background), palette, len);
353
+ return self;
354
+ }
355
+
356
+ static VALUE
357
+ rg_set_default_colors(VALUE self)
358
+ {
359
+ vte_terminal_set_default_colors(_SELF(self));
360
+ return self;
361
+ }
362
+
363
+ static VALUE
364
+ rg_set_background_image(VALUE self, VALUE image_or_path)
365
+ {
366
+ if (RVAL2CBOOL(rb_obj_is_kind_of(image_or_path, rb_cString))) {
367
+ vte_terminal_set_background_image_file(_SELF(self),
368
+ RVAL2CSTR(image_or_path));
369
+ } else {
370
+ vte_terminal_set_background_image(_SELF(self),
371
+ RVAL2GDKPIXBUF(image_or_path));
372
+ }
373
+
374
+ return self;
375
+ }
376
+
377
+ static VALUE
378
+ rg_set_background_tint_color(VALUE self, VALUE color)
379
+ {
380
+ vte_terminal_set_background_tint_color(_SELF(self), RVAL2GDKCOLOR(color));
381
+ return self;
382
+ }
383
+
384
+ static VALUE
385
+ rg_set_background_saturation(VALUE self, VALUE saturation)
386
+ {
387
+ vte_terminal_set_background_saturation(_SELF(self),
388
+ NUM2DBL(saturation));
389
+ return self;
390
+ }
391
+
392
+ static VALUE
393
+ rg_set_background_transparent(VALUE self, VALUE transparent)
394
+ {
395
+ vte_terminal_set_background_transparent(_SELF(self),
396
+ RVAL2CBOOL(transparent));
397
+ return self;
398
+ }
399
+
400
+ static VALUE
401
+ rg_set_cursor_blinks(VALUE self, VALUE blink)
402
+ {
403
+ VteTerminalCursorBlinkMode mode;
404
+
405
+ mode = RVAL2CBOOL(blink) ? VTE_CURSOR_BLINK_ON : VTE_CURSOR_BLINK_OFF;
406
+ vte_terminal_set_cursor_blink_mode(_SELF(self), mode);
407
+ return self;
408
+ }
409
+
410
+ static VALUE
411
+ rg_set_cursor_blink_mode(VALUE self, VALUE rb_mode)
412
+ {
413
+ VteTerminalCursorBlinkMode mode;
414
+
415
+ mode = RVAL2VTETERMINALCURSORBLINKMODE(rb_mode);
416
+ vte_terminal_set_cursor_blink_mode(_SELF(self), mode);
417
+ return self;
418
+ }
419
+
420
+ static VALUE
421
+ rg_cursor_blink_mode(VALUE self)
422
+ {
423
+ VteTerminalCursorBlinkMode mode;
424
+
425
+ mode = vte_terminal_get_cursor_blink_mode(_SELF(self));
426
+ return VTETERMINALCURSORBLINKMODE2RVAL(mode);
427
+ }
428
+
429
+ static VALUE
430
+ rg_set_cursor_shape(VALUE self, VALUE rb_shape)
431
+ {
432
+ VteTerminalCursorShape shape;
433
+
434
+ shape = RVAL2VTETERMINALCURSORSHAPE(rb_shape);
435
+ vte_terminal_set_cursor_shape(_SELF(self), shape);
436
+ return self;
437
+ }
438
+
439
+ static VALUE
440
+ rg_cursor_shape(VALUE self)
441
+ {
442
+ VteTerminalCursorShape shape;
443
+
444
+ shape = vte_terminal_get_cursor_shape(_SELF(self));
445
+ return VTETERMINALCURSORSHAPE2RVAL(shape);
446
+ }
447
+
448
+ static VALUE
449
+ rg_child_exit_status(VALUE self)
450
+ {
451
+ return INT2NUM(vte_terminal_get_child_exit_status(_SELF(self)));
452
+ }
453
+
454
+ static VALUE
455
+ rg_set_scrollback_lines(VALUE self, VALUE lines)
456
+ {
457
+ vte_terminal_set_scrollback_lines(_SELF(self), NUM2LONG(lines));
458
+ return self;
459
+ }
460
+
461
+ static VALUE
462
+ rg_im_append_menuitems(VALUE self, VALUE menushell)
463
+ {
464
+ vte_terminal_im_append_menuitems(_SELF(self), RVAL2GTKMENUSHELL(menushell));
465
+ return self;
466
+ }
467
+
468
+ static VALUE
469
+ rg_set_font(VALUE self, VALUE desc_or_name)
470
+ {
471
+ if (rb_obj_is_kind_of(desc_or_name, rb_cString)) {
472
+ vte_terminal_set_font_from_string(_SELF(self), RVAL2CSTR(desc_or_name));
473
+ } else {
474
+ vte_terminal_set_font(_SELF(self), RVAL2PANGOFONTDESCRIPTION(desc_or_name));
475
+ }
476
+
477
+ return self;
478
+ }
479
+
480
+ static VALUE
481
+ rg_font(VALUE self)
482
+ {
483
+ PangoFontDescription *font_desc;
484
+ font_desc = (PangoFontDescription *)vte_terminal_get_font(_SELF(self));
485
+ return PANGOFONTDESCRIPTION2RVAL(font_desc);
486
+ }
487
+
488
+ static VALUE
489
+ rg_set_allow_bold(VALUE self, VALUE allow_bold)
490
+ {
491
+ vte_terminal_set_allow_bold(_SELF(self), RVAL2CBOOL(allow_bold));
492
+ return self;
493
+ }
494
+
495
+ static VALUE
496
+ rg_allow_bold_p(VALUE self)
497
+ {
498
+ return CBOOL2RVAL(vte_terminal_get_allow_bold(_SELF(self)));
499
+ }
500
+
501
+ static VALUE
502
+ rg_has_selection_p(VALUE self)
503
+ {
504
+ return CBOOL2RVAL(vte_terminal_get_has_selection(_SELF(self)));
505
+ }
506
+
507
+ static VALUE
508
+ rg_set_word_chars(VALUE self, VALUE word_chars)
509
+ {
510
+ vte_terminal_set_word_chars(_SELF(self), RVAL2CSTR_ACCEPT_NIL(word_chars));
511
+ return self;
512
+ }
513
+
514
+ static VALUE
515
+ rg_word_char_p(VALUE self, VALUE c)
516
+ {
517
+ return CBOOL2RVAL(vte_terminal_is_word_char(_SELF(self), NUM2UINT(c)));
518
+ }
519
+
520
+ static VALUE
521
+ rg_set_backspace_binding(VALUE self, VALUE binding)
522
+ {
523
+ vte_terminal_set_backspace_binding(_SELF(self), RVAL2VTETERMINALERASEBINDING(binding));
524
+ return self;
525
+ }
526
+
527
+ static VALUE
528
+ rg_set_delete_binding(VALUE self, VALUE binding)
529
+ {
530
+ vte_terminal_set_delete_binding(_SELF(self), RVAL2VTETERMINALERASEBINDING(binding));
531
+ return self;
532
+ }
533
+
534
+ static VALUE
535
+ rg_mouse_autohide_p(VALUE self)
536
+ {
537
+ return CBOOL2RVAL(vte_terminal_get_mouse_autohide(_SELF(self)));
538
+ }
539
+
540
+ static VALUE
541
+ rg_set_mouse_autohide(VALUE self, VALUE setting)
542
+ {
543
+ vte_terminal_set_mouse_autohide(_SELF(self), RVAL2CBOOL(setting));
544
+ return self;
545
+ }
546
+
547
+ static VALUE
548
+ rg_reset(VALUE self, VALUE full, VALUE clear_history)
549
+ {
550
+ vte_terminal_reset(_SELF(self), RVAL2CBOOL(full),
551
+ RVAL2CBOOL(clear_history));
552
+ return self;
553
+ }
554
+
555
+ static gboolean
556
+ term_is_selected_cb(VteTerminal *terminal, glong column, glong row,
557
+ gpointer data)
558
+ {
559
+ gboolean result = TRUE;
560
+ VALUE callback = (VALUE)data;
561
+
562
+ if (!NIL_P(callback)) {
563
+ VALUE rb_result;
564
+ rb_result = rb_funcall(callback, id_call, 3, GOBJ2RVAL(terminal),
565
+ LONG2NUM(column), LONG2NUM(row));
566
+ result = RVAL2CBOOL(rb_result);
567
+ }
568
+
569
+ return result;
570
+ }
571
+
572
+ static VALUE
573
+ rg_get_text(int argc, VALUE *argv, VALUE self)
574
+ {
575
+ VALUE get_attrs, include_trailing_spaces, proc, rb_text;
576
+ GArray *attrs = NULL;
577
+ char *text;
578
+
579
+ rb_scan_args(argc, argv, "02&", &get_attrs,
580
+ &include_trailing_spaces, &proc);
581
+
582
+ if (get_attrs != Qfalse)
583
+ attrs = g_array_new(FALSE, TRUE, sizeof(VteCharAttributes));
584
+
585
+ if (RVAL2CBOOL(include_trailing_spaces)) {
586
+ text = vte_terminal_get_text_include_trailing_spaces(
587
+ _SELF(self), term_is_selected_cb, (gpointer)proc, attrs);
588
+ } else {
589
+ text = vte_terminal_get_text(_SELF(self), term_is_selected_cb,
590
+ (gpointer)proc, attrs);
591
+ }
592
+ rb_text = CSTR2RVAL(text);
593
+ free(text);
594
+
595
+ if (attrs) {
596
+ VALUE rb_attrs;
597
+ rb_attrs = attrary2rval(attrs);
598
+ g_array_free(attrs, TRUE);
599
+ return rb_ary_new3(2, rb_text, rb_attrs);
600
+ } else {
601
+ return rb_text;
602
+ }
603
+ }
604
+
605
+ static VALUE
606
+ rg_get_text_range(int argc, VALUE *argv, VALUE self)
607
+ {
608
+ VALUE start_row, start_col, end_row, end_col, get_attrs, proc, rb_text;
609
+ GArray *attrs = NULL;
610
+ char *text;
611
+
612
+ rb_scan_args(argc, argv, "41&", &start_row, &start_col,
613
+ &end_row, &end_col, &get_attrs, &proc);
614
+
615
+ if (get_attrs != Qfalse)
616
+ attrs = g_array_new(FALSE, TRUE, sizeof(VteCharAttributes));
617
+
618
+ text = vte_terminal_get_text_range(_SELF(self),
619
+ NUM2LONG(start_row),
620
+ NUM2LONG(start_col),
621
+ NUM2LONG(end_row),
622
+ NUM2LONG(end_col),
623
+ term_is_selected_cb,
624
+ (gpointer)proc,
625
+ attrs);
626
+ rb_text = CSTR2RVAL(text);
627
+ free(text);
628
+
629
+ if (attrs) {
630
+ VALUE rb_attrs;
631
+ rb_attrs = attrary2rval(attrs);
632
+ g_array_free(attrs, TRUE);
633
+ return rb_ary_new3(2, rb_text, rb_attrs);
634
+ } else {
635
+ return rb_text;
636
+ }
637
+ }
638
+
639
+ static VALUE
640
+ rg_cursor_position(VALUE self)
641
+ {
642
+ glong column, row;
643
+ vte_terminal_get_cursor_position(_SELF(self), &column, &row);
644
+ return rb_ary_new3(2, LONG2NUM(column), LONG2NUM(row));
645
+ }
646
+
647
+ static VALUE
648
+ rg_match_clear_all(VALUE self)
649
+ {
650
+ vte_terminal_match_clear_all(_SELF(self));
651
+ return self;
652
+ }
653
+
654
+ static VALUE
655
+ rg_match_add(VALUE self, VALUE match)
656
+ {
657
+ return INT2NUM(vte_terminal_match_add(_SELF(self), RVAL2CSTR(match)));
658
+ }
659
+
660
+ static VALUE
661
+ rg_match_set_cursor(VALUE self, VALUE tag, VALUE cursor)
662
+ {
663
+ if (NIL_P(cursor) || RVAL2GTYPE(cursor) == GDK_TYPE_CURSOR) {
664
+ vte_terminal_match_set_cursor(_SELF(self), NUM2INT(tag), RVAL2GDKCURSOR(cursor));
665
+ } else if (RVAL2GTYPE(cursor) == GDK_TYPE_CURSOR_TYPE) {
666
+ vte_terminal_match_set_cursor_type(_SELF(self), NUM2INT(tag), RVAL2GDKCURSORTYPE(cursor));
667
+ } else {
668
+ vte_terminal_match_set_cursor_name(_SELF(self), NUM2INT(tag), RVAL2CSTR(cursor));
669
+ }
670
+
671
+ return self;
672
+ }
673
+
674
+ static VALUE
675
+ rg_match_remove(VALUE self, VALUE tag)
676
+ {
677
+ vte_terminal_match_remove(_SELF(self), NUM2INT(tag));
678
+ return self;
679
+ }
680
+
681
+ static VALUE
682
+ rg_match_check(VALUE self, VALUE column, VALUE row)
683
+ {
684
+ char *string;
685
+ int tag;
686
+
687
+ string = vte_terminal_match_check(_SELF(self), NUM2LONG(column),
688
+ NUM2LONG(row), &tag);
689
+ if (string) {
690
+ VALUE rb_string;
691
+ rb_string = CSTR2RVAL(string);
692
+ free(string);
693
+ return rb_ary_new3(2, rb_string, INT2NUM(tag));
694
+ } else {
695
+ return Qnil;
696
+ }
697
+ }
698
+
699
+ static VALUE
700
+ rg_default_emulation(VALUE self)
701
+ {
702
+ return CSTR2RVAL(vte_terminal_get_default_emulation(_SELF(self)));
703
+ }
704
+
705
+ static VALUE
706
+ rg_status_line(VALUE self)
707
+ {
708
+ return CSTR2RVAL(vte_terminal_get_status_line(_SELF(self)));
709
+ }
710
+
711
+ static VALUE
712
+ rg_adjustment(VALUE self)
713
+ {
714
+ return GOBJ2RVAL(vte_terminal_get_adjustment(_SELF(self)));
715
+ }
716
+
717
+ static VALUE
718
+ rg_char_width(VALUE self)
719
+ {
720
+ return LONG2NUM(vte_terminal_get_char_width(_SELF(self)));
721
+ }
722
+
723
+ static VALUE
724
+ rg_char_height(VALUE self)
725
+ {
726
+ return LONG2NUM(vte_terminal_get_char_height(_SELF(self)));
727
+ }
728
+
729
+ static VALUE
730
+ rg_row_count(VALUE self)
731
+ {
732
+ return LONG2NUM(vte_terminal_get_row_count(_SELF(self)));
733
+ }
734
+
735
+ static VALUE
736
+ rg_column_count(VALUE self)
737
+ {
738
+ return LONG2NUM(vte_terminal_get_column_count(_SELF(self)));
739
+ }
740
+
741
+ static VALUE
742
+ rg_window_title(VALUE self)
743
+ {
744
+ return CSTR2RVAL(vte_terminal_get_window_title(_SELF(self)));
745
+ }
746
+
747
+ static VALUE
748
+ rg_icon_title(VALUE self)
749
+ {
750
+ return CSTR2RVAL(vte_terminal_get_icon_title(_SELF(self)));
751
+ }
752
+
753
+ static VALUE
754
+ rg_pty_new(VALUE self, VALUE flags)
755
+ {
756
+ VtePty *result;
757
+ GError *error = NULL;
758
+
759
+ result = vte_terminal_pty_new(_SELF(self), RVAL2VTEPTYFLAGS(flags), &error);
760
+ if (error)
761
+ RAISE_GERROR(error);
762
+
763
+ return GOBJ2RVAL(result);
764
+ }
765
+
766
+ static VALUE
767
+ rg_search_find_next(VALUE self)
768
+ {
769
+ gboolean result;
770
+
771
+ result = vte_terminal_search_find_next(_SELF(self));
772
+
773
+ return CBOOL2RVAL(result);
774
+ }
775
+
776
+ static VALUE
777
+ rg_search_find_previous(VALUE self)
778
+ {
779
+ gboolean result;
780
+
781
+ result = vte_terminal_search_find_previous(_SELF(self));
782
+
783
+ return CBOOL2RVAL(result);
784
+ }
785
+
786
+ static VALUE
787
+ rg_search_get_wrap_around_p(VALUE self)
788
+ {
789
+ gboolean result;
790
+
791
+ result = vte_terminal_search_get_wrap_around(_SELF(self));
792
+
793
+ return CBOOL2RVAL(result);
794
+ }
795
+
796
+ static VALUE
797
+ rg_search_set_wrap_around(VALUE self, VALUE wrap_around)
798
+ {
799
+ vte_terminal_search_set_wrap_around(_SELF(self), RVAL2CBOOL(wrap_around));
800
+
801
+ return self;
802
+ }
803
+
804
+ static VALUE
805
+ rg_select_all(VALUE self)
806
+ {
807
+ vte_terminal_select_all(_SELF(self));
808
+
809
+ return self;
810
+ }
811
+
812
+ static VALUE
813
+ rg_select_none(VALUE self)
814
+ {
815
+ vte_terminal_select_none(_SELF(self));
816
+
817
+ return self;
818
+ }
819
+
820
+ static VALUE
821
+ rg_set_opacity(VALUE self, VALUE opacity)
822
+ {
823
+ vte_terminal_set_opacity(_SELF(self), NUM2UINT(opacity));
824
+
825
+ return self;
826
+ }
827
+
828
+ static VALUE
829
+ rg_watch_child(VALUE self, VALUE child_pid)
830
+ {
831
+ vte_terminal_watch_child(_SELF(self), NUM2INT(child_pid));
832
+
833
+ return self;
834
+ }
835
+
836
+ static VALUE
837
+ rg_write_contents(int argc, VALUE *argv, VALUE self)
838
+ {
839
+ VALUE stream, flags, rb_cancellable;
840
+ GCancellable *cancellable;
841
+ gboolean result;
842
+ GError *error = NULL;
843
+
844
+ rb_scan_args(argc, argv, "21", &stream, &flags, &rb_cancellable);
845
+ cancellable = NIL_P(rb_cancellable) ? NULL : RVAL2GCANCELLABLE(rb_cancellable);
846
+
847
+ result = vte_terminal_write_contents(_SELF(self),
848
+ RVAL2GOUTPUTSTREAM(stream),
849
+ RVAL2VTETERMINALWRITEFLAGS(flags),
850
+ cancellable,
851
+ &error);
852
+ if (error)
853
+ RAISE_GERROR(error);
854
+
855
+ return CBOOL2RVAL(result);
856
+ }
857
+
858
+ void
859
+ Init_vte_terminal(VALUE mVte)
860
+ {
861
+ VALUE RG_TARGET_NAMESPACE;
862
+
863
+ id_new = rb_intern("new");
864
+ id_call = rb_intern("call");
865
+
866
+ RG_TARGET_NAMESPACE = G_DEF_CLASS(VTE_TYPE_TERMINAL, "Terminal", mVte);
867
+
868
+ G_DEF_CLASS(VTE_TYPE_TERMINAL_ERASE_BINDING, "EraseBinding", RG_TARGET_NAMESPACE);
869
+ G_DEF_CLASS(VTE_TYPE_TERMINAL_CURSOR_BLINK_MODE, "CursorBlinkMode", RG_TARGET_NAMESPACE);
870
+ G_DEF_CLASS(VTE_TYPE_TERMINAL_CURSOR_SHAPE, "CursorShape", RG_TARGET_NAMESPACE);
871
+ G_DEF_CLASS(VTE_TYPE_TERMINAL_WRITE_FLAGS, "WriteFlags", RG_TARGET_NAMESPACE);
872
+
873
+ RG_DEF_METHOD(initialize, 0);
874
+
875
+ RG_DEF_METHOD(fork_command, -1);
876
+
877
+ RG_DEF_METHOD(feed, 1);
878
+ RG_DEF_METHOD(feed_child, 1);
879
+ RG_DEF_METHOD(feed_child_binary, 1);
880
+
881
+ RG_DEF_METHOD(copy_clipboard, 0);
882
+ RG_DEF_METHOD(paste_clipboard, 0);
883
+ RG_DEF_METHOD(copy_primary, 0);
884
+ RG_DEF_METHOD(paste_primary, 0);
885
+
886
+ RG_DEF_METHOD(set_size, 2);
887
+
888
+ RG_DEF_METHOD(set_audible_bell, 1);
889
+ RG_DEF_METHOD_P(audible_bell, 0);
890
+ RG_DEF_METHOD(set_visible_bell, 1);
891
+ RG_DEF_METHOD_P(visible_bell, 0);
892
+
893
+ RG_DEF_METHOD(set_scroll_background, 1);
894
+ RG_DEF_METHOD(set_scroll_on_output, 1);
895
+ RG_DEF_METHOD(set_scroll_on_keystroke, 1);
896
+
897
+ RG_DEF_METHOD(set_color_dim, 1);
898
+ RG_DEF_METHOD(set_color_bold, 1);
899
+ RG_DEF_METHOD(set_color_foreground, 1);
900
+ RG_DEF_METHOD(set_color_background, 1);
901
+ RG_DEF_METHOD(set_color_cursor, 1);
902
+ RG_DEF_METHOD(set_color_highlight, 1);
903
+ RG_DEF_METHOD(set_colors, 3);
904
+ RG_DEF_METHOD(set_default_colors, 0);
905
+ RG_DEF_METHOD(set_background_image, 1);
906
+ RG_DEF_METHOD(set_background_tint_color, 1);
907
+ RG_DEF_METHOD(set_background_saturation, 1);
908
+ RG_DEF_METHOD(set_background_transparent, 1);
909
+ RG_DEF_METHOD(set_cursor_blinks, 1);
910
+ RG_DEF_METHOD(set_cursor_blink_mode, 1);
911
+ RG_DEF_METHOD(cursor_blink_mode, 0);
912
+ RG_DEF_METHOD(set_cursor_shape, 1);
913
+ RG_DEF_METHOD(cursor_shape, 0);
914
+ RG_DEF_METHOD(child_exit_status, 0);
915
+ RG_DEF_METHOD(set_scrollback_lines, 1);
916
+
917
+ RG_DEF_METHOD(im_append_menuitems, 1);
918
+
919
+ RG_DEF_METHOD(set_font, 1);
920
+ RG_DEF_METHOD(font, 0);
921
+ RG_DEF_METHOD(set_allow_bold, 1);
922
+ RG_DEF_METHOD_P(allow_bold, 0);
923
+ RG_DEF_METHOD_P(has_selection, 0);
924
+ RG_DEF_ALIAS("have_selection?", "has_selection?");
925
+ RG_DEF_METHOD(set_word_chars, 1);
926
+ RG_DEF_METHOD_P(word_char, 1);
927
+ RG_DEF_METHOD(set_backspace_binding, 1);
928
+ RG_DEF_METHOD(set_delete_binding, 1);
929
+ RG_DEF_METHOD_P(mouse_autohide, 0);
930
+ RG_DEF_METHOD(set_mouse_autohide, 1);
931
+
932
+ RG_DEF_METHOD(reset, 2);
933
+
934
+ RG_DEF_METHOD(get_text, -1);
935
+ RG_DEF_METHOD(get_text_range, -1);
936
+
937
+ RG_DEF_METHOD(cursor_position, 0);
938
+
939
+ RG_DEF_METHOD(match_clear_all, 0);
940
+ RG_DEF_METHOD(match_add, 1);
941
+ RG_DEF_METHOD(match_set_cursor, 2);
942
+ RG_DEF_METHOD(match_remove, 1);
943
+ RG_DEF_METHOD(match_check, 2);
944
+ RG_DEF_METHOD(default_emulation, 0);
945
+ RG_DEF_METHOD(status_line, 0);
946
+ RG_DEF_METHOD(adjustment, 0);
947
+ RG_DEF_METHOD(char_width, 0);
948
+ RG_DEF_METHOD(char_height, 0);
949
+ RG_DEF_METHOD(row_count, 0);
950
+ RG_DEF_METHOD(column_count, 0);
951
+ RG_DEF_METHOD(window_title, 0);
952
+ RG_DEF_METHOD(icon_title, 0);
953
+ RG_DEF_METHOD(pty_new, 1);
954
+ RG_DEF_METHOD(search_find_next, 0);
955
+ RG_DEF_METHOD(search_find_previous, 0);
956
+ RG_DEF_METHOD_P(search_get_wrap_around, 0);
957
+ RG_DEF_METHOD(search_set_wrap_around, 1);
958
+ RG_DEF_ALIAS("search_wrap_around=", "search_set_wrap_around");
959
+ RG_DEF_METHOD(select_all, 0);
960
+ RG_DEF_METHOD(select_none, 0);
961
+ RG_DEF_METHOD(set_opacity, 1);
962
+ RG_DEF_METHOD(watch_child, 1);
963
+ RG_DEF_METHOD(write_contents, -1);
964
+ }