rbcurse 1.4.0 → 1.4.1.pre2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. data/NOTES +68 -0
  2. data/README.markdown +73 -330
  3. data/TODO2.txt +2 -2
  4. data/VERSION +1 -1
  5. data/examples/abasiclist.rb +8 -2
  6. data/examples/alpmenu.rb +1 -1
  7. data/examples/app.rb +1 -24
  8. data/examples/appdirtree.rb +1 -1
  9. data/examples/appemail.rb +8 -14
  10. data/examples/appemaillb.rb +2 -2
  11. data/examples/appgcompose.rb +7 -5
  12. data/examples/common/file.rb +40 -0
  13. data/examples/{rmail.rb → common/rmail.rb} +0 -0
  14. data/examples/data/README.markdown +9 -0
  15. data/examples/data/brew.txt +38 -0
  16. data/examples/data/color.2 +37 -0
  17. data/examples/data/gemlist.txt +60 -0
  18. data/examples/data/lotr.txt +12 -0
  19. data/examples/data/ports.txt +136 -0
  20. data/examples/data/tasks.txt +27 -0
  21. data/examples/{todocsv.csv → data/todocsv.csv} +0 -0
  22. data/examples/data/unix1.txt +21 -0
  23. data/examples/data/unix2.txt +11 -0
  24. data/examples/dbdemo.rb +49 -14
  25. data/examples/{appgmail.rb → deprecated/appgmail.rb} +1 -1
  26. data/examples/{splitp.rb → deprecated/splitp.rb} +0 -0
  27. data/examples/{testscrolllb.rb → deprecated/testscrolllb.rb} +0 -0
  28. data/examples/{testscrollp.rb → deprecated/testscrollp.rb} +0 -0
  29. data/examples/{testscrollta.rb → deprecated/testscrollta.rb} +0 -0
  30. data/examples/{testscrolltable.rb → deprecated/testscrolltable.rb} +0 -0
  31. data/examples/{testsplit.rb → deprecated/testsplit.rb} +0 -0
  32. data/examples/{testsplit2.rb → deprecated/testsplit2.rb} +0 -0
  33. data/examples/{testsplit3.rb → deprecated/testsplit3.rb} +0 -0
  34. data/examples/{testsplit3_1.rb → deprecated/testsplit3_1.rb} +0 -0
  35. data/examples/{testsplit3a.rb → deprecated/testsplit3a.rb} +0 -0
  36. data/examples/{testsplit3b.rb → deprecated/testsplit3b.rb} +0 -0
  37. data/examples/{testsplitta.rb → deprecated/testsplitta.rb} +0 -0
  38. data/examples/{testsplittv.rb → deprecated/testsplittv.rb} +0 -0
  39. data/examples/{testsplittvv.rb → deprecated/testsplittvv.rb} +0 -0
  40. data/examples/{testtpane.rb → deprecated/testtpane.rb} +0 -0
  41. data/examples/{testtpane2.rb → deprecated/testtpane2.rb} +0 -0
  42. data/examples/{testtpanetable.rb → deprecated/testtpanetable.rb} +0 -0
  43. data/examples/dirtree.rb +17 -7
  44. data/examples/experimental/resultsetdemo.rb +280 -0
  45. data/examples/experimental/testmform.rb +35 -0
  46. data/examples/{testscroller.rb → experimental/testscroller.rb} +1 -19
  47. data/examples/experimental/teststackflow.rb +111 -0
  48. data/examples/menu1.rb +1 -0
  49. data/examples/multispl.rb +4 -4
  50. data/examples/newmessagebox.rb +130 -0
  51. data/examples/newtabbedwindow.rb +100 -0
  52. data/examples/newtesttabp.rb +0 -3
  53. data/examples/qdfilechooser.rb +0 -3
  54. data/examples/rfe.rb +134 -18
  55. data/examples/rfe_renderer.rb +48 -2
  56. data/examples/sqlc.rb +2 -1
  57. data/examples/sqlm.rb +0 -2
  58. data/examples/table1.rb +1 -7
  59. data/examples/term2.rb +4 -1
  60. data/examples/test1.rb +0 -5
  61. data/examples/test2.rb +42 -31
  62. data/examples/testapp2.rb +8 -1
  63. data/examples/testchars.rb +0 -4
  64. data/examples/testcombo.rb +5 -9
  65. data/examples/testkeypress.rb +0 -3
  66. data/examples/testmenu.rb +0 -4
  67. data/examples/testmulticomp.rb +3 -5
  68. data/examples/testmulticontainer.rb +94 -0
  69. data/examples/testtable.rb +0 -5
  70. data/examples/testtabp.rb +16 -18
  71. data/examples/testtodo.rb +1 -5
  72. data/examples/testwsshortcuts.rb +64 -0
  73. data/examples/testwsshortcuts2.rb +126 -0
  74. data/examples/viewtodo.rb +1 -4
  75. data/lib/rbcurse.rb +1 -1
  76. data/lib/rbcurse/app.rb +92 -69
  77. data/lib/rbcurse/applicationheader.rb +46 -6
  78. data/lib/rbcurse/celleditor.rb +1 -9
  79. data/lib/rbcurse/comboboxcellrenderer.rb +0 -4
  80. data/lib/rbcurse/common/ansiparser.rb +117 -0
  81. data/{examples → lib/rbcurse/common}/appmethods.rb +25 -0
  82. data/lib/rbcurse/common/basestack.rb +407 -0
  83. data/lib/rbcurse/common/bordertitle.rb +41 -0
  84. data/lib/rbcurse/common/chunk.rb +177 -0
  85. data/lib/rbcurse/common/colorparser.rb +71 -0
  86. data/lib/rbcurse/common/keydefs.rb +30 -0
  87. data/lib/rbcurse/common/widgetshortcuts.rb +302 -0
  88. data/lib/rbcurse/deprecated/README.markdown +12 -0
  89. data/lib/rbcurse/{rscrollpane.rb → deprecated/rscrollpane.rb} +0 -0
  90. data/lib/rbcurse/{rsplitpane.rb → deprecated/rsplitpane.rb} +0 -0
  91. data/lib/rbcurse/{rsplitpane2.rb → deprecated/rsplitpane2.rb} +0 -0
  92. data/lib/rbcurse/{rviewport.rb → deprecated/rviewport.rb} +0 -0
  93. data/lib/rbcurse/experimental/README.markdown +14 -0
  94. data/lib/rbcurse/experimental/resultsettextview.rb +585 -0
  95. data/lib/rbcurse/experimental/stackflow.rb +478 -0
  96. data/lib/rbcurse/extras/bottomline.rb +85 -16
  97. data/lib/rbcurse/extras/box.rb +58 -0
  98. data/lib/rbcurse/extras/directorylist.rb +1 -1
  99. data/lib/rbcurse/extras/horizlist.rb +203 -0
  100. data/lib/rbcurse/extras/listselectable.rb +8 -0
  101. data/lib/rbcurse/extras/multiform.rb +330 -0
  102. data/lib/rbcurse/extras/multilinelabel.rb +142 -0
  103. data/lib/rbcurse/extras/newmessagebox.rb +328 -0
  104. data/lib/rbcurse/extras/newtabbedpane.rb +612 -0
  105. data/lib/rbcurse/extras/newtabbedwindow.rb +68 -0
  106. data/lib/rbcurse/extras/padreader.rb +189 -0
  107. data/lib/rbcurse/extras/rcomboedit.rb +256 -0
  108. data/lib/rbcurse/extras/resultsetbrowser.rb +281 -0
  109. data/lib/rbcurse/extras/statusline.rb +44 -6
  110. data/lib/rbcurse/extras/tabularwidget.rb +141 -104
  111. data/lib/rbcurse/extras/textpad.rb +516 -0
  112. data/lib/rbcurse/extras/viewer.rb +2 -0
  113. data/lib/rbcurse/io.rb +120 -3
  114. data/lib/rbcurse/listcellrenderer.rb +2 -1
  115. data/lib/rbcurse/listkeys.rb +1 -1
  116. data/lib/rbcurse/listscrollable.rb +72 -7
  117. data/lib/rbcurse/rbasiclistbox.rb +64 -12
  118. data/lib/rbcurse/rchangeevent.rb +0 -1
  119. data/lib/rbcurse/rcombo.rb +54 -59
  120. data/lib/rbcurse/rcommandwindow.rb +46 -10
  121. data/lib/rbcurse/rcontainer.rb +415 -0
  122. data/lib/rbcurse/rdialogs.rb +242 -165
  123. data/lib/rbcurse/rinputdataevent.rb +0 -1
  124. data/lib/rbcurse/rlistbox.rb +19 -9
  125. data/lib/rbcurse/rmessagebox.rb +1 -5
  126. data/lib/rbcurse/rmulticontainer.rb +64 -61
  127. data/lib/rbcurse/rmultitextview.rb +0 -2
  128. data/lib/rbcurse/rpopupmenu.rb +0 -2
  129. data/lib/rbcurse/rscrollform.rb +61 -12
  130. data/lib/rbcurse/rtabbedpane.rb +89 -73
  131. data/lib/rbcurse/rtabbedwindow.rb +53 -211
  132. data/lib/rbcurse/rtable.rb +0 -2
  133. data/lib/rbcurse/rtextarea.rb +14 -14
  134. data/lib/rbcurse/rtextview.rb +165 -50
  135. data/lib/rbcurse/rvimsplit.rb +15 -12
  136. data/lib/rbcurse/rwidget.rb +404 -150
  137. data/lib/rbcurse/table/tablecellrenderer.rb +1 -4
  138. data/lib/rbcurse/table/tabledatecellrenderer.rb +0 -3
  139. data/lib/ver/ncurses.rb +1 -9
  140. data/lib/ver/rpad.rb +375 -0
  141. data/lib/ver/window.rb +262 -440
  142. metadata +73 -31
