examples/hello_ncurses.rb (1455B) - raw
1 #!/usr/bin/env ruby
2
3 # $Id: hello_ncurses.rb,v 1.3 2002-02-28 13:50:03 t-peters Exp $
4
5 # this ncurses-ruby program follows an ancient tradition of example
6 # computer programs: When invoked, it prints a friendly greeting on the
7 # screen and exits.
8 #
9 # Copyright (C) 2002 Tobias Peters <t-peters@users.berlios.de>
10 #
11 # You may use, modify, and redistribute this file without restriction.
12
13
14
15 # First, we have to tell Ruby to use the Ncurses extension module:
16
17 require "ncursesw"
18
19
20
21 # Second, every program using ncurses must initialize the ncurses library
22 # before the first call to any ncurses function:
23
24 Ncurses.initscr
25
26
27
28 # Now the program can use ncurses facilities for screen output. It will print
29 # a greeting to the 5th line on the screen, starting at column 20
30
31 Ncurses.mvaddstr(4, 19, "Hello, world!");
32
33 # Note that ncurses counts lines and columns starting from 0, and that it
34 # expects the line number first and the column number second every time it
35 # expects a coordinate pair.
36
37
38
39 # The previous function call did not alter the screen at all. Ncurses makes
40 # all changes first to an internal buffer. The contents of this buffer is
41 # copied to the screen with the following function call:
42
43 Ncurses.refresh
44
45
46 # Now pause for a short while, enough time for the program user to read the
47 # greeting and greet back.
48
49 sleep(2.5)
50
51
52 # The program has almost finished its task. It only needs to put the screen
53 # back to its normal state:
54
55 Ncurses.endwin
56
57