rbcurse-core 0.0.13 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,162 +9,164 @@
9
9
 
10
10
 
11
11
  require 'rbcurse/core/include/listeditable'
12
- module ViEditable
13
- include ListEditable
12
+ module RubyCurses
13
+ module ViEditable
14
+ include ListEditable
14
15
 
15
- def vieditable_init
16
- $log.debug " inside vieditable_init "
17
- @editable = true
18
- bind_key( ?C, :edit_line)
19
- #bind_key( ?o, :insert_line)
20
- #bind_key( ?O) { insert_line(@current_index-1) }
21
- bind_key( ?o) { insert_line(@current_index+1) }
22
- bind_key( ?O) { insert_line(@current_index) }
23
- bind_key( ?D, :delete_eol)
24
- bind_key( [?d, ?$], :delete_eol)
25
- bind_key( [?d, ?d] , :delete_line )
26
- bind_key( [?d, ?w], :delete_word )
27
- bind_key( [?d, ?t], :delete_till )
28
- bind_key( [?d, ?f], :delete_forward )
29
- bind_key( ?\C-_ ) { @undo_handler.undo if @undo_handler }
30
- bind_key( ?u ) { @undo_handler.undo if @undo_handler }
31
- bind_key( ?\C-r ) { @undo_handler.redo if @undo_handler }
32
- bind_key( ?x, :delete_curr_char )
33
- bind_key( ?X, :delete_prev_char )
34
- bind_key( [?y, ?y] , :kill_ring_save )
35
- bind_key( ?p, :yank ) # paste after this line
36
- bind_key( ?P ) { yank(@current_index - 1) } # should be before this line
37
- bind_key(?w, :forward_word)
38
- bind_key(?f, :forward_char)
39
- bind_key(?\M-y, :yank_pop)
40
- bind_key(?\M-w, :kill_ring_save)
41
- @_events.push :CHANGE # thru vieditable
16
+ def vieditable_init
17
+ $log.debug " inside vieditable_init "
18
+ @editable = true
19
+ bind_key( ?C, :edit_line)
20
+ #bind_key( ?o, :insert_line)
21
+ #bind_key( ?O) { insert_line(@current_index-1) }
22
+ bind_key( ?o) { insert_line(@current_index+1) }
23
+ bind_key( ?O) { insert_line(@current_index) }
24
+ bind_key( ?D, :delete_eol)
25
+ bind_key( [?d, ?$], :delete_eol)
26
+ bind_key( [?d, ?d] , :delete_line )
27
+ bind_key( [?d, ?w], :delete_word )
28
+ bind_key( [?d, ?t], :delete_till )
29
+ bind_key( [?d, ?f], :delete_forward )
30
+ bind_key( ?\C-_ ) { @undo_handler.undo if @undo_handler }
31
+ bind_key( ?u ) { @undo_handler.undo if @undo_handler }
32
+ bind_key( ?\C-r ) { @undo_handler.redo if @undo_handler }
33
+ bind_key( ?x, :delete_curr_char )
34
+ bind_key( ?X, :delete_prev_char )
35
+ bind_key( [?y, ?y] , :kill_ring_save )
36
+ bind_key( ?p, :yank ) # paste after this line
37
+ bind_key( ?P ) { yank(@current_index - 1) } # should be before this line
38
+ bind_key(?w, :forward_word)
39
+ bind_key(?f, :forward_char)
40
+ bind_key(?\M-y, :yank_pop)
41
+ bind_key(?\M-w, :kill_ring_save)
42
+ @_events.push :CHANGE # thru vieditable
42
43
 
