Profanity!

March 4, 2005

The last week or so I've been working on Profanity, a Ruby windowing library for Curses. It's features include relative window geometry, a include an HTML-like markup for styled text, and proper terminal resizes support. I've whipped up a couple of example movies to demonstrate the geometry engine and styled text:

  • profanity-2050228.mpg: An example of the geometry engine handling terminal resizes.
  • profanity-2050228.mpg: An example of window constraints, window gravity, and styled text (notice how styles can be applied to window titles as well as contents).

By the way, if you're having trouble with these movies, try them in MPlayer (I'm usually an Xine guy myself, but it seems to mangle these too). In the interest of staving of the torch- and pitchfork-wielding mob of people who can't get either movie to play, here are a few still shots from each (click the thumbnails for the full image):

profanity 20050228-00 profanity 20050228-01 profanity 20050228-02 profanity 20050228-03 profanity 20050301-00 profanity 20050301-01 profanity 20050301-02

Finally, here is a simple example from CVS) which demonstrates what Profanity code looks like:


require 'profanity'

# create a basic window class
class HelloWorldWindow < Profanity::Window
  # contents of this window
  LINES = [
    "<center>Welcome to <u>Profanity</u>!</center>",
    '<center>Press <b>Q</b> or <b>ESC</b> to quit.</center>',
  ]

  # override Window#draw_contents for our own devious purposes
  def draw_contents
    clear
    puts LINES
  end
end

# create the profanity window manager
wm = Profanity::WindowManager.new

# create geometry, and fix height to 4 lines
geom = Profanity::Geometry.new(0.5, 0.5, 0.7, 0.0)
geom.height_absolute = 4

# set gravity to center of the screen
geom.gravity.x = geom.gravity.y = 0.5

# create our window, show and refresh it
win = HelloWorldWindow.new(wm, geom, 'Hello World')
win.show; win.refresh

# run until the user presses q, ctrl-c, or escape
wm.run { |key| break if [?q, 27, Curses::KEY_CTRL_C].include?(key) }