Sha256: 81f7de5812f16f280ed44189577b1479096d4876a1c0e8276c3a43b7a54086b6

Contents?: true

Size: 580 Bytes

Versions: 1

Compression:

Stored size: 580 Bytes

Contents

#include "ruby.h"
#include <readline/readline.h>

static VALUE readline_buffer_ext(VALUE self, VALUE str){
  rb_secure(4);
  StringValue(str);

  if(rl_line_buffer == NULL)
    return Qnil;

#ifdef HAVE_RL_DELETE_TEXT
  rl_delete_text(0, rl_end);
#else
  rl_line_buffer[rl_end = 0] = '\0';
#endif
  rl_insert_text(RSTRING_PTR(str));
  rl_redisplay();

  return rb_str_new(rl_line_buffer, strlen(rl_line_buffer));
}

void Init_readline_buffer_ext() {
  rb_define_singleton_method(rb_const_get(rb_cObject, rb_intern("Readline")),
    "line_buffer=",
    readline_buffer_ext, 1);
}

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
readline_buffer-0.9.2 ext/readline_buffer_ext/readline_buffer_ext.c