43
- end
44
- ##
45
- # Separate mappings for listboxes.
46
- # Some methods don;'t make sense for listboxes and are crashing
47
- # since not present for them. f was being overwritten, too.
48
- # Sorry for duplication, need to clean this somehow.
49
- def vieditable_init_listbox
50
- $log.debug " inside vieditable_init_listbox "
51
- @editable = true
52
- bind_key( ?C, :edit_line)
53
- bind_key( ?o) { insert_line(@current_index+1) }
54
- bind_key( ?O) { insert_line(@current_index) }
55
- bind_key( [?d, ?d] , :delete_line )
56
- bind_key( ?\C-_ ) { @undo_handler.undo if @undo_handler }
57
- bind_key( ?u ) { @undo_handler.undo if @undo_handler }
58
- bind_key( ?\C-r ) { @undo_handler.redo if @undo_handler }
59
- bind_key( [?y, ?y] , :kill_ring_save )
60
- bind_key( ?p, :yank ) # paste after this line
61
- #bind_key( ?P ) { yank(@current_index - 1) } # should be before this line
62
- # seems -1 was pasting 2 lines before
63
- bind_key( ?P ) { yank(@current_index - 0) } # should be before this line
64
- bind_key(?w, :forward_word)
65
- bind_key(?\M-y, :yank_pop)
66
- bind_key(?\C-y, :yank)
67
- bind_key(?\M-w, :kill_ring_save)
68
- @_events.push :CHANGE # thru vieditable
69
- #bind_key( ?D, :delete_eol)
70
- #bind_key( [?d, ?$], :delete_eol)
71
- #bind_key(?f, :forward_char)
72
- #bind_key( ?x, :delete_curr_char )
73
- #bind_key( ?X, :delete_prev_char )
74
- #bind_key( [?d, ?w], :delete_word )
75
- #bind_key( [?d, ?t], :delete_till )
76
- #bind_key( [?d, ?f], :delete_forward )
44
+ end
45
+ ##
46
+ # Separate mappings for listboxes.
47
+ # Some methods don;'t make sense for listboxes and are crashing
48
+ # since not present for them. f was being overwritten, too.
49
+ # Sorry for duplication, need to clean this somehow.
50
+ def vieditable_init_listbox
51
+ $log.debug " inside vieditable_init_listbox "
52
+ @editable = true
53
+ bind_key( ?C, :edit_line)
54
+ bind_key( ?o) { insert_line(@current_index+1) }
55
+ bind_key( ?O) { insert_line(@current_index) }
56
+ bind_key( [?d, ?d] , :delete_line )
57
+ bind_key( ?\C-_ ) { @undo_handler.undo if @undo_handler }
58
+ bind_key( ?u ) { @undo_handler.undo if @undo_handler }
59
+ bind_key( ?\C-r ) { @undo_handler.redo if @undo_handler }
60
+ bind_key( [?y, ?y] , :kill_ring_save )
61
+ bind_key( ?p, :yank ) # paste after this line
62
+ #bind_key( ?P ) { yank(@current_index - 1) } # should be before this line
63
+ # seems -1 was pasting 2 lines before
64
+ bind_key( ?P ) { yank(@current_index - 0) } # should be before this line
65
+ bind_key(?w, :forward_word)
66
+ bind_key(?\M-y, :yank_pop)
67
+ bind_key(?\C-y, :yank)
68
+ bind_key(?\M-w, :kill_ring_save)
69
+ @_events.push :CHANGE # thru vieditable
70
+ #bind_key( ?D, :delete_eol)
71
+ #bind_key( [?d, ?$], :delete_eol)
72
+ #bind_key(?f, :forward_char)
73
+ #bind_key( ?x, :delete_curr_char )
74
+ #bind_key( ?X, :delete_prev_char )
75
+ #bind_key( [?d, ?w], :delete_word )
76
+ #bind_key( [?d, ?t], :delete_till )
77
+ #bind_key( [?d, ?f], :delete_forward )
77
78
 
78
- end
79
+ end
79
80
 
