Giter Club home page Giter Club logo

remedy's Introduction

Remedy

Remedy is a console interaction framework along the lines of Curses written in pure Ruby with an Object-Oriented approach and well-seperated concerns making it easy to use what you need and ignore the rest.

TravisCI Code Climate

If you have any suggestions or find any bugs, drop them in GitHub/issues so I can keep track of them. Thanks!

Installation

Add this line to your application's Gemfile:

  gem 'remedy'

If you're only going to use part of Remedy, you can tell Bundler to not automatically require the whole thing:

  gem 'remedy', require: false

And then execute:

$ bundle

Or install it yourself as:

$ gem install remedy

Usage

Remedy makes a few different classes and modules available to allow straight forward half-duplex communication with users via the console.

There are objects for input as well as output, including low level console keystroke reads and screen drawing.

Interaction

The Interaction object wraps raw keyboard reads and streamlines some aspects of accepting keyboard input.

  include Remedy
  user_input = Interaction.new

  user_input.loop do |key|
    puts key
  end

Viewport

Viewport is the object that draws on your screen, you can give it any compatible Remedy::Partial object, or something that responds like one.

  include Remedy
  joke = Content.new
  joke << "Q: What's the difference between a duck?"
  joke << "A: Purple, because ice cream has no bones!"

  screen = Viewport.new
  screen.draw joke

Remedy::Partial has the subclasses Header, Footer, and Content.

You can use the above classes to divide your Views into 3 seperate pieces. Content will be truncated as needed to accomodate the header and footer and the dimensions of the console. You can also specify the cursor/scroll position of the content being drawn, and when specifying headers or footers, you must.

  include Remedy
  title = Header.new
  title << "Someone Said These Were Good"

  jokes = Content.new
  jokes << %q{1. A woman gets on a bus with her baby. The bus driver says: 'Ugh, that's the ugliest baby I've ever seen!' The woman walks to the rear of the bus and sits down, fuming. She says to a man next to her: 'The driver just insulted me!' The man says: 'You go up there and tell him off. Go on, I'll hold your monkey for you.'}
  jokes << %q{2. I went to the zoo the other day, there was only one dog in it, it was a shitzu.}

  disclaimer = Footer.new
  disclaimer << "According to a survey they were funny. I didn't make them."

  screen = Viewport.new
  screen.draw jokes, Size.new(0,0), title, disclaimer

Console

If you want easy access to some lower level console commands, you can use Console.

The most interesting function in my opinion is the callback that gets triggered when the user resizes the console window.

  include Remedy

  screen = Viewport.new
  notice = Content.new
  notice << "You just resized your screen!\n\nBrilliant!"

  Console.set_console_resized_hook! do
    screen.draw notice
  end

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

remedy's People

Contributors

acook avatar colstrom avatar phitherekreborn avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.