ncumbra 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +25 -0
- data/Gemfile +6 -0
- data/LICENSE +21 -0
- data/README.md +48 -0
- data/README.md.bak +15 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/examples/ex1.rb +85 -0
- data/examples/ex2.rb +128 -0
- data/examples/ex21.rb +136 -0
- data/examples/ex3.rb +163 -0
- data/examples/ex4.rb +142 -0
- data/examples/ex5.rb +103 -0
- data/examples/exbox.rb +141 -0
- data/examples/exm1.rb +137 -0
- data/examples/keys.rb +67 -0
- data/examples/tt.rb +462 -0
- data/lib/umbra/box.rb +137 -0
- data/lib/umbra/button.rb +130 -0
- data/lib/umbra/buttongroup.rb +96 -0
- data/lib/umbra/checkbox.rb +42 -0
- data/lib/umbra/dialog.rb +214 -0
- data/lib/umbra/eventhandler.rb +134 -0
- data/lib/umbra/field.rb +503 -0
- data/lib/umbra/form.rb +473 -0
- data/lib/umbra/keymappinghandler.rb +96 -0
- data/lib/umbra/label.rb +95 -0
- data/lib/umbra/labeledfield.rb +97 -0
- data/lib/umbra/listbox.rb +384 -0
- data/lib/umbra/menu.rb +93 -0
- data/lib/umbra/messagebox.rb +348 -0
- data/lib/umbra/pad.rb +340 -0
- data/lib/umbra/radiobutton.rb +71 -0
- data/lib/umbra/textbox.rb +417 -0
- data/lib/umbra/togglebutton.rb +140 -0
- data/lib/umbra/version.rb +3 -0
- data/lib/umbra/widget.rb +220 -0
- data/lib/umbra/window.rb +270 -0
- data/lib/umbra.rb +47 -0
- data/umbra.gemspec +27 -0
- metadata +127 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e2e982667f4938fcec8de0033c42123cef862f3a4ccdf605abfd509852949b2b
|
4
|
+
data.tar.gz: 259e0d105fbbae4bfa07d3470be80d726cee091de29447a7ae70a994b376c262
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e7ce64a554e6644cb8303da6bd76d2a837c8009231adf5c680acf4af3324ae3351a763fa96a66e9e554ca3dde008fe9b696ccce21a1831a0128bf7f30e4dceeb
|
7
|
+
data.tar.gz: 32acff4e2f0c371a512fd8258ad5f1d565b97f22b0af067ebbbcff5f8009bbb37c0f3e499f371680ae3a964eb43cad834903b300f750a53905e5eab14cb52081
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2018 kepler
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# Umbra
|
2
|
+
|
3
|
+
stripped version of canis (ncurses ruby)
|
4
|
+
|
5
|
+
- Minimal functionality
|
6
|
+
- Very close to ncurses, should not try to wrap everything
|
7
|
+
- load only what you need
|
8
|
+
- not necessarily object oriented, that is not a goal
|
9
|
+
- should be able to use a file or widget from here without having to copy too much
|
10
|
+
- should be able to understand one file without having to understand entire library
|
11
|
+
- should be easy for others to change as per their needs, or copy parts.
|
12
|
+
-
|
13
|
+
|
14
|
+
|
15
|
+
Currently, not looking at ALT keys, this may change in the future. Only single and control keys and function keys trapped
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
Add this line to your application's Gemfile:
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
gem 'umbra'
|
22
|
+
```
|
23
|
+
|
24
|
+
And then execute:
|
25
|
+
|
26
|
+
$ bundle
|
27
|
+
|
28
|
+
Or install it yourself as:
|
29
|
+
|
30
|
+
$ gem install umbra
|
31
|
+
|
32
|
+
## Usage
|
33
|
+
|
34
|
+
TODO: Write usage instructions here
|
35
|
+
|
36
|
+
## Development
|
37
|
+
|
38
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
39
|
+
|
40
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
41
|
+
|
42
|
+
## Contributing
|
43
|
+
|
44
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/mare-imbrium/umbra.
|
45
|
+
|
46
|
+
## License
|
47
|
+
|
48
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/README.md.bak
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# umbra
|
2
|
+
|
3
|
+
stripped version of canis (ncurses ruby)
|
4
|
+
|
5
|
+
- Minimal functionality
|
6
|
+
- Very close to ncurses, should not try to wrap everything
|
7
|
+
- load only what you need
|
8
|
+
- not necessarily object oriented, that is not a goal
|
9
|
+
- should be able to use a file or widget from here without having to copy too much
|
10
|
+
- should be able to understand one file without having to understand entire library
|
11
|
+
- should be easy for others to change as per their needs, or copy parts.
|
12
|
+
-
|
13
|
+
|
14
|
+
|
15
|
+
Currently, not looking at ALT keys, this may change in the future. Only single and control keys and function keys trapped
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "umbra"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/examples/ex1.rb
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# example showing only labels on a window
|
3
|
+
# 2018-03-10
|
4
|
+
require 'umbra'
|
5
|
+
require 'umbra/label'
|
6
|
+
|
7
|
+
def startup
|
8
|
+
require 'logger'
|
9
|
+
require 'date'
|
10
|
+
|
11
|
+
path = File.join(ENV["LOGDIR"] || "./" ,"v.log")
|
12
|
+
file = File.open(path, File::WRONLY|File::TRUNC|File::CREAT)
|
13
|
+
$log = Logger.new(path)
|
14
|
+
$log.level = Logger::DEBUG
|
15
|
+
today = Date.today
|
16
|
+
$log.info "Started up on #{today}"
|
17
|
+
FFI::NCurses.init_pair(10, FFI::NCurses::BLACK, FFI::NCurses::GREEN) # statusline
|
18
|
+
end
|
19
|
+
def statusline win, str, col = 0
|
20
|
+
win.printstring( FFI::NCurses.LINES-1, col, str, 10)
|
21
|
+
end
|
22
|
+
begin
|
23
|
+
include Umbra
|
24
|
+
init_curses
|
25
|
+
startup
|
26
|
+
win = Window.new
|
27
|
+
statusline(win, " "*(win.width-0), 0)
|
28
|
+
statusline(win, "Press q to quit #{win.height}:#{win.width}", 20)
|
29
|
+
title = Label.new( :text => "Demo of Labels", :row => 0, :col => 0 , :width => FFI::NCurses.COLS-1,
|
30
|
+
:justify => :center, :color_pair => 0)
|
31
|
+
|
32
|
+
form = Form.new win
|
33
|
+
form.add_widget title
|
34
|
+
labels = ["Name: ", "Address: ","Mobile No.", "Email Id:","Hobbies: "]
|
35
|
+
labs = []
|
36
|
+
row = 3
|
37
|
+
col = 5
|
38
|
+
labels.each_with_index {|lab, ix|
|
39
|
+
w = Label.new( :text => lab, :row => row, :col => col )
|
40
|
+
labs << w
|
41
|
+
row += 2
|
42
|
+
w.color_pair = 1
|
43
|
+
w.attr = FFI::NCurses::A_BOLD
|
44
|
+
form.add_widget w
|
45
|
+
}
|
46
|
+
labels = ["Roger Federer", "20 Slam Drive","9810012345", "ihumble@tennis.com","golf, programming"]
|
47
|
+
row = 3
|
48
|
+
col = 30
|
49
|
+
labels.each_with_index {|lab, ix|
|
50
|
+
w = Label.new( :text => lab, :row => row, :col => col , :width => 50)
|
51
|
+
labs << w
|
52
|
+
row += 2
|
53
|
+
w.color_pair = 1
|
54
|
+
w.attr = FFI::NCurses::A_REVERSE
|
55
|
+
form.add_widget w
|
56
|
+
}
|
57
|
+
form.pack
|
58
|
+
win.wrefresh
|
59
|
+
|
60
|
+
y = x = 1
|
61
|
+
while (ch = win.getkey) != 113
|
62
|
+
#y, x = win.getbegyx(win.pointer)
|
63
|
+
old_y, old_x = y, x
|
64
|
+
case ch
|
65
|
+
when FFI::NCurses::KEY_RIGHT
|
66
|
+
when FFI::NCurses::KEY_LEFT
|
67
|
+
# go back higher level
|
68
|
+
when FFI::NCurses::KEY_UP
|
69
|
+
when FFI::NCurses::KEY_DOWN
|
70
|
+
end
|
71
|
+
#FIXME after scrolling, pointer is showing wrong file here
|
72
|
+
statusline(win, "Pressed #{ch} on ", 70)
|
73
|
+
win.wrefresh
|
74
|
+
end
|
75
|
+
|
76
|
+
rescue Object => e
|
77
|
+
@window.destroy if @window
|
78
|
+
FFI::NCurses.endwin
|
79
|
+
puts e
|
80
|
+
puts e.backtrace.join("\n")
|
81
|
+
ensure
|
82
|
+
@window.destroy if @window
|
83
|
+
FFI::NCurses.endwin
|
84
|
+
puts
|
85
|
+
end
|
data/examples/ex2.rb
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# example showing only labels and fields a window
|
3
|
+
# 2018-03-10
|
4
|
+
require 'umbra'
|
5
|
+
require 'umbra/label'
|
6
|
+
require 'umbra/field'
|
7
|
+
|
8
|
+
def create_footer_window h = 2 , w = FFI::NCurses.COLS, t = FFI::NCurses.LINES-2, l = 0
|
9
|
+
ewin = Window.new(h, w , t, l)
|
10
|
+
end
|
11
|
+
def _alert str
|
12
|
+
win = create_footer_window
|
13
|
+
#FFI::NCurses.init_pair(12, COLOR_WHITE, FFI::NCurses::RED)
|
14
|
+
cp = create_color_pair(COLOR_RED, COLOR_WHITE)
|
15
|
+
win.wbkgd(FFI::NCurses.COLOR_PAIR(cp)) # white on red, defined here
|
16
|
+
win.printstring(0,1, str)
|
17
|
+
win.wrefresh
|
18
|
+
win.getkey
|
19
|
+
win.destroy
|
20
|
+
end
|
21
|
+
def startup
|
22
|
+
require 'logger'
|
23
|
+
require 'date'
|
24
|
+
|
25
|
+
path = File.join(ENV["LOGDIR"] || "./" ,"v.log")
|
26
|
+
file = File.open(path, File::WRONLY|File::TRUNC|File::CREAT)
|
27
|
+
$log = Logger.new(path)
|
28
|
+
$log.level = Logger::DEBUG
|
29
|
+
today = Date.today
|
30
|
+
$log.info "Field demo #{$0} started on #{today}"
|
31
|
+
FFI::NCurses.init_pair(10, FFI::NCurses::BLACK, FFI::NCurses::GREEN) # statusline
|
32
|
+
end
|
33
|
+
def statusline win, str, col = 0
|
34
|
+
win.printstring( FFI::NCurses.LINES-1, col, str, 10)
|
35
|
+
end
|
36
|
+
begin
|
37
|
+
include Umbra
|
38
|
+
init_curses
|
39
|
+
startup
|
40
|
+
#FFI::NCurses.init_pair(12, COLOR_WHITE, FFI::NCurses::RED)
|
41
|
+
win = Window.new
|
42
|
+
statusline(win, " "*(win.width-0), 0)
|
43
|
+
statusline(win, "Press C-q to quit #{win.height}:#{win.width}", 20)
|
44
|
+
title = Label.new( :text => "Demo of Fields", :row => 0, :col => 0 , :width => FFI::NCurses.COLS-1,
|
45
|
+
:justify => :center, :color_pair => CP_BLACK)
|
46
|
+
|
47
|
+
form = Form.new win
|
48
|
+
form.add_widget title
|
49
|
+
labels = ["Name:", "Age:", "Address:","Mobile No.:", "Email Id:","Hobbies:"]
|
50
|
+
labs = []
|
51
|
+
row = 3
|
52
|
+
col = 5
|
53
|
+
labels.each_with_index {|lab, ix|
|
54
|
+
w = Label.new( :text => lab, :row => row, :col => col , :width => 20)
|
55
|
+
labs << w
|
56
|
+
row += 2
|
57
|
+
w.color_pair = CP_WHITE
|
58
|
+
w.justify = :right
|
59
|
+
w.attr = FFI::NCurses::A_BOLD
|
60
|
+
form.add_widget w
|
61
|
+
}
|
62
|
+
labels = ["Roger Federer", "20 Slam Drive","9810012345", "ihumble@tennis.com","golf, programming"]
|
63
|
+
labels = ["name", "age", "address","mobile", "email","hobbies"]
|
64
|
+
|
65
|
+
row = 3
|
66
|
+
col = 30
|
67
|
+
fhash = {}
|
68
|
+
labels.each_with_index {|lab, ix|
|
69
|
+
w = Field.new( :name => lab, :row => row, :col => col , :width => 50)
|
70
|
+
fhash[lab] = w
|
71
|
+
row += 2
|
72
|
+
w.color_pair = CP_CYAN
|
73
|
+
w.attr = FFI::NCurses::A_REVERSE
|
74
|
+
w.highlight_color_pair = CP_YELLOW
|
75
|
+
w.highlight_attr = REVERSE
|
76
|
+
w.null_allowed = true
|
77
|
+
form.add_widget w
|
78
|
+
}
|
79
|
+
message_label = Label.new({text: "Message comes here C-q to quit",
|
80
|
+
:name=>"message_label",:row => win.height-2, :col => 2, :width => 60,
|
81
|
+
:height => 2, :color_pair => CP_MAGENTA})
|
82
|
+
form.add_widget message_label
|
83
|
+
#fhash["mobile"].type = :integer
|
84
|
+
fhash["mobile"].chars_allowed = /[\d\-]/
|
85
|
+
fhash["mobile"].maxlen = 10
|
86
|
+
fhash["mobile"].bind_event(:CHANGE) do |f|
|
87
|
+
message_label.text = "#{f.getvalue.size()} chars entered"
|
88
|
+
statusline(win, "#{f.getvalue.size()} chars entered")
|
89
|
+
message_label.repaint_required
|
90
|
+
end
|
91
|
+
fhash["email"].chars_allowed = /[\w\+\.\@]/
|
92
|
+
fhash["email"].valid_regex = /\w+\@\w+\.\w+/
|
93
|
+
fhash["age"].valid_range = (18..100)
|
94
|
+
fhash["age"].type = :integer
|
95
|
+
fhash["hobbies"].maxlen = 100
|
96
|
+
form.pack
|
97
|
+
form.select_first_field
|
98
|
+
win.wrefresh
|
99
|
+
|
100
|
+
y = x = 1
|
101
|
+
while (ch = win.getkey) != FFI::NCurses::KEY_CTRL_Q
|
102
|
+
begin
|
103
|
+
form.handle_key ch
|
104
|
+
rescue => e
|
105
|
+
_alert(e.to_s)
|
106
|
+
$log.error e
|
107
|
+
$log.error e.backtrace.join("\n")
|
108
|
+
e = nil
|
109
|
+
end
|
110
|
+
win.wrefresh
|
111
|
+
end
|
112
|
+
|
113
|
+
rescue => e
|
114
|
+
win.destroy if win
|
115
|
+
FFI::NCurses.endwin
|
116
|
+
puts "printing inside rescue"
|
117
|
+
puts e
|
118
|
+
puts e.backtrace.join("\n")
|
119
|
+
e = nil
|
120
|
+
ensure
|
121
|
+
win.destroy if win
|
122
|
+
FFI::NCurses.endwin
|
123
|
+
if e
|
124
|
+
puts "printing inside ensure"
|
125
|
+
puts e
|
126
|
+
puts e.backtrace.join("\n")
|
127
|
+
end
|
128
|
+
end
|
data/examples/ex21.rb
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# example showing labeledfield
|
3
|
+
# 2018-03-10
|
4
|
+
require 'umbra'
|
5
|
+
require 'umbra/label'
|
6
|
+
require 'umbra/labeledfield'
|
7
|
+
|
8
|
+
def create_footer_window h = 2 , w = FFI::NCurses.COLS, t = FFI::NCurses.LINES-2, l = 0
|
9
|
+
ewin = Window.new(h, w , t, l)
|
10
|
+
end
|
11
|
+
def _alert str
|
12
|
+
win = create_footer_window
|
13
|
+
#FFI::NCurses.init_pair(12, COLOR_WHITE, FFI::NCurses::RED)
|
14
|
+
cp = create_color_pair(COLOR_RED, COLOR_WHITE)
|
15
|
+
win.wbkgd(FFI::NCurses.COLOR_PAIR(cp)) # white on red, defined here
|
16
|
+
win.printstring(0,1, str)
|
17
|
+
win.wrefresh
|
18
|
+
win.getkey
|
19
|
+
win.destroy
|
20
|
+
end
|
21
|
+
def startup
|
22
|
+
require 'logger'
|
23
|
+
require 'date'
|
24
|
+
|
25
|
+
path = File.join(ENV["LOGDIR"] || "./" ,"v.log")
|
26
|
+
file = File.open(path, File::WRONLY|File::TRUNC|File::CREAT)
|
27
|
+
$log = Logger.new(path)
|
28
|
+
$log.level = Logger::DEBUG
|
29
|
+
today = Date.today
|
30
|
+
$log.info "Field demo #{$0} started on #{today}"
|
31
|
+
FFI::NCurses.init_pair(10, FFI::NCurses::BLACK, FFI::NCurses::GREEN) # statusline
|
32
|
+
end
|
33
|
+
def statusline win, str, col = 0
|
34
|
+
win.printstring( FFI::NCurses.LINES-1, col, str, 10)
|
35
|
+
end
|
36
|
+
begin
|
37
|
+
include Umbra
|
38
|
+
init_curses
|
39
|
+
startup
|
40
|
+
#FFI::NCurses.init_pair(12, COLOR_WHITE, FFI::NCurses::RED)
|
41
|
+
win = Window.new
|
42
|
+
statusline(win, " "*(win.width-0), 0)
|
43
|
+
statusline(win, "Press C-q to quit #{win.height}:#{win.width}", 20)
|
44
|
+
title = Label.new( :text => "Demo of LabeledFields", :row => 0, :col => 0 , :width => FFI::NCurses.COLS-1,
|
45
|
+
:justify => :center, :color_pair => CP_BLACK)
|
46
|
+
|
47
|
+
form = Form.new win
|
48
|
+
form.add_widget title
|
49
|
+
labels = ["Name:", "Age:", "Address:","Mobile No.:", "Email Id:","Hobbies:"]
|
50
|
+
labs = []
|
51
|
+
row = 3
|
52
|
+
col = 5
|
53
|
+
=begin
|
54
|
+
labels.each_with_index {|lab, ix|
|
55
|
+
w = Label.new( :text => lab, :row => row, :col => col , :width => 20)
|
56
|
+
labs << w
|
57
|
+
row += 2
|
58
|
+
w.color_pair = CP_WHITE
|
59
|
+
w.justify = :right
|
60
|
+
w.attr = FFI::NCurses::A_BOLD
|
61
|
+
form.add_widget w
|
62
|
+
}
|
63
|
+
=end
|
64
|
+
labels = ["Name:", "Age:", "Address:","Mobile No.:", "Email Id:","Hobbies:"]
|
65
|
+
names = ["name", "age", "address","mobile", "email","hobbies"]
|
66
|
+
|
67
|
+
row = 3
|
68
|
+
col = 30
|
69
|
+
fhash = {}
|
70
|
+
names.each_with_index {|lab, ix|
|
71
|
+
w = LabeledField.new( :name => lab, :row => row, :col => col , :width => 50, label: labels[ix],
|
72
|
+
:label_highlight_attr => BOLD
|
73
|
+
)
|
74
|
+
fhash[lab] = w
|
75
|
+
row += 2
|
76
|
+
w.color_pair = CP_CYAN
|
77
|
+
w.attr = FFI::NCurses::A_REVERSE
|
78
|
+
w.highlight_color_pair = CP_YELLOW
|
79
|
+
w.highlight_attr = REVERSE
|
80
|
+
w.null_allowed = true
|
81
|
+
form.add_widget w
|
82
|
+
}
|
83
|
+
message_label = Label.new({text: "Message comes here C-q to quit",
|
84
|
+
:name=>"message_label",:row => win.height-2, :col => 2, :width => 60,
|
85
|
+
:height => 2, :color_pair => CP_MAGENTA})
|
86
|
+
form.add_widget message_label
|
87
|
+
#fhash["mobile"].type = :integer
|
88
|
+
fhash["mobile"].chars_allowed = /[\d\-]/
|
89
|
+
fhash["mobile"].maxlen = 10
|
90
|
+
fhash["mobile"].mnemonic = "m"
|
91
|
+
fhash["name"].mnemonic = "n"
|
92
|
+
fhash["age"].mnemonic = "a"
|
93
|
+
fhash["address"].mnemonic = "d"
|
94
|
+
fhash["mobile"].bind_event(:CHANGE) do |f|
|
95
|
+
message_label.text = "#{f.getvalue.size()} chars entered"
|
96
|
+
statusline(win, "#{f.getvalue.size()} chars entered")
|
97
|
+
message_label.repaint_required
|
98
|
+
end
|
99
|
+
fhash["email"].chars_allowed = /[\w\+\.\@]/
|
100
|
+
fhash["email"].valid_regex = /\w+\@\w+\.\w+/
|
101
|
+
fhash["age"].valid_range = (18..100)
|
102
|
+
fhash["age"].type = :integer
|
103
|
+
fhash["hobbies"].maxlen = 100
|
104
|
+
form.pack
|
105
|
+
form.select_first_field
|
106
|
+
win.wrefresh
|
107
|
+
|
108
|
+
y = x = 1
|
109
|
+
while (ch = win.getkey) != FFI::NCurses::KEY_CTRL_Q
|
110
|
+
begin
|
111
|
+
form.handle_key ch
|
112
|
+
rescue => e
|
113
|
+
_alert(e.to_s)
|
114
|
+
$log.error e
|
115
|
+
$log.error e.backtrace.join("\n")
|
116
|
+
e = nil
|
117
|
+
end
|
118
|
+
win.wrefresh
|
119
|
+
end
|
120
|
+
|
121
|
+
rescue => e
|
122
|
+
win.destroy if win
|
123
|
+
FFI::NCurses.endwin
|
124
|
+
puts "printing inside rescue"
|
125
|
+
puts e
|
126
|
+
puts e.backtrace.join("\n")
|
127
|
+
e = nil
|
128
|
+
ensure
|
129
|
+
win.destroy if win
|
130
|
+
FFI::NCurses.endwin
|
131
|
+
if e
|
132
|
+
puts "printing inside ensure"
|
133
|
+
puts e
|
134
|
+
puts e.backtrace.join("\n")
|
135
|
+
end
|
136
|
+
end
|
data/examples/ex3.rb
ADDED
@@ -0,0 +1,163 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# example showing labels and fields and buttons
|
3
|
+
# 2018-03-11
|
4
|
+
require 'umbra'
|
5
|
+
require 'umbra/label'
|
6
|
+
require 'umbra/field'
|
7
|
+
require 'umbra/button'
|
8
|
+
require 'umbra/togglebutton'
|
9
|
+
require 'umbra/checkbox'
|
10
|
+
require 'umbra/buttongroup'
|
11
|
+
require 'umbra/radiobutton'
|
12
|
+
|
13
|
+
def startup
|
14
|
+
require 'logger'
|
15
|
+
require 'date'
|
16
|
+
|
17
|
+
path = File.join(ENV["LOGDIR"] || "./" ,"v.log")
|
18
|
+
file = File.open(path, File::WRONLY|File::TRUNC|File::CREAT)
|
19
|
+
$log = Logger.new(path)
|
20
|
+
$log.level = Logger::DEBUG
|
21
|
+
today = Time.now.to_s
|
22
|
+
$log.info "Button demo #{$0} started on #{today}"
|
23
|
+
FFI::NCurses.init_pair(10, FFI::NCurses::BLACK, FFI::NCurses::GREEN) # statusline
|
24
|
+
end
|
25
|
+
def statusline win, str, col = 1
|
26
|
+
# LINES-2 prints on second last line so that box can be seen
|
27
|
+
win.printstring( FFI::NCurses.LINES-2, col, str, 6, REVERSE)
|
28
|
+
end
|
29
|
+
begin
|
30
|
+
include Umbra
|
31
|
+
init_curses
|
32
|
+
startup
|
33
|
+
#win = Window.new
|
34
|
+
win = Window.new 21,100, 0, 20
|
35
|
+
statusline(win, " "*(win.width-0), 0)
|
36
|
+
win.box
|
37
|
+
statusline(win, "Press C-q to quit #{win.height}:#{win.width}", 20)
|
38
|
+
str = " Demo of Buttons "
|
39
|
+
win.title str
|
40
|
+
|
41
|
+
catch(:close) do
|
42
|
+
form = Form.new win
|
43
|
+
labels = ["Name: ", "Address: ","Mobile No.", "Email Id:","Hobbies: "]
|
44
|
+
labs = []
|
45
|
+
row = 3
|
46
|
+
col = 5
|
47
|
+
labels.each_with_index {|lab, ix|
|
48
|
+
w = Label.new( :text => lab, :row => row, :col => col )
|
49
|
+
labs << w
|
50
|
+
row += 2
|
51
|
+
w.color_pair = 1
|
52
|
+
w.attr = BOLD
|
53
|
+
form.add_widget w
|
54
|
+
}
|
55
|
+
labels = ["Roger Federer", "20 Slam Drive","9810012345", "ihumble@tennis.com","golf, programming"]
|
56
|
+
labels = ["name", "address","mobile", "email","hobbies"]
|
57
|
+
|
58
|
+
row = 3
|
59
|
+
col = 30
|
60
|
+
labels.each_with_index {|lab, ix|
|
61
|
+
w = Field.new( :name => lab, :row => row, :col => col , :width => 50)
|
62
|
+
labs << w
|
63
|
+
row += 2
|
64
|
+
w.color_pair = 1
|
65
|
+
w.attr = REVERSE
|
66
|
+
form.add_widget w
|
67
|
+
}
|
68
|
+
|
69
|
+
message_label = Label.new({text: "Message comes here C-q to quit",
|
70
|
+
:name=>"message_label",:row => win.height-2, :col => 2, :width => 60,
|
71
|
+
:height => 2, :color_pair => 5})
|
72
|
+
|
73
|
+
row += 0
|
74
|
+
togglebutton = ToggleButton.new()
|
75
|
+
togglebutton.value = true
|
76
|
+
togglebutton.onvalue = " Toggle Down "
|
77
|
+
togglebutton.offvalue =" Untoggle "
|
78
|
+
togglebutton.row = row
|
79
|
+
togglebutton.col = col
|
80
|
+
togglebutton.command do
|
81
|
+
if togglebutton.value
|
82
|
+
message_label.text = "Toggle button was pressed"
|
83
|
+
else
|
84
|
+
message_label.text = "UNToggle button was pressed"
|
85
|
+
end
|
86
|
+
# we need this since we have done away with dsl_property
|
87
|
+
message_label.repaint_required = true
|
88
|
+
end
|
89
|
+
form.add_widget togglebutton
|
90
|
+
|
91
|
+
check = Checkbox.new text: "No Frames", value: true, row: row+1, col: col, mnemonic: "N"
|
92
|
+
check1 = Checkbox.new text: "Use https", value: false, row: row+2, col: col, mnemonic: "U"
|
93
|
+
row += 2
|
94
|
+
form.add_widget check, check1
|
95
|
+
[ check, check1 ].each do |cb|
|
96
|
+
cb.command do
|
97
|
+
message_label.text = "#{cb.text} is now #{cb.value}"
|
98
|
+
message_label.repaint_required = true
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
radio1 = RadioButton.new text: "Red", value: "Red", row: check.row, col: col+20
|
103
|
+
radio2 = RadioButton.new text: "Blue", value: "Blue", row: check1.row, col: col+20
|
104
|
+
group = ButtonGroup.new "Color"
|
105
|
+
group.add(radio1).add(radio2)
|
106
|
+
form.add_widget radio1, radio2
|
107
|
+
group.command do
|
108
|
+
message_label.text = "#{group.name} #{group.value} has been selected"
|
109
|
+
message_label.repaint_required = true
|
110
|
+
end
|
111
|
+
|
112
|
+
ok_butt = Button.new( :name => 'ok', :text => 'Ok', :row => row+2, :col => col, :width => 10 , :color_pair => 0, :mnemonic => 'O')
|
113
|
+
cancel_butt = Button.new( :name => 'cancel', :text => 'Cancel', :row => row+2, :col => col + 20, :width => 10 , :color_pair => 0, mnemonic: 'C')
|
114
|
+
form.add_widget ok_butt
|
115
|
+
form.add_widget cancel_butt
|
116
|
+
FFI::NCurses.mvwhline(win.pointer, ok_butt.row+1, 1, FFI::NCurses::ACS_HLINE, win.width-2)
|
117
|
+
cancel_butt.command do
|
118
|
+
throw :close
|
119
|
+
end
|
120
|
+
ok_butt.command do
|
121
|
+
form.focusables.each_with_index {|f, ix|
|
122
|
+
if f.class.to_s == "Field"
|
123
|
+
$log.debug "FIELD #{f.name} = #{f.text}"
|
124
|
+
else
|
125
|
+
$log.debug "WIDGET #{f.class.to_s}, #{f.name} = #{f.text}"
|
126
|
+
end
|
127
|
+
}
|
128
|
+
throw :close
|
129
|
+
end
|
130
|
+
|
131
|
+
|
132
|
+
form.add_widget message_label
|
133
|
+
|
134
|
+
form.pack
|
135
|
+
form.select_first_field
|
136
|
+
win.wrefresh
|
137
|
+
|
138
|
+
y = x = 1
|
139
|
+
while (ch = win.getch) != FFI::NCurses::KEY_CTRL_Q
|
140
|
+
begin
|
141
|
+
form.handle_key ch
|
142
|
+
rescue => e
|
143
|
+
puts e
|
144
|
+
puts e.backtrace.join("\n")
|
145
|
+
end
|
146
|
+
win.wrefresh
|
147
|
+
end
|
148
|
+
end # close
|
149
|
+
|
150
|
+
rescue => e
|
151
|
+
win.destroy if win
|
152
|
+
win = nil
|
153
|
+
FFI::NCurses.endwin
|
154
|
+
puts e
|
155
|
+
puts e.backtrace.join("\n")
|
156
|
+
ensure
|
157
|
+
win.destroy if win
|
158
|
+
FFI::NCurses.endwin
|
159
|
+
if e
|
160
|
+
puts e
|
161
|
+
puts e.backtrace.join("\n")
|
162
|
+
end
|
163
|
+
end
|