Sha256: b5f124e15f3b40143d87de18d20a77f669951b6ffaf66fcd639d618b1b5af2b4

Contents?: true

Size: 1.2 KB

Versions: 2

Compression:

Stored size: 1.2 KB

Contents

require 'readline'
module Gm
  module Notepad
    # A configuration module for the Readline module
    module Readline

      # Check history for existing matches
      completion_function = proc do |string|
        ::Readline::HISTORY.grep(/^#{Regexp.escape(string)}/)
      end
      if ::Readline.respond_to?("basic_word_break_characters=")
        ::Readline.basic_word_break_characters= " \t\n`><=;|&{("
      end

      # With a sucessful completion add this to the end
      ::Readline.completion_append_character = " "

      # Without this, when I had in history the following: ["{name}"]
      # And would type `{\t` into the shell, I would get the following
      # result: "{{name}".
      ::Readline.completer_word_break_characters = ""

      # Hook-in the above completion function
      ::Readline.completion_proc = completion_function

      # In the interactive shell, where are we sending the prompts?
      # If this defaults to $stdout then if we are directing $stdout
      # to a file, we end up typing blind into the terminal
      ::Readline.output = $stderr

      def self.input_getter(**config)
        -> { ::Readline.readline("#{config.fetch(:shell_prompt, ">")}  ", true) }
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
gm-notepad-0.0.6 lib/gm/notepad/readline.rb
gm-notepad-0.0.5 lib/gm/notepad/readline.rb