rbcurse 1.1.5 → 1.2.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. data/CHANGELOG +45 -0
  2. data/Makefile +1 -1
  3. data/Manifest.txt +91 -0
  4. data/NOTES +349 -2
  5. data/README.markdown +12 -0
  6. data/VERSION +1 -1
  7. data/examples/abasiclist.rb +25 -0
  8. data/examples/alpmenu.rb +42 -0
  9. data/examples/app.rb +883 -0
  10. data/examples/appcombo.rb +17 -0
  11. data/examples/appdirtree.rb +73 -0
  12. data/examples/appemail.rb +164 -0
  13. data/examples/appemaillb.rb +308 -0
  14. data/examples/appgcompose.rb +303 -0
  15. data/examples/appgmail.rb +951 -0
  16. data/examples/atree.rb +56 -0
  17. data/examples/dirtree.rb +78 -0
  18. data/examples/focusmanager.rb +31 -0
  19. data/examples/imap.rb +48 -0
  20. data/examples/menu1.rb +79 -0
  21. data/examples/multispl.rb +86 -0
  22. data/examples/rfe.rb +3 -4
  23. data/examples/rmail.rb +188 -0
  24. data/examples/s.rb +10 -0
  25. data/examples/scrollbar.rb +104 -0
  26. data/examples/splitp.rb +56 -0
  27. data/examples/table1.rb +30 -0
  28. data/examples/term.rb +48 -0
  29. data/examples/term2.rb +54 -0
  30. data/examples/test1.rb +4 -2
  31. data/examples/test2.rb +9 -9
  32. data/examples/testapp.rb +44 -0
  33. data/examples/testapp2.rb +51 -0
  34. data/examples/testcombo.rb +2 -2
  35. data/examples/testgmail.rb +46 -0
  36. data/examples/testlistbox.rb +0 -1
  37. data/examples/testmultispl.rb +199 -0
  38. data/examples/testree.rb +127 -0
  39. data/examples/testscroller.rb +0 -1
  40. data/examples/testscrolllb.rb +1 -1
  41. data/examples/testscrollp.rb +2 -1
  42. data/examples/testscrollta.rb +1 -1
  43. data/examples/testscrolltable.rb +1 -2
  44. data/examples/testsplit.rb +1 -1
  45. data/examples/testsplit2.rb +1 -1
  46. data/examples/testsplit3.rb +1 -1
  47. data/examples/testsplit3_1.rb +1 -1
  48. data/examples/testsplit3a.rb +1 -1
  49. data/examples/testsplit3b.rb +1 -1
  50. data/examples/testsplitta.rb +1 -1
  51. data/examples/testsplittv.rb +1 -1
  52. data/examples/testsplittvv.rb +1 -1
  53. data/examples/testtodo.rb +491 -488
  54. data/examples/testvimsplit.rb +111 -0
  55. data/examples/todo.db +0 -0
  56. data/examples/todocsv.csv +28 -0
  57. data/examples/viewtodo.rb +408 -403
  58. data/lib/rbcurse/action.rb +1 -0
  59. data/lib/rbcurse/app.rb +1294 -0
  60. data/lib/rbcurse/applicationheader.rb +7 -2
  61. data/lib/rbcurse/checkboxcellrenderer.rb +0 -12
  62. data/lib/rbcurse/colormap.rb +34 -8
  63. data/lib/rbcurse/comboboxcellrenderer.rb +0 -11
  64. data/lib/rbcurse/defaultlistselectionmodel.rb +23 -7
  65. data/lib/rbcurse/extras/bottomline.rb +1681 -0
  66. data/lib/rbcurse/extras/directorylist.rb +445 -0
  67. data/lib/rbcurse/extras/directorytree.rb +69 -0
  68. data/lib/rbcurse/extras/divider.rb +310 -0
  69. data/lib/rbcurse/extras/focusmanager.rb +31 -0
  70. data/lib/rbcurse/extras/listselectable.rb +222 -0
  71. data/lib/rbcurse/extras/masterdetail.rb +164 -0
  72. data/lib/rbcurse/extras/menutree.rb +63 -0
  73. data/lib/rbcurse/extras/rlink.rb +27 -0
  74. data/lib/rbcurse/extras/rmenulink.rb +21 -0
  75. data/lib/rbcurse/extras/scrollbar.rb +134 -0
  76. data/lib/rbcurse/extras/stdscrwindow.rb +247 -0
  77. data/lib/rbcurse/extras/tabular.rb +258 -0
  78. data/lib/rbcurse/extras/tabularwidget.rb +1070 -0
  79. data/lib/rbcurse/extras/viewer.rb +106 -0
  80. data/lib/rbcurse/io.rb +137 -80
  81. data/lib/rbcurse/keylabelprinter.rb +4 -0
  82. data/lib/rbcurse/listcellrenderer.rb +91 -59
  83. data/lib/rbcurse/listscrollable.rb +93 -95
  84. data/lib/rbcurse/listselectable.rb +60 -7
  85. data/lib/rbcurse/ractionevent.rb +67 -0
  86. data/lib/rbcurse/rbasiclistbox.rb +688 -0
  87. data/lib/rbcurse/rcombo.rb +5 -5
  88. data/lib/rbcurse/rcommandwindow.rb +555 -0
  89. data/lib/rbcurse/rinputdataevent.rb +12 -0
  90. data/lib/rbcurse/rlistbox.rb +305 -124
  91. data/lib/rbcurse/rmenu.rb +99 -46
  92. data/lib/rbcurse/rmessagebox.rb +13 -6
  93. data/lib/rbcurse/rmulticontainer.rb +54 -93
  94. data/lib/rbcurse/rmultisplit.rb +731 -0
  95. data/lib/rbcurse/rmultitextview.rb +3 -2
  96. data/lib/rbcurse/rpopupmenu.rb +0 -1
  97. data/lib/rbcurse/rprogress.rb +117 -0
  98. data/lib/rbcurse/rscrollpane.rb +2 -1
  99. data/lib/rbcurse/rsplitpane.rb +94 -20
  100. data/lib/rbcurse/rsplitpane2.rb +1009 -0
  101. data/lib/rbcurse/rtabbedpane.rb +3 -2
  102. data/lib/rbcurse/rtabbedwindow.rb +0 -1
  103. data/lib/rbcurse/rtable.rb +92 -64
  104. data/lib/rbcurse/rtextarea.rb +91 -57
  105. data/lib/rbcurse/rtextview.rb +223 -70
  106. data/lib/rbcurse/rtree.rb +723 -0
  107. data/lib/rbcurse/rviewport.rb +2 -1
  108. data/lib/rbcurse/rvimsplit.rb +768 -0
  109. data/lib/rbcurse/rwidget.rb +524 -325
  110. data/lib/rbcurse/table/tablecellrenderer.rb +1 -1
  111. data/lib/rbcurse/table/tabledatecellrenderer.rb +0 -1
  112. data/lib/rbcurse/tree/treecellrenderer.rb +137 -0
  113. data/lib/rbcurse/tree/treemodel.rb +428 -0
  114. data/lib/rbcurse/vieditable.rb +14 -13
  115. data/lib/ver/ncurses.rb +6 -0
  116. data/lib/ver/window.rb +67 -32
  117. metadata +99 -23
  118. data/bin/rbcurse +0 -0
  119. data/examples/rvimsplit.rb +0 -376
  120. data/examples/todo.rb +0 -1
  121. data/lib/rbcurse/rform.rb +0 -845
  122. data/lib/rbcurse/selectable.rb +0 -94
  123. data/rbcurse.gemspec +0 -188