data/examples/testtodo.rb CHANGED
@@ -1,8 +1,4 @@
1
- #$LOAD_PATH << "/Users/rahul/work/projects/rbcurse/"
2
- require 'rubygems'
3
- #require 'ncurses' # FFI
4
1
  require 'logger'
5
- #require 'ver/keyboard'
6
2
  require 'rbcurse'
7
3
  require 'rbcurse/rcombo'
8
4
  require 'rbcurse/rtable'
@@ -115,7 +111,7 @@ module TestTodo
115
111
  d = @data
116
112
  require 'csv'
117
113
  #CSV.open('todocsv.csv', 'w') do |writer|
118
- CSV.open("todocsv.csv", "w") do |writer|
114
+ CSV.open("data/todocsv.csv", "w") do |writer|
119
115
  #writer << [nil, nil]
120
116
  d.each do |row|
121
117
  #parced_cells = CSV.generate_rows(row, row.size, buf)
@@ -0,0 +1,64 @@
1
+ # this is a test program, tests out tabbed panes. type F1 to exit
2
+ #
3
+ require 'rbcurse'
4
+ require 'rbcurse/common/widgetshortcuts'
5
+
6
+ include RubyCurses
7
+
8
+ class SetupMessagebox
9
+ include RubyCurses::WidgetShortcuts
10
+ def initialize config={}, &block
11
+ @window = VER::Window.root_window
12
+ @form = Form.new @window
13
+ end
14
+ def run
15
+ _create_form
16
+ @form.repaint
17
+ @window.wrefresh
18
+ while ((ch = @window.getchar()) != 999)
19
+ break if ch == ?\C-q.getbyte(0)
20
+ @form.handle_key ch
21
+ @window.wrefresh
22
+ end
23
+ end
24
+ def _create_form
25
+ widget_shortcuts_init
26
+ stack :margin_top => 2, :margin_left => 3, :width => 50 , :color => :cyan, :bgcolor => :black do
27
+ label :text => " Details ", :color => :blue, :attr => :reverse, :width => :expand, :justify => :center
28
+ blank
29
+ field :text => "john", :attr => :reverse, :label => "%15s" % ["Name: "]
30
+ field :label => "%15s" % ["Address: "], :width => 15, :attr => :reverse
31
+ check :text => "Using version control", :value => true, :onvalue => "yes", :offvalue => "no"
32
+ check :text => "Upgraded to Lion", :value => false, :onvalue => "yes", :offvalue => "no"
33
+ blank
34
+ radio :text => "Linux", :value => "LIN", :group => :os
35
+ radio :text => "OSX", :value => "OSX", :group => :os
36
+ radio :text => "Window", :value => "Win", :group => :os
37
+ flow :margin_top => 2, :margin_left => 4, :item_width => 15 do
38
+ button :text => "Ok"
39
+ button :text => "Cancel"
40
+ button :text => "Apply"
41
+ end
42
+ end
43
+ end
44
+
45
+ end
46
+ if $0 == __FILE__
47
+ # Initialize curses
48
+ begin
49
+ # XXX update with new color and kb
50
+ VER::start_ncurses # this is initializing colors via ColorMap.setup
51
+ $log = Logger.new((File.join(ENV["LOGDIR"] || "./" ,"rbc13.log")))
52
+ $log.level = Logger::DEBUG
53
+ tp = SetupMessagebox.new()
54
+ buttonindex = tp.run
55
+ $log.debug "XXX: MESSAGEBOX retirned #{buttonindex} "
56
+ rescue => ex
57
+ ensure
58
+ VER::stop_ncurses
59
+ p ex if ex
60
+ p(ex.backtrace.join("\n")) if ex
61
+ $log.debug( ex) if ex
62
+ $log.debug(ex.backtrace.join("\n")) if ex
63
+ end
64
+ end
@@ -0,0 +1,126 @@
1
+ # this is a test program, tests out tabbed panes. type F1 to exit
2
+ #
3
+ require 'rbcurse'
4
+ require 'rbcurse/common/widgetshortcuts'
5
+
6
+ include RubyCurses
7
+ include RubyCurses::Utils
8
+
9
+ class SetupMessagebox
10
+ include RubyCurses::WidgetShortcuts
11
+ def initialize config={}, &block
12
+ @window = VER::Window.root_window
13
+ @form = Form.new @window
14
+ end
15
+ def run
16
+ _create_form
17
+ @form.repaint
18
+ @window.wrefresh
19
+ catch(:close) do
20
+ while ((ch = @window.getchar()) != 999)
21
+ break if ch == ?\C-q.getbyte(0)
22
+ @form.handle_key ch
23
+ @window.wrefresh
24
+ end
25
+ end # catch
26
+ end
27
+ def _create_form
28
+ widget_shortcuts_init
29
+ stack :margin_top => 1, :width => :expand do
30
+ label :text => " Details ", :color => :cyan, :attr => :reverse, :width => :expand, :justify => :center
31
+ flow :margin_top => 1, :margin_left => 4, :item_width => 50 do
32
+ stack :margin_top => 0, :margin_left => 3, :width => 50 , :color => :cyan, :bgcolor => :black do
33
+ box do
34
+ field :text => "steve", :attr => :reverse, :label => "%15s" % ["Name: "]
35
+ field :label => "%15s" % ["Address: "], :width => 15, :attr => :reverse
36
+ blank
37
+ check :text => "Using version control", :value => true, :onvalue => "yes", :offvalue => "no" do |eve|
38
+ unless eve.item.value
39
+ alert "NO VC! We need to talk"
40
+ end
41
+ end
42
+ check :text => "Upgraded to Lion", :value => false, :onvalue => "yes", :offvalue => "no" do |eve|
43
+ unless eve.item.value
44
+ alert "You goin back to Snow Leopard?"
45
+ end
46
+ end
47
+ end # box
48
+ end
49
+ stack :margin_top => 0, :margin_left => 3, :width => 50 , :color => :cyan, :bgcolor => :black do
50
+ box :title => "OS Maintenance", :margin_left => 2 do
51
+ radio :text => "Linux", :value => "LIN", :group => :os
52
+ radio :text => "OSX", :value => "OSX", :group => :os
53
+ radio :text => "Window", :value => "Win", :group => :os
54
+ blank
55
+ flow :item_width => 15 do
56
+ button :text => "Install" do
57
+ # you can avoid this by giving the radio buttons your own Variable (see test2.rb)
58
+ choice = @variables[:os].value
59
+ case choice
60
+ when ""
61
+ alert "Select an OS"
62
+ when "OSX", "LIN"
63
+ alert "Good choice"
64
+ else
65
+ alert "Pfft !"
66
+ end
67
+ end
68
+ button :text => "Uninstall"
69
+ button :text => "Delete"
70
+ end
71
+ end # box
72
+ end
73
+ end # flow
74
+ #button :text => "Execute"
75
+ text = [" #[reverse]Unix Philosophy #[end] ",
76
+ "#[fg=green, underline]Eric Raymond#[end] in his book, #[fg=green, underline]The Art of Unix Programming#[end] summarized the Unix philosophy.",
77
+ " ",
78
+ "Rule of #[fg=yellow]Modularity#[end]: Write simple parts connected by clean interfaces.",
79
+ "Rule of #[fg=blue]Clarity#[end]: #[bold]Clarity#[end] is better than cleverness.",
80
+ "Rule of #[fg=red]Separation#[end]: Separate #[bold]policy#[end] from mechanism; separate interfaces from engines.",
81
+ "Rule of #[fg=green]Simplicity#[end]: Design for #[bold]simplicity;#[end] add complexity only where you must.",
82
+ "Rule of #[fg=magenta]Parsimony#[end]: Write a big program only when it is clear by demonstration that nothing else will do.",
83
+ "Rule of #[fg=cyan]Representation#[end]: Fold knowledge into #[bold]data#[end] so program logic can be stupid and robust"]
84
+ text << "For more check: #[underline]http://en.wikipedia.org/wiki/Unix_philosophy#Eric_Raymond#[end]"
85
+ formatted = []
86
+ #text.each { |line| formatted << @window.convert_to_chunk(line) }
87
+
88
+ #textview :text => formatted
89
+ #textview do |t| t.formatted_text(text, :tmux) end
90
+ t = textview :title => 'tmux format'
91
+ t.formatted_text(text, :tmux)
92
+ t1 = textview :title => 'ansi formatted document'
93
+ text = File.open("data/color.2","r").readlines
94
+ t1.formatted_text(text, :ansi)
95
+
96
+ flow do
97
+ #box do
98
+ button :text => " Ok " do alert "Pressed okay" end
99
+ button :text => "Cancel" do confirm "Quit?" ; throw :close; end
100
+ button :text => "Apply "
101
+ #end
102
+ end
103
+
104
+ end
105
+
106
+ end
107
+ end
108
+ if $0 == __FILE__
109
+ # Initialize curses
110
+ begin
111
+ # XXX update with new color and kb
112
+ VER::start_ncurses # this is initializing colors via ColorMap.setup
113
+ $log = Logger.new((File.join(ENV["LOGDIR"] || "./" ,"rbc13.log")))
114
+ $log.level = Logger::DEBUG
115
+ tp = SetupMessagebox.new()
116
+ buttonindex = tp.run
117
+ $log.debug "XXX: MESSAGEBOX retirned #{buttonindex} "
118
+ rescue => ex
119
+ ensure
120
+ VER::stop_ncurses
121
+ p ex if ex
122
+ p(ex.backtrace.join("\n")) if ex
123
+ $log.debug( ex) if ex
124
+ $log.debug(ex.backtrace.join("\n")) if ex
125
+ end
126
+ end
data/examples/viewtodo.rb CHANGED
@@ -1,6 +1,3 @@
1
- $LOAD_PATH << "/Users/rahul/work/projects/rbcurse/"
2
- require 'rubygems'
3
- #require 'ncurses' # FFI
4
1
  require 'logger'
