Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tty2-reader

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tty2-reader

  • 0.9.0.3
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

TTY2::Reader

Gem Version Build status

A tty-reader fork with the objective of adding a customized word completion mechanism.

TTY2::Reader intends to be an up to date clone of TTY::Reader, solely extending it with a customized word completion mechanism. This page only covers the applied modifications.

Modifications

  • Renamed to TTY2::Reader
  • Extended KeyEvent with Line object
  • Added word completion

Installation

Add this line to your application's Gemfile:

gem "tty2-reader"

And then execute:

$ bundle

Or install it yourself as:

$ gem install tty2-reader

API

1.1 on

You can register to listen on a key pressed events. This can be done by calling on with a event name(s):

reader.on(:keypress) { |event| .... }

or listen for multiple events:

reader.on(:keyctrl_x, :keyescape) { |event| ... }

The KeyEvent object is yielded to a block whenever a particular key event fires. The event responds to:

  • key - key pressed
  • value - value of the key pressed
  • line - the Line object of the currently edited line, a new Line object with empty content otherwise

The value returns the actual key pressed and the line the content for the currently edited line or is empty.

The key is an object that responds to following messages:

  • name - the name of the event such as :up, :down, letter or digit
  • meta - true if event is non-standard key associated
  • shift - true if shift has been pressed with the key
  • ctrl - true if ctrl has been pressed with the key For example, to add listen to vim like navigation keys, one would do the following:
reader.on(:keypress) do |event|
  if event.value == "j"
    ...
  end
  if event.value == "k"
    ...
  end
end

You can subscribe to more than one event:

reader.on(:keypress) { |event| ... }
      .on(:keydown)  { |event| ... }

Configuration

2.1. :completion_handler

This option allows you to define possible completions. It accepts a proc with the word that is to be completed as a first, and a context in which the word is to be completed as a second argument. By default set to nil. To use this:

reader = TTY2::Reader.new(completion_handler: ->(word, context) { ... })

2.2. :completion_suffix

This option allows you to add a suffix to completed words. By default, no suffix is added. To add a suffix:

reader = TTY2::Reader.new(completion_suffix: " ")

2.3. :completion_cycling

This option controls cycling through completion suggestions. By default set to true, and can be disabled with:

reader = TTY2::Reader.new(completion_cycling: false)

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/zzyzwicz/tty2-reader.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the TTY2::Reader project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

Copyright for portions of project TTY2::Reader are held by Piotr Murach, 2017 as part of project TTY::Reader. All other copyright for project TTY2::Reader are held by zzyzwicz, 2021.

FAQs

Package last updated on 07 Feb 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc