diff --git a/NEWS b/NEWS index bf4f7adf2..342aa1bbd 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,7 @@ DFHack future DFHack 0.40.13-r1 Internals: - unified spatter structs + - added ruby df.print_color(color, string) method for dfhack console Fixes: - no more -e after terminating diff --git a/plugins/ruby/ruby.cpp b/plugins/ruby/ruby.cpp index ea4becd6a..93d6501f0 100644 --- a/plugins/ruby/ruby.cpp +++ b/plugins/ruby/ruby.cpp @@ -543,6 +543,18 @@ static VALUE rb_dfprint_str(VALUE self, VALUE s) return Qnil; } +static VALUE rb_dfprint_color(VALUE self, VALUE c, VALUE s) +{ + if (r_console) { + color_value old_col = r_console->color(); + r_console->color(color_value(rb_num2ulong(c))); + r_console->print("%s", rb_string_value_ptr(&s)); + r_console->color(old_col); + } else + console_proxy->print("%s", rb_string_value_ptr(&s)); + return Qnil; +} + static VALUE rb_dfprint_err(VALUE self, VALUE s) { printerr("%s", rb_string_value_ptr(&s)); @@ -1072,6 +1084,7 @@ static void ruby_bind_dfhack(void) { rb_define_singleton_method(rb_cDFHack, "get_vtable_ptr", RUBY_METHOD_FUNC(rb_dfget_vtable_ptr), 1); rb_define_singleton_method(rb_cDFHack, "dfhack_run", RUBY_METHOD_FUNC(rb_dfhack_run), 1); rb_define_singleton_method(rb_cDFHack, "print_str", RUBY_METHOD_FUNC(rb_dfprint_str), 1); + rb_define_singleton_method(rb_cDFHack, "print_color", RUBY_METHOD_FUNC(rb_dfprint_color), 2); rb_define_singleton_method(rb_cDFHack, "print_err", RUBY_METHOD_FUNC(rb_dfprint_err), 1); rb_define_singleton_method(rb_cDFHack, "malloc", RUBY_METHOD_FUNC(rb_dfmalloc), 1); rb_define_singleton_method(rb_cDFHack, "free", RUBY_METHOD_FUNC(rb_dffree), 1);