rbcurse-core 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. data/README.md +69 -0
  2. data/VERSION +1 -0
  3. data/examples/abasiclist.rb +151 -0
  4. data/examples/alpmenu.rb +46 -0
  5. data/examples/app.sample +17 -0
  6. data/examples/atree.rb +100 -0
  7. data/examples/common/file.rb +45 -0
  8. data/examples/data/README.markdown +9 -0
  9. data/examples/data/brew.txt +38 -0
  10. data/examples/data/color.2 +37 -0
  11. data/examples/data/gemlist.txt +60 -0
  12. data/examples/data/lotr.txt +12 -0
  13. data/examples/data/ports.txt +136 -0
  14. data/examples/data/table.txt +37 -0
  15. data/examples/data/tasks.csv +88 -0
  16. data/examples/data/tasks.txt +27 -0
  17. data/examples/data/todo.txt +10 -0
  18. data/examples/data/todocsv.csv +28 -0
  19. data/examples/data/unix1.txt +21 -0
  20. data/examples/data/unix2.txt +11 -0
  21. data/examples/dbdemo.rb +487 -0
  22. data/examples/dirtree.rb +90 -0
  23. data/examples/newtabbedwindow.rb +100 -0
  24. data/examples/newtesttabp.rb +92 -0
  25. data/examples/tabular.rb +132 -0
  26. data/examples/tasks.rb +167 -0
  27. data/examples/term2.rb +83 -0
  28. data/examples/testkeypress.rb +72 -0
  29. data/examples/testlistbox.rb +158 -0
  30. data/examples/testmessagebox.rb +140 -0
  31. data/examples/testree.rb +106 -0
  32. data/examples/testwsshortcuts.rb +66 -0
  33. data/examples/testwsshortcuts2.rb +127 -0
  34. data/lib/rbcurse.rb +8 -0
  35. data/lib/rbcurse/core/docs/index.txt +73 -0
  36. data/lib/rbcurse/core/include/action.rb +40 -0
  37. data/lib/rbcurse/core/include/appmethods.rb +112 -0
  38. data/lib/rbcurse/core/include/bordertitle.rb +41 -0
  39. data/lib/rbcurse/core/include/chunk.rb +182 -0
  40. data/lib/rbcurse/core/include/io.rb +953 -0
  41. data/lib/rbcurse/core/include/listcellrenderer.rb +140 -0
  42. data/lib/rbcurse/core/include/listeditable.rb +317 -0
  43. data/lib/rbcurse/core/include/listscrollable.rb +590 -0
  44. data/lib/rbcurse/core/include/listselectable.rb +264 -0
  45. data/lib/rbcurse/core/include/multibuffer.rb +83 -0
  46. data/lib/rbcurse/core/include/orderedhash.rb +77 -0
  47. data/lib/rbcurse/core/include/ractionevent.rb +67 -0
  48. data/lib/rbcurse/core/include/rchangeevent.rb +27 -0
  49. data/lib/rbcurse/core/include/rhistory.rb +62 -0
  50. data/lib/rbcurse/core/include/rinputdataevent.rb +47 -0
  51. data/lib/rbcurse/core/include/vieditable.rb +170 -0
  52. data/lib/rbcurse/core/system/colormap.rb +163 -0
  53. data/lib/rbcurse/core/system/keyboard.rb +150 -0
  54. data/lib/rbcurse/core/system/keydefs.rb +30 -0
  55. data/lib/rbcurse/core/system/ncurses.rb +218 -0
  56. data/lib/rbcurse/core/system/panel.rb +162 -0
  57. data/lib/rbcurse/core/system/window.rb +901 -0
  58. data/lib/rbcurse/core/util/ansiparser.rb +117 -0
  59. data/lib/rbcurse/core/util/app.rb +1235 -0
  60. data/lib/rbcurse/core/util/basestack.rb +407 -0
  61. data/lib/rbcurse/core/util/bottomline.rb +1850 -0
  62. data/lib/rbcurse/core/util/colorparser.rb +71 -0
  63. data/lib/rbcurse/core/util/focusmanager.rb +31 -0
  64. data/lib/rbcurse/core/util/padreader.rb +189 -0
  65. data/lib/rbcurse/core/util/rcommandwindow.rb +587 -0
  66. data/lib/rbcurse/core/util/rdialogs.rb +619 -0
  67. data/lib/rbcurse/core/util/viewer.rb +149 -0
  68. data/lib/rbcurse/core/util/widgetshortcuts.rb +505 -0
  69. data/lib/rbcurse/core/widgets/applicationheader.rb +102 -0
  70. data/lib/rbcurse/core/widgets/box.rb +58 -0
  71. data/lib/rbcurse/core/widgets/divider.rb +310 -0
  72. data/lib/rbcurse/core/widgets/keylabelprinter.rb +178 -0
  73. data/lib/rbcurse/core/widgets/rcombo.rb +238 -0
  74. data/lib/rbcurse/core/widgets/rcontainer.rb +415 -0
  75. data/lib/rbcurse/core/widgets/rlink.rb +30 -0
  76. data/lib/rbcurse/core/widgets/rlist.rb +723 -0
  77. data/lib/rbcurse/core/widgets/rmenu.rb +939 -0
  78. data/lib/rbcurse/core/widgets/rmenulink.rb +22 -0
  79. data/lib/rbcurse/core/widgets/rmessagebox.rb +373 -0
  80. data/lib/rbcurse/core/widgets/rprogress.rb +118 -0
  81. data/lib/rbcurse/core/widgets/rtabbedpane.rb +615 -0
  82. data/lib/rbcurse/core/widgets/rtabbedwindow.rb +68 -0
  83. data/lib/rbcurse/core/widgets/rtextarea.rb +920 -0
  84. data/lib/rbcurse/core/widgets/rtextview.rb +780 -0
  85. data/lib/rbcurse/core/widgets/rtree.rb +787 -0
  86. data/lib/rbcurse/core/widgets/rwidget.rb +3040 -0
  87. data/lib/rbcurse/core/widgets/scrollbar.rb +143 -0
  88. data/lib/rbcurse/core/widgets/statusline.rb +94 -0
  89. data/lib/rbcurse/core/widgets/tabular.rb +264 -0
  90. data/lib/rbcurse/core/widgets/tabularwidget.rb +1211 -0
  91. data/lib/rbcurse/core/widgets/textpad.rb +516 -0
  92. data/lib/rbcurse/core/widgets/tree/treecellrenderer.rb +150 -0
  93. data/lib/rbcurse/core/widgets/tree/treemodel.rb +428 -0
  94. metadata +156 -0
