rubysl-curses 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/curses/view.rb DELETED
@@ -1,91 +0,0 @@
1
- #!/usr/local/bin/ruby
2
-
3
- require "curses"
4
- include Curses
5
-
6
- #
7
- # main
8
- #
9
-
10
- if ARGV.size != 1 then
11
- printf("usage: view file\n");
12
- exit
13
- end
14
- begin
15
- fp = open(ARGV[0], "r")
16
- rescue
17
- raise "cannot open file: #{ARGV[1]}"
18
- end
19
-
20
- # signal(SIGINT, finish)
21
-
22
- init_screen
23
- #keypad(stdscr, TRUE)
24
- nonl
25
- cbreak
26
- noecho
27
- #scrollok(stdscr, TRUE)
28
-
29
- # slurp the file
30
- data_lines = []
31
- fp.each_line { |l|
32
- data_lines.push(l)
33
- }
34
- fp.close
35
-
36
-
37
- lptr = 0
38
- while TRUE
39
- i = 0
40
- while i < lines
41
- setpos(i, 0)
42
- #clrtoeol
43
- addstr(data_lines[lptr + i]) #if data_lines[lptr + i]
44
- i += 1
45
- end
46
- refresh
47
-
48
- explicit = FALSE
49
- n = 0
50
- while TRUE
51
- c = getch.chr
52
- if c =~ /[0-9]/
53
- n = 10 * n + c.to_i
54
- else
55
- break
56
- end
57
- end
58
-
59
- n = 1 if !explicit && n == 0
60
-
61
- case c
62
- when "n" #when KEY_DOWN
63
- i = 0
64
- while i < n
65
- if lptr + lines < data_lines.size then
66
- lptr += 1
67
- else
68
- break
69
- end
70
- i += 1
71
- end
72
- #wscrl(i)
73
-
74
- when "p" #when KEY_UP
75
- i = 0
76
- while i < n
77
- if lptr > 0 then
78
- lptr -= 1
79
- else
80
- break
81
- end
82
- i += 1
83
- end
84
- #wscrl(-i)
85
-
86
- when "q"
87
- break
88
- end
89
-
90
- end
91
- close_screen
data/lib/curses/view2.rb DELETED
@@ -1,115 +0,0 @@
1
- #!/usr/local/bin/ruby
2
-
3
- require "curses"
4
-
5
- if ARGV.size != 1 then
6
- printf("usage: view file\n");
7
- exit
8
- end
9
- begin
10
- fp = open(ARGV[0], "r")
11
- rescue
12
- raise "cannot open file: #{ARGV[1]}"
13
- end
14
-
15
- # signal(SIGINT, finish)
16
-
17
- Curses.init_screen
18
- Curses.nonl
19
- Curses.cbreak
20
- Curses.noecho
21
-
22
- $screen = Curses.stdscr
23
-
24
- $screen.scrollok(true)
25
- #$screen.keypad(true)
26
-
27
- # slurp the file
28
- $data_lines = []
29
- fp.each_line { |l|
30
- $data_lines.push(l.chop)
31
- }
32
- fp.close
33
-
34
- $top = 0
35
- $data_lines[0..$screen.maxy-1].each_with_index{|line, idx|
36
- $screen.setpos(idx, 0)
37
- $screen.addstr(line)
38
- }
39
- $screen.setpos(0,0)
40
- $screen.refresh
41
-
42
- def scroll_up
43
- if( $top > 0 )
44
- $screen.scrl(-1)
45
- $top -= 1
46
- str = $data_lines[$top]
47
- if( str )
48
- $screen.setpos(0, 0)
49
- $screen.addstr(str)
50
- end
51
- return true
52
- else
53
- return false
54
- end
55
- end
56
-
57
- def scroll_down
58
- if( $top + $screen.maxy < $data_lines.length )
59
- $screen.scrl(1)
60
- $top += 1
61
- str = $data_lines[$top + $screen.maxy - 1]
62
- if( str )
63
- $screen.setpos($screen.maxy - 1, 0)
64
- $screen.addstr(str)
65
- end
66
- return true
67
- else
68
- return false
69
- end
70
- end
71
-
72
- while true
73
- result = true
74
- c = Curses.getch
75
- case c
76
- when Curses::KEY_DOWN, Curses::KEY_CTRL_N
77
- result = scroll_down
78
- when Curses::KEY_UP, Curses::KEY_CTRL_P
79
- result = scroll_up
80
- when Curses::KEY_NPAGE, ?\s # white space
81
- for i in 0..($screen.maxy - 2)
82
- if( ! scroll_down )
83
- if( i == 0 )
84
- result = false
85
- end
86
- break
87
- end
88
- end
89
- when Curses::KEY_PPAGE
90
- for i in 0..($screen.maxy - 2)
91
- if( ! scroll_up )
92
- if( i == 0 )
93
- result = false
94
- end
95
- break
96
- end
97
- end
98
- when Curses::KEY_LEFT, Curses::KEY_CTRL_T
99
- while( scroll_up )
100
- end
101
- when Curses::KEY_RIGHT, Curses::KEY_CTRL_B
102
- while( scroll_down )
103
- end
104
- when ?q
105
- break
106
- else
107
- $screen.setpos(0,0)
108
- $screen.addstr("[unknown key `#{Curses.keyname(c)}'=#{c}] ")
109
- end
110
- if( !result )
111
- Curses.beep
112
- end
113
- $screen.setpos(0,0)
114
- end
115
- Curses.close_screen
data/lib/rubysl-curses.rb DELETED
@@ -1,7 +0,0 @@
1
- require "rubysl-curses/version"
2
-
3
- module RubySL
4
- module Curses
5
- # Your code goes here...
6
- end
7
- end