Commit graph

438 commits

Author SHA1 Message Date
tomoya ishida
3568e7aef7 [ruby/reline] Fix line wrapped cursor position
(https://github.com/ruby/reline/pull/791)

Cursor position calculation was wrong when the input line contains "\1" or CSI escape sequence.

a1943daaf4
2024-12-10 10:28:22 +00:00
tomoya ishida
5f65321915 [ruby/reline] Combine MAPPINGS(single byte input to symbol) with
key_bindings(escape sequence to symbol)
(https://github.com/ruby/reline/pull/715)

6a7e249374
2024-12-06 07:09:24 +00:00
tomoya ishida
36aeb12aa9 [ruby/reline] Implement buffered output to Reline::ANSI
(https://github.com/ruby/reline/pull/790)

Minimize the call of STDOUT.write
This will improve rendering performance especially when there is a busy thread `Thread.new{loop{}}`

a6fe45f5ba
2024-12-02 16:44:49 +00:00
tomoya ishida
7e02410bf8 [ruby/reline] Don't skip start_with check on encoding-incompatible
candidates
(https://github.com/ruby/reline/pull/787)

8588be652f
2024-11-29 19:07:35 +00:00
Mari Imaizumi
c06dcba964 [ruby/reline] Fix RELINE_TEST_ENCODING
(https://github.com/ruby/reline/pull/743)

* Fix RELINE_TEST_ENCODING

It was not working because it was not environment variable.

* Fix Encoding::CompatibilityError: Shift_JIS is not compatible with UTF-8

Error: test_completion_append_character(Reline::KeyActor::EmacsTest): Encoding::CompatibilityError: Shift_JIS is not compatible with UTF-8
/home/runner/work/reline/reline/lib/reline/line_editor.rb:814:in 'block in Reline::LineEditor#filter_normalize_candidates'
/home/runner/work/reline/reline/lib/reline/line_editor.rb:808:in 'Array#select'
/home/runner/work/reline/reline/lib/reline/line_editor.rb:808:in 'Reline::LineEditor#filter_normalize_candidates'
/home/runner/work/reline/reline/lib/reline/line_editor.rb:831:in 'Reline::LineEditor#perform_completion'
/home/runner/work/reline/reline/lib/reline/line_editor.rb:1434:in 'Reline::LineEditor#complete'
/home/runner/work/reline/reline/lib/reline/line_editor.rb:961:in 'Method#call'
/home/runner/work/reline/reline/lib/reline/line_editor.rb:961:in 'Reline::LineEditor#wrap_method_call'
/home/runner/work/reline/reline/lib/reline/line_editor.rb:1029:in 'block in Reline::LineEditor#process_key'
/home/runner/work/reline/reline/lib/reline/line_editor.rb:932:in 'Reline::LineEditor#run_for_operators'
/home/runner/work/reline/reline/lib/reline/line_editor.rb:1028:in 'Reline::LineEditor#process_key'
/home/runner/work/reline/reline/lib/reline/line_editor.rb:1051:in 'Reline::LineEditor#normal_char'
/home/runner/work/reline/reline/lib/reline/line_editor.rb:1089:in 'Reline::LineEditor#input_key'
/home/runner/work/reline/reline/test/reline/helper.rb:124:in 'block in Reline::TestCase#input_keys'
/home/runner/work/reline/reline/test/reline/helper.rb:117:in 'Array#each'
/home/runner/work/reline/reline/test/reline/helper.rb:117:in 'Reline::TestCase#input_keys'
/home/runner/work/reline/reline/test/reline/test_key_actor_emacs.rb:948:in 'Reline::KeyActor::EmacsTest#test_completion_append_character'
===============================================================================
===============================================================================
Error: test_continuous_completion_disabled_with_perfect_match(Reline::KeyActor::EmacsTest): Encoding::CompatibilityError: Shift_JIS is not compatible with UTF-8
/home/runner/work/reline/reline/lib/reline/line_editor.rb:814:in 'block in Reline::LineEditor#filter_normalize_candidates'
/home/runner/work/reline/reline/lib/reline/line_editor.rb:808:in 'Array#select'
/home/runner/work/reline/reline/lib/reline/line_editor.rb:808:in 'Reline::LineEditor#filter_normalize_candidates'
/home/runner/work/reline/reline/lib/reline/line_editor.rb:831:in 'Reline::LineEditor#perform_completion'
/home/runner/work/reline/reline/lib/reline/line_editor.rb:1434:in 'Reline::LineEditor#complete'
/home/runner/work/reline/reline/lib/reline/line_editor.rb:961:in 'Method#call'
/home/runner/work/reline/reline/lib/reline/line_editor.rb:961:in 'Reline::LineEditor#wrap_method_call'
/home/runner/work/reline/reline/lib/reline/line_editor.rb:1029:in 'block in Reline::LineEditor#process_key'
/home/runner/work/reline/reline/lib/reline/line_editor.rb:932:in 'Reline::LineEditor#run_for_operators'
/home/runner/work/reline/reline/lib/reline/line_editor.rb:1028:in 'Reline::LineEditor#process_key'
/home/runner/work/reline/reline/lib/reline/line_editor.rb:1051:in 'Reline::LineEditor#normal_char'
/home/runner/work/reline/reline/lib/reline/line_editor.rb:1089:in 'Reline::LineEditor#input_key'
/home/runner/work/reline/reline/test/reline/helper.rb:124:in 'block in Reline::TestCase#input_keys'
/home/runner/work/reline/reline/test/reline/helper.rb:117:in 'Array#each'
/home/runner/work/reline/reline/test/reline/helper.rb:117:in 'Reline::TestCase#input_keys'
/home/runner/work/reline/reline/test/reline/test_key_actor_emacs.rb:936:in 'Reline::KeyActor::EmacsTest#test_continuous_completion_disabled_with_perfect_match'
===============================================================================
===============================================================================
Error: test_continuous_completion_with_perfect_match(Reline::KeyActor::EmacsTest): Encoding::CompatibilityError: Shift_JIS is not compatible with UTF-8
/home/runner/work/reline/reline/lib/reline/line_editor.rb:814:in 'block in Reline::LineEditor#filter_normalize_candidates'
/home/runner/work/reline/reline/lib/reline/line_editor.rb:808:in 'Array#select'
/home/runner/work/reline/reline/lib/reline/line_editor.rb:808:in 'Reline::LineEditor#filter_normalize_candidates'
/home/runner/work/reline/reline/lib/reline/line_editor.rb:831:in 'Reline::LineEditor#perform_completion'
/home/runner/work/reline/reline/lib/reline/line_editor.rb:1434:in 'Reline::LineEditor#complete'
/home/runner/work/reline/reline/lib/reline/line_editor.rb:961:in 'Method#call'
/home/runner/work/reline/reline/lib/reline/line_editor.rb:961:in 'Reline::LineEditor#wrap_method_call'
/home/runner/work/reline/reline/lib/reline/line_editor.rb:1029:in 'block in Reline::LineEditor#process_key'
/home/runner/work/reline/reline/lib/reline/line_editor.rb:932:in 'Reline::LineEditor#run_for_operators'
/home/runner/work/reline/reline/lib/reline/line_editor.rb:1028:in 'Reline::LineEditor#process_key'
/home/runner/work/reline/reline/lib/reline/line_editor.rb:1051:in 'Reline::LineEditor#normal_char'
/home/runner/work/reline/reline/lib/reline/line_editor.rb:1089:in 'Reline::LineEditor#input_key'
/home/runner/work/reline/reline/test/reline/helper.rb:124:in 'block in Reline::TestCase#input_keys'
/home/runner/work/reline/reline/test/reline/helper.rb:117:in 'Array#each'
/home/runner/work/reline/reline/test/reline/helper.rb:117:in 'Reline::TestCase#input_keys'
/home/runner/work/reline/reline/test/reline/test_key_actor_emacs.rb:924:in 'Reline::KeyActor::EmacsTest#test_continuous_completion_with_perfect_match'
===============================================================================
Finished in 2.118582151 seconds.
385 tests, 1762 assertions, 0 failures, 3 errors, 0 pendings, 3 omissions, 0 notifications

4df825c48f
2024-11-29 18:15:46 +00:00
tomoya ishida
c1dcd1d496 [ruby/reline] KeyStroke handles multibyte character
(https://github.com/ruby/reline/pull/713)

5a8da85f2b
2024-11-26 17:58:43 +00:00
tomoya ishida
0f41cc442e [ruby/reline] Fix tab completion appending quote
(https://github.com/ruby/reline/pull/782)

cbf213291c
2024-11-25 17:38:50 +00:00
tomoya ishida
bf47b1b523 [ruby/reline] Fix completion quote, preposing and target calculation
bug
(https://github.com/ruby/reline/pull/763)

d3ba7216eb
2024-11-24 15:45:18 +00:00
tomoya ishida
25d17868de [ruby/reline] Refactor perform_completon
(https://github.com/ruby/reline/pull/778)

Flatten recursive method
Remove CompletionState::COMPLETE

aa5b278f3d
2024-11-11 15:31:04 +00:00
tomoya ishida
5eaa4c76c6 [ruby/reline] Remove unused things from reline/unicode.rb
(https://github.com/ruby/reline/pull/759)

* Remove garbage(nil) from Reline::Unicode.split_by_width result

* Remove unused width from Reline::Unicode vi_ ed_ em_ method return value

* Remove unused height from Unicode.split_by_width return value

* Rename split_by_width to split_line_by_width and add legacy split_by_width for IRB

f32446ebc4
2024-11-10 19:11:58 +00:00
YO4
b99c17a95b [ruby/reline] Windows fix (https://github.com/ruby/reline/pull/775)
* test_yamatanooroti: close tempfile before unlink

* test_yamatanooroti: omit because of windows does not support job control

* test_yamatanooroti: change startup message detection for windows

* windows.rb: can call win32api using nil as NULL for pointer argument

Exception occurred when interrupted with Ctrl+C on legacy conhost

* windows.rb: fix get_screen_size

return [window height, buffer width] insted of [buffer height, buffer width]

* windows.rb: import scroll_down() from ansi.rb

* windows.rb: add auto linewrap control if VT output not supported (legacy console)

* unfreeze WIN32API pointer arguments

They internally duplicate arguments so api functions write to another place.
This breaks the console mode detection with ruby-head.

* remove useless code from Win32API#call

argument repacking and return value tweaking is not needed for Reline::Windows requirements.

* Correctly handle top of console viewport

* Revert "remove useless code from Win32API#call"

This reverts commit 060ba140ed.

* Revert "windows.rb: can call win32api using nil as NULL for pointer argument"

This reverts commit 93a23bc5d0.

47c1ffbabe
2024-11-08 03:28:57 +00:00
tomoya ishida
979e447d7e [ruby/reline] nonprinting_start and nonprinting_end should be
removed
(https://github.com/ruby/reline/pull/771)

e36441652a
2024-10-24 16:36:39 +00:00
Wu
78378cae66 append completion_append_character only when continous completion is … (#764)
* append completion_append_character only when continous completion is not possible

* refactoring

* remove debug puts
2024-10-24 14:12:41 +00:00
Wu
e288604eb3 [ruby/reline] Use IO's encoding instead of Encoding.default_external
(https://github.com/ruby/reline/pull/765)

* use IO's encoding

* refactoring

* remove unused encoding params

* (for retriggering CI) remove unused encoding params

f09772adab
2024-10-22 14:43:18 +00:00
tomoya ishida
98fce00cab [ruby/reline] Support continuous tab completion
(https://github.com/ruby/reline/pull/761)

Continuous tab completion is possible in GNU Readline.
If dig_perfect_match_proc is set, continuous tab completion will be disabled.

469a52846b
2024-10-13 04:55:41 +00:00
John Bampton
afacb8ada5
[DOC] Fix spelling 2024-10-12 12:48:10 +00:00
tomoya ishida
09761e4789 [ruby/reline] Fix incremental search cancel bug
(https://github.com/ruby/reline/pull/748)

bf0f8fa333
2024-10-02 17:47:02 +00:00
tomoya ishida
e320da6097 [ruby/reline] Fix Reline crash with invalid encoding history
(https://github.com/ruby/reline/pull/751)

e9d4b37e34
2024-10-01 17:01:38 +00:00
tomoya ishida
9a766777d4 [ruby/reline] Split render_differential to LineEditor's rendering
logic and actual differential rendering part
(https://github.com/ruby/reline/pull/731)

c90f08f7e3
2024-09-04 11:58:03 +00:00
tomoya ishida
ad9d2c6435 [ruby/reline] Fix redisplay/insert_text called from pre_input_hook
(https://github.com/ruby/reline/pull/742)

* Fix redisplay/insert_text called from pre_input_hook

* Rename insert_pasted_text to insert_multiline_text

It is now used from Reline.insert_text which is not inserting pasted text

694a540939
2024-09-03 15:19:44 +00:00
Mari Imaizumi
a2b3cb65ea [ruby/reline] Implement re-read-init-file
(https://github.com/ruby/reline/pull/740)

59e4ade807
2024-08-31 03:26:50 +00:00
tomoya ishida
17a4c7cfcf [ruby/reline] Fix rendering bug of nomultiline prompt
(https://github.com/ruby/reline/pull/730)

Fix bug of `print('a'*10); Reline.readline('>')` wrong rendering

c0469a12b9
2024-07-12 12:21:26 +00:00
tomoya ishida
c2e2c5975d [ruby/reline] Fix vi_yank or vi_delete_meta copies nil bug
(https://github.com/ruby/reline/pull/726)

46b30b07c9
2024-06-18 14:57:19 +00:00
tomoya ishida
f465045dd6 [ruby/reline] Remove instance variable @first_char
(https://github.com/ruby/reline/pull/717)

When Reline reads EOF, Reline.readline should return nil if and only if input is empty

cc74b3686a
2024-06-06 11:20:29 +00:00
tomoya ishida
f567633a16 [ruby/reline] Refactor input key reading
(https://github.com/ruby/reline/pull/712)

* Add key binding matching status :matching_matched

* Simplify read_2nd_character

* Add a comment of matching status and EOF

* Matching status to a constant

* Expand complicated ternary operators to case-when

64deec100b
2024-06-05 04:04:09 +00:00
Hiroaki Osawa
5d33ff36dc [ruby/reline] In ed_search_[prev|next]_history, make the cursor come
to the end of the line when there is no search substr
(https://github.com/ruby/reline/pull/714)

* In ed_search_prev_history, make the cursor come to the end of the line when there is no search substr

* In ed_search_next_history, make the cursor come to the end of the line when there is no search substr

* Implemented ActionState to search with empty substr if the previous operation was search with empty string.

* Use a simple 2-element array to represent action_state

95ee80bd70
2024-06-03 14:05:51 +00:00
tomoya ishida
91d4a7ae0c [ruby/reline] Improve key binding match/matching check
(https://github.com/ruby/reline/pull/709)

* Improve key binding match/matching check

* Rename key_actors to default_key_bindings

* Make key_stroke.expand always return a value

* Update add_default_key_binding to use a add_default_key_binding_by_keymap internally

Co-authored-by: Stan Lo <stan001212@gmail.com>

---------

353ec236e2

Co-authored-by: Stan Lo <stan001212@gmail.com>
2024-06-03 13:15:05 +00:00
Stan Lo
cda69b5910 [ruby/reline] Overhaul io gate structure
(https://github.com/ruby/reline/pull/666)

* Overhaul IO gate structure

1. Move IO related classes to `lib/reline/io/` directory.
2. Rename `GeneralIO` to `Dumb`.
3. Use IO classes as instances instead of classes.

* Update lib/reline/io/ansi.rb

Co-authored-by: tomoya ishida <tomoyapenguin@gmail.com>

---------

dc1518e1ac

Co-authored-by: tomoya ishida <tomoyapenguin@gmail.com>
2024-06-01 10:28:08 +00:00
verdy89
7c6e4bc7ca [ruby/reline] Implement the redo command
(https://github.com/ruby/reline/pull/707)

* Implement the redo command

* Commented out a test that does not pass

* Changed key assignment for redo from "\C-[" to "\C-g"

* Changed redo key assignment from `\C-g` to `\M-\C-_`

* Revert the first implemantation

* Implemented redo by sharing `@past_lines` between undo and redo

* Fixed the index of past_lines that is updated when the cursor is moved

* Fixed deletion of the redo history in regular input

* Renamed variables: past_lines -> input_lines

* Rename @position to @input_lines_position

* Deleted unused variables: `@old_byte_pointer` and `@old_line_index`

0b2d9fab5f
2024-05-27 16:38:22 +00:00
Mari Imaizumi
9d01f657b3 [ruby/reline] Implement the undo command
(https://github.com/ruby/reline/pull/701)

* Refactor send

* Implement the undo command

* Fix @past_lines initialization

* Improve assertion

* Hide to save buffer in insert_pasted_text

* Replace @using_delete_command with @undoing

* Refactor `@past_lines`

4ab72f9cbd
2024-05-14 01:58:31 +00:00
tomoya ishida
68b6fe7048 [ruby/reline] Avoid STDIN.winsize called in require "reline"
(https://github.com/ruby/reline/pull/703)

21891c47c4
2024-05-10 17:19:42 +00:00
tomoya ishida
26446cccc9 [ruby/reline] Implement bracketed paste insert
(https://github.com/ruby/reline/pull/655)

e92dcbf514
2024-05-08 16:00:30 +00:00
tomoya ishida
d679afe9f9 [ruby/reline] Add name defined in readline to completion key
bindings C-i C-p C-n
(https://github.com/ruby/reline/pull/698)

1314787bbb
2024-05-05 07:09:52 +00:00
tomoya ishida
eb82ea6218 [ruby/reline] Fix prompt width calculation bug. Test with colored
prompt
(https://github.com/ruby/reline/pull/695)

24aab01cbc
2024-05-02 06:06:31 +00:00
tomoya ishida
814d4b5e2c [ruby/reline] Input with eof and no newline bugfix
(https://github.com/ruby/reline/pull/671)

0d66c335a1
2024-04-29 13:23:03 +00:00
tomoya ishida
ae701031f5 [ruby/reline] Completely support full-width characters in
differential rendering
(https://github.com/ruby/reline/pull/654)

* Add a cut variation of Reline::Unicode.take_range method take_mbchar_range

* Consider fullwidth take_range in differential rendering

29714df09f
2024-04-29 12:08:59 +00:00
tomoya ishida
cf24a0483e [ruby/reline] Long line performance
(https://github.com/ruby/reline/pull/688)

* Improve C-e (ed_move_to_end) performance for long line

* Reline::Unicode.split_by_width optimization for RESET_SGR

0c8d3c827a
2024-04-24 17:33:40 +00:00
tomoya ishida
53a67efc9a [ruby/reline] Separate prompt and input line in rendering
(https://github.com/ruby/reline/pull/652)

* Separate prompt and input line in rendering

Often, only one of prompt and input changes.
Split prompt+input_line to a separate rendering item will improve differential rendering performance.

* Rename method wrapped_prompt_lines to more descriptive name

16d82f1f23
2024-04-23 14:45:22 +00:00
Mari Imaizumi
604c29e8a2 [ruby/reline] Implement show-all-if-ambiguous feature
(https://github.com/ruby/reline/pull/683)

0fe4fdc794
2024-04-19 12:08:22 +00:00
Kenichi Kamiya
a3b7a7bc21
[ruby/reline] Remove unused variable
(https://github.com/ruby/reline/pull/684)

ce30c23730
2024-04-18 11:07:09 +09:00
tomoya ishida
15b659ca93 [ruby/reline] Refactor nomultiline and multiline mode difference
(https://github.com/ruby/reline/pull/653)

* Support multiline input in Reline.readline internally, reduce multiline-singleline branch

* Add readline(singleline) prompt test with force inserting multiline text

97846095d7
2024-04-17 16:12:20 +00:00
tomoya ishida
79df0f135e [ruby/reline] Refactor history move and history search
(https://github.com/ruby/reline/pull/651)

90e43e01d4
2024-04-16 14:06:22 +00:00
Mari Imaizumi
639449fe8d [ruby/reline] Implement changing editing mode
(https://github.com/ruby/reline/pull/681)

501b9a6c5f
2024-04-16 11:58:49 +00:00
Mari Imaizumi
0a4e3f23e6 [ruby/reline] Remove not implemented method
(https://github.com/ruby/reline/pull/680)

84762fc588
2024-04-15 13:31:38 +00:00
tomoya ishida
43f4da3ebf [ruby/reline] Fix vi_to_column which was broken
(https://github.com/ruby/reline/pull/679)

9e93ad52e7
2024-04-15 13:15:58 +00:00
Mari Imaizumi
339128b190 [ruby/reline] Refactored Default Key Bindings
(https://github.com/ruby/reline/pull/678)

* Reduce duplicate method

* Configured default key mapping with Readline when the method exists

* Remove undefined methods

155f7047bb
2024-04-14 17:33:51 +00:00
tomoya ishida
1648c4436e [ruby/reline] Refactor waiting_proc and waiting_operator_proc
(https://github.com/ruby/reline/pull/649)

* Fix waiting_proc precedence

* Fix waiting_operator bugs

* Add waiting_proc and vi_waiting_operator test

* Fix vi waiting operator arg number

vi_arg and vi_waiting_operator_arg should be multiplied

* Implement `yy` copies whole line in vi_command mode

* Simplify incremental search cancel test

* Add complex vi test with waiting_proc and vi_waiting_operator, split test input

777dffae1c
2024-04-14 14:28:15 +00:00
Michael J. Giarlo
76b10f2ee1 [ruby/reline] Support menu-complete-backward command for upward
navigation
(https://github.com/ruby/reline/pull/677)

Fixes https://github.com/ruby/reline/pull/675

This commit extracts the upward navigation condition in `LineEditor#input_key` to a new private method, and adds a new alias. This change allows Reline to support upward navigation in when a user has configured `inputrc` to map Shift-Tab to `menu-complete-backward`, a common setting in Bash (>= 4.x).

Instead of special-casing upward navigation in `LineEditor#input_key`, we now allow it to be processed by the branch that calls `process_key`. The extracted method no longer includes the editing mode check since this check is already made by `#wrap_method_call` by the time `#completion_journey_up` (or `#menu_complete_backward`) is called. Since upward navigation is happening in a method other than `#input_key` now, the `completion_occurs` variable that used to be local to `#input_key` is changed to an instance variable so that the new method can change its value. (I see many examples of mutating such instance variables in `LineEditor`, so I assumed this would be an uncontroversial change consistent with the coding practices already in place.)

Test coverage of this change has been added to the emacs and vi `KeyActor` tests.

Many thanks to @ima1zumi for their very helpful comments on #675 which encouraged me to contribute this work!

2ccdb374a4
2024-04-14 09:13:20 +00:00
tomoya ishida
8088c88d01
[ruby/reline] Handle INT signal correctly, remove handle_cleared
because clear(C-l) is not a signal
(https://github.com/ruby/reline/pull/646)

3debb0ae2f
2024-04-04 17:18:47 +09:00
tomoya ishida
80e31663f3
[ruby/reline] Fix audoindent including "\v", escape "\v" for
rendering
(https://github.com/ruby/reline/pull/648)

9c51c577ca
2024-04-04 17:18:47 +09:00