@@ -0,0 +1,106 @@
1
+ require 'rbcurse'
2
+ require 'rbcurse/core/widgets/rtree'
3
+
4
+ if $0 == __FILE__
5
+ $choice = ARGV[0].to_i || 1
6
+ class Tester
7
+ def initialize
8
+ acolor = $reversecolor
9
+ end
10
+ def run
11
+ @window = VER::Window.root_window
12
+ @form = Form.new @window
13
+
14
+ h = 20; w = 75; t = 3; l = 4
15
+ #$choice = 1
16
+ case $choice
17
+ when 1
18
+ root = TreeNode.new "ROOT"
19
+ subroot = TreeNode.new "subroot"
20
+ leaf1 = TreeNode.new "leaf 1"
21
+ leaf2 = TreeNode.new "leaf 2"
22
+
23
+ model = DefaultTreeModel.new root
24
+ #model.insert_node_into(subroot, root, 0)
25
+ #model.insert_node_into(leaf1, subroot, 0)
26
+ #model.insert_node_into(leaf2, subroot, 1)
27
+ root << subroot
28
+ subroot << leaf1 << leaf2
29
+ leaf1 << "leaf11"
30
+ leaf1 << "leaf12"
31
+
32
+ root.add "blocky", true do
33
+ add "block2"
34
+ add "block3" do
35
+ add "block31"
36
+ end
37
+ end
38
+ Tree.new @form, :data => model, :row =>2, :col=>2, :height => 20, :width => 30
39
+
40
+ when 2
41
+
42
+ # use an array to populate
43
+ # we need to do root_visible = false so you get just a list
44
+ model = %W[ ruby lua jruby smalltalk haskell scheme perl lisp ]
45
+ Tree.new @form, :data => model, :row =>2, :col=>2, :height => 20, :width => 30
46
+
47
+ when 3
48
+
49
+ # use an Has to populate
50
+ #model = { :ruby => %W[ "jruby", "mri", "yarv", "rubinius", "macruby" ], :python => %W[ cpython jython laden-swallow ] }
51
+ model = { :ruby => [ "jruby", {:mri => %W[ 1.8.6 1.8.7]}, {:yarv => %W[1.9.1 1.9.2]}, "rubinius", "macruby" ], :python => %W[ cpython jython pypy ] }
52
+
53
+ Tree.new @form, :data => model, :row =>2, :col=>2, :height => 20, :width => 30
54
+ #when 4
55
+ else
56
+ Tree.new @form, :row =>2, :col=>2, :height => 20, :width => 30 do
57
+ root "root" do
58
+ branch "vim" do
59
+ leaf "vimrc"
60
+ end
61
+ branch "ack" do
62
+ leaf "ackrc"
63
+ end
64
+ end
65
+ end
66
+
67
+ end
68
+
69
+ #
70
+ help = "C-q to quit. <ENTER> to expand nodes. j/k to navigate. Pass command-line argument 1,2,3,4 #{$0} "
71
+ RubyCurses::Label.new @form, {:text => help, :row => 1, :col => 2, :color => :cyan}
72
+ @form.repaint
73
+ @window.wrefresh
74
+ Ncurses::Panel.update_panels
75
+ while((ch = @window.getchar()) != ?\C-q.getbyte(0))
76
+ ret = @form.handle_key(ch)
77
+ @window.wrefresh
78
+ if ret == :UNHANDLED
79
+ str = keycode_tos ch
80
+ $log.debug " UNHANDLED #{str} by Vim #{ret} "
81
+ end
82
+ end
83
+
84
+ @window.destroy
85
+
86
+ end
87
+ end
88
+ include RubyCurses
89
+ include RubyCurses::Utils
90
+ # Initialize curses
91
+ begin
92
+ # XXX update with new color and kb
93
+ VER::start_ncurses # this is initializing colors via ColorMap.setup
94
+ $log = Logger.new("rbc13.log")
95
+ $log.level = Logger::DEBUG
96
+ n = Tester.new
97
+ n.run
98
+ rescue => ex
99
+ ensure
100
+ VER::stop_ncurses
101
+ p ex if ex
102
+ puts(ex.backtrace.join("\n")) if ex
103
+ $log.debug( ex) if ex
104
+ $log.debug(ex.backtrace.join("\n")) if ex
105
+ end
106
+ end
@@ -0,0 +1,66 @@
1
+ # this is a test program, tests out tabbed panes. type F1 to exit
2
+ #
3
+ require 'rbcurse'
4
+ require 'rbcurse/core/util/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" do throw :close; end
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
+ catch(:close) do
54
+ tp = SetupMessagebox.new()
55
+ buttonindex = tp.run
56
+ $log.debug "XXX: MESSAGEBOX retirned #{buttonindex} "
57
+ end
58
+ rescue => ex
59
+ ensure
60
+ VER::stop_ncurses
61
+ p ex if ex
62
+ p(ex.backtrace.join("\n")) if ex
63
+ $log.debug( ex) if ex
64
+ $log.debug(ex.backtrace.join("\n")) if ex
65
+ end
66
+ end
@@ -0,0 +1,127 @@
1
+ # this is a test program, tests out widget shortcuts. type C-q to exit
2
+ #
3
+ require 'rbcurse'
4
+ require 'rbcurse/core/util/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
+ #text = `ri -f bs String`.split("\n")
95
+ t1.formatted_text(text, :ansi)
96
+
97
+ flow do
98
+ #box do
99
+ button :text => " Ok " do alert "Pressed okay" end
100
+ button :text => "Cancel" do confirm "Do you wish to Quit?" ; throw :close; end
101
+ button :text => "Apply "
102
+ #end
103
+ end
104
+
105
+ end
106
+
107
+ end
108
+ end
109
+ if $0 == __FILE__
110
+ # Initialize curses
111
+ begin
112
+ # XXX update with new color and kb
113
+ VER::start_ncurses # this is initializing colors via ColorMap.setup
114
+ $log = Logger.new((File.join(ENV["LOGDIR"] || "./" ,"rbc13.log")))
115
+ $log.level = Logger::DEBUG
116
+ tp = SetupMessagebox.new()
117
+ buttonindex = tp.run
118
+ $log.debug "XXX: MESSAGEBOX retirned #{buttonindex} "
119
+ rescue => ex
120
+ ensure
121
+ VER::stop_ncurses
122
+ p ex if ex
123
+ p(ex.backtrace.join("\n")) if ex
124
+ $log.debug( ex) if ex
125
+ $log.debug(ex.backtrace.join("\n")) if ex
126
+ end
127
+ end
data/lib/rbcurse.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'ffi-ncurses'
2
+ require 'rbcurse/core/system/ncurses'
3
+ require 'rbcurse/core/system/window'
4
+ require 'rbcurse/core/widgets/rwidget'
5
+ require 'rbcurse/core/util/rdialogs'
6
+ class Rbcurse
7
+ VERSION = '0.0.0'
8
+ end
@@ -0,0 +1,73 @@
1
+ G E N E R A L H E L P
2
+ <q> to quit this window. <Space> to scroll.
3
+
4
+ ==============================================================================
5
+ 1. General Help
6
+
7
+ F10 - exit application. Also, <C-q>
8
+ F1 - Help
9
+
10
+ In some applications, the following may have been provided:
11
+
12
+ Alt-x - additional commands
13
+ : - additional commands
14
+ :! - system command
15
+ <C-x>c - system command
16
+
17
+ ==============================================================================
18
+ 2. Form
19
+
20
+ <Tab> and <backtab> navigate between widgets.
21
+
22
+ ==============================================================================
23
+ 3. Multiline widgets
24
+
25
+ In most widgets such as _list_, _textview_, _table_, and _tree_ the
26
+ following vim-bindings are applicable.
27
+
28
+ j,k,l,h, gg, G, C-d, C-b
29
+
30
+ <space> scrolls in _textview_.
31
+
32
+ Some multiline widgets such as _list_ and _tree_ may move to first item
33
+ starting with j or k or <char> on pressing char. To get vim-bindings use
34
+ <Alt-v>. Now to go to first row with <char>, type f<char>. This behavior
35
+ is modified using the flag one_key_selection.
36
+
37
+
38
+ ==============================================================================
39
+ 4. Editable Widgets
40
+
41
+ In _field_ and editable _textarea_, some emacs/Pine keys such as C-e,
42
+ C-a, C-k (delete till end) are available.
43
+
44
+ <C-a> - start of line
45
+ <C-e> - end of line
46
+ <C-k> - delete till end of line
47
+ <M-i> - toggle overwrite mode
48
+
49
+ ==============================================================================
50
+ 5. Buttons
51
+
52
+ _Button_ can be fired using <space> or <ENTER>. The default button, if
53
+ declared, is shown with as > Ok < as against other buttons, shown as [
54
+ Cancel ]. This can be fired by hitting <ENTER> anywhere on the form
55
+ (unless the current widget traps <ENTER>).
56
+
57
+ Hotkeys are available using Alt-<key>.
58
+
59
+ ==============================================================================
60
+ 6. Selection in lists
61
+
62
+ <space> - toggle selection
63
+ <C-Space> - range select
64
+ <a> - select all
65
+ <u> - unselect all (should be changed, as conflicts with
66
+ vim undo)
67
+ <*> - invert selection
68
+
69
+ <-> - ask unselect
70
+ <+> - ask select
71
+
72
+ -----------------------------------------------------------------------------
73
+ q to quit, gg to goto top.
@@ -0,0 +1,40 @@
1
+ require 'rbcurse/core/widgets/rwidget'
2
+ #include Ncurses # FFI 2011-09-8
3
+ include RubyCurses
4
+ module RubyCurses
5
+ ## encapsulates behaviour allowing centralization
6
+ # == Example
7
+ # a = Action.new("&New Row") { commands }
8
+ # a.accelerator "Alt N"
9
+ # menu.add(a)
10
+ # b = Button.new form do
11
+ # action a
12
+ # ...
13
+ # end
14
+ class Action < Proc
15
+ include EventHandler
16
+ include ConfigSetup
17
+ # name used on button or menu
18
+ dsl_property :name
19
+ dsl_property :enabled
20
+ dsl_accessor :tooltip_text
21
+ dsl_accessor :help_text
22
+ dsl_accessor :mnemonic
23
+ dsl_accessor :accelerator
24
+
25
+ def initialize name, config={}, &block
26
+ super &block
27
+ @name = name
28
+ @name.freeze
29
+ @enabled = true
30
+ config_setup config # @config.each_pair { |k,v| variable_set(k,v) }
31
+ @_events = [:FIRE]
32
+ end
33
+ def call
34
+ return unless @enabled
35
+ fire_handler :FIRE, self
36
+ super
37
+ end
38
+ end # class
39
+ end # module
40
+
@@ -0,0 +1,112 @@
1
+ module RubyCurses
2
+ module Utils
3
+ private
4
+ def _suspend clear=true
5
+ return unless block_given?
6
+ Ncurses.def_prog_mode
7
+ if clear
8
+ Ncurses.endwin
9
+ # NOTE: avoid false since screen remains half off
10
+ # too many issues
11
+ else
12
+ system "/bin/stty sane"
13
+ end
14
+ yield if block_given?
15
+ Ncurses.reset_prog_mode
16
+ if !clear
17
+ # Hope we don't screw your terminal up with this constantly.
18
+ VER::stop_ncurses
19
+ VER::start_ncurses
20
+ #@form.reset_all # not required
21
+ end
22
+ @form.repaint if @form
23
+ @window.wrefresh if @window
24
+ Ncurses::Panel.update_panels
25
+ end
26
+ #
27
+ # Suspends to shell so user can execute commands.
28
+ # Maybe not be able to get your prompt correctly.
29
+ #
30
+ public
31
+ def suspend
32
+ _suspend(false) do
33
+ system("tput cup 26 0")
34
+ system("tput ed")
35
+ system("echo Enter C-d to return to application")
36
+ system (ENV['PS1']='\s-\v\$ ') if ENV['SHELL']== '/bin/bash'
37
+ system(ENV['SHELL']);
38
+ end
39
+ end
40
+
41
+ #
42
+ # Displays application help using either array provided
43
+ # or checking for :help_text method
44
+ # @param [Array] help text
45
+ def display_app_help help_array= nil
46
+ if help_array
47
+ arr = help_array
48
+ elsif respond_to? :help_text
49
+ arr = help_text
50
+ else
51
+ arr = []
52
+ arr << " NO HELP SPECIFIED FOR APP #{self} "
53
+ arr << " "
54
+ arr << " --- General help --- "
55
+ arr << " F10 - exit application "
56
+ arr << " Alt-x - select commands "
57
+ arr << " : - select commands "
58
+ arr << " "
59
+ end
60
+ case arr
61
+ when String
62
+ arr = arr.split("\n")
63
+ when Array
64
+ end
65
+ w = arr.max_by(&:length).length
66
+
67
+ require 'rbcurse/core/util/viewer'
68
+ RubyCurses::Viewer.view(arr, :layout => [2, 10, [4+arr.size, 24].min, w+2],:close_key => KEY_ENTER, :title => "<Enter> to close", :print_footer => true) do |t|
69
+ # you may configure textview further here.
70
+ #t.suppress_borders true
71
+ #t.color = :black
72
+ #t.bgcolor = :white
73
+ # or
74
+ t.attr = :reverse
75
+ end
76
+ end
77
+ #
78
+ # prompts user for unix command and displays output in viewer
79
+ #
80
+ def shell_output
81
+ cmd = get_string("Enter shell command:", 50)
82
+ if cmd && !cmd.empty?
83
+ run_command cmd
84
+ end
85
+ end
86
+
87
+ #
88
+ # executes given command and displays in viewer
89
+ # @param [String] unix command, e.g., git -st
90
+ def run_command cmd
91
+ # http://whynotwiki.com/Ruby_/_Process_management#What_happens_to_standard_error_.28stderr.29.3F
92
+ require 'rbcurse/core/util/viewer'
93
+ begin
94
+ res = `#{cmd} 2>&1`
95
+ rescue => ex
96
+ res = ex.to_s
97
+ res << ex.backtrace.join("\n")
98
+ end
99
+ res.gsub!("\t"," ")
100
+ RubyCurses::Viewer.view(res.split("\n"), :close_key => KEY_ENTER, :title => "<Enter> to close, M-l M-h to scroll")
101
+ end
102
+ def shell_out command
103
+ @window.hide
104
+ Ncurses.endwin
105
+ system command
106
+ Ncurses.refresh
107
+ #Ncurses.curs_set 0 # why ?
108
+ @window.show
109
+ end
110
+ end # utils
111
+ end # module RubyC
112
+ include RubyCurses::Utils