-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path05-simple_attributes.rb
69 lines (54 loc) · 1.38 KB
/
05-simple_attributes.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# pager functionality by Joseph Spainhour <spainhou@bellsouth.net>
require 'rubygems'
require 'ncurses'
require 'open-uri' # try loading an http url for fun :)
# make sure there's one arguments
if ARGV.length != 1
puts "Usage: #{__FILE__} <a c file name>"
exit(1)
end
# attempt to open the file given by the first arg
begin
file = open(ARGV.first, "r");
rescue
STDERR.puts "Cannot open input file #{ARGV.first}"
exit(1)
end
begin
Ncurses.initscr
cols = Ncurses.getmaxx(Ncurses.stdscr)
rows = Ncurses.getmaxy(Ncurses.stdscr)
prev = ""
while not file.eof?
ch = file.getc.chr
xpos = Ncurses.getcurx(Ncurses.stdscr)
ypos = Ncurses.getcury(Ncurses.stdscr)
if ypos == rows - 1
Ncurses.printw "<-Press Any Key->"
Ncurses.getch
Ncurses.clear
Ncurses.move(0, 0)
end
if prev == '/' and ch == '*'
Ncurses.attron(Ncurses::A_BOLD)
xpos = Ncurses.getcurx(Ncurses.stdscr)
ypos = Ncurses.getcury(Ncurses.stdscr)
Ncurses.move(ypos, xpos - 1)
Ncurses.printw("/#{ch}")
else
Ncurses.printw(ch)
end
Ncurses.refresh
if prev == '*' and ch == '/'
Ncurses.attroff(Ncurses::A_BOLD)
end
prev = ch
end
rescue Exception => e
Ncurses.printw e.inspect + "\n"
Ncurses.printw e.backtrace.join("\n")
Ncurses.getch
ensure
Ncurses.endwin
file.close
end