80
- # currently only adding delete_line and some yank pop functions
81
- # These will all give wrong results in table due to _header_offset
82
- def vieditable_init_tabular
83
- $log.debug " inside vieditable_init tabular"
84
- @editable = true
85
- #bind_key( ?C, :edit_line)
86
- #bind_key( ?o, :insert_line)
87
- #bind_key( ?O) { insert_line(@current_index-1) }
88
- #bind_key( ?o) { insert_line(@current_index+1) }
89
- #bind_key( ?O) { insert_line(@current_index) }
90
- bind_key( [?d, ?d] , :delete_line )
91
- #bind_key( ?\C-_ ) { @undo_handler.undo if @undo_handler }
92
- #bind_key( ?u ) { @undo_handler.undo if @undo_handler }
93
- #bind_key( ?\C-r ) { @undo_handler.redo if @undo_handler }
94
- bind_key( [?y, ?y] , :kill_ring_save )
95
- bind_key( ?p, :yank ) # paste after this line
96
- bind_key( ?P ) { yank(@current_index - 1) } # should be before this line
97
- bind_key(?\M-y, :yank_pop)
98
- bind_key(?\M-w, :kill_ring_save)
99
- @_events.push :CHANGE # thru vieditable
100
- end
81
+ # currently only adding delete_line and some yank pop functions
82
+ # These will all give wrong results in table due to _header_offset
83
+ def vieditable_init_tabular
84
+ $log.debug " inside vieditable_init tabular"
85
+ @editable = true
86
+ #bind_key( ?C, :edit_line)
87
+ #bind_key( ?o, :insert_line)
88
+ #bind_key( ?O) { insert_line(@current_index-1) }
89
+ #bind_key( ?o) { insert_line(@current_index+1) }
90
+ #bind_key( ?O) { insert_line(@current_index) }
91
+ bind_key( [?d, ?d] , :delete_line )
92
+ #bind_key( ?\C-_ ) { @undo_handler.undo if @undo_handler }
93
+ #bind_key( ?u ) { @undo_handler.undo if @undo_handler }
94
+ #bind_key( ?\C-r ) { @undo_handler.redo if @undo_handler }
95
+ bind_key( [?y, ?y] , :kill_ring_save )
96
+ bind_key( ?p, :yank ) # paste after this line
97
+ bind_key( ?P ) { yank(@current_index - 1) } # should be before this line
98
+ bind_key(?\M-y, :yank_pop)
99
+ bind_key(?\M-w, :kill_ring_save)
100
+ @_events.push :CHANGE # thru vieditable
101
+ end
101
102
 
