GitHub

@@ -377,14 +377,9 @@ print_hint(void)

377377

#ifndef MRB_USE_READLINE

378378

/* Print the command line prompt of the REPL */

379379

static void

380-

print_cmdline(int code_block_open)

380+

print_cmdline(int code_block_open, int line_num)

381381

{

382-

if (code_block_open) {

383-

printf("* ");

384-

}

385-

else {

386-

printf("> ");

387-

}

382+

printf("%d%c ", line_num, code_block_open ? '*' : '>');

388383

fflush(stdout);

389384

}

390385

#endif

@@ -470,6 +465,7 @@ main(int argc, char **argv)

470465

int n;

471466

int i;

472467

mrb_bool code_block_open = FALSE;

468+

int line_num = 1;

473469

int ai;

474470

unsigned int stack_keep = 0;

475471

@@ -550,7 +546,7 @@ main(int argc, char **argv)

550546

}

551547552548

#ifndef MRB_USE_READLINE

553-

print_cmdline(code_block_open);

549+

print_cmdline(code_block_open, line_num);

554550555551

signal(SIGINT, ctrl_c_handler);

556552

char_index = 0;

@@ -567,6 +563,7 @@ main(int argc, char **argv)

567563

ruby_code[0] = '\0';

568564

last_code_line[0] = '\0';

569565

code_block_open = FALSE;

566+

line_num = 1;

570567

puts("^C");

571568

input_canceled = 0;

572569

continue;

@@ -586,10 +583,15 @@ main(int argc, char **argv)

586583

ruby_code[0] = '\0';

587584

last_code_line[0] = '\0';

588585

code_block_open = FALSE;

586+

line_num = 1;

589587

puts("^C");

590588

}

591589

signal(SIGINT, ctrl_c_handler);

592-

line = MIRB_READLINE(code_block_open ? "* " : "> ");

590+

{

591+

char prompt[32];

592+

snprintf(prompt, sizeof(prompt), "%d%c ", line_num, code_block_open ? '*' : '>');

593+

line = MIRB_READLINE(prompt);

594+

}

593595

signal(SIGINT, SIG_DFL);

594596595597

if (line == NULL) {

@@ -607,6 +609,7 @@ main(int argc, char **argv)

607609

}

608610

MIRB_LINE_FREE(line);

609611

#endif

612+

line_num++;

610613611614

done:

612615

if (code_block_open) {

@@ -654,6 +657,7 @@ main(int argc, char **argv)

654657

char* msg = mrb_locale_from_utf8(parser->error_buffer[0].message, -1);

655658

printf("line %d: %s\n", parser->error_buffer[0].lineno, msg);

656659

mrb_locale_free(msg);

660+

line_num = 1;

657661

}

658662

else {

659663

/* generate bytecode */

@@ -699,6 +703,7 @@ main(int argc, char **argv)

699703

}

700704

ruby_code[0] = '\0';

701705

last_code_line[0] = '\0';

706+

line_num = 1;

702707

mrb_gc_arena_restore(mrb, ai);

703708

}

704709

mrb_parser_free(parser);

Read the original on github.com ↗