6 printf("usage: view file\n");
10 fp = open(ARGV[0], "r")
12 raise "cannot open file: #{ARGV[1]}"
15 # signal(SIGINT, finish)
22 $screen = Curses.stdscr
24 $screen.scrollok(true)
30 $data_lines.push(l.chop)
35 $data_lines[0..$screen.maxy-1].each_with_index{|line, idx|
36 $screen.setpos(idx, 0)
46 str = $data_lines[$top]
58 if( $top + $screen.maxy < $data_lines.length )
61 str = $data_lines[$top + $screen.maxy - 1]
63 $screen.setpos($screen.maxy - 1, 0)
76 when Curses::KEY_DOWN, Curses::KEY_CTRL_N
78 when Curses::KEY_UP, Curses::KEY_CTRL_P
80 when Curses::KEY_NPAGE, ?\s # white space
81 for i in 0..($screen.maxy - 2)
89 when Curses::KEY_PPAGE
90 for i in 0..($screen.maxy - 2)
98 when Curses::KEY_LEFT, Curses::KEY_CTRL_T
101 when Curses::KEY_RIGHT, Curses::KEY_CTRL_B
108 $screen.addstr("[unknown key `#{Curses.keyname(c)}'=#{c}] ")