5
2
  require 'rbcurse'
6
3
  require 'rbcurse/rcombo'
@@ -143,7 +140,7 @@ module ViewTodo
143
140
  File.open("todo.csv", "w") { |f| YAML.dump( d, f )}
144
141
  buf =''
145
142
  require 'csv'
146
- CSV.open('todocsv.csv', 'w') do |writer|
143
+ CSV.open('data/todocsv.csv', 'w') do |writer|
147
144
  #writer << [nil, nil]
148
145
  d.each do |row|
149
146
  #parced_cells = CSV.generate_rows(row, row.size, buf)
data/lib/rbcurse.rb CHANGED
@@ -4,5 +4,5 @@ require 'ver/window'
4
4
  require 'rbcurse/rwidget'
5
5
  require 'rbcurse/rdialogs'
6
6
  class Rbcurse
7
- VERSION = '1.4.0'
7
+ VERSION = '1.4.1'
8
8
  end
data/lib/rbcurse/app.rb CHANGED
@@ -18,7 +18,7 @@ $tt.name = "$tt"
18
18
  require 'forwardable'
19
19
  module Kernel
20
20
  extend Forwardable
21
- def_delegators :$tt, :ask, :say, :agree, :choose, :numbered_menu, :display_text, :display_text_interactive, :display_list, :say_with_pause, :hide_bottomline
21
+ def_delegators :$tt, :ask, :say, :agree, :choose, :numbered_menu, :display_text, :display_text_interactive, :display_list, :say_with_pause, :hide_bottomline, :say_with_wait
22
22
  end