102
- ##
103
- # edit current or given line
104
- def edit_line lineno=@current_index
105
- line = self[lineno]
106
- prompt = "Edit: "
107
- maxlen = 80
108
- config={};
109
- oldline = line.dup
110
- config[:default] = line
111
- ret, str = rbgetstr(@form.window, $error_message_row, $error_message_col, prompt, maxlen, config)
112
- $log.debug " rbgetstr returned #{ret} , #{str} "
113
- return if ret != 0
114
- self[lineno].replace(str)
115
- fire_handler :CHANGE, InputDataEvent.new(0,oldline.length, self, :DELETE_LINE, lineno, oldline) # 2008-12-24 18:34
116
- fire_handler :CHANGE, InputDataEvent.new(0,str.length, self, :INSERT_LINE, lineno, str)
117
- @repaint_required = true
118
- @widget_scrolled = true
119
- end
120
- ##
121
- # insert a line
122
- # FIXME needs to fire handler 2010-05-23 11:40
123
- def insert_line lineno=@current_index
124
- prompt = "Insert: "
125
- maxlen = 80
126
- #config={};
127
- #config[:default] = line
128
- #ret, str = rbgetstr(@form.window, $error_message_row, $error_message_col, prompt, maxlen, config)
129
- ret, str = input_string prompt
130
- #ret, str = rbgetstr(@form.window, @row+@height-1, @col+1, prompt, maxlen, config)
131
- $log.debug " rbgetstr returned #{ret} , #{str} "
132
- return if ret != 0
133
- @list.insert lineno, str
134
- ## added handler on 2010-05-23 11:46 - undo works - tested in testlistbox.rb
135
- fire_handler :CHANGE, InputDataEvent.new(0,str.length, self, :INSERT_LINE, lineno, str)
136
- @widget_scrolled = true
137
- @repaint_required = true
138
- end
139
- ##
140
- # common method to edit given string
141
- # @param [String] string to edit/modify
142
- # @param [String] prompt to display before string
143
- # @param [int] max length of input
144
- # @return [0, -1] return value 0 if okay, -1 if error
145
- #
146
- def edit_string string, prompt="Edit: ", maxlen=80
147
- config={};
148
- config[:default] = string
149
- ret, str = rbgetstr(@form.window, $error_message_row, $error_message_col, prompt, maxlen, config)
150
- #return str if ret == 0
151
- #return ""
152
- end
153
- ##
154
- # common method to input a blank string
155
- # @param [String] prompt to display before string
156
- # @param [int] max length of input
157
- # @return [0, -1] return value 0 if okay, -1 if error
158
- def input_string prompt="Insert: ", maxlen=80
159
- #ret, str = rbgetstr(@form.window, $error_message_row, $error_message_col, prompt, maxlen, config)
160
- ret, str = rbgetstr(@form.window, $error_message_row, $error_message_col, prompt, maxlen, config)
161
- #return str if ret == 0
162
- #return ""
163
- end
164
- def edit_chars
103
+ ##
104
+ # edit current or given line
105
+ def edit_line lineno=@current_index
106
+ line = self[lineno]
107
+ prompt = "Edit: "
108
+ maxlen = 80
109
+ config={};
110
+ oldline = line.dup
111
+ config[:default] = line
112
+ ret, str = rbgetstr(@form.window, $error_message_row, $error_message_col, prompt, maxlen, config)
113
+ $log.debug " rbgetstr returned #{ret} , #{str} "
114
+ return if ret != 0
115
+ self[lineno].replace(str)
116
+ fire_handler :CHANGE, InputDataEvent.new(0,oldline.length, self, :DELETE_LINE, lineno, oldline) # 2008-12-24 18:34
117
+ fire_handler :CHANGE, InputDataEvent.new(0,str.length, self, :INSERT_LINE, lineno, str)
118
+ @repaint_required = true
119
+ @widget_scrolled = true
120
+ end
121
+ ##
122
+ # insert a line
123
+ # FIXME needs to fire handler 2010-05-23 11:40
124
+ def insert_line lineno=@current_index
125
+ prompt = "Insert: "
126
+ maxlen = 80
127
+ #config={};
128
+ #config[:default] = line
129
+ #ret, str = rbgetstr(@form.window, $error_message_row, $error_message_col, prompt, maxlen, config)
130
+ ret, str = input_string prompt
131
+ #ret, str = rbgetstr(@form.window, @row+@height-1, @col+1, prompt, maxlen, config)
132
+ $log.debug " rbgetstr returned #{ret} , #{str} "
133
+ return if ret != 0
134
+ @list.insert lineno, str
135
+ ## added handler on 2010-05-23 11:46 - undo works - tested in testlistbox.rb
136
+ fire_handler :CHANGE, InputDataEvent.new(0,str.length, self, :INSERT_LINE, lineno, str)
137
+ @widget_scrolled = true
138
+ @repaint_required = true
139
+ end
140
+ ##
141
+ # common method to edit given string
142
+ # @param [String] string to edit/modify
143
+ # @param [String] prompt to display before string
144
+ # @param [int] max length of input
145
+ # @return [0, -1] return value 0 if okay, -1 if error
146
+ #
147
+ def edit_string string, prompt="Edit: ", maxlen=80
148
+ config={};
149
+ config[:default] = string
150
+ ret, str = rbgetstr(@form.window, $error_message_row, $error_message_col, prompt, maxlen, config)
151
+ #return str if ret == 0
152
+ #return ""
153
+ end
154
+ ##
155
+ # common method to input a blank string
156
+ # @param [String] prompt to display before string
157
+ # @param [int] max length of input
158
+ # @return [0, -1] return value 0 if okay, -1 if error
159
+ def input_string prompt="Insert: ", maxlen=80
160
+ #ret, str = rbgetstr(@form.window, $error_message_row, $error_message_col, prompt, maxlen, config)
161
+ ret, str = rbgetstr(@form.window, $error_message_row, $error_message_col, prompt, maxlen, config)
162
+ #return str if ret == 0
163
+ #return ""
164
+ end
165
+ def edit_chars
165
166
 
