Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected completion_append_character when tab-completing #754

Closed
sjanusz-r7 opened this issue Oct 4, 2024 · 0 comments · Fixed by #764
Closed

Unexpected completion_append_character when tab-completing #754

sjanusz-r7 opened this issue Oct 4, 2024 · 0 comments · Fixed by #764
Labels
bug Something isn't working

Comments

@sjanusz-r7
Copy link

Description

The completion_append_character seems to be appended when there are still more autocomplete values available

This is my current code:

require 'reline'
COMPLETION_VALUES = ['my_dir/http/linux/apache', 'my_dir/http/linux/ngnix', 'my_dir/windows/chrome', 'my_dir/linux/enum'].freeze

tab_complete_lambda = proc do |_str, _preposing = nil, _postposing = nil|
  COMPLETION_VALUES
end

begin
  prompt = 'Prompt > '
  use_history = false
  getting_input = true

  Reline.completion_append_character = ' '
  Reline.completion_proc = tab_complete_lambda

  while getting_input
    text = Reline.readmultiline(prompt, use_history) do |multiline_input|
      # Accept the input until 'end' is entered
      multiline_input.split.last == 'end'
    end

    getting_input = false
    puts 'You entered:'
    puts text
  end
  # If you want to exit, type Ctrl-C
rescue Interrupt
  puts '^C'
end

Current Behaviour

  1. Type in my_<TAB>
  2. I receive my_dir/<SPACE>

The space is unexpected as I can still auto-complete more things.

Expected behaviour

  1. Type in my_<TAB>
  2. I receive my_dir/ (No space)
  3. I can continue to tab the remaining completions my_dir/<tab> and receive my_dir/http/linux as a completion

The space is should not be appended - as there's still more values to be tab-completed, such as my_dir/http/linux etc

Potential fix

It looks like we might not want to append completion_append_character if there are still more items available in the completion_proc list:

if not just_show_list and target < completed
@buffer_of_lines[@line_index] = (preposing + completed + completion_append_character.to_s + postposing).split("\n")[@line_index] || String.new(encoding: @encoding)
line_to_pointer = (preposing + completed + completion_append_character.to_s).split("\n")[@line_index] || String.new(encoding: @encoding)
@byte_pointer = line_to_pointer.bytesize
end

Terminal Emulator

MacOS Terminal

Reline Version

0.5.10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging a pull request may close this issue.

2 participants