- restore mirb_completion.c/h from before readline removal
- add editor adapter for tab completion (mirb_setup_editor_completion,
mirb_get_completions, mirb_free_completions)
- add TAB key handling in mirb_editor.c
- fix string literal completion: properly detect when cursor is outside
a string by scanning forward, allow string/array/hash literals as
safe receivers for method completion
Co-authored-by: Claude <noreply@anthropic.com>
- fix Enter in middle of line with trailing blank continuation line:
now properly splits the line and removes redundant blank line
- fix auto-indentation when inserting in middle of existing code:
calculate indent from lines up to cursor, not entire buffer
- add mirb_buffer_delete_line() for removing lines from buffer
Co-authored-by: Claude <noreply@anthropic.com>
Previously, all continuation lines showed the same line number (e.g.,
"1*" for every line). Now each line shows its actual line number:
1> class Foo
2* def bar
3* end
4* end
Add mirb_editor_set_prompt_format() which accepts printf-style format
strings (e.g., "%d> ", "%d* ") and calculates the correct prompt length
for each line to ensure proper cursor positioning.
Co-authored-by: Claude <noreply@anthropic.com>
Add in-memory command history for mirb sessions:
- Up arrow on first line: navigate to older history entries
- Down arrow on last line: navigate to newer history entries
- Current input is preserved when browsing and restored when
navigating past the newest entry
- History uses a circular buffer (100 entries max)
- Duplicate consecutive entries are not added
Co-authored-by: Claude <noreply@anthropic.com>
Headers in mrbgems are now categorized into three types:
- src/*.h: gem internal only
- include/*.h: inter-gem use (visible to dependent gems)
- include/export/*.h: external API (exported via mruby-config --cflags)
This prevents internal headers like *_hal.h from being exposed to
external users while maintaining inter-gem header accessibility.
Co-authored-by: Claude <noreply@anthropic.com>
Remove readline/linenoise dependency and implement custom multi-line
editor with:
- Terminal raw mode handling (POSIX termios)
- Multi-line buffer with cursor navigation
- Auto-indentation for Ruby blocks
- Auto-dedentation when typing 'end' or '}'
- Natural terminal scrolling behavior
- Emacs-style keybindings (Ctrl+A/E/K/U/W/Y, Alt+B/F/D)
This eliminates GPL licensing concerns from readline while providing
better multi-line editing than the previous single-line implementation.
The MRUBY_MIRB_READLINE environment variable is no longer supported
as readline integration has been completely removed; ref #6626
Co-authored-by: Claude <noreply@anthropic.com>
Add ANSI color support to mirb for better visual distinction:
- green prompts (both ready '>' and continuation '*')
- red error messages (syntax errors, runtime errors, warnings)
- bold result indicator ('=>')
Colors are automatically disabled when:
- output is not a TTY
- TERM is unset or "dumb"
- NO_COLOR environment variable is set
Co-authored-by: Claude <noreply@anthropic.com>
- automatically indent continuation lines based on block depth
- detect block-opening keywords (def, class, if, do, etc.) and braces
- use ANSI escape sequences to fix indentation for:
- block-closing keywords (end, })
- mid-block keywords (else, elsif, rescue, ensure, when)
- only active for interactive TTY input with ANSI support
- requires GNU readline (not available with linenoise)
Co-authored-by: Claude <noreply@anthropic.com>
changed block spacing from {|param| to {|param| (space before brace)
for consistency with the most common pattern in the codebase.
Co-authored-by: Claude <noreply@anthropic.com>
added parentheses to to_enum call where the return value is used,
explicitly specifying :each for readability.
Co-authored-by: Claude <noreply@anthropic.com>
added parentheses to to_enum call where the return value is used,
explicitly specifying :each for readability.
Co-authored-by: Claude <noreply@anthropic.com>
added parentheses to all `to_enum` and `super` calls where the return
value is used (returned, assigned, or passed to another method). this
makes the code style consistent with the guideline that method calls
should use parentheses when their return values are consumed.
changes:
- return to_enum :symbol -> return to_enum(:symbol)
- return to_enum :symbol, arg -> return to_enum(:symbol, arg)
- super message, name -> super(message, name)
affected files: 10error.rb, array.rb, enum.rb, hash.rb, kernel.rb,
numeric.rb, range.rb
Co-authored-by: Claude <noreply@anthropic.com>
fixed a bug where tab completion on complex expressions like "d.new(1).a"
would corrupt local variables, causing them to become nil.
the root cause was that evaluating complex receiver expressions during tab
completion ran mrb_vm_run() without proper stack management (stack_keep)
and environment adjustment that mirb's main REPL loop performs. this
corrupted the local variable storage.
the fix restricts tab completion to only evaluate simple receiver
expressions (variable/constant names without operators or method calls).
complex expressions are skipped for completion. this means:
- works: d.<tab> completes methods of variable d
- works: String.<tab> completes methods of constant String
- skipped: d.new(1).<tab> provides no completion
this is a reasonable trade-off that prevents the corruption bug while
still supporting the most common completion scenarios.
also updated mirb_eval_receiver() to use the compiler context for proper
local variable resolution, with argument order matching mrb_parse_string.
Co-authored-by: Claude <noreply@anthropic.com>
implements context-aware tab completion for mirb supporting all readline
variants (GNU readline, libedit, linenoise) with graceful degradation
when no readline library is available.
completion features:
- method names on objects (e.g., "hello".re<Tab> completes to reverse, replace)
- local variables from compiler context
- global variables via Ruby introspection
- constants and class names
- Ruby keywords
architecture:
- core completion engine is library-agnostic
- thin adapters for readline/libedit and linenoise
- context detection based on cursor position analysis
- safe receiver evaluation with exception handling
- proper word break characters so "String.new" works correctly
implementation adds:
- mirb_completion.h: interface definitions and data structures
- mirb_completion.c: complete implementation (~670 lines)
- mirb.c: integration with setup/cleanup calls
Co-authored-by: Claude <noreply@anthropic.com>
addresses #6626 where users building portable binaries need explicit control
over readline detection instead of auto-detection.
MRUBY_MIRB_READLINE values:
auto (default) - auto-detect: try readline, then edit, then linenoise
readline, gnu - force GNU readline only
edit, libedit - force libedit only
linenoise - force linenoise only
none, off, false, disabled - use plain input mode (no readline)
close#6626
Co-authored-by: Claude <noreply@anthropic.com>
runtime errors now distinguish between:
- errors in current input: show relative line number
- errors from previously defined methods: show method context
examples:
1> a.foo
line 1: undefined method 'a' for Object (NoMethodError)
1> def foo
2* bar
3* end
1> foo
(mirb):in foo: undefined method 'bar' for Object (NoMethodError)
this provides better context since method name is more useful
than line number for errors in previously defined code
Co-authored-by: Claude <noreply@anthropic.com>