166
- end
167
- def edit_word
167
+ end
168
+ def edit_word
168
169
 
169
- end
170
+ end
171
+ end # module
170
172
  end # module
@@ -1,162 +1,165 @@
1
1
  require 'rbcurse/core/system/ncurses'
2
- module ColorMap
3
- # 2010-09-20 12:22 changed colors from string to symbol
4
- ## private
5
- # returns a color constant for a human color string
6
- def ColorMap.get_color_const colorstring
7
- # added check for fixnum if we go beyond these constants 2011-11-28
8
- # e.g. to use full 256 colors
9
- return colorstring if colorstring.is_a? Fixnum
10
- ret = FFI::NCurses.const_get "COLOR_#{colorstring.to_s.upcase}"
11
- end
12
- ## private
13
- # creates a new color pair, puts in color map and returns color_pair
14
- # number
15
- def ColorMap.install_color fgc, bgc
2
+
3
+ module RubyCurses
4
+ module ColorMap
5
+ # 2010-09-20 12:22 changed colors from string to symbol
6
+ ## private
7
+ # returns a color constant for a human color string
8
+ def ColorMap.get_color_const colorstring
9
+ # added check for fixnum if we go beyond these constants 2011-11-28
10
+ # e.g. to use full 256 colors
11
+ return colorstring if colorstring.is_a? Fixnum
12
+ ret = FFI::NCurses.const_get "COLOR_#{colorstring.to_s.upcase}"
13
+ end
14
+ ## private
15
+ # creates a new color pair, puts in color map and returns color_pair
16
+ # number
17
+ def ColorMap.install_color fgc, bgc
16
18
  #$log.debug " install_color found #{fgc} #{@bgc} "
17
19
  @color_id += 1
18
- fg = ColorMap.get_color_const fgc
19
- bg = ColorMap.get_color_const bgc
20
- FFI::NCurses.init_pair(@color_id, fg, bg);
21
- $color_map[[fgc, bgc]] = @color_id
22
- return @color_id
23
- end
24
- #
25
- # returns the colors that make up the given pair
26
- # you may want to find what makes up $bottomcolor and set color and bgcolor with it.
27
- # @param [Fixnum] color_pair
28
- # @return [Symbol, Symbol] foreground and backgrounf color
29
- # @example
30
- # color, bgcolor = get_colors_for_pair $datacolor
31
- #
32
- def ColorMap.get_colors_for_pair pair
33
- $color_map.invert[pair]
34
- end
35
- ## public
36
- # returns a color_pair for a given foreground and background color
37
- def ColorMap.get_color fgc, bgc=$def_bg_color
38
- fgc = fgc.to_sym if fgc.is_a? String
39
- bgc = bgc.to_sym if bgc.is_a? String
40
- if $color_map.include? [fgc, bgc]
41
- #$log.debug " get_color found #{fgc} #{@bgc} "
42
- return $color_map[[fgc, bgc]]
43
- else
44
- #$log.debug " get_color NOT found #{fgc} #{@bgc} "
45
- return ColorMap.install_color fgc, bgc
20
+ fg = ColorMap.get_color_const fgc
21
+ bg = ColorMap.get_color_const bgc
22
+ FFI::NCurses.init_pair(@color_id, fg, bg);
23
+ $color_map[[fgc, bgc]] = @color_id
24
+ return @color_id
25
+ end
26
+ #
27
+ # returns the colors that make up the given pair
28
+ # you may want to find what makes up $bottomcolor and set color and bgcolor with it.
29
+ # @param [Fixnum] color_pair
30
+ # @return [Symbol, Symbol] foreground and backgrounf color
31
+ # @example
32
+ # color, bgcolor = get_colors_for_pair $datacolor
33
+ #
34
+ def ColorMap.get_colors_for_pair pair
35
+ $color_map.invert[pair]
36
+ end
37
+ ## public
38
+ # returns a color_pair for a given foreground and background color
39
+ def ColorMap.get_color fgc, bgc=$def_bg_color
40
+ fgc = fgc.to_sym if fgc.is_a? String
41
+ bgc = bgc.to_sym if bgc.is_a? String
42
+ if $color_map.include? [fgc, bgc]
43
+ #$log.debug " get_color found #{fgc} #{@bgc} "
44
+ return $color_map[[fgc, bgc]]
45
+ else
46
+ #$log.debug " get_color NOT found #{fgc} #{@bgc} "
47
+ return ColorMap.install_color fgc, bgc
48
+ end
49
+ end
50
+ def ColorMap.colors
51
+ @@colors
52
+ end
53
+ # returns true if color is a valid one, else false
54
+ # @param [Symbol] color such as :black :cyan :yellow
55
+ # @return [Boolean] true if valid, else false
56
+ def ColorMap.is_color? color
57
+ return true if color.is_a? Fixnum # so we can use 256 colors
58
+ @@colors.include? color.to_sym
46
59
  end
