rbcurse-core 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +69 -0
- data/VERSION +1 -0
- data/examples/abasiclist.rb +151 -0
- data/examples/alpmenu.rb +46 -0
- data/examples/app.sample +17 -0
- data/examples/atree.rb +100 -0
- data/examples/common/file.rb +45 -0
- data/examples/data/README.markdown +9 -0
- data/examples/data/brew.txt +38 -0
- data/examples/data/color.2 +37 -0
- data/examples/data/gemlist.txt +60 -0
- data/examples/data/lotr.txt +12 -0
- data/examples/data/ports.txt +136 -0
- data/examples/data/table.txt +37 -0
- data/examples/data/tasks.csv +88 -0
- data/examples/data/tasks.txt +27 -0
- data/examples/data/todo.txt +10 -0
- data/examples/data/todocsv.csv +28 -0
- data/examples/data/unix1.txt +21 -0
- data/examples/data/unix2.txt +11 -0
- data/examples/dbdemo.rb +487 -0
- data/examples/dirtree.rb +90 -0
- data/examples/newtabbedwindow.rb +100 -0
- data/examples/newtesttabp.rb +92 -0
- data/examples/tabular.rb +132 -0
- data/examples/tasks.rb +167 -0
- data/examples/term2.rb +83 -0
- data/examples/testkeypress.rb +72 -0
- data/examples/testlistbox.rb +158 -0
- data/examples/testmessagebox.rb +140 -0
- data/examples/testree.rb +106 -0
- data/examples/testwsshortcuts.rb +66 -0
- data/examples/testwsshortcuts2.rb +127 -0
- data/lib/rbcurse.rb +8 -0
- data/lib/rbcurse/core/docs/index.txt +73 -0
- data/lib/rbcurse/core/include/action.rb +40 -0
- data/lib/rbcurse/core/include/appmethods.rb +112 -0
- data/lib/rbcurse/core/include/bordertitle.rb +41 -0
- data/lib/rbcurse/core/include/chunk.rb +182 -0
- data/lib/rbcurse/core/include/io.rb +953 -0
- data/lib/rbcurse/core/include/listcellrenderer.rb +140 -0
- data/lib/rbcurse/core/include/listeditable.rb +317 -0
- data/lib/rbcurse/core/include/listscrollable.rb +590 -0
- data/lib/rbcurse/core/include/listselectable.rb +264 -0
- data/lib/rbcurse/core/include/multibuffer.rb +83 -0
- data/lib/rbcurse/core/include/orderedhash.rb +77 -0
- data/lib/rbcurse/core/include/ractionevent.rb +67 -0
- data/lib/rbcurse/core/include/rchangeevent.rb +27 -0
- data/lib/rbcurse/core/include/rhistory.rb +62 -0
- data/lib/rbcurse/core/include/rinputdataevent.rb +47 -0
- data/lib/rbcurse/core/include/vieditable.rb +170 -0
- data/lib/rbcurse/core/system/colormap.rb +163 -0
- data/lib/rbcurse/core/system/keyboard.rb +150 -0
- data/lib/rbcurse/core/system/keydefs.rb +30 -0
- data/lib/rbcurse/core/system/ncurses.rb +218 -0
- data/lib/rbcurse/core/system/panel.rb +162 -0
- data/lib/rbcurse/core/system/window.rb +901 -0
- data/lib/rbcurse/core/util/ansiparser.rb +117 -0
- data/lib/rbcurse/core/util/app.rb +1235 -0
- data/lib/rbcurse/core/util/basestack.rb +407 -0
- data/lib/rbcurse/core/util/bottomline.rb +1850 -0
- data/lib/rbcurse/core/util/colorparser.rb +71 -0
- data/lib/rbcurse/core/util/focusmanager.rb +31 -0
- data/lib/rbcurse/core/util/padreader.rb +189 -0
- data/lib/rbcurse/core/util/rcommandwindow.rb +587 -0
- data/lib/rbcurse/core/util/rdialogs.rb +619 -0
- data/lib/rbcurse/core/util/viewer.rb +149 -0
- data/lib/rbcurse/core/util/widgetshortcuts.rb +505 -0
- data/lib/rbcurse/core/widgets/applicationheader.rb +102 -0
- data/lib/rbcurse/core/widgets/box.rb +58 -0
- data/lib/rbcurse/core/widgets/divider.rb +310 -0
- data/lib/rbcurse/core/widgets/keylabelprinter.rb +178 -0
- data/lib/rbcurse/core/widgets/rcombo.rb +238 -0
- data/lib/rbcurse/core/widgets/rcontainer.rb +415 -0
- data/lib/rbcurse/core/widgets/rlink.rb +30 -0
- data/lib/rbcurse/core/widgets/rlist.rb +723 -0
- data/lib/rbcurse/core/widgets/rmenu.rb +939 -0
- data/lib/rbcurse/core/widgets/rmenulink.rb +22 -0
- data/lib/rbcurse/core/widgets/rmessagebox.rb +373 -0
- data/lib/rbcurse/core/widgets/rprogress.rb +118 -0
- data/lib/rbcurse/core/widgets/rtabbedpane.rb +615 -0
- data/lib/rbcurse/core/widgets/rtabbedwindow.rb +68 -0
- data/lib/rbcurse/core/widgets/rtextarea.rb +920 -0
- data/lib/rbcurse/core/widgets/rtextview.rb +780 -0
- data/lib/rbcurse/core/widgets/rtree.rb +787 -0
- data/lib/rbcurse/core/widgets/rwidget.rb +3040 -0
- data/lib/rbcurse/core/widgets/scrollbar.rb +143 -0
- data/lib/rbcurse/core/widgets/statusline.rb +94 -0
- data/lib/rbcurse/core/widgets/tabular.rb +264 -0
- data/lib/rbcurse/core/widgets/tabularwidget.rb +1211 -0
- data/lib/rbcurse/core/widgets/textpad.rb +516 -0
- data/lib/rbcurse/core/widgets/tree/treecellrenderer.rb +150 -0
- data/lib/rbcurse/core/widgets/tree/treemodel.rb +428 -0
- metadata +156 -0
@@ -0,0 +1,27 @@
|
|
1
|
+
=begin
|
2
|
+
* Name: ChangeEvent
|
3
|
+
* Description: Event used to notify interested parties that state of component has changed
|
4
|
+
* Author: rkumar (arunachalesha)
|
5
|
+
|
6
|
+
--------
|
7
|
+
* Date: 2010-02-26 11:32
|
8
|
+
* License:
|
9
|
+
Same as Ruby's License (http://www.ruby-lang.org/LICENSE.txt)
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
# Event created when state changed (as in ViewPort)
|
14
|
+
module RubyCurses
|
15
|
+
class ChangeEvent
|
16
|
+
attr_accessor :source
|
17
|
+
def initialize source
|
18
|
+
@source = source
|
19
|
+
end
|
20
|
+
def to_s
|
21
|
+
inspect
|
22
|
+
end
|
23
|
+
def inspect
|
24
|
+
"ChangeEvent #{@source}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# ----------------------------------------------------------------------------- #
|
2
|
+
# File: rhistory.rb
|
3
|
+
# Description: a module that pops up history, and then updates selected value
|
4
|
+
# This goes with Field.
|
5
|
+
# e.g.,
|
6
|
+
# field.extend(FieldHistory)
|
7
|
+
#
|
8
|
+
# The module name History was throwing up errors
|
9
|
+
# Author: rkumar http://github.com/rkumar/rbcurse/
|
10
|
+
# Date: 2011-11-27 - 18:10
|
11
|
+
# License: Same as Ruby's License (http://www.ruby-lang.org/LICENSE.txt)
|
12
|
+
# Last update: 2011-11-27 - 20:11
|
13
|
+
# ----------------------------------------------------------------------------- #
|
14
|
+
#
|
15
|
+
# supply history for this object, at least give an empty array
|
16
|
+
# widget would typically be Field,
|
17
|
+
# otherwise it should implement *text()* for getting and setting value
|
18
|
+
# and a *CHANGED* event for when user has modified a value and moved out
|
19
|
+
# You can externally set $history_key to any unused key, otherwise it is M-h
|
20
|
+
module RubyCurses
|
21
|
+
extend self
|
22
|
+
module FieldHistory
|
23
|
+
# pass the array of history values
|
24
|
+
def history arr
|
25
|
+
return @history unless arr
|
26
|
+
@history = arr
|
27
|
+
$history_key ||= ?\M-h
|
28
|
+
# ensure that the field is not overriding this in handle_key
|
29
|
+
bind_key($history_key) { _show_history }
|
30
|
+
# widget should have CHANGED event, or this will either give error, or just not work
|
31
|
+
# else please update history whenever you want a value to be retrieved
|
32
|
+
bind(:CHANGED) { @history << @text unless @history.include? @text }
|
33
|
+
end
|
34
|
+
|
35
|
+
# pass in some configuration for histroy such as row and column to show popup on
|
36
|
+
def history_config config={}
|
37
|
+
@_history_config = config
|
38
|
+
end
|
39
|
+
|
40
|
+
# popup the hist
|
41
|
+
#
|
42
|
+
private
|
43
|
+
def _show_history
|
44
|
+
return unless @history
|
45
|
+
list = @history
|
46
|
+
# calculate r and c
|
47
|
+
c = @_history_config[:col] || @col # this is also dependent on window coords, as in a status_window or messagebox
|
48
|
+
r = @row - 10
|
49
|
+
if @row < 10
|
50
|
+
r = @row + 1
|
51
|
+
end
|
52
|
+
r = @_history_config[:row] || r
|
53
|
+
ret = popuplist(list, :row => r, :col => c, :title => " History ")
|
54
|
+
if ret
|
55
|
+
self.text = list[ret]
|
56
|
+
self.set_form_col
|
57
|
+
end
|
58
|
+
@form.repaint if @form
|
59
|
+
@window.wrefresh if @window
|
60
|
+
end
|
61
|
+
end # mod History
|
62
|
+
end # mod RubyC
|
@@ -0,0 +1,47 @@
|
|
1
|
+
=begin
|
2
|
+
* Name: InputDataEvent
|
3
|
+
* Description: Event created when data modified in Field or TextEdit
|
4
|
+
* Author: rkumar (arunachalesha)
|
5
|
+
|
6
|
+
--------
|
7
|
+
* Date: 2008-12-24 17:27
|
8
|
+
* License:
|
9
|
+
Same as Ruby's License (http://www.ruby-lang.org/LICENSE.txt)
|
10
|
+
|
11
|
+
NOTE: this is how we used to write code in the Java days. Anyone reading this source,
|
12
|
+
this is NOT how to code in rubyland. Please see this link, for how to code such as class:
|
13
|
+
http://blog.grayproductions.net/articles/all_about_struct
|
14
|
+
|
15
|
+
=end
|
16
|
+
|
17
|
+
# Event created when data modified in Field or TextEdit
|
18
|
+
# 2008-12-24 17:54
|
19
|
+
module RubyCurses
|
20
|
+
class InputDataEvent
|
21
|
+
attr_accessor :index0, :index1, :source, :type, :row, :text
|
22
|
+
def initialize index0, index1, source, type, row, text
|
23
|
+
@index0 = index0
|
24
|
+
@index1 = index1
|
25
|
+
@source = source
|
26
|
+
@type = type
|
27
|
+
@row = row
|
28
|
+
@text = text
|
29
|
+
end
|
30
|
+
# until now to_s was returning inspect, but to make it easy for users let us return the value
|
31
|
+
# they most expect which is the text that was changed
|
32
|
+
def to_s
|
33
|
+
inspect
|
34
|
+
end
|
35
|
+
def inspect
|
36
|
+
## now that textarea.to_s prints content we shouldn pass it here.
|
37
|
+
#"#{@type.to_s}, #{@source}, ind0:#{@index0}, ind1:#{@index1}, row:#{@row}, text:#{@text}"
|
38
|
+
"#{@type.to_s}, ind0:#{@index0}, ind1:#{@index1}, row:#{@row}, text:#{@text}"
|
39
|
+
end
|
40
|
+
# this is so that earlier applications were getting source in the block, not an event. they
|
41
|
+
# were doing a fld.getvalue, so we must keep those apps running
|
42
|
+
# @since 1.2.0 added 2010-09-11 12:25
|
43
|
+
def getvalue
|
44
|
+
@source.getvalue
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,170 @@
|
|
1
|
+
#**************************************************************
|
2
|
+
# Author: rkumar (arunachalesha)
|
3
|
+
# Date: 2010-03-11 22:18
|
4
|
+
# Provides the caller ability to do some edit operations
|
5
|
+
# on list widgets using either keys (vim largely)
|
6
|
+
# or a menu. made originally for textview and multitextview
|
7
|
+
#
|
8
|
+
#**************************************************************
|
9
|
+
|
10
|
+
|
11
|
+
require 'rbcurse/core/include/listeditable'
|
12
|
+
module ViEditable
|
13
|
+
include ListEditable
|
14
|
+
|
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
|
42
|
+
|
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 )
|
77
|
+
|
78
|
+
end
|
79
|
+
|
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
|
101
|
+
|
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
|
165
|
+
|
166
|
+
end
|
167
|
+
def edit_word
|
168
|
+
|
169
|
+
end
|
170
|
+
end # module
|
@@ -0,0 +1,163 @@
|
|
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.upcase}"
|
11
|
+
#raise "color const nil ColorMap 8 " if !ret
|
12
|
+
end
|
13
|
+
## private
|
14
|
+
# creates a new color pair, puts in color map and returns color_pair
|
15
|
+
# number
|
16
|
+
def ColorMap.install_color fgc, bgc
|
17
|
+
#$log.debug " install_color found #{fgc} #{@bgc} "
|
18
|
+
@color_id += 1
|
19
|
+
fg = ColorMap.get_color_const fgc
|
20
|
+
bg = ColorMap.get_color_const bgc
|
21
|
+
FFI::NCurses.init_pair(@color_id, fg, bg);
|
22
|
+
$color_map[[fgc, bgc]] = @color_id
|
23
|
+
return @color_id
|
24
|
+
end
|
25
|
+
#
|
26
|
+
# returns the colors that make up the given pair
|
27
|
+
# you may want to find what makes up $bottomcolor and set color and bgcolor with it.
|
28
|
+
# @param [Fixnum] color_pair
|
29
|
+
# @return [Symbol, Symbol] foreground and backgrounf color
|
30
|
+
# @example
|
31
|
+
# color, bgcolor = get_colors_for_pair $datacolor
|
32
|
+
#
|
33
|
+
def ColorMap.get_colors_for_pair pair
|
34
|
+
$color_map.invert[pair]
|
35
|
+
end
|
36
|
+
## public
|
37
|
+
# returns a color_pair for a given foreground and background color
|
38
|
+
def ColorMap.get_color fgc, bgc=$def_bg_color
|
39
|
+
fgc = fgc.to_sym if fgc.is_a? String
|
40
|
+
bgc = bgc.to_sym if bgc.is_a? String
|
41
|
+
if $color_map.include? [fgc, bgc]
|
42
|
+
#$log.debug " get_color found #{fgc} #{@bgc} "
|
43
|
+
return $color_map[[fgc, bgc]]
|
44
|
+
else
|
45
|
+
#$log.debug " get_color NOT found #{fgc} #{@bgc} "
|
46
|
+
return ColorMap.install_color fgc, bgc
|
47
|
+
end
|
48
|
+
end
|
49
|
+
def ColorMap.colors
|
50
|
+
@@colors
|
51
|
+
end
|
52
|
+
# returns true if color is a valid one, else false
|
53
|
+
# @param [Symbol] color such as :black :cyan :yellow
|
54
|
+
# @return [Boolean] true if valid, else false
|
55
|
+
def ColorMap.is_color? color
|
56
|
+
return true if color.is_a? Fixnum # so we can use 256 colors
|
57
|
+
@@colors.include? color.to_sym
|
58
|
+
end
|
59
|
+
|
60
|
+
## public
|
61
|
+
# setup color map at start of application
|
62
|
+
def ColorMap.setup
|
63
|
+
@color_id = 0
|
64
|
+
$color_map = {}
|
65
|
+
FFI::NCurses.start_color();
|
66
|
+
# Initialize few color pairs
|
67
|
+
$def_fg_color = :white # pls set these 2 for your application
|
68
|
+
$def_bg_color = :black
|
69
|
+
#COLORS = [COLOR_BLACK, COLOR_RED, COLOR_GREEN, COLOR_YELLOW, COLOR_BLUE,
|
70
|
+
# COLOR_MAGENTA, COLOR_CYAN, COLOR_WHITE]
|
71
|
+
@@colors = [:black, :red, :green, :yellow, :blue, :magenta, :cyan, :white]
|
72
|
+
|
73
|
+
# make foreground colors
|
74
|
+
bg = ColorMap.get_color_const $def_bg_color
|
75
|
+
@@colors[0...@@colors.size].each_with_index do |color, i|
|
76
|
+
next if color == $def_bg_color # NOTE hope this doesn't do something if you change def_bg
|
77
|
+
ColorMap.install_color color, $def_bg_color
|
78
|
+
end
|
79
|
+
$reversecolor = ColorMap.get_color $def_bg_color, $def_fg_color
|
80
|
+
$popupcolor = ColorMap.get_color :cyan, $def_fg_color
|
81
|
+
|
82
|
+
$errorcolor = ColorMap.get_color :white, :red
|
83
|
+
#$promptcolor = $selectedcolor = ColorMap.get_color(:yellow, :red)
|
84
|
+
$promptcolor = ColorMap.get_color(:yellow, :red)
|
85
|
+
$normalcolor = $datacolor = ColorMap.get_color(:white, :black)
|
86
|
+
$bottomcolor = $topcolor = ColorMap.get_color(:white, :blue)
|
87
|
+
$selectedcolor = $datacolor # since we now use reverse attr in list
|
88
|
+
|
89
|
+
$row_selected_attr = Ncurses::A_REVERSE
|
90
|
+
$row_focussed_attr = Ncurses::A_BOLD
|
91
|
+
$row_attr = Ncurses::A_NORMAL
|
92
|
+
|
93
|
+
# $log.debug " colormap SETUP: #{$datacolor} #{$reversecolor} "
|
94
|
+
end
|
95
|
+
|
96
|
+
end # modul
|
97
|
+
if $0 == __FILE__
|
98
|
+
require 'logger'
|
99
|
+
require 'ver/window'
|
100
|
+
#include Ncurses # FFI 2011-09-8
|
101
|
+
include ColorMap
|
102
|
+
# Initialize curses
|
103
|
+
begin
|
104
|
+
$log = Logger.new("rbc13.log")
|
105
|
+
VER::start_ncurses
|
106
|
+
@window = VER::Window.root_window
|
107
|
+
$log.level = Logger::DEBUG
|
108
|
+
ColorMap.setup
|
109
|
+
|
110
|
+
# Create the window to be associated with the form
|
111
|
+
# Un post form and free the memory
|
112
|
+
|
113
|
+
catch(:close) do
|
114
|
+
# $log.debug "START ---------"
|
115
|
+
# need to pass a form, not window.
|
116
|
+
r = 1; c = 2; i=0
|
117
|
+
attr = Ncurses::A_NORMAL
|
118
|
+
@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')
|
119
|
+
|
120
|
+
|
121
|
+
|
122
|
+
while((ch = @window.getchar()) != FFI::NCurses::KEY_F1 )
|
123
|
+
next if ch == -1
|
124
|
+
break if ch == ?q.getbyte(0)
|
125
|
+
case ch
|
126
|
+
when ?r.getbyte(0)
|
127
|
+
attr |= Ncurses::A_REVERSE
|
128
|
+
when ?b.getbyte(0)
|
129
|
+
attr |= Ncurses::A_BOLD
|
130
|
+
when ?n.getbyte(0)
|
131
|
+
attr = Ncurses::A_NORMAL
|
132
|
+
when ?u.getbyte(0)
|
133
|
+
attr |= Ncurses::A_UNDERLINE
|
134
|
+
else
|
135
|
+
i = ch.chr.to_i
|
136
|
+
i = 1 if i > ColorMap::colors.length-1
|
137
|
+
end
|
138
|
+
bg = ColorMap::colors[i]
|
139
|
+
@@colors = %w[black red green yellow blue magenta cyan white]
|
140
|
+
@window.printstring r, c, "%-40s" % "red #{bg} ", ColorMap.get_color('red',bg) , attr
|
141
|
+
@window.printstring 2, c, "%-40s" % "blue #{bg} ", ColorMap.get_color('blue',bg) , attr
|
142
|
+
@window.printstring 3, c, "%-40s" % "white #{bg} ", ColorMap.get_color('white',bg) , attr
|
143
|
+
@window.printstring 4, c, "%-40s" % "green #{bg} ", ColorMap.get_color('green',bg) , attr
|
144
|
+
@window.printstring 5, c, "%-40s" % "cyan #{bg} ", ColorMap.get_color('cyan',bg) , attr
|
145
|
+
@window.printstring 6, c, "%-40s" % "magenta #{bg} ", ColorMap.get_color('magenta',bg) , attr
|
146
|
+
@window.printstring 7, c, "black #{bg} ", ColorMap.get_color('black',bg) , attr
|
147
|
+
@window.wrefresh
|
148
|
+
end
|
149
|
+
# VER::Keyboard.focus = tp
|
150
|
+
end
|
151
|
+
rescue => ex
|
152
|
+
ensure
|
153
|
+
# @panel = @window.panel if @window
|
154
|
+
# Ncurses::Panel.del_panel(@panel) if !@panel.nil?
|
155
|
+
# @window.delwin if !@window.nil?
|
156
|
+
@window.destroy unless @window.nil?
|
157
|
+
VER::stop_ncurses
|
158
|
+
p ex if ex
|
159
|
+
p(ex.backtrace.join("\n")) if ex
|
160
|
+
# $log.debug( ex) if ex
|
161
|
+
# $log.debug(ex.backtrace.join("\n")) if ex
|
162
|
+
end
|
163
|
+
end
|