Sha256: e1b0ba5ae5bf65605c0ff406d0b808344983b24736fbbeb3fc6f83f538cdb2d0
Contents?: true
Size: 1.61 KB
Versions: 17
Compression:
Stored size: 1.61 KB
Contents
module Vedeu module Input # Captures input from the user via {Vedeu::Terminal#input} and # translates special characters into symbols. # class Capture # Instantiate Vedeu::Input::Input and capture keypress(es). # # @param (see #initialize) # @return (see #read) def self.read(reader) new(reader).read end # Returns a new instance of Vedeu::Input::Input. # # @param reader [IO] An object that responds to `#read`. # Typically, this is Vedeu::Terminal. # @return [Vedeu::Input::Input] def initialize(reader) @reader = reader end # Triggers either a ':_command_' event with the command when the # reader is in cooked mode, or when in raw mode, the keypress # event with the key(s) pressed. # # @return [Array|String|Symbol] def read if reader.raw_mode? Vedeu.trigger(:_keypress_, keypress) elsif reader.fake_mode? Vedeu.trigger(:_editor_, keypress) else Vedeu.trigger(:_command_, command) end end protected # @!attribute [r] reader # @return [IO] attr_reader :reader private # Returns the translated (when possible) keypress(es). # # @return [String|Symbol] def keypress key = input Vedeu::Input::Translator.translate(key) end # Returns the input from the terminal. # # @return [String] def input @input ||= reader.read end alias_method :command, :input end # Input end # Input end # Vedeu
Version data entries
17 entries across 17 versions & 1 rubygems