23
23
  include RubyCurses
24
24
  include RubyCurses::Utils
@@ -77,7 +77,7 @@ module RubyCurses
77
77
  attr_reader :window
78
78
  attr_writer :quit_key
79
79
  # the row on which to prompt user for any inputs
80
- attr_accessor :prompt_row
80
+ #attr_accessor :prompt_row # 2011-10-17 14:06:22
81
81
 
82
82
  extend Forwardable
83
83
  def_delegators :$tt, :ask, :say, :agree, :choose, :numbered_menu, :display_text, :display_text_interactive, :display_list
@@ -93,7 +93,7 @@ module RubyCurses
93
93
  @variables = {}
94
94
  # if we are creating child objects then we will not use outer form. this object will manage
95
95
  @current_object = []
96
- @_system_commands = %w{ bind_global bind_component }
96
+ @_system_commands = %w{ bind_global bind_component field_help_text }
97
97
 
98
98
  init_vars
99
99
  $log.debug "XXX APP CONFIG: #{@config} " if $log.debug?
@@ -107,8 +107,8 @@ module RubyCurses
107
107
  init_ncurses
108
108
  end
109
109
  $lastline = Ncurses.LINES - 1
110
- @message_row = Ncurses.LINES-1
111
- @prompt_row = @message_row # hope to use for ask etc
110
+ #@message_row = Ncurses.LINES-1
111
+ #@prompt_row = @message_row # hope to use for ask etc # 2011-10-17 14:06:27
112
112
  unless $log
