views:

303

answers:

5

So, there are web frameworks, there are GUI frameworks, I was just wondering if there was a console/command line framework for ruby?

Specifically, I would like to be able to:

  1. Have a particular view wherein I could tab to different input segments. Exactly like you can do with forms on a web page.
  2. I would like the usual console shortcuts to work (ctr-k, ctr-a, ctr-e, etc)
  3. If the cursor is at a certain input position, sometimes I would like it to response to a single key press event, rather than my having to enter text and then press enter.

Does not have to be a unified framework. But I notice that it does seem somewhat cumbersome to write console apps in ruby. Are there any tools that make this easier?

+3  A: 

Maybe http://rbcurse.rubyforge.org/ can help

mtvee
+1  A: 

Found two more (used neither though):

BTW, I think you had library, not framework in mind. It's a bit unrealistic expecting someone to develop console-based MVC framework... Anyway, everyone is free to try porting Rails... ;)

Edit: Actually, using text-based browser with a web application written with accessibility in mind could give you what you need. Plus you get web interface for free! ;)

Mladen Jablanović
Yeah, the text based browser would be pretty cool. I suppose it is time that I grow up and stop writing any non web-based applications. But I do like the "interface" (command line completion, history, etc) that consoles provide.
Stephen Cagle
A: 

By the time you read this, someone's probably written an Emacs mode for this purpose!

(I'm not sure if I'm kidding)

Carl Smotricz
+4  A: 

Judging from your questions it sounds like your like looking for curses-based frameworks. But in case that you're not, here are some console/irb-related gems I've written that may be useful:

  • hirb - view framework for associating classes with views
  • bond - custom readline completion made easy
  • boson - console command framework

Now to answer your questions:

  1. Though I don't know how to do it, there is this nice curses app whose source code you could read.
  2. require 'readline' gives you those keybindings
  3. require 'highline'; answer = HighLine.new.ask('ask something') {|e| e.character = true }
A: 

I think SimpleConsole is what you are looking for:

It’s a tiny framework to get console applications developed quickly. It might be overkill for scripts, but is pretty useful for some applications. [...] SimpleConsole has a controller and a view, the controller sets up variables for the view to present. The view is optional, but is handy in the cases that you have a lot of ‘puts’ methods and you want to separate them from your logic.

Michael Kohl
Cool idea, of course, without extensive and simple documentation, getting up and rolling with this is more work than just rolling your own. That is the problem with low "barrier to entry" kind of problems. :)
Stephen Cagle