GitHub

File tree

  • mrbgems/mruby-bin-mirb/tools/mirb

Original file line numberDiff line numberDiff line change

@@ -340,6 +340,7 @@ mirb_editor_init(mirb_editor *ed)

340340

ed->prompt_cont_fmt = NULL;

341341

ed->line_num_base = 1;

342342

ed->use_color = FALSE;

343+

mirb_highlight_init(&ed->highlight, FALSE);

343344

ed->initialized = TRUE;

344345
345346

return TRUE;

@@ -573,6 +574,7 @@ void

573574

mirb_editor_set_color(mirb_editor *ed, mrb_bool enable)

574575

{

575576

ed->use_color = enable;

577+

mirb_highlight_init(&ed->highlight, enable);

576578

}

577579
578580

/*

@@ -657,10 +659,13 @@ refresh_display(mirb_editor *ed)

657659

mirb_term_cursor_col(1);

658660

mirb_term_clear_below();

659661
662+

/* Reset highlight state for fresh scan */

663+

mirb_highlight_reset(&ed->highlight);

664+
660665

/* Redraw all lines */

661666

for (size_t i = 0; i < ed->buf.line_count; i++) {

662667

print_prompt(ed, i);

663-

printf("%s", mirb_buffer_line_at(&ed->buf, i));

668+

mirb_highlight_print_line(&ed->highlight, mirb_buffer_line_at(&ed->buf, i));

664669
665670

if (i < ed->buf.line_count - 1) {

666671

printf("\r\n");

Original file line numberDiff line numberDiff line change

@@ -11,6 +11,7 @@

1111

#include "mirb_term.h"

1212

#include "mirb_buffer.h"

1313

#include "mirb_history.h"

14+

#include "mirb_highlight.h"

1415
1516

/*

1617

* Editor result codes

@@ -72,6 +73,8 @@ typedef struct mirb_editor {

7273
7374

mrb_bool initialized; /* editor is initialized */

7475

mrb_bool use_color; /* use colored output */

76+
77+

mirb_highlighter highlight; /* syntax highlighting state */

7578

} mirb_editor;

7679
7780

/*

Read the original on github.com ↗