113
113
  path = File.join(ENV["LOGDIR"] || "./" ,"rbc13.log")
114
114
  file = File.open(path, File::WRONLY|File::TRUNC|File::CREAT)
@@ -117,15 +117,10 @@ module RubyCurses
117
117
  colors = Ncurses.COLORS
118
118
  $log.debug "START #{colors} colors --------- #{$0} win: #{@window} "
119
119
  end
120
- =begin
121
- # trying without 2011-10-8
122
- require 'rbcurse/extras/stdscrwindow'
123
- awin = StdscrWindow.new
124
- $tt.window = awin; $tt.message_row = @message_row
125
- =end
126
120
  end
127
121
  def logger; return $log; end
128
122
  def close
123
+ raw_message_destroy
129
124
  $log.debug " INSIDE CLOSE, #{@stop_ncurses_on_close} "
130
125
  @window.destroy if !@window.nil?
131
126
  $log.debug " INSIDE CLOSE, #{@stop_ncurses_on_close} "
@@ -145,13 +140,18 @@ module RubyCurses
145
140
  @form.repaint
146
141
  @window.wrefresh
147
142
  Ncurses::Panel.update_panels
143
+ @break_key = ?\C-q.getbyte(0)
148
144
  while((ch = @window.getchar()) != @quit_key )
