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

Reline not offering completions on empty input #814

Open
ddoherty03 opened this issue Feb 2, 2025 · 0 comments
Open

Reline not offering completions on empty input #814

ddoherty03 opened this issue Feb 2, 2025 · 0 comments

Comments

@ddoherty03
Copy link

At the prompt, if a user just types TAB, I want to display all completions available. It appears that reline only displays completions if there is something typed at the prompt.

Here is an example that illustrates the issue from ChatGPT:

#!/usr/bin/env ruby

require 'reline'

# Force Emacs mode so that Tab completion is the standard behavior
# (In some Reline versions these are just methods, not setters)
Reline.emacs_editing_mode

# A debug completion function that prints when it's called:
def debug_completion(input)
  warn "[DEBUG] completion_proc called with '#{input.inspect}'"
  if input.empty?
    %w[apple banana cherry]
  else
    %w[apple banana cherry].grep(/^#{Regexp.escape(input)}/)
  end
end

Reline.completion_proc = method(:debug_completion)

loop do
  line = Reline.readline("> ", true)
  break if line.nil? || line.strip.downcase == "exit"
  puts "You typed: #{line}"
end

Hitting TAB and nothing else at the prompt should offer 'apple', 'banana', and 'cherry', but it offers nothing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant