Skip to content

Reline not offering completions on empty input #814

Open

Description

@ddoherty03

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.

Activity

  1. tompng commented on Apr 23, 2025

    @tompng
    Member

    This is an incompatibility with Readline. GNU Readline (gem readline-ext) shows candidates.

    require 'readline'
    p Readline => Readline::VERSION #=> {Readline=>"8.2"}
    Readline.completion_proc = proc { |target| %w[apple banana cherry] }
    Readline.readline('> ', true)
  2. added
    bugSomething isn't working
    and removed
    bugSomething isn't working
    on Apr 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions