Recipe 21.1.
Resources
HighLine, written by James Edward Gray II and Gregory Brown, is available as the highline gem. The
Curses and
Readline libraries come preinstalled with Ruby (even on Windows, if you use the one-click installer). If...
Recipe 21.2. Getting Input One Line at a Time
Problem
You're writing an interactive console program, and you want to get
line-based input from the user. You present the user with a prompt, and he types some data before hitting enter.
So...
Recipe 21.3. Getting Input One Character at a Time
Problem
You're writing an interactive application or a terminal-based game. You want to read a
user's input from standard input a single character at a time.
Solution
Most Ruby in...
Recipe 21.4. Parsing Command-Line Arguments
Problem
You want to make your Ruby script take
command-line
arguments, the way most Unix utilities and scripts do.
Solution
If you want to treat your command-line arguments as a simpl...
Recipe 21.5. Testing Whether a Program Is Running Interactively
Problem
You want to see whether there's another person on the other end of your program, or whether the program has been hooked up to a file or the output of another prog...
Recipe 21.6. Setting Up and Tearing Down a Curses Program
Problem
To write a program that uses Curses or Ncurses, you have to write a lot of
setup and
cleanup code. You'd like to factor that out.
Solution
Here's a wrapper method tha...
Recipe 21.7. Clearing the Screen
Problem
You're writing a console application, and you want it to clear the screen.
Solution
Capture the output of the Unix clear command as a string and print it whenever you want to clear the sc...
Recipe 21.8. Determining Terminal Size
Problem
Within a terminal-based application, you want to find the size of the terminal: how many rows and columns are available for you to draw on.
Solution
This is easy if you're using the Curs...
Recipe 21.9. Changing Text Color
Problem
You want to display
multicolored text on the console.
Solution
The simplest solution is to use HighLine. It lets you enclose
color commands in an ERb template that gets interpreted withi...
Recipe 21.10. Reading a Password
Problem
You want to prompt the user for a password, or otherwise capture input without echoing it to the screen for all to see.
Solution
The
ruby-password library makes this easy, but it's not avai...
Recipe 21.11. Allowing Input Editing with Readline
Problem
You want to let your users edit their lines of input as they write them, the way irb does.
Solution
Use the readline library. Instead of
reading directly from standar...
Recipe 21.12. Making Your Keyboard Lights Blink
Problem
You want to control the three standard keyboard LEDs (num lock, caps lock, and scroll lock) from a Ruby script.
Solution
Use the Blinkenlights library, available as the blinkenl...
Recipe 21.13. Creating a GUI Application with Tk
Credit: Kevin Marshall
Problem
You need to create a program that has a graphical user interface (GUI).
Solution
Use the
Tk library. It's language-independent, cross-platform, and b...
Recipe 21.14. Creating a GUI Application with wxRuby
Problem
You want to write a portable GUI application that looks better than a Tk application.
Solution
Use the
wxRuby library, available as a third-party download. It uses nativ...
Recipe 21.15. Creating a GUI Application with Ruby/GTK
Problem
You want to write a GUI application that uses the
GTK widget library, perhaps so you can integrate it with the Gnome desktop environment.
Solution
Use the Ruby bindings to ...
Recipe 21.16. Creating a Mac OS X Application with RubyCocoa
Credit: Alun ap Rhisiart
Problem
You want to create a native Mac OS X program with a graphical user interface.
Solution
Use the Mac OS X Cocoa library along with Ruby...
С 2009 года мы стали переводить структура сайта на различные языки. Сайт теперь будет содержать книги не только на английском языке, но также и на других европейских языках, в том числе и на Русском языке.