rndk 0.2.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -4
- data/TODO +21 -1
- data/demos/appointment.rb +279 -299
- data/demos/clock.rb +13 -8
- data/demos/rss-reader.rb +84 -0
- data/examples/01-hello-world.rb +13 -11
- data/examples/02-colors.rb +14 -21
- data/examples/03-markup.rb +7 -7
- data/examples/04-quick-widgets.rb +2 -2
- data/examples/05-position-widget.rb +50 -31
- data/examples/06-callbacks.rb +77 -0
- data/examples/07-traverse.rb +90 -0
- data/examples/10-all-widgets.rb +165 -0
- data/examples/calendar.rb +20 -32
- data/examples/entry.rb +15 -20
- data/examples/label.rb +11 -11
- data/examples/scroll.rb +16 -60
- data/examples/slider.rb +18 -19
- data/examples/viewer.rb +65 -0
- data/lib/rndk.rb +28 -7
- data/lib/rndk/alphalist.rb +309 -313
- data/lib/rndk/button.rb +239 -157
- data/lib/rndk/buttonbox.rb +136 -103
- data/lib/rndk/calendar.rb +246 -203
- data/lib/rndk/core/color.rb +63 -13
- data/lib/rndk/core/display.rb +1 -1
- data/lib/rndk/core/draw.rb +11 -11
- data/lib/rndk/core/markup.rb +21 -21
- data/lib/rndk/core/quick_widgets.rb +75 -96
- data/lib/rndk/core/screen.rb +145 -102
- data/lib/rndk/core/traverse.rb +150 -136
- data/lib/rndk/core/utils.rb +5 -6
- data/lib/rndk/core/widget.rb +207 -191
- data/lib/rndk/core/widget_bind.rb +108 -0
- data/lib/rndk/dialog.rb +88 -56
- data/lib/rndk/entry.rb +79 -64
- data/lib/rndk/fscale.rb +38 -20
- data/lib/rndk/fslider.rb +38 -23
- data/lib/rndk/graph.rb +92 -53
- data/lib/rndk/itemlist.rb +80 -62
- data/lib/rndk/label.rb +111 -77
- data/lib/rndk/radio.rb +138 -128
- data/lib/rndk/scale.rb +123 -122
- data/lib/rndk/scroll.rb +444 -391
- data/lib/rndk/scroller.rb +21 -21
- data/lib/rndk/slider.rb +149 -140
- data/lib/rndk/template.rb +74 -61
- data/lib/rndk/version.rb +1 -1
- data/lib/rndk/viewer.rb +499 -298
- metadata +8 -14
- data/demos/fileview.rb +0 -141
- data/lib/rndk/dscale.rb +0 -13
- data/lib/rndk/fselect.rb +0 -938
- data/lib/rndk/histogram.rb +0 -412
- data/lib/rndk/marquee.rb +0 -244
- data/lib/rndk/matrix.rb +0 -1189
- data/lib/rndk/mentry.rb +0 -619
- data/lib/rndk/menu.rb +0 -478
- data/lib/rndk/selection.rb +0 -630
- data/lib/rndk/swindow.rb +0 -766
- data/lib/rndk/uscale.rb +0 -14
- data/lib/rndk/uslider.rb +0 -14
data/demos/clock.rb
CHANGED
@@ -11,19 +11,24 @@ require 'rndk/label'
|
|
11
11
|
|
12
12
|
begin
|
13
13
|
# Set up RNDK
|
14
|
-
|
14
|
+
screen = RNDK::Screen.new
|
15
15
|
RNDK::Color.init
|
16
16
|
|
17
17
|
# Initial time string
|
18
18
|
mesg = ['</1/B>HH:MM:SS']
|
19
19
|
|
20
20
|
# Declare the labels.
|
21
|
-
label = RNDK::Label.new(
|
21
|
+
label = RNDK::Label.new(screen, {
|
22
|
+
:x => RNDK::CENTER,
|
23
|
+
:y => RNDK::CENTER,
|
24
|
+
:text => mesg,
|
25
|
+
:shadow => true
|
26
|
+
})
|
22
27
|
|
23
28
|
# Woops, something bad happened
|
24
29
|
if label.nil?
|
25
|
-
|
26
|
-
RNDK::Screen.
|
30
|
+
screen.destroy
|
31
|
+
RNDK::Screen.finish
|
27
32
|
|
28
33
|
puts "Cannot create the label. Is the window too small?"
|
29
34
|
exit 1
|
@@ -47,18 +52,18 @@ begin
|
|
47
52
|
mesg = [str]
|
48
53
|
|
49
54
|
# Set the label contents
|
50
|
-
label.set(mesg
|
55
|
+
label.set(:text => mesg)
|
51
56
|
|
52
57
|
# Draw the label and sleep
|
53
|
-
label.draw
|
58
|
+
label.draw
|
54
59
|
Ncurses.napms(500)
|
55
60
|
end
|
56
61
|
|
57
|
-
RNDK::Screen.
|
62
|
+
RNDK::Screen.finish
|
58
63
|
|
59
64
|
# In case something goes wrong
|
60
65
|
rescue Exception => e
|
61
|
-
RNDK::Screen.
|
66
|
+
RNDK::Screen.finish
|
62
67
|
|
63
68
|
puts e
|
64
69
|
puts e.inspect
|
data/demos/rss-reader.rb
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# A simple RSS reader.
|
4
|
+
# It receives a feed address as an argument, defaulting to the
|
5
|
+
# Ruby Language feed if not provided.
|
6
|
+
#
|
7
|
+
# When an item is selected, it's content pops-up.
|
8
|
+
#
|
9
|
+
require 'rss'
|
10
|
+
require 'open-uri'
|
11
|
+
require 'rndk/label'
|
12
|
+
require 'rndk/scroll'
|
13
|
+
|
14
|
+
DEFAULT_URL = 'https://www.ruby-lang.org/en/feeds/news.rss'
|
15
|
+
|
16
|
+
begin
|
17
|
+
# which feed
|
18
|
+
url = DEFAULT_URL
|
19
|
+
url = ARGV.first if ARGV.first
|
20
|
+
|
21
|
+
# retrieving things
|
22
|
+
puts 'Fetching feeds...'
|
23
|
+
feed = RSS::Parser.parse (open url)
|
24
|
+
|
25
|
+
# starting RNDK
|
26
|
+
screen = RNDK::Screen.new
|
27
|
+
RNDK::Color.init
|
28
|
+
|
29
|
+
# building label
|
30
|
+
title = ["<C></77>#{feed.channel.title}",
|
31
|
+
"</76>Press ESC to quit"]
|
32
|
+
|
33
|
+
label = RNDK::Label.new(screen, {
|
34
|
+
:x => RNDK::CENTER,
|
35
|
+
:y => RNDK::TOP,
|
36
|
+
:title => "</77>#{feed.channel.title}"
|
37
|
+
})
|
38
|
+
|
39
|
+
# will show the titles at scroll widget
|
40
|
+
titles = []
|
41
|
+
feed.items.each { |item| titles << item.title }
|
42
|
+
|
43
|
+
# building scroll
|
44
|
+
scroll = RNDK::Scroll.new(screen, {
|
45
|
+
:x => RNDK::CENTER,
|
46
|
+
:y => 4,
|
47
|
+
:width => RNDK::Screen.width/2,
|
48
|
+
:height => RNDK::Screen.height/2 - 5,
|
49
|
+
:title => "<C></77>Items",
|
50
|
+
:items => titles,
|
51
|
+
:numbers => true,
|
52
|
+
:highlight => RNDK::Color[:cyan],
|
53
|
+
})
|
54
|
+
screen.refresh
|
55
|
+
|
56
|
+
loop do
|
57
|
+
scroll.activate
|
58
|
+
|
59
|
+
# Scroll exited, thus the
|
60
|
+
# user selected an item
|
61
|
+
# or pressed ESC to get out
|
62
|
+
if scroll.exit_type == :NORMAL
|
63
|
+
|
64
|
+
# Getting current item's content
|
65
|
+
index = scroll.current_item
|
66
|
+
raw_message = feed.items[index].description
|
67
|
+
|
68
|
+
# Removing '\n' at the end of all the lines.
|
69
|
+
message = []
|
70
|
+
raw_message.lines.each { |line| message << line.chomp }
|
71
|
+
|
72
|
+
# Show current item's content on a pop-up
|
73
|
+
screen.popup_label message
|
74
|
+
|
75
|
+
# user pressed ESC - wants to quit
|
76
|
+
elsif scroll.exit_type == :ESCAPE_HIT
|
77
|
+
|
78
|
+
# good bye!
|
79
|
+
RNDK::Screen.finish
|
80
|
+
exit
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
data/examples/01-hello-world.rb
CHANGED
@@ -7,7 +7,7 @@ require 'rndk/label'
|
|
7
7
|
|
8
8
|
begin
|
9
9
|
# Startup Ncurses and RNDK
|
10
|
-
|
10
|
+
screen = RNDK::Screen.new
|
11
11
|
|
12
12
|
# Set up RNDK colors
|
13
13
|
RNDK::Color.init
|
@@ -24,32 +24,34 @@ begin
|
|
24
24
|
]
|
25
25
|
|
26
26
|
# Declare the labels.
|
27
|
-
label = RNDK::Label.new(
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
27
|
+
label = RNDK::Label.new(screen, {
|
28
|
+
:x => RNDK::CENTER,
|
29
|
+
:y => RNDK::CENTER,
|
30
|
+
:text => mesg,
|
31
|
+
})
|
32
|
+
|
33
33
|
|
34
34
|
if label.nil?
|
35
35
|
# Clean up the memory.
|
36
|
-
|
36
|
+
screen.destroy
|
37
37
|
|
38
38
|
# End curses...
|
39
|
-
RNDK::Screen.
|
39
|
+
RNDK::Screen.finish
|
40
40
|
|
41
41
|
puts "Cannot create the label. Is the window too small?"
|
42
42
|
exit 1
|
43
43
|
end
|
44
44
|
|
45
45
|
# Draw the RNDK screen and waits for space to be pressed.
|
46
|
-
|
46
|
+
screen.refresh
|
47
47
|
label.wait(' ')
|
48
48
|
|
49
49
|
# Ending Ncurses and RNDK
|
50
|
-
RNDK::Screen.
|
50
|
+
RNDK::Screen.finish
|
51
51
|
end
|
52
52
|
|
53
53
|
# Note: Unlike C's CDK, there's no need to clean up
|
54
54
|
# widgets/screens when finishing execution.
|
55
|
+
# You might need to do it when deleting widgets
|
56
|
+
# casually, though.
|
55
57
|
|
data/examples/02-colors.rb
CHANGED
@@ -11,7 +11,7 @@ begin
|
|
11
11
|
RNDK::Color.init
|
12
12
|
|
13
13
|
# Disabling the blinking cursor
|
14
|
-
|
14
|
+
RNDK::blink_cursor true
|
15
15
|
|
16
16
|
# Welcome to our Calendar Widget!
|
17
17
|
#
|
@@ -25,30 +25,23 @@ begin
|
|
25
25
|
#
|
26
26
|
# RNDK::Color[:foreground]
|
27
27
|
#
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
0, # year
|
37
|
-
RNDK::Color[:red_yellow], # day attrib
|
38
|
-
RNDK::Color[:cyan_white], # month attrib
|
39
|
-
RNDK::Color[:black_cyan], # year attrib
|
40
|
-
RNDK::Color[:red], # highlight
|
41
|
-
true, # has box?
|
42
|
-
false) # has shadow?
|
28
|
+
cal = RNDK::Calendar.new(screen, {
|
29
|
+
:x => RNDK::CENTER,
|
30
|
+
:y => RNDK::CENTER,
|
31
|
+
:title => "Colored calendar",
|
32
|
+
:day_color => RNDK::Color[:red_yellow],
|
33
|
+
:highlight => RNDK::Color[:red],
|
34
|
+
})
|
35
|
+
# Oh yeah
|
43
36
|
cal.activate
|
44
37
|
|
45
|
-
RNDK::Screen.
|
38
|
+
RNDK::Screen.finish
|
46
39
|
|
47
|
-
# Assuring we end RNDK in case something
|
48
|
-
# bad happens.
|
49
|
-
# You'll see this a lot on the examples.
|
40
|
+
# Assuring we end RNDK in case something
|
41
|
+
# bad happens.
|
42
|
+
# You'll see this a lot on the examples.
|
50
43
|
rescue Exception => e
|
51
|
-
RNDK::Screen.
|
44
|
+
RNDK::Screen.finish
|
52
45
|
|
53
46
|
puts e
|
54
47
|
puts e.inspect
|
data/examples/03-markup.rb
CHANGED
@@ -57,16 +57,16 @@ begin
|
|
57
57
|
msg << "<C>All RNDK color pairs (press 'q' to quit)"
|
58
58
|
|
59
59
|
# Show label with that huge message.
|
60
|
-
label = RNDK::Label.new(screen,
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
60
|
+
label = RNDK::Label.new(screen, {
|
61
|
+
:x => RNDK::CENTER,
|
62
|
+
:y => 1,
|
63
|
+
:text => msg,
|
64
|
+
:shadow => true
|
65
|
+
})
|
66
66
|
|
67
67
|
screen.refresh
|
68
68
|
label.wait('q') # wait for key to be pressed
|
69
69
|
|
70
|
-
RNDK::Screen.
|
70
|
+
RNDK::Screen.finish
|
71
71
|
end
|
72
72
|
|
@@ -57,13 +57,13 @@ begin
|
|
57
57
|
screen.popup_label ["You just said '#{value}'"]
|
58
58
|
|
59
59
|
# Finally, the end!
|
60
|
-
RNDK::Screen.
|
60
|
+
RNDK::Screen.finish
|
61
61
|
|
62
62
|
puts "...and as always, thanks for watching!"
|
63
63
|
|
64
64
|
# Just in case something bad happens.
|
65
65
|
rescue Exception => e
|
66
|
-
RNDK::Screen.
|
66
|
+
RNDK::Screen.finish
|
67
67
|
|
68
68
|
puts e
|
69
69
|
puts e.inspect
|
@@ -33,69 +33,88 @@
|
|
33
33
|
require 'rndk/entry'
|
34
34
|
|
35
35
|
begin
|
36
|
+
title = "</77>Entry"
|
36
37
|
label = "</U/5>Position me:<!U!5> "
|
37
38
|
|
38
39
|
# Set up RNDK
|
39
40
|
curses_win = Ncurses.initscr
|
40
|
-
|
41
|
+
screen = RNDK::Screen.new(curses_win)
|
41
42
|
|
42
43
|
# Set up RNDK colors
|
43
44
|
RNDK::Color.init
|
44
45
|
|
45
46
|
# Create the entry field widget.
|
46
|
-
entry = RNDK::Entry.new(
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
:MIXED,
|
54
|
-
30, # w
|
55
|
-
0,
|
56
|
-
256,
|
57
|
-
true,
|
58
|
-
false)
|
47
|
+
entry = RNDK::Entry.new(screen, {
|
48
|
+
:x => RNDK::CENTER,
|
49
|
+
:y => RNDK::BOTTOM,
|
50
|
+
:label => label,
|
51
|
+
:title => title,
|
52
|
+
:field_width => 30
|
53
|
+
})
|
59
54
|
|
60
55
|
if entry.nil?
|
61
|
-
|
62
|
-
RNDK::Screen.
|
56
|
+
screen.destroy
|
57
|
+
RNDK::Screen.finish
|
63
58
|
|
64
59
|
puts "Cannot create the entry box. Is the window too small?"
|
65
60
|
exit 1
|
66
61
|
end
|
67
62
|
|
63
|
+
# Create a label explaining the keybindings
|
64
|
+
help = ["</77>Keybindings",
|
65
|
+
"Up Arrow Moves the widget up one row.",
|
66
|
+
|
67
|
+
"Down Arrow Moves the widget down one row.",
|
68
|
+
"Left Arrow Moves the widget left one column",
|
69
|
+
"Right Arrow Moves the widget right one column",
|
70
|
+
"1 Moves the widget down one row and left one column.",
|
71
|
+
"2 Moves the widget down one row.",
|
72
|
+
"3 Moves the widget down one row and right one column.",
|
73
|
+
"4 Moves the widget left one column.",
|
74
|
+
"5 Centers the widget both vertically and horizontally.",
|
75
|
+
"6 Moves the widget right one column",
|
76
|
+
"7 Moves the widget up one row and left one column.",
|
77
|
+
"8 Moves the widget up one row.",
|
78
|
+
"9 Moves the widget up one row and right one column.",
|
79
|
+
"t Moves the widget to the top of the screen.",
|
80
|
+
"b Moves the widget to the bottom of the screen.",
|
81
|
+
"l Moves the widget to the left of the screen.",
|
82
|
+
"r Moves the widget to the right of the screen.",
|
83
|
+
"c Centers the widget between the left and right of the window.",
|
84
|
+
"C Centers the widget between the top and bottom of the window.",
|
85
|
+
"Escape Returns the widget to its original position.",
|
86
|
+
"Return Exits the function and leaves the Widget where"]
|
87
|
+
|
88
|
+
label = RNDK::Label.new(screen, :text => help)
|
89
|
+
label.draw
|
90
|
+
|
68
91
|
# Let the user move the widget around the window.
|
69
|
-
entry.draw
|
92
|
+
entry.draw
|
70
93
|
entry.position
|
71
94
|
|
72
95
|
# Activate the entry field.
|
73
|
-
info = entry.activate
|
96
|
+
info = entry.activate
|
74
97
|
|
75
98
|
# Tell them what they typed.
|
76
99
|
if entry.exit_type == :ESCAPE_HIT
|
77
|
-
mesg = [
|
78
|
-
"<C>You hit escape. No information passed back.",
|
100
|
+
mesg = ["<C>You hit escape. No information passed back.",
|
79
101
|
"",
|
80
|
-
"<C>Press any key to continue."
|
81
|
-
|
82
|
-
rndkscreen.popup_label mesg
|
102
|
+
"<C>Press any key to continue."]
|
103
|
+
screen.popup_label mesg
|
83
104
|
|
84
105
|
elsif entry.exit_type == :NORMAL
|
85
|
-
mesg = [
|
86
|
-
"<C
|
87
|
-
"<C>%.*s" % [236, info], # FIXME magic number
|
106
|
+
mesg = ["<C>You typed in the following",
|
107
|
+
"<C></77>#{info}",
|
88
108
|
"",
|
89
|
-
"<C>Press any key to continue."
|
90
|
-
|
91
|
-
rndkscreen.popup_label mesg
|
109
|
+
"<C>Press any key to continue."]
|
110
|
+
screen.popup_label mesg
|
92
111
|
end
|
93
112
|
|
94
|
-
RNDK::Screen.
|
113
|
+
RNDK::Screen.finish
|
95
114
|
|
96
115
|
# Just in case something bad happens.
|
97
116
|
rescue Exception => e
|
98
|
-
RNDK::Screen.
|
117
|
+
RNDK::Screen.finish
|
99
118
|
|
100
119
|
puts e
|
101
120
|
puts e.inspect
|
@@ -0,0 +1,77 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Shows a scrollbar with your files and keep
|
4
|
+
# asking to interrupt scrolling.
|
5
|
+
#
|
6
|
+
# It means you can set custom functions to
|
7
|
+
# execute right before and right after processing
|
8
|
+
# input on the widget.
|
9
|
+
#
|
10
|
+
# To exit press ENTER or TAB.
|
11
|
+
#
|
12
|
+
require 'rndk/scroll'
|
13
|
+
|
14
|
+
begin
|
15
|
+
screen = RNDK::Screen.new
|
16
|
+
RNDK::Color.init
|
17
|
+
|
18
|
+
# Creating scroll based on your current dir's files.
|
19
|
+
# Nothing should be new here
|
20
|
+
title = "<C></77>Your files"
|
21
|
+
list = `ls -l`.lines
|
22
|
+
|
23
|
+
scroll = RNDK::Scroll.new(screen, {
|
24
|
+
:x => RNDK::CENTER,
|
25
|
+
:y => RNDK::CENTER,
|
26
|
+
:scroll_bar => RNDK::LEFT,
|
27
|
+
:width => RNDK::Screen.width/2,
|
28
|
+
:height => RNDK::Screen.height/2,
|
29
|
+
:title => title,
|
30
|
+
:items => list,
|
31
|
+
:highlight => RNDK::Color[:green]
|
32
|
+
})
|
33
|
+
|
34
|
+
# Here comes the good stuff.
|
35
|
+
# We're assigning blocks to run before and after
|
36
|
+
# the widget processes your input.
|
37
|
+
#
|
38
|
+
# Right before processing input, it'll create
|
39
|
+
# this popup dialog.
|
40
|
+
# Based on your answer it will stop scrolling or not.
|
41
|
+
#
|
42
|
+
# That's because a if a `before_processing` block
|
43
|
+
# return false, it aborts processing the current
|
44
|
+
# char.
|
45
|
+
# If it returns true, it keeps going.
|
46
|
+
#
|
47
|
+
scroll.bind_signal(:before_input) do |key|
|
48
|
+
message = ["</73>You just pressed </74>#{Ncurses.keyname key}",
|
49
|
+
"</73>Skip current action?"]
|
50
|
+
buttons = ["Yes", "No"]
|
51
|
+
|
52
|
+
choice = screen.popup_dialog(message, buttons)
|
53
|
+
|
54
|
+
if choice == 0 then false else true end
|
55
|
+
end
|
56
|
+
|
57
|
+
# This is run after the widget processes your
|
58
|
+
# input.
|
59
|
+
# It's commented to avoid annoyance.
|
60
|
+
# Uncomment for awesomeness
|
61
|
+
|
62
|
+
#scroll.bind_signal(:after_input) { screen.popup_label "</75>You did it!" }
|
63
|
+
|
64
|
+
|
65
|
+
# Finally, we activate the widget!
|
66
|
+
scroll.activate
|
67
|
+
|
68
|
+
RNDK::Screen.finish
|
69
|
+
|
70
|
+
# Just in case something bad happens.
|
71
|
+
rescue Exception => e
|
72
|
+
RNDK::Screen.finish
|
73
|
+
puts e
|
74
|
+
puts e.inspect
|
75
|
+
puts e.backtrace
|
76
|
+
end
|
77
|
+
|