-
Notifications
You must be signed in to change notification settings - Fork 2
/
ctitle.rb
53 lines (41 loc) · 1006 Bytes
/
ctitle.rb
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
require 'ncurses'
class MyScreen
def initialize(ncurses_screen, &blk)
@screen = ncurses_screen
instance_eval &blk if block_given?
end
def center(row, text)
start_col = ((cols) - text.size) / 2
@screen.mvaddstr row, start_col, text
end
def right_justify row, text
@screen.mvprintw row, 0, "%#{cols}s", text
end
def left_justify row, text
@screen.mvprintw row, 0, "%-#{cols}s", text
end
private
def rows_and_cols
rows, cols = [], []
@screen.getmaxyx(rows, cols)
[rows.first, cols.first]
end
def cols
rows_and_cols.last
end
end
begin
window = Ncurses.initscr
Ncurses.cbreak
MyScreen.new window do
center 1, "Penguin Soccer Finals"
center 5, "Cattle DungSamples from Temecula"
center 7, "Catatonic Theater"
center 9, "Why Do Ions Hate Each Other?"
right_justify 11, "this is right justified"
left_justify 13, "this is left justified"
end
window.getch
ensure
Ncurses.endwin
end