47
- end
48
- def ColorMap.colors
49
- @@colors
50
- end
51
- # returns true if color is a valid one, else false
52
- # @param [Symbol] color such as :black :cyan :yellow
53
- # @return [Boolean] true if valid, else false
54
- def ColorMap.is_color? color
55
- return true if color.is_a? Fixnum # so we can use 256 colors
56
- @@colors.include? color.to_sym
57
- end
58
60
 
59
- ## public
60
- # setup color map at start of application
61
- def ColorMap.setup
62
- @color_id = 0
63
- $color_map = {}
64
- FFI::NCurses.start_color();
65
- # Initialize few color pairs
66
- $def_fg_color = :white # pls set these 2 for your application
67
- $def_bg_color = :black
68
- #COLORS = [COLOR_BLACK, COLOR_RED, COLOR_GREEN, COLOR_YELLOW, COLOR_BLUE,
69
- # COLOR_MAGENTA, COLOR_CYAN, COLOR_WHITE]
70
- @@colors = [:black, :red, :green, :yellow, :blue, :magenta, :cyan, :white]
61
+ ## public
62
+ # setup color map at start of application
63
+ def ColorMap.setup
64
+ @color_id = 0
65
+ $color_map = {}
66
+ FFI::NCurses.start_color();
67
+ # Initialize few color pairs
68
+ $def_fg_color = :white # pls set these 2 for your application
69
+ $def_bg_color = :black
70
+ #COLORS = [COLOR_BLACK, COLOR_RED, COLOR_GREEN, COLOR_YELLOW, COLOR_BLUE,
71
+ # COLOR_MAGENTA, COLOR_CYAN, COLOR_WHITE]
72
+ @@colors = [:black, :red, :green, :yellow, :blue, :magenta, :cyan, :white]
71
73
 
72
- # make foreground colors
73
- bg = ColorMap.get_color_const $def_bg_color
74
- @@colors[0...@@colors.size].each_with_index do |color, i|
75
- next if color == $def_bg_color # NOTE hope this doesn't do something if you change def_bg
76
- ColorMap.install_color color, $def_bg_color
77
- end
78
- $reversecolor = ColorMap.get_color $def_bg_color, $def_fg_color
79
- $popupcolor = ColorMap.get_color :cyan, $def_fg_color
74
+ # make foreground colors
75
+ bg = ColorMap.get_color_const $def_bg_color
76
+ @@colors[0...@@colors.size].each_with_index do |color, i|
77
+ next if color == $def_bg_color # NOTE hope this doesn't do something if you change def_bg
78
+ ColorMap.install_color color, $def_bg_color
79
+ end
80
+ $reversecolor = ColorMap.get_color $def_bg_color, $def_fg_color
81
+ $popupcolor = ColorMap.get_color :cyan, $def_fg_color
80
82
 