@@ -0,0 +1,17 @@
1
+ require 'rbcurse/app'
2
+
3
+ App.new do
4
+ header = app_header "rbcurse 1.2.0", :text_center => "Combo Demo", :text_right =>"New Improved!", :color => :black, :bgcolor => :white, :attr => :bold
5
+ message "Press F1 to exit from here"
6
+
7
+ stack :margin_top => 2, :margin => 10, :width => 80 do
8
+ list = %w[ highline ncurses thor tzinfo rack mail]
9
+ flow do
10
+ label "a label"
11
+ a = combo :list => list, :color_pair => $reversecolor #:bgcolor => :white, :color => :black
12
+ end
13
+ blank
14
+ b = combo :list => list, :color_pair => $reversecolor # , :label => 'a bbael'
15
+ b.set_label "a label" # this is unaware of stack margin
16
+ end # stack
17
+ end # app
@@ -0,0 +1,73 @@
1
+ require 'rbcurse/app'
2
+ require 'fileutils'
3
+ require 'rbcurse/tree/treemodel'
4
+ require 'rbcurse/extras/directorylist'
5
+ require 'rbcurse/extras/directorytree'
6
+
7
+ # TODO - tree expand - also populate list
8
+ # TODO - startup = populate list
9
+ App.new do
10
+ this = self
11
+ # this is for tree to get only directories
12
+ def _directories wd
13
+ $log.debug " directories got XXX: #{wd} "
14
+ d = Dir.new(wd)
15
+ ent = d.entries.reject{|e| !File.directory? File.join(wd,e)}
16
+ $log.debug " directories got XXX: #{ent} "
17
+ ent.delete(".");ent.delete("..")
18
+ return ent
19
+ end
20
+ ht = 24
21
+ borderattrib = :reverse
22
+ dl = RubyCurses::DirectoryList.new nil, :width=>40, :height => ht, :border_attrib => borderattrib, :selection_mode => :multiple, :suppress_borders => true
23
+ dl.title_attrib = "reverse"
24
+ #@l.bind :LIST_SELECTION_EVENT do |ev|
25
+ dl.bind :PRESS do |ev|
26
+ value = ev.source.text
27
+ #TODO when selecting, sync tree with this
28
+ end
29
+ pwd = Dir.getwd
30
+ entries = _directories pwd
31
+ patharray = pwd.split("/")
32
+ # we have an array of path, to add recursively, one below the other`
33
+ nodes = []
34
+ patharray[0]="/" if patharray.first == ""
35
+ nodes << TreeNode.new(patharray.shift)
36
+ patharray.each do |e|
37
+ nodes << nodes.last.add(e)
38
+ end
39
+ last = nodes.last
40
+ nodes.last.add entries
41
+ model = DefaultTreeModel.new nodes.first
42
+ header = app_header "rbcurse 1.2.0", :text_center => "Yet Another File Manager", :text_right =>"Directory Lister", :color => :black, :bgcolor => :white#, :attr => Ncurses::A_BLINK
43
+ message "Press Enter to expand/collapse"
44
+
45
+
46
+
47
+ stack :margin_top => 1, :margin => 0, :width => :EXPAND do
48
+ vimsplit :height => Ncurses.LINES-2, :weight => 0.4, :orientation => :VERTICAL, :suppress_borders => true do |s|
49
+ # TODO make this into a separate class in extras DirectoryTree
50
+ #@t = tree :data => model, :height => ht, :border_attrib => borderattrib, :suppress_borders => true
51
+ @t = RubyCurses::DirectoryTree.new nil, :data => model, :height => ht, :border_attrib => borderattrib, :suppress_borders => true, :default_value => last
52
+ # store for later use
53
+ @t.config[:dl] = dl
54
+ @t.config[:app] = this
55
+ def @t.selected_path_changed path
56
+ dl = @config[:dl]
57
+ dl.current_path path
58
+ end
59
+ def @t.path_expanded path
60
+ dl = @config[:dl]
61
+ dl.current_path path
62
+ o = @config[:app]
63
+ o.message " #{path} will be expanded "
64
+ end
65
+ @t.expand_node last #
66
+ #@t.mark_parents_expanded last # make parents visible
67
+ @t.expand_parents last # make parents visible and expand
68
+ s.add @t, :FIRST
69
+ #@l = list_box :height => ht, :border_attrib => borderattrib, :selection_mode => :multiple
70
+ s.add dl, :SECOND
71
+ end # vimsplit
72
+ end # flow
73
+ end # app
@@ -0,0 +1,164 @@
1
+ require 'rbcurse/app'
2
+ require 'fileutils'
3
+ require './rmail'
4
+ # You need mailread.rb which is present in 1.8, but missing in 1.9
5
+ # I've loaded it here ... http://gist.github.com/634166 with line encoding
6
+ # You need to fix paths of local mbox files
7
+
8
+ def testchoose
9
+ # list filters as you type
10
+ $log.debug "called test1 " if $log.debug?
11
+ str = choose "*", :title => "Files", :prompt => "Choose a file: "
12
+ end
13
+ def testnumberedmenu
14
+ list1 = %w{ ruby perl python erlang rake java lisp scheme chicken }
15
+ list1[0] = %w{ ruby ruby1.9 ruby1.8.x jruby rubinius ROR }
16
+ str = numbered_menu list1, { :title => "Languages: ", :prompt => "Select :" }
17
+ say "We got #{str} "
18
+ end
19
+ def testdisplay_list
20
+ # scrollable list
21
+ str = display_list Dir.glob("t*.rb"), :title => "Select a file"
22
+ message "We got #{str} "
23
+ end
24
+ def testdisplay_text
25
+ str = display_text_interactive File.read($0), :title => "Select a file"
26
+ end
27
+ def testdir
28
+ # this behaves like vim's file selector, it fills in values
29
+ str = ask("File? ", Pathname) do |q|
30
+ q.completion_proc = Proc.new {|str| Dir.glob(str +"*").collect { |f| File.directory?(f) ? f+"/" : f } }
31
+ q.helptext = "Enter start of filename and tab to get completion"
32
+ end
33
+ message "We got #{str} "
34
+ end
35
+ def test
36
+ #require 'rbcurse/rcommandwindow'
37
+ #rc = CommandWindow.new
38
+ scr = Ncurses.stdscr
39
+ #scr.color_set $promptcolor, nil
40
+ Ncurses.attron(Ncurses.COLOR_PAIR($promptcolor))
41
+ Ncurses.mvprintw 27,0,"helllllo theeeerE "
42
+ Ncurses.attroff(Ncurses.COLOR_PAIR($promptcolor))
43
+ scr.refresh()
44
+ end
45
+ def saveas1
46
+ @tv.saveas
47
+ end
48
+
49
+ # experimental.
50
+ # if components have some commands, can we find a way of passing the command to them
51
+ # method_missing gave a stack overflow.
52
+ def execute_this(meth, *args)
53
+ $log.debug "app email got #{meth} " if $log.debug?
54
+ cc = @vim.current_component
55
+ [cc, @lb2, @tv].each do |c|
56
+ if c.respond_to?(meth, true)
57
+ c.send(meth, *args)
58
+ return true
59
+ end
60
+ end
61
+ false
62
+ end
63
+
64
+ App.new do
65
+ ht = 24
66
+ @messages = nil
67
+ $unread_hash = {}
68
+ @tv = nil
69
+ borderattrib = :reverse
70
+ @header = app_header "rbcurse 1.2.0", :text_center => "Yet Another Email Client that sucks", :text_right =>"", :color => :black, :bgcolor => :white#, :attr => Ncurses::A_BLINK
71
+ message "Press F1 to exit ...................................................."
72
+
73
+
74
+ stack :margin_top => 1, :margin => 0, :width => :EXPAND do
75
+ # NOTE: please fix the next 2 lines based on where your mbox files reside
76
+ model = ["~/mbox"]
77
+ others = "~/mail/"
78
+ boxes = Dir.new(File.expand_path(others)).entries
79
+ boxes.delete(".")
80
+ boxes.delete("..")
81
+ boxes = boxes.collect do |e| others+e; end
82
+ model.push *boxes
83
+
84
+ #@vim = MasterDetail.new @form, :row => 1, :col => 1, :width => :EXPAND
85
+ @vim = master_detail :width => :EXPAND
86
+ @dirs = list_box :list => model, :height => ht, :border_attrib => borderattrib, :suppress_borders => true
87
+ @dirs.one_key_selection = false
88
+
89
+ # commands that can be mapped to or executed using M-x
90
+ # however, commands of components aren't yet accessible.
91
+ def get_commands
92
+ %w{ testchoose testnumberedmenu testdisplay_list testdisplay_text testdir saveas1 }
93
+ end
94
+ # we override so as to only print basename. Also, print unread count
95
+ def @dirs.convert_value_to_text(text, crow)
96
+ str = File.basename(text)
97
+ if $unread_hash.has_key?(str)
98
+ str << " (#{$unread_hash[str]})"
99
+ else
100
+ str
101
+ end
102
+ end
103
+ def test1XX
104
+ $log.debug "called test1 " if $log.debug?
105
+ str = choose "*.rb", :title => "Files", :prompt => "Choose a file: "
106
+ end
107
+ @vim.set_left_component @dirs
108
+
109
+
110
+ @mails = []
111
+ headings = %w{ Stat # Date From Subject }
112
+ @lb2 = tabular_widget :suppress_borders => true
113
+ @lb2.columns = headings
114
+ @lb2.column_align 1, :right
115
+ @lb2.column_align 0, :right
116
+ @lb2.header_fgcolor :white
117
+ @lb2.header_bgcolor :cyan
118
+ @vim.set_right_top_component @lb2
119
+ @dirs.bind :PRESS do |e|
120
+ @lines = []
121
+ mx = Mbox.new File.expand_path(e.text)
122
+ mx.array_each do |text|
123
+ @lines << text
124
+ end
125
+ message_immediate " #{e.text} has #{@lines.size} messages"
126
+ $unread_hash[File.basename(e.text)] = mx.unread_count
127
+ @lb2.set_content @lines
128
+ @lb2.estimate_column_widths=true
129
+ @messages = mx.mails()
130
+ end
131
+ @lb2.bind :PRESS do |e|
132
+ case @lb2
133
+ when RubyCurses::TabularWidget
134
+ if e.action_command == :header
135
+ # now does sorting on multiple keys
136
+ else
137
+ index = e.source.current_index - 1 # this should check what first data index is
138
+ if index >= 0
139
+ @tv.set_content(@messages[index].body, :WRAP_WORD)
140
+ end
141
+ end
142
+ else
143
+ @tv.set_content(@messages[e.source.current_index].body, :WRAP_WORD)
144
+ end
145
+ end
146
+ @lb2.bind :ENTER_ROW do |e|
147
+ @header.text_right "Row #{e.current_index} of #{@messages.size} "
148
+ #message_immediate "Row #{e.current_index} of #{@messages.size} "
149
+ raw_message "Row #{e.current_index} of #{@messages.size} "
150
+ x = e.current_index
151
+ y = @messages.size
152
+ #raw_progress((x*1.0)/y)
153
+ raw_progress([x,y])
154
+ end
155
+
156
+ @tv = @vim.set_right_bottom_component "Email body comes here. "
157
+ @tv.suppress_borders true
158
+ @tv.border_attrib = borderattrib
159
+ end # stack
160
+ @form.bind_key(?\M-v) { test11() }
161
+ @form.bind_key(?\M-V) { testme() }
162
+ @form.bind_key(?\M-c) { test1() }
163
+ @form.bind_key(?\M-C) { test2() }
164
+ end # app
@@ -0,0 +1,308 @@
1
+ require 'rbcurse/app'
2
+ require 'rbcurse/rvimsplit'
3
+ require 'fileutils'
4
+ require 'rbcurse/extras/tabularwidget'
5
+ require './rmail'
6
+ class ColumnBrowse < Widget
7
+ require 'forwardable'
8
+ extend Forwardable
9
+ def_delegators :@vim, :on_enter, :on_leave, :handle_key
10
+ def initialize form, config={}, &block
11
+ @focusable = true
12
+ @height = Ncurses.LINES-2
13
+ @weight = 0.25
14
+ super
15
+ _create_vimsplit
16
+ init_vars
17
+ end
18
+ def init_vars
19
+ @first_time = true
20
+ @repaint_required = true
21
+ end
22
+ def repaint
23
+ if @first_time
24
+ @first_time = nil
25
+ [@vim, @left, @right1, @right2].each { |e|
26
+ e.set_buffering(:target_window => @target_window || @form.window, :form => @form)
27
+ }
28
+ end
29
+ @vim.repaint
30
+ end
31
+ def set_left_component comp
32
+ @left = @vim.add comp, :FIRST
33
+ _add_component comp
34
+ @left
35
+ end
36
+ def set_right_top_component comp
37
+ @added_top = true
38
+ @right1 = @vim.add comp, :SECOND, 0.5
39
+ _add_component comp
40
+ @right1
41
+ end
42
+ def set_right_bottom_component comp
43
+ raise "Please add top component first!" unless @added_top
44
+ # what if user gives in wrong order !!
45
+ @gb = @vim.add :grabbar, :SECOND, 0
46
+ @right2 = @vim.add comp, :SECOND, nil
47
+ @gb.next(@right2)
48
+ _add_component comp
49
+ @right2
50
+ end
51
+ private
52
+ def _add_component comp #:nodoc:
53
+ #comp.parent = self
54
+ #comp.form = @form
55
+ end
56
+ def _create_vimsplit #:nodoc:
57
+ @vim = VimSplit.new nil, :row => @row, :col => @col, :width => @width, :height => @height, :weight => @weight, :orientation => :VERTICAL, :suppress_borders => true do |s|
58
+ s.parent_component = self
59
+ #s.target_window = @form.window
60
+ #s.add @left, :FIRST
61
+ #s.add @right1, :SECOND
62
+ #s.add @right2, :SECOND
63
+ s.bind :COMPONENT_RESIZE_EVENT do |e|
64
+ #alert "got a resize event #{e.type} "
65
+ case e.type
66
+ when :INCREASE
67
+ case e.source
68
+ when @right2
69
+ increase_body
70
+ when @right1
71
+ increase_headers
72
+ when @left
73
+
74
+ end
75
+ when :DECREASE
76
+ case e.source
77
+ when @right2
78
+ increase_headers
79
+ when @right1
80
+ increase_body
81
+ when @left
82
+ @left.width -= 1
83
+ @right2.col -=1
84
+ @right1.col -=1
85
+ @right1.width +=1
86
+ @right2.width +=1
87
+ @right2.repaint_required true
88
+ @right1.repaint_required true
89
+ @left.repaint_required true
90
+ end
91
+ when :EXPAND
92
+ case e.source
93
+ when @right2
94
+ h = 3
95
+ @right2.row(@right1.row + h)
96
+ oldh = @right1.height
97
+ @right1.height = h
98
+ @right1.current_index = 0
99
+ @right2.height += (oldh - h)
100
+ @right2.repaint_required true
101
+ @right1.repaint_required true
102
+ when @right1
103
+ h = 3
104
+ @right2.row(@right2.row + (@right2.height - 3))
105
+ oldh = @right2.height
106
+ @right2.height = h
107
+ #@right1.current_index = 0
108
+ @right1.height += (oldh - h)
109
+ @right2.repaint_required true
110
+ @right1.repaint_required true
111
+ end
112
+ end
113
+ end # bind
114
+ end
115
+ end # def
116
+ def increase_headers
117
+ @right2.row @right2.row()+1
118
+ @right1.height +=1
119
+ @right2.height -=1
120
+ @right2.repaint_required true
121
+ @right1.repaint_required true
122
+ end
123
+ def increase_body
124
+ @right2.row @right2.row()-1
125
+ @right1.height -=1
126
+ @right2.height +=1
127
+ @right2.repaint_required true
128
+ @right1.repaint_required true
129
+ end
130
+ end # class
131
+
132
+ class MailCellRenderer #< ListCellRenderer
133
+ include RubyCurses::ConfigSetup
134
+ include RubyCurses::Utils
135
+ dsl_accessor :justify # :right, :left, :center # added 2008-12-22 19:02
136
+ dsl_accessor :display_length # please give this to ensure the we only print this much
137
+ dsl_accessor :height # if you want a multiline label.
138
+ dsl_accessor :text # text of label
139
+ dsl_accessor :color, :bgcolor
140
+ dsl_accessor :row, :col
141
+ dsl_accessor :parent #usuall the table to get colors and other default info
142
+
143
+ def initialize text="", config={}, &block
144
+ @text = text
145
+ @editable = false
146
+ @focusable = false
147
+ config_setup config # @config.each_pair { |k,v| variable_set(k,v) }
148
+ instance_eval &block if block_given?
149
+ init_vars
150
+ end
151
+ # NOTE: please call super() if you override this
152
+ def init_vars #:nodoc:
153
+ # omg, some classes won't have justify !!
154
+ #@justify ||= (@parent.justify || :left)
155
+ unless @justify
156
+ if @parent.respond_to? :justify
157
+ @justify ||= (@parent.justify || :left)
158
+ else
159
+ @justify ||= :left
160
+ end
161
+ end
162
+ @format = @justify.to_sym == :right ? "%*s" : "%-*s"
163
+ @display_length ||= 10
164
+ # create color pairs once for this 2010-09-26 20:53
165
+ end
166
+ # creates pairs of colors at start
167
+ # since often classes are overriding init_vars, so not gettin created
168
+ def create_color_pairs
169
+ @color_pair = get_color $datacolor
170
+ @pairs = Hash.new(@color_pair)
171
+ @attrs = Hash.new(Ncurses::A_NORMAL)
172
+ color_pair = get_color $selectedcolor, @parent.selected_color, @parent.selected_bgcolor
173
+ @pairs[:normal] = @color_pair
174
+ @pairs[:selected] = color_pair
175
+ @pairs[:focussed] = @pairs[:normal]
176
+ @attrs[:selected] = $row_selected_attr
177
+ @attrs[:focussed] = $row_focussed_attr
178
+
179
+ end
180
+ #def getvalue
181
+ #@text
182
+ #end
183
+ ##
184
+ # sets @color_pair and @attr
185
+ def select_colors focussed, selected
186
+ create_color_pairs unless @pairs
187
+ raise ArgumentError, "pairs hash is null. Changes have happened in listcellrenderer" unless @pairs
188
+ @color_pair = @pairs[:normal]
189
+ @attr = $row_attr
190
+ # give precedence to a selected row
191
+ if selected
192
+ @color_pair = @pairs[:selected]
193
+ @attr = @attrs[:selected]
194
+ elsif focussed
195
+ @color_pair = @pairs[:focussed]
196
+ @attr = @attrs[:focussed]
197
+ end
198
+ end
199
+
200
+ ##
201
+ # paint a list box cell
202
+ #
203
+ # @param [Buffer] window or buffer object used for printing
204
+ # @param [Fixnum] row
205
+ # @param [Fixnum] column
206
+ # @param [Fixnum] actual index into data, some lists may have actual data elsewhere and
207
+ # display data separate. e.g. rfe_renderer (directory listing)
208
+ # @param [String] text to print in cell
209
+ # @param [Boolean, cell focussed, not focussed
210
+ # @param [Boolean] cell selected or not
211
+ def repaint graphic, r=@row,c=@col, row_index=-1,value=@text, focussed=false, selected=false
212
+
213
+ select_colors focussed, selected
214
+ # if listboxes width is reduced, display_len remains the same
215
+ # XXX FIXME parent may not be the list but a container like rfe !!
216
+ # maybe caller should update at start of repain loop.
217
+ #@display_length = @parent.width - 2 - @parent.left_margin
218
+
219
+ value=value.to_s
220
+ if !@display_length.nil?
221
+ if value.length > @display_length
222
+ value = value[0..@display_length-1]
223
+ end
224
+ # added 2010-09-27 11:05 TO UNCOMMENT AND TEST IT OUT
225
+ if @justify == :center
226
+ value = value.center(@display_length)
227
+ end
228
+ end
229
+ len = @display_length || value.length
230
+ graphic.printstring r, c, @format % [len, value], @color_pair, @attr
231
+ if value =~ /^ *O/
232
+ graphic.mvchgat(y=r, x=c,3, Ncurses::A_NORMAL, $promptcolor, nil)
233
+ else
234
+ graphic.mvchgat(y=r, x=c,3, Ncurses::A_NORMAL, $datacolor, nil)
235
+ end
236
+
237
+ end # repaiat
238
+
239
+ end # class
240
+
241
+ App.new do
242
+ # this is for tree to get only directories
243
+ ht = 24
244
+ @messages = nil
245
+ @tv = nil
246
+ borderattrib = :reverse
247
+ @header = app_header "rbcurse 1.2.0", :text_center => "Yet Another Email Client that sucks", :text_right =>"", :color => :black, :bgcolor => :white#, :attr => Ncurses::A_BLINK
248
+ message "Press F1 to exit ...................................................."
249
+
250
+
251
+
252
+
253
+
254
+ stack :margin_top => 1, :margin => 0, :width => :EXPAND do
255
+ model = ["~/mbox"]
256
+ boxes = Dir.new(File.expand_path("~/mail/")).entries
257
+ boxes.delete(".")
258
+ boxes.delete("..")
259
+ boxes = boxes.collect do |e| "~/mail/"+e; end
260
+ model.push *boxes
261
+ #@vim = vimsplit :height => Ncurses.LINES-2, :weight => 0.25, :orientation => :VERTICAL do |s|
262
+ # try with new listbox
263
+ @vim = ColumnBrowse.new @form, :row => 1, :col => 1, :width => :EXPAND
264
+ @dirs = list_box :list => model, :height => ht, :border_attrib => borderattrib, :suppress_borders => true
265
+ @dirs.one_key_selection = false
266
+ def @dirs.convert_value_to_text(text, crow) ; File.basename(text); end
267
+ @vim.set_left_component @dirs
268
+
269
+ #@tw = TabularWidget.new nil
270
+ @mails = []
271
+ # FIXME why was list required in next, should have managed. length
272
+ # error
273
+ @lb2 = list_box :border_attrib => borderattrib, :suppress_borders => true #, :list => []
274
+ @lb2.one_key_selection = false
275
+ def @lb2.create_default_cell_renderer
276
+ return MailCellRenderer.new "", {"color"=>@color, "bgcolor"=>@bgcolor, "parent" => self, "display_length"=> @width-@internal_width-@left_margin}
277
+ end
278
+ @vim.set_right_top_component @lb2
279
+ @dirs.bind :PRESS do |e|
280
+ @lines = []
281
+ mx = Mbox.new File.expand_path(e.text)
282
+ mx.formatted_each do |text|
283
+ @lines << text
284
+ #@tw.add text
285
+ end
286
+ message " #{e.text} has #{@lines.size} messages"
287
+ @lb2.list @lines
288
+ @messages = mx.mails()
289
+ end
290
+ @lb2.bind :PRESS do |e|
291
+ #alert " line clicked #{e.source.current_index} "
292
+ @tv.set_content(@messages[e.source.current_index].body, :WRAP_WORD)
293
+ end
294
+ @lb2.bind :ENTER_ROW do |e|
295
+ @header.text_right "Row #{e.current_index+1} of #{@messages.size} "
296
+ end
297
+
298
+ #s.add @dirs, :FIRST
299
+ #@tw.columns = [
300
+ #s.add @lb2, :SECOND
301
+ #@tv = textview
302
+ #s.add "email body comes here. Press Enter on list above", :SECOND
303
+ @tv = @vim.set_right_bottom_component "email body comes here. "
304
+ #@tv = s.components_for(:SECOND).last
305
+ @tv.suppress_borders true
306
+ @tv.border_attrib = borderattrib
307
+ end # stack
308
+ end # app