Class: VTerm
- Inherits:
-
Object
- Object
- VTerm
- Defined in:
- lib/vterm/version.rb,
ext/vterm/vterm.c
Defined Under Namespace
Classes: Screen
Constant Summary collapse
- VERSION =
'0.0.5'
Instance Method Summary collapse
- #initialize(rows, cols) ⇒ Object constructor
- #read(*args) ⇒ Object
- #screen ⇒ Object
- #set_utf8(is_utf8) ⇒ Object
- #size ⇒ Object
- #write(bytes) ⇒ Object
Constructor Details
#initialize(rows, cols) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'ext/vterm/vterm.c', line 103
static VALUE
rb_vterm_initialize(VALUE self, VALUE rows, VALUE cols)
{
vterm_data_t *vt_data;
vt_data = malloc(sizeof(vterm_data_t));
DATA_PTR(self) = vt_data;
vt_data->vt = vterm_new(NUM2INT(rows), NUM2INT(cols));
return Qnil;
}
|
Instance Method Details
#read(*args) ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'ext/vterm/vterm.c', line 172
static VALUE
rb_vterm_read(int argc, VALUE *argv, VALUE self)
{
vterm_data_t *vt_data;
size_t bufsize;
size_t specified_size;
vt_data = (vterm_data_t*)DATA_PTR(self);
bufsize = vterm_output_get_buffer_current(vt_data->vt);
if (argc == 1) {
specified_size = (size_t)NUM2INT(argv[0]);
if (specified_size < bufsize) {
bufsize = specified_size;
}
} else if (argc != 0) {
rb_raise(rb_eArgError, "buffer size must be unspecified or only one");
}
if (bufsize == 0) {
return rb_str_new_cstr("");
} else if (bufsize > 0) {
char outbuf[bufsize];
vterm_output_read(vt_data->vt, outbuf, bufsize);
return rb_str_new(outbuf, bufsize);
} else {
return Qnil;
}
}
|
#screen ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'ext/vterm/vterm.c', line 127
static VALUE
rb_vterm_screen(VALUE self)
{
vterm_data_t *vt_data;
vterm_screen_data_t *vt_screen_data;
VALUE vt_screen;
vt_data = (vterm_data_t*)DATA_PTR(self);
vt_screen = rb_vterm_screen_alloc(cVTermScreen);
vt_screen_data = malloc(sizeof(vterm_screen_data_t));
vt_screen_data->vtscreen = vterm_obtain_screen(vt_data->vt);
DATA_PTR(vt_screen) = vt_screen_data;
return vt_screen;
}
|
#set_utf8(is_utf8) ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'ext/vterm/vterm.c', line 144
static VALUE
rb_vterm_set_utf8(VALUE self, VALUE is_utf8)
{
vterm_data_t *vt_data;
vt_data = (vterm_data_t*)DATA_PTR(self);
if (rb_equal(is_utf8, Qfalse) || rb_equal(is_utf8, Qnil)) {
vterm_set_utf8(vt_data->vt, 0);
} else {
vterm_set_utf8(vt_data->vt, 1);
}
return Qnil;
}
|
#size ⇒ Object
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'ext/vterm/vterm.c', line 200
static VALUE
rb_vterm_get_size(VALUE self)
{
int rows, cols;
vterm_data_t *vt_data;
VALUE result;
vt_data = (vterm_data_t*)DATA_PTR(self);
vterm_get_size(vt_data->vt, &rows, &cols);
result = rb_ary_new();
rb_ary_push(result, INT2NUM(rows));
rb_ary_push(result, INT2NUM(cols));
return result;
}
|
#write(bytes) ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'ext/vterm/vterm.c', line 159
static VALUE
rb_vterm_write(VALUE self, VALUE bytes)
{
vterm_data_t *vt_data;
char *str;
vt_data = (vterm_data_t*)DATA_PTR(self);
str = StringValueCStr(bytes);
vterm_input_write(vt_data->vt, str, strlen(str));
return Qnil;
}
|