149
- str = keycode_tos ch
150
- @keyblock.call(str.gsub(/-/, "_").to_sym) if @keyblock
151
- $log.debug "#{ch} got (#{str})"
145
+ break if ch == @break_key
146
+
147
+ if @keyblock
148
+ str = keycode_tos ch
149
+ @keyblock.call(str.gsub(/-/, "_").to_sym) # not used ever
150
+ end
151
+
152
152
  yield ch if block # <<<----
153
153
  @form.handle_key ch
154
- @form.repaint
154
+ #@form.repaint # was this duplicate ?? handle calls repaint not needed
155
155
  @window.wrefresh
156
156
  end
157
157
  end
@@ -185,46 +185,41 @@ module RubyCurses
185
185
  # a label so it can be printed.
186
186
  def message text
187
187
  $status_message.value = text # trying out 2011-10-9
188
- @message.value = text
188
+ #@message.value = text # 2011-10-17 14:07:01
189
189
  end
190
+ # @deprecated please use {#status_line} instead of a message label
190
191
  def message_row row
191
192
  raise "Please use create_message_label first as message_label is no longer default behaviour" unless @message_label
192
193
  @message_label.row = row
193
194
  end
194
195
  # during a process, when you wish to update status, since ordinarily the thread is busy
195
196
  # and form does not get control back, so the window won't refresh.
196
- # NOTE: use this only if +message+ is not working
197
- # XXX Not sure if this is working after move to ffi-ncurses, check the demos
197
+ # This will only update on keystroke since it uses statusline
198
+ # @deprecated please use {#status_line} instead of a message label
198
199
  def message_immediate text
200
+ $log.warn "DEPRECATED, use message(), or say_with_pause, or say"
199
201
  $status_message.value = text # trying out 2011-10-9 user needs to use in statusline command
200
- message text
201
- if @message_label
202
- @message_label.repaint
203
- @window.refresh
204
- end
202
+ # 2011-10-17 knocking off label, should be printed on status_line
205
203
  end
206
- # NOTE XXX using stdscr results in the screen going black if a dialog
207
- # or other window is popped up, this was great but has not worked out.
208
- # print directly onto stdscr so that form or window does not require repainting
209
- # and cursor not messed. however, once form paints then this will be overwritten
210
- # so at end of printing raw_messages, use message() for final status.
211
204
  # Usage: application is inside a long processing loop and wishes to print ongoing status
212
- # (similar to message_immediate) but faster and less involved
213
- # @deprecated since it uses stdscr. Use say_with_pause or use rdialogs status_window, see test2.rb
214
- def raw_message text
215
- $log.warn "WARNING: don't use this method as it uses stdscr. Use rdialogs statuswindow."
216
- row = @message_label ? @message_label.row : Ncurses.LINES-1
217
- # experimentally trying stdscr instead of label
218
- scr = FFI::NCurses.stdscr
219
- text = "%-80s" % text
220
- Ncurses.mvprintw row ,0, text
221
- #@_stext ||= ""
222
- #@_stext << text
223
- ## appending is quite a pain, maybe we should make it separate.
224
- #stext = "%-80s" % @_stext
225
- #Ncurses.mvprintw row ,0, stext[-80..-1]
226
- #scr.refresh() # NW w FFI XXX
227
- #FFI::NCurses.refresh
205
+ # NOTE: if you use this, you must use raw_message_destroy at some stage, after processing
206
+ # or on_leave of object.
207
+ # @deprecated Use say_with_pause or use rdialogs status_window, see test2.rb
208
+ def raw_message text, config={}, &blk
209
+ $raw_window ||= one_line_window last_line(), config, &blk
210
+ width = $raw_window.width == 0 ? FFI::NCurses.COLS : $raw_window.width
211
+ text = "%-*s" % [width, text]
212
+
213
+ $raw_window.attron(Ncurses.COLOR_PAIR($normalcolor) )
214
+ $raw_window.printstring 0,0,text, $normalcolor #, 'normal' if @title
215
+ $raw_window.wrefresh
216
+
217
+ end
218
+ def raw_message_destroy
219
+ if $raw_window
220
+ $raw_window.destroy
221
+ $raw_window = nil
222
+ end
228
223
  end
229
224
  # shows a simple progress bar on last row, using stdscr
230
225
  # @param [Float, Array<Fixnum,Fixnum>] percentage, or part/total
@@ -331,11 +326,12 @@ module RubyCurses
331
326
  end
332
327
  # bind a key to a method at global (form) level
333
328
  # Note that individual component may be overriding this.
329
+ # FIXME: why are we using rawmessage and then getchar when ask would suffice
334
330
  def bind_global
335
331
  opts = get_all_commands
336
332
  cmd = ask("Select a command (TAB for choices) : ", opts)
