Before inserting a newline, re-indent the current line to match
the expected indent level. This fixes cases where the user typed
with incorrect indentation.
Co-authored-by: Claude <noreply@anthropic.com>
When TAB triggers auto-indentation, preserve the cursor's relative
position within the line instead of moving it to the indent boundary.
Co-authored-by: Claude <noreply@anthropic.com>
Instead of just removing 2 spaces, perform_dedent() now calculates
the expected indent level from previous lines and aligns to that.
Co-authored-by: Claude <noreply@anthropic.com>
Extend auto-dedent to trigger when typing dedent keywords, not just
end and }. Now dedent occurs when completing: else, elsif, when,
rescue, ensure.
Co-authored-by: Claude <noreply@anthropic.com>
When splitting a line with Enter, check if the new line starts with
a dedenting keyword (end, else, elsif, when, rescue, ensure, }) and
reduce indentation by one level.
Co-authored-by: Claude <noreply@anthropic.com>
TAB now performs auto-indentation instead of completion when:
- cursor is at start of line
- cursor is at end of line
- character before cursor is whitespace
Auto-indent calculates expected indent level from previous lines
and adjusts current line. Dedenting keywords (end, else, elsif,
when, rescue, ensure, }) reduce indent by one level.
Co-authored-by: Claude <noreply@anthropic.com>
when pressing Ctrl+K on an empty line, delete the entire line instead
of doing nothing. this makes it easier to clean up empty lines while
editing multi-line input.
Co-authored-by: Claude <noreply@anthropic.com>
pressing Enter in the middle of multi-line input now always inserts
a new line instead of evaluating, even if the code is syntactically
complete. evaluation only occurs when cursor is at the end of the
last line.
Co-authored-by: Claude <noreply@anthropic.com>
- 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>