aboutsummaryrefslogtreecommitdiff
path: root/content/posts/2005-03-04-profanity.html
blob: 98c10747bfbe35a8c0122202feb87343d6da728f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
---
date: "2005-03-04T01:38:28Z"
title: Profanity!
---

<p>
The last week or so I've been working on <a href='http://cvs.pablotron.org/?m=profanity'>Profanity</a>, a <a href='http://ruby-lang.org/'>Ruby</a> windowing library for Curses.  It's features include relative window geometry, a include an <acronym title='HyperText Markup Language'>HTML</acronym>-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:
</p>

<ul>
<li><a href='/download/profanity-20050228.mpg'><code>profanity-2050228.mpg</code></a>: An example of the geometry engine handling terminal resizes.</li>
<li><a href='/download/profanity-20050228.mpg'><code>profanity-2050228.mpg</code></a>: An example of window constraints, window gravity, and styled text (notice how styles can be applied to window titles as well as contents).</li>
</ul>

<p>
By the way, if you're having trouble with these movies, try them in <a href='http://www.mplayerhq.hu/'>MPlayer</a> (I'm usually an <a href='http://xine.sf.net/'>Xine</a> 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):
</p>

<p>
<a href='/software/profanity/demos/20050228-shots/00.png'><img src='/software/profanity/demos/20050228-shots/thumb/00.png' width='160' height='164' title='profanity 20050228-00' alt='profanity 20050228-00' border='0' /></a>
<a href='/software/profanity/demos/20050228-shots/01.png'><img src='/software/profanity/demos/20050228-shots/thumb/01.png' width='160' height='164' title='profanity 20050228-01' alt='profanity 20050228-01' border='0' /></a>
<a href='/software/profanity/demos/20050228-shots/02.png'><img src='/software/profanity/demos/20050228-shots/thumb/02.png' width='160' height='164' title='profanity 20050228-02' alt='profanity 20050228-02' border='0' /></a>
<a href='/software/profanity/demos/20050228-shots/03.png'><img src='/software/profanity/demos/20050228-shots/thumb/03.png' width='160' height='164' title='profanity 20050228-03' alt='profanity 20050228-03' border='0' /></a>

<a href='/software/profanity/demos/20050301-shots/00.png'><img src='/software/profanity/demos/20050301-shots/thumb/00.png' width='160' height='164' title='profanity 20050301-00' alt='profanity 20050301-00' border='0' /></a>
<a href='/software/profanity/demos/20050301-shots/01.png'><img src='/software/profanity/demos/20050301-shots/thumb/01.png' width='160' height='164' title='profanity 20050301-01' alt='profanity 20050301-01' border='0' /></a>
<a href='/software/profanity/demos/20050301-shots/02.png'><img src='/software/profanity/demos/20050301-shots/thumb/02.png' width='160' height='164' title='profanity 20050301-02' alt='profanity 20050301-02' border='0' /></a>
</p>

<p>
Finally, here is a <a href='http://cvs.pablotron.org/cgi-bin/viewcvs.cgi/profanity/doc/examples/hello.rb?rev=1.1&view=auto'>simple example from <acronym title='Concurrent Versioning System'>CVS</acronym>)</a> which demonstrates what Profanity code looks like:
</p>

<div style='font-size: 75%; background-color: #eee; padding: 10px;
margin: 10px 30px 10px 30px; border: 1px solid black;'>
<pre>
<code>
require 'profanity'

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

  # 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) }
</code>
</pre>
</div>