337
333
  if cmd.nil? || cmd == ""
338
- raw_message "Aborted."
334
+ say_with_pause "Aborted."
339
335
  return
340
336
  end
341
337
  key = []
@@ -343,16 +339,18 @@ module RubyCurses
343
339
  raw_message "Enter one or 2 keys. Finish with ENTER. Enter first key:"
344
340
  #raw_message "Enter first key:"
345
341
  ch = @window.getchar()
342
+ raw_message_destroy
346
343
  if [KEY_ENTER, 10, 13, ?\C-g.getbyte(0)].include? ch
347
- raw_message "Aborted."
344
+ say_with_pause "Aborted."
348
345
  return
349
346
  end
350
347
  key << ch
351
348
  str << keycode_tos(ch)
352
349
  raw_message "Enter second key or hit return:"
353
350
  ch = @window.getchar()
351
+ raw_message_destroy
354
352
  if ch == 3 || ch == ?\C-g.getbyte(0)
355
- raw_message "Aborted."
353
+ say_with_pause "Aborted."
356
354
  return
357
355
  end
358
356
  if ch == 10 || ch == KEY_ENTER || ch == 13
@@ -361,19 +359,31 @@ module RubyCurses
361
359
  str << keycode_tos(ch)
362
360
  end
363
361
  if !key.empty?
364
- raw_message "Binding #{cmd} to #{str} "
362
+ say_with_pause "Binding #{cmd} to #{str} "
365
363
  key = key[0] if key.size == 1
366
364
  #@form.bind_key(key, cmd.to_sym) # not finding it, getting called by that comp
367
365
  @form.bind_key(key){ send(cmd.to_sym) }
368
366
  end
369
367
  #message "Bound #{str} to #{cmd} "
368
+ raw_message_destroy
370
369
  end
371
370
  def bind_component
371
+ say_with_pause "Todo. <press>"
372
372
  # the idea here is to get the current component
373
373
  # and bind some keys to some methods.
374
374
  # however, how do we divine the methods we can map to
375
375
  # and also in some cases the components itself has multiple components
376
376
  end
377
+ # displays help_text associated with field. 2011-10-15
378
+ def field_help_text
379
+ f = @form.get_current_field
380
+ if f.respond_to?('help_text')
381
+ h = f.help_text
382
+ alert "#{h}"
383
+ else
384
+ alert "Could not get field #{f} or does not respond to helptext"
385
+ end
386
+ end
377
387
  # prompts user for a command. we need to get this back to the calling app
378
388
  # or have some block stuff TODO
379
389
  # Actually, this is naive, you would want to pass some values in like current data value
@@ -412,7 +422,7 @@ module RubyCurses
412
422
  if cmd == "close"
413
423
  throw :close # other seg faults in del_panel window.destroy executes 2x
414
424
  else
415
- send cmd, *cmdline
425
+ res = send cmd, *cmdline
416
426
  end
417
427
  else
418
428
  alert "#{self.class} does not respond to #{cmd} "
@@ -613,8 +623,18 @@ module RubyCurses
613
623
  end
614
624
  return w
615
625
  end
616
- def textview *args, &block
617
- require 'rbcurse/rtextview'
626
+ # similar definitions for textview and resultsettextview
627
+ # NOTE This is not allowing me to send blocks,
628
+ # so do not use for containers
629
+ {
630
+ 'rbcurse/rtextview' => 'TextView',
631
+ 'rbcurse/experimental/resultsettextview' => 'ResultsetTextView',
632
+ 'rbcurse/rcontainer' => 'Container',
633
+ 'rbcurse/extras/rcontainer2' => 'Container2',
634
+ }.each_pair {|k,p|
635
+ eval(
636
+ "def #{p.downcase} *args, &block
637
+ require \"#{k}\"
618
638
  config = {}
619
639
  # TODO confirm events many more
620
640
  events = [ :PRESS, :LEAVE, :ENTER ]
@@ -624,15 +644,17 @@ module RubyCurses
624
644
  _position(config)
625
645
  # if no width given, expand to flows width
626
646
  config[:width] ||= @stack.last.width if @stack.last
627
- raise "height needed for textview" if !config.has_key? :height
647
+ raise \"height needed for #{p.downcase}\" if !config.has_key? :height
628
648
  useform = nil
629
649
  useform = @form if @current_object.empty?
630
- w = TextView.new useform, config
650
+ w = #{p}.new useform, config
631
651
  if block
632
652
  w.bind(block_event, &block)
633
653
  end
634
654
  return w
635
- end
655
+ end"
656
+ )
657
+ }
636
658
  # progress bar
637
659
  def progress *args, &block
638
660
  require 'rbcurse/rprogress'
@@ -1012,10 +1034,8 @@ module RubyCurses
1012
1034
  s = Stack.new(mt, mr, w)
1013
1035
  @app_row += mt
1014
1036
  mr += @stack.last.margin if @stack.last