81
- $errorcolor = ColorMap.get_color :white, :red
82
- #$promptcolor = $selectedcolor = ColorMap.get_color(:yellow, :red)
83
- $promptcolor = ColorMap.get_color(:yellow, :red)
84
- $normalcolor = $datacolor = ColorMap.get_color(:white, :black)
85
- $bottomcolor = $topcolor = ColorMap.get_color(:white, :blue)
86
- $selectedcolor = $datacolor # since we now use reverse attr in list
83
+ $errorcolor = ColorMap.get_color :white, :red
84
+ #$promptcolor = $selectedcolor = ColorMap.get_color(:yellow, :red)
85
+ $promptcolor = ColorMap.get_color(:yellow, :red)
86
+ $normalcolor = $datacolor = ColorMap.get_color(:white, :black)
87
+ $bottomcolor = $topcolor = ColorMap.get_color(:white, :blue)
88
+ $selectedcolor = $datacolor # since we now use reverse attr in list
87
89
 
88
- $row_selected_attr = Ncurses::A_REVERSE
89
- $row_focussed_attr = Ncurses::A_BOLD
90
- $row_attr = Ncurses::A_NORMAL
90
+ $row_selected_attr = Ncurses::A_REVERSE
91
+ $row_focussed_attr = Ncurses::A_BOLD
92
+ $row_attr = Ncurses::A_NORMAL
91
93
 
92
- # $log.debug " colormap SETUP: #{$datacolor} #{$reversecolor} "
93
- end
94
+ # $log.debug " colormap SETUP: #{$datacolor} #{$reversecolor} "
95
+ end
96
+
97
+ end # modul
98
+ if $0 == __FILE__
99
+ require 'logger'
100
+ require 'ver/window'
101
+ #include Ncurses # FFI 2011-09-8
102
+ include ColorMap
103
+ # Initialize curses
104
+ begin
105
+ $log = Logger.new("rbc13.log")
106
+ VER::start_ncurses
107
+ @window = VER::Window.root_window
108
+ $log.level = Logger::DEBUG
109
+ ColorMap.setup
94
110
 
95
- end # modul
96
- if $0 == __FILE__
97
- require 'logger'
98
- require 'ver/window'
99
- #include Ncurses # FFI 2011-09-8
100
- include ColorMap
101
- # Initialize curses
102
- begin
103
- $log = Logger.new("rbc13.log")
104
- VER::start_ncurses
105
- @window = VER::Window.root_window
106
- $log.level = Logger::DEBUG
107
- ColorMap.setup
111
+ # Create the window to be associated with the form
112
+ # Un post form and free the memory
108
113
 
109
- # Create the window to be associated with the form
110
- # Un post form and free the memory
114
+ catch(:close) do
115
+ # $log.debug "START ---------"
116
+ # need to pass a form, not window.
117
+ r = 1; c = 2; i=0
118
+ attr = Ncurses::A_NORMAL
119
+ @window.printstring 20, c, "press 0-9 to change BG color, F1/q to quit. r-everse, n-ormal,b-old ", ColorMap.get_color('white')
111
120
 
112
- catch(:close) do
113
- # $log.debug "START ---------"
114
- # need to pass a form, not window.
115
- r = 1; c = 2; i=0
116
- attr = Ncurses::A_NORMAL
117
- @window.printstring 20, c, "press 0-9 to change BG color, F1/q to quit. r-everse, n-ormal,b-old ", ColorMap.get_color('white')
118
121
 
119
-
120
122
 