1015
- #@stack << mr
1016
1037
  @stack << s
1017
- #instance_eval &block if block_given?
1018
- yield_or_eval &block if block_given? # modified 2010-11-17 20:36
1038
+ yield_or_eval &block if block_given?
1019
1039
  @stack.pop
1020
1040
  @instack = false if @stack.empty?
1021
1041
  @app_row = 0 if @stack.empty?
@@ -1034,8 +1054,7 @@ module RubyCurses
1034
1054
  col += config[:margin] || 0
1035
1055
  @flowstack << col
1036
1056
  @flowcol = col
1037
- #instance_eval &block if block_given?
1038
- yield_or_eval &block if block_given? # modified 2010-11-17 20:36
1057
+ yield_or_eval &block if block_given?
1039
1058
  @flowstack.pop
1040
1059
  @inflow = false if @flowstack.empty?
1041
1060
  end
@@ -1059,6 +1078,8 @@ module RubyCurses
1059
1078
  longest
1060
1079
  end
1061
1080
  # returns longest item
1081
+ # rows = list.max_by(&:length)
1082
+ #
1062
1083
  def longest_in_list2 list #:nodoc:
1063
1084
  longest = list.inject(list[0]) do |memo,word|
1064
1085
  memo.length >= word.length ? memo : word
@@ -1073,10 +1094,11 @@ module RubyCurses
1073
1094
  end
1074
1095
  # Now i am not creating this unless user wants it. Pls avoid it.
1075
1096
  # Use either say_with_pause, or put $status_message in command of statusline
1076
- # @deprecated
1097
+ # @deprecated please use {#status_line} instead of a message label
1077
1098
  def create_message_label row=Ncurses.LINES-1
1078
1099
  @message_label = RubyCurses::Label.new @form, {:text_variable => @message, :name=>"message_label",:row => row, :col => 0, :display_length => Ncurses.COLS, :height => 1, :color => :white}
1079
1100
  end
1101
+
1080
1102
  def run &block
1081
1103
  begin
1082
1104
 
@@ -1106,7 +1128,7 @@ module RubyCurses
1106
1128
  @_command_history ||= Array.new
1107
1129
  # previous command should be in opts, otherwise it is not in this context
1108
1130
  cmd = ask("Command: ", opts){ |q| q.default = @_previous_command; q.history = @_command_history }
1109
- if cmd == ""
1131
+ if cmd.nil? || cmd == ""
1110
1132
  else
1111
1133
  @_command_history << cmd unless @_command_history.include? cmd
1112
1134
  cmdline = cmd.split
@@ -1122,11 +1144,11 @@ module RubyCurses
1122
1144
  end
1123
1145
  if respond_to?(cmd, true)
1124
1146
  @_previous_command = cmd
1125
- raw_message "calling #{cmd} "
1147
+ #raw_message "calling #{cmd} "
1126
1148
  begin
1127
1149
  send cmd, *cmdline
1128
1150
  rescue => exc
1129
- $log.debug "ERR EXC: send throwing an exception now. Duh. IMAP keeps crashing haha !! #{exc} " if $log.debug?
1151
+ $log.error "ERR EXC: send throwing an exception now. Duh. IMAP keeps crashing haha !! #{exc} " if $log.debug?
1130
1152
  if exc
1131
1153
  $log.debug( exc)
1132
1154
  $log.debug(exc.backtrace.join("\n"))
@@ -1141,11 +1163,11 @@ module RubyCurses
1141
1163
  @form.bind_key(KEY_F1){ display_app_help }
1142
1164
  @form.bind_key([?q,?q]){ throw :close } if $log.debug?
1143
1165
 
1144
- @message = Variable.new
1145
- @message.value = ""
1166
+ #@message = Variable.new
1167
+ #@message.value = ""
1146
1168
  $status_message ||= Variable.new # remember there are multiple levels of apps
1147
1169
  $status_message.value = ""
1148
- $error_message.update_command { @message.set_value($error_message.value) }
1170
+ #$error_message.update_command { @message.set_value($error_message.value) }
1149
1171
  if block
1150
1172
  begin
1151
1173
  #yield(self, @window, @form)
@@ -1220,10 +1242,11 @@ module RubyCurses
1220
1242
  end
1221
1243
  elsif @instack
1222
1244
  # most likely you won't have row and col. should we check or just go ahead
1245
+ # what if he has put it 2011-10-19 as in a container
1223
1246
  col = @stack.last.margin
1224
- config[:row] = @app_row
1225
- config[:col] = col
1226
- @app_row += config[:height] || 1
1247
+ config[:row] ||= @app_row
1248
+ config[:col] ||= col
1249
+ @app_row += config[:height] || 1 #unless config[:no_advance]
1227
1250
  # TODO need to allow stack to have its spacing, but we don't have an object as yet.
1228
1251
  end
1229
1252
  end