121
- while((ch = @window.getchar()) != FFI::NCurses::KEY_F1 )
122
- next if ch == -1
123
- break if ch == ?q.getbyte(0)
124
- case ch
125
- when ?r.getbyte(0)
126
- attr |= Ncurses::A_REVERSE
127
- when ?b.getbyte(0)
128
- attr |= Ncurses::A_BOLD
129
- when ?n.getbyte(0)
130
- attr = Ncurses::A_NORMAL
131
- when ?u.getbyte(0)
132
- attr |= Ncurses::A_UNDERLINE
133
- else
134
- i = ch.chr.to_i
135
- i = 1 if i > ColorMap::colors.length-1
123
+ while((ch = @window.getchar()) != FFI::NCurses::KEY_F1 )
124
+ next if ch == -1
125
+ break if ch == ?q.getbyte(0)
126
+ case ch
127
+ when ?r.getbyte(0)
128
+ attr |= Ncurses::A_REVERSE
129
+ when ?b.getbyte(0)
130
+ attr |= Ncurses::A_BOLD
131
+ when ?n.getbyte(0)
132
+ attr = Ncurses::A_NORMAL
133
+ when ?u.getbyte(0)
134
+ attr |= Ncurses::A_UNDERLINE
135
+ else
136
+ i = ch.chr.to_i
137
+ i = 1 if i > ColorMap::colors.length-1
138
+ end
139
+ bg = ColorMap::colors[i]
140
+ @@colors = %w[black red green yellow blue magenta cyan white]
141
+ @window.printstring r, c, "%-40s" % "red #{bg} ", ColorMap.get_color('red',bg) , attr
142
+ @window.printstring 2, c, "%-40s" % "blue #{bg} ", ColorMap.get_color('blue',bg) , attr
143
+ @window.printstring 3, c, "%-40s" % "white #{bg} ", ColorMap.get_color('white',bg) , attr
144
+ @window.printstring 4, c, "%-40s" % "green #{bg} ", ColorMap.get_color('green',bg) , attr
145
+ @window.printstring 5, c, "%-40s" % "cyan #{bg} ", ColorMap.get_color('cyan',bg) , attr
146
+ @window.printstring 6, c, "%-40s" % "magenta #{bg} ", ColorMap.get_color('magenta',bg) , attr
147
+ @window.printstring 7, c, "black #{bg} ", ColorMap.get_color('black',bg) , attr
148
+ @window.wrefresh
136
149
  end
137
- bg = ColorMap::colors[i]
138
- @@colors = %w[black red green yellow blue magenta cyan white]
139
- @window.printstring r, c, "%-40s" % "red #{bg} ", ColorMap.get_color('red',bg) , attr
140
- @window.printstring 2, c, "%-40s" % "blue #{bg} ", ColorMap.get_color('blue',bg) , attr
141
- @window.printstring 3, c, "%-40s" % "white #{bg} ", ColorMap.get_color('white',bg) , attr
142
- @window.printstring 4, c, "%-40s" % "green #{bg} ", ColorMap.get_color('green',bg) , attr
143
- @window.printstring 5, c, "%-40s" % "cyan #{bg} ", ColorMap.get_color('cyan',bg) , attr
144
- @window.printstring 6, c, "%-40s" % "magenta #{bg} ", ColorMap.get_color('magenta',bg) , attr
145
- @window.printstring 7, c, "black #{bg} ", ColorMap.get_color('black',bg) , attr
146
- @window.wrefresh
150
+ # VER::Keyboard.focus = tp
147
151
  end
148
- # VER::Keyboard.focus = tp
149
- end
150
- rescue => ex
151
- ensure
152
- # @panel = @window.panel if @window
153
- # Ncurses::Panel.del_panel(@panel) if !@panel.nil?
154
- # @window.delwin if !@window.nil?
155
- @window.destroy unless @window.nil?
152
+ rescue => ex
153
+ ensure
154
+ # @panel = @window.panel if @window
155
+ # Ncurses::Panel.del_panel(@panel) if !@panel.nil?
156
+ # @window.delwin if !@window.nil?
157
+ @window.destroy unless @window.nil?
156
158
  VER::stop_ncurses
157
- p ex if ex
158
- p(ex.backtrace.join("\n")) if ex
159
- # $log.debug( ex) if ex
160
- # $log.debug(ex.backtrace.join("\n")) if ex
159
+ p ex if ex
160
+ p(ex.backtrace.join("\n")) if ex
161
+ # $log.debug( ex) if ex
162
+ # $log.debug(ex.backtrace.join("\n")) if ex
163
+ end
161
164
  end
162
165
  end