rndk 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.yardopts +1 -0
  4. data/README.md +61 -42
  5. data/demos/appointment.rb +2 -2
  6. data/demos/clock.rb +1 -1
  7. data/demos/fileview.rb +0 -0
  8. data/examples/01-hello-world.rb +1 -1
  9. data/examples/02-colors.rb +1 -1
  10. data/examples/03-markup.rb +6 -4
  11. data/examples/04-quick-widgets.rb +1 -0
  12. data/examples/05-position-widget.rb +1 -1
  13. data/examples/entry.rb +76 -0
  14. data/examples/label.rb +51 -0
  15. data/examples/scroll.rb +68 -42
  16. data/examples/slider.rb +70 -0
  17. data/lib/rndk/alphalist.rb +224 -116
  18. data/lib/rndk/button.rb +4 -2
  19. data/lib/rndk/buttonbox.rb +1 -1
  20. data/lib/rndk/calendar.rb +18 -23
  21. data/lib/rndk/core/draw.rb +0 -30
  22. data/lib/rndk/core/quick_widgets.rb +9 -10
  23. data/lib/rndk/core/utils.rb +6 -6
  24. data/lib/rndk/core/widget.rb +9 -1
  25. data/lib/rndk/dialog.rb +1 -6
  26. data/lib/rndk/dscale.rb +1 -1
  27. data/lib/rndk/entry.rb +266 -116
  28. data/lib/rndk/fscale.rb +1 -1
  29. data/lib/rndk/fselect.rb +13 -15
  30. data/lib/rndk/fslider.rb +1 -1
  31. data/lib/rndk/graph.rb +1 -1
  32. data/lib/rndk/histogram.rb +1 -1
  33. data/lib/rndk/itemlist.rb +1 -1
  34. data/lib/rndk/label.rb +7 -6
  35. data/lib/rndk/marquee.rb +1 -1
  36. data/lib/rndk/matrix.rb +1 -1
  37. data/lib/rndk/mentry.rb +8 -8
  38. data/lib/rndk/menu.rb +1 -1
  39. data/lib/rndk/radio.rb +1 -1
  40. data/lib/rndk/scale.rb +1 -1
  41. data/lib/rndk/scroll.rb +138 -55
  42. data/lib/rndk/scroller.rb +9 -1
  43. data/lib/rndk/selection.rb +1 -1
  44. data/lib/rndk/slider.rb +123 -42
  45. data/lib/rndk/swindow.rb +10 -10
  46. data/lib/rndk/template.rb +1 -1
  47. data/lib/rndk/uscale.rb +1 -1
  48. data/lib/rndk/uslider.rb +1 -1
  49. data/lib/rndk/version.rb +1 -1
  50. data/lib/rndk/viewer.rb +3 -3
  51. data/rndk.gemspec +1 -1
  52. metadata +7 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c8f9ad279e8103fa755fa296a6ce77f841d44447
4
- data.tar.gz: 645cac649bc64fc804541c71868800aa28b172e4
3
+ metadata.gz: 658d93a038f41e69767bd1f8a24f0ed69ab21d61
4
+ data.tar.gz: 085b8d4cf88241e7ed481736a8356be356341628
5
5
  SHA512:
6
- metadata.gz: 66e6a0f5bdda584d982e13ecb89643c09f0acc07061c9de05912ecdaff70abf22163d87eba05fd4405d5fbff2672e75188cf07d37a7a22d121a65386612f5a12
7
- data.tar.gz: 6ab7a46f6aa062a58d3b79a7620665eae38e1b0f6bfbeff64eaa4fd31a78d5dd700b5c9845789b12fda15c7ca77a27e8e8a2976338e1ebf1ee6f3d319b46f457
6
+ metadata.gz: f632241c52b6accf9e017d3e2d8e26e7836d46fcbcbfcd14a3dfa8b092da98fd69500be4921a8744f87d8ecaef19bb1aacfb6cfd0e599deb227b1612242e35e1
7
+ data.tar.gz: 4b18178e17b1ab81820caaf5a79fc0ab0bf66f31dfb2bf92f47c1b517fe2ced0a8c594dfb50573a391117b2b0197ace571d152257bdd05a0024c0e1710cb88c7
data/.gitignore CHANGED
@@ -21,3 +21,4 @@ spec/reports
21
21
  test/tmp
22
22
  test/version_tmp
23
23
  tmp
24
+
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ -m markdown
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  # Ruby Ncurses Development Kit (RNDK)
2
+ [![Gem Version](https://badge.fury.io/rb/rndk.png)](http://badge.fury.io/rb/rndk)
2
3
 
3
4
  `rndk` aims to be a powerful, well-documented and easy-to-use
4
5
  Ncurses Development Kit in Ruby. Besides abstracting away Ncurses'
@@ -10,51 +11,50 @@ applications, easily creating nice apps for the console.
10
11
  `RNDK` is a fork from `tawny-cdk`, a [Chris Sauro Ruby port][tawny]
11
12
  of [Thomas Dickey's Curses Development Kit][cdk] (in C).
12
13
 
13
- Currently implemented widgets:
14
-
15
- * Alphalist
16
- * Button
17
- * Buttonbox
18
- * Calendar
19
- * Dialog
20
- * Entry
21
- * File Selector
22
- * Graph
23
- * Histogram
24
- * Item List
25
- * Label
26
- * Matrix
27
- * Marquee
28
- * Menu
29
- * Multiple Line Entry
30
- * Radio List
31
- * Scale
32
- * Scrolling List
33
- * Scrolling Window
34
- * Selection List
35
- * Slider
36
- * Template
37
- * Viewer
14
+ Here's the list of currently implemented widgets:
15
+
16
+ | Widget | Description | Has examples? |
17
+ | --------------------- | ----------------------------------------------- | ------------- |
18
+ | Alphalist | Scrolling list of alphabetically sorted words | not yet |
19
+ | Button | Message attached to a callback | not yet |
20
+ | Buttonbox | Labeled set of buttons | not yet |
21
+ | Calendar | Pop-up traversable calendar | yes! |
22
+ | Dialog | Dialog box with a message and some buttons | not yet |
23
+ | Entry | Text-entry box with a label | yes! |
24
+ | File Selector | Interact graphically with the file system | not yet |
25
+ | Graph | Plots a graph with x/y coordinates | not yet |
26
+ | Histogram | Vertical/horizontal histogram | not yet |
27
+ | Item List | Select from a preset item list | not yet |
28
+ | Label | Pop-up label window | yes! |
29
+ | Matrix | Matrix widget | not yet |
30
+ | Marquee | Movable text | not yet |
31
+ | Menu | Pull-down menu list | not yet |
32
+ | Multiple Line Entry | Multiple-line entry box with a label | not yet |
33
+ | Radio List | Radio item list | not yet |
34
+ | Scale | Draggable scale box with a label | not yet |
35
+ | Scrolling List | Scrolling item list | yes! |
36
+ | Scrolling Window | Display scrollable long messages | not yet |
37
+ | Selection List | Selection list widget | not yet |
38
+ | Slider | Visual slider box | yes! |
39
+ | Template | Insert info on a field with a pre-set format | not yet |
40
+ | Viewer | View contents of a file on a scrollable box | not yet |
41
+
42
+ The ones with examples (on the root `examples` directory) are ready to use.
43
+ The others are kinda unstable, since the API is being completely rewritten.
44
+ Also, [click here for screenshots][widgets]!
38
45
 
39
46
  ## WARNING
40
47
 
41
- This is a very unstable Work-in-Progress library.
48
+ This is a very unstable Work-in-Progress library. I'm currently reviewing
49
+ `tawny-cdk`'s API, so a lot of things are changing real fast.
42
50
 
43
- I'm currently reviewing `tawny-cdk`'s API, so a lot of things are
44
- changing real fast.
51
+ Be sure to know that whenever I remove this notice, things will be nicer. For
52
+ now, I recommend you to **not** use `rndk` for production programs!
45
53
 
46
- Be sure to know that whenever I remove this notice, things will be
47
- nicer.
48
-
49
- For now, I recommend you to **not** use `rndk` for production
50
- programs!
51
-
52
- ## Requirements
54
+ ## Installation
53
55
 
54
56
  `rndk` requires the gem `ffi-ncurses`.
55
57
 
56
- ## Installation
57
-
58
58
  Add this line to your application's Gemfile:
59
59
 
60
60
  gem 'rndk'
@@ -69,26 +69,34 @@ Or install it yourself as:
69
69
 
70
70
  ## Usage
71
71
 
72
+ [Take a look at the Wiki][wiki]! There's some tutorials and
73
+ resources there.
74
+
72
75
  The `examples` directory contains lots of sample usages for every
73
76
  widget available. To execute them, go to the `rndk` root folder
74
77
  and run:
75
78
 
76
79
  ruby -Ilib examples/YOUR_EXAMPLE_HERE
77
80
 
78
- There's also some more comples demo applications under the `demos`
81
+ There's also some more complex demo applications under the `demos`
79
82
  directory. Do the same:
80
83
 
81
84
  ruby -Ilib demos/YOUR_DEMO_HERE
82
85
 
83
86
  ## Contributing
84
87
 
88
+ Any help would be largely appreciated! For a list of things
89
+ to do, see the `TODO` file.
90
+
85
91
  Currently `rndk` has a C-like API, since it was directly taken
86
- from `cdk`. The top priority is to make it more rubyish (maybe
87
- studying [rbcurse]?).
92
+ from `cdk`. The top priority is to make it more rubyish.
93
+
94
+ I'm getting inspiration from [rbcurse] and some non-ruby Widget
95
+ sets.
88
96
 
89
- Also, see the `TODO` file.
97
+ Step-by-step guide to contribute:
90
98
 
91
- 1. Fork it
99
+ 1. Fork this repository
92
100
  2. Create your feature branch (`git checkout -b my-new-feature`)
93
101
  3. Commit your changes (`git commit -am 'Add some feature'`)
94
102
  4. Push to the branch (`git push origin my-new-feature`)
@@ -97,4 +105,15 @@ Also, see the `TODO` file.
97
105
  [tawny]:https://github.com/masterzora/tawny-cdk
98
106
  [cdk]:http://invisible-island.net/cdk/
99
107
  [rbcurse]:https://github.com/rkumar/rbcurse
108
+ [wiki]:https://github.com/alexdantas/rndk/wiki
109
+ [widgets]:https://github.com/alexdantas/rndk/wiki/widgets
110
+
111
+ ## Contact
112
+
113
+ Hi, I'm Alexandre Dantas! Thanks for having interest in this project. Please
114
+ take the time to visit any of the links below.
115
+
116
+ * `rndk` homepage: http://www.alexdantas.net/projects/rndk
117
+ * Contact: `eu @ alexdantas.net`
118
+ * My homepage: http://www.alexdantas.net
100
119
 
data/demos/appointment.rb CHANGED
@@ -175,7 +175,7 @@ class Appointment
175
175
  marker = Appointment::GPAppointmentAttributes[selection]
176
176
 
177
177
  # Create the entry field for the description.
178
- entry = RNDK::ENTRY.new(calendar.screen,
178
+ entry = RNDK::Entry.new(calendar.screen,
179
179
  RNDK::CENTER,
180
180
  RNDK::CENTER,
181
181
  '<C>Enter a description of the appointment.',
@@ -292,7 +292,7 @@ class Appointment
292
292
  end
293
293
 
294
294
  # Create the label widget
295
- label = RNDK::LABEL.new(calendar.screen, RNDK::CENTER, RNDK::CENTER, mesg, true, false)
295
+ label = RNDK::Label.new(calendar.screen, RNDK::CENTER, RNDK::CENTER, mesg, true, false)
296
296
  label.draw(label.box)
297
297
  label.wait(' ')
298
298
  label.destroy
data/demos/clock.rb CHANGED
@@ -18,7 +18,7 @@ begin
18
18
  mesg = ['</1/B>HH:MM:SS']
19
19
 
20
20
  # Declare the labels.
21
- label = RNDK::LABEL.new(rndkscreen, RNDK::CENTER, RNDK::CENTER, mesg, true, true)
21
+ label = RNDK::Label.new(rndkscreen, RNDK::CENTER, RNDK::CENTER, mesg, true, true)
22
22
 
23
23
  # Woops, something bad happened
24
24
  if label.nil?
data/demos/fileview.rb CHANGED
File without changes
@@ -24,7 +24,7 @@ begin
24
24
  ]
25
25
 
26
26
  # Declare the labels.
27
- label = RNDK::LABEL.new(rndkscreen, # screen
27
+ label = RNDK::Label.new(rndkscreen, # screen
28
28
  RNDK::CENTER, # x
29
29
  RNDK::CENTER, # y
30
30
  mesg, # message
@@ -40,7 +40,7 @@ begin
40
40
  RNDK::Color[:red], # highlight
41
41
  true, # has box?
42
42
  false) # has shadow?
43
- cal.activate []
43
+ cal.activate
44
44
 
45
45
  RNDK::Screen.end_rndk
46
46
 
@@ -4,9 +4,10 @@
4
4
  # Also, how to use RNDK's color markup on strings.
5
5
  #
6
6
  # Colors on text are achieved by foreground/background
7
- # color pairs. Run the example now.
7
+ # color pairs.
8
+ # Stop reading, run the example now.
8
9
  #
9
- # As you just say, they go from 1 to 80, going on the
10
+ # As you just saw, they go from 1 to 80, going on the
10
11
  # following order in sets of 8 and from background to
11
12
  # foreground:
12
13
  #
@@ -39,6 +40,7 @@ begin
39
40
  # * To start a color, do `</XX>`, where XX is a color pair
40
41
  # from 1 to 80.
41
42
  # * To stop it, do `<!XX>`, where XX is the same as above.
43
+ # * To center the text, do `<C>`.
42
44
 
43
45
  msg = []
44
46
  msg << "</1>Pair01<!1> </2>Pair02<!2> </3>Pair03<!3> </4>Pair04<!4> </5>Pair05<!5> </6>Pair06<!6> </7>Pair07<!7> </8>Pair08<!8>"
@@ -55,10 +57,10 @@ begin
55
57
  msg << "<C>All RNDK color pairs (press 'q' to quit)"
56
58
 
57
59
  # Show label with that huge message.
58
- label = RNDK::LABEL.new(screen,
60
+ label = RNDK::Label.new(screen,
59
61
  RNDK::CENTER, # x
60
62
  1, # y
61
- msg,
63
+ msg, # message
62
64
  true, # has box?
63
65
  true) # has shadow?
64
66
 
@@ -4,6 +4,7 @@
4
4
  # temporary pre-made Widgets with a single action.
5
5
  #
6
6
  # They're automatically included within `require 'rndk'`.
7
+ #
7
8
  require 'rndk'
8
9
 
9
10
  begin
@@ -43,7 +43,7 @@ begin
43
43
  RNDK::Color.init
44
44
 
45
45
  # Create the entry field widget.
46
- entry = RNDK::ENTRY.new(rndkscreen,
46
+ entry = RNDK::Entry.new(rndkscreen,
47
47
  RNDK::CENTER, # x
48
48
  RNDK::CENTER, # y
49
49
  '',
data/examples/entry.rb ADDED
@@ -0,0 +1,76 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Shows off the Entry widget by asking you to
4
+ # type anything.
5
+ # Then it tells you what you sent to it.
6
+ #
7
+ require 'rndk/entry'
8
+
9
+ begin
10
+ # Startup RNDK and Colors
11
+ rndkscreen = RNDK::Screen.new
12
+ RNDK::Color.init
13
+
14
+ # Watch out for that markup
15
+ # See example 'markup.rb' for details
16
+ title = "<C></77>Tell me something"
17
+ label = "</U/5>Oh yeah<!U!5>:"
18
+
19
+ # Create the entry field widget.
20
+ entry = RNDK::Entry.new(rndkscreen,
21
+ RNDK::CENTER,
22
+ RNDK::CENTER,
23
+ title,
24
+ label,
25
+ Ncurses::A_NORMAL,
26
+ '.',
27
+ :MIXED, # behavior
28
+ 40,
29
+ 0,
30
+ 256,
31
+ true,
32
+ false)
33
+
34
+ # Is the widget nil?
35
+ if entry.nil?
36
+ RNDK::Screen.end_rndk
37
+
38
+ puts "Cannot create the entry box. Is the window too small?"
39
+ exit 1
40
+ end
41
+
42
+ # Draw the screen.
43
+ rndkscreen.refresh
44
+
45
+ # Activate the entry field.
46
+ info = entry.activate
47
+
48
+ mesg = []
49
+ # Tell them what they typed.
50
+ if entry.exit_type == :ESCAPE_HIT
51
+ mesg = ["<C>You hit escape. No information passed back.",
52
+ "<C>Press any key to continue."]
53
+
54
+ elsif entry.exit_type == :NORMAL
55
+ mesg = ["<C>You typed in the following",
56
+ "<C>(#{info})",
57
+ "",
58
+ "<C>Press any key to continue."]
59
+ end
60
+
61
+ # Quick widget - see example 'quick-widgets.rb' for details
62
+ rndkscreen.popup_label mesg
63
+
64
+ # Quitting
65
+ RNDK::Screen.end_rndk
66
+
67
+ # Just in case something bad happens.
68
+ rescue Exception => e
69
+ RNDK::Screen.end_rndk
70
+
71
+ puts e
72
+ puts e.inspect
73
+ puts e.backtrace
74
+ exit 1
75
+ end
76
+
data/examples/label.rb ADDED
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Shows some colored lines within
4
+ # a Label widget.
5
+ require 'rndk/label'
6
+
7
+ begin
8
+ # Starting things up
9
+ rndkscreen = RNDK::Screen.new
10
+ RNDK::Color.init
11
+
12
+ # Set the labels with some nice markup
13
+ mesg = [
14
+ "</29/B>This line should have a yellow foreground and a blue background.",
15
+ "</5/B>This line should have a white foreground and a blue background.",
16
+ "</26/B>This line should have a yellow foreground and a red background.",
17
+ "<C>This line should be set to whatever the screen default is."
18
+ ]
19
+
20
+ label = RNDK::Label.new(rndkscreen,
21
+ RNDK::CENTER,
22
+ RNDK::CENTER,
23
+ mesg,
24
+ true,
25
+ true)
26
+
27
+ if label.nil?
28
+ RNDK::Screen.end_rndk
29
+
30
+ puts 'Cannot create the label. Is the window too small?'
31
+ exit 1
32
+ end
33
+
34
+ # Draw the RNDK screen and waits for
35
+ # space to be pressed.
36
+ rndkscreen.refresh
37
+ label.wait(' ')
38
+
39
+ # Clean up
40
+ RNDK::Screen.end_rndk
41
+
42
+ # Just in case something bad happens.
43
+ rescue Exception => e
44
+ RNDK::Screen.end_rndk
45
+
46
+ puts e
47
+ puts e.inspect
48
+ puts e.backtrace
49
+ exit 1
50
+ end
51
+
data/examples/scroll.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  #
3
- # Displays a Scroll list with the current
4
- # directory's files.
3
+ # Displays a Scroll list with the current directory's files.
5
4
  #
6
5
  # You can also modify it at runtime with the keys:
7
6
  #
@@ -9,41 +8,48 @@
9
8
  # * 'i' inserts item
10
9
  # * 'd' deletes item
11
10
  #
12
- require 'rndk/scroll'
13
-
14
- # It creates new labels to add to the Scroll List.
11
+ # After selecting an item, we pop-up the user with it's name.
15
12
  #
16
- # Ignore this for now, read the rest first.
17
- $count = 0
18
- def new_label(prefix)
19
- result = "%s%d" % [prefix, $count]
20
- $count += 1
21
- return result
22
- end
13
+ require 'rndk/scroll'
23
14
 
24
15
  begin
25
16
  # Set up RNDK and colors
26
17
  rndkscreen = RNDK::Screen.new
27
- RNDK::Draw.initRNDKColor
18
+ RNDK::Color.init
19
+
20
+ # Turning off the blinking cursor
21
+ Ncurses.curs_set 0
28
22
 
29
23
  # Use the current directory list to fill the radio list
30
- item = []
31
- count = RNDK.getDirectoryContents(".", item)
24
+ item = RNDK.get_directory_contents '.'
25
+
26
+ # Pay attention to the markup:
27
+ # * <C> centers the text,
28
+ # * </XX> is a color pair
29
+ # See example 'markup.rb' for more details.
30
+ title = <<END
31
+ <C></77>Pick a file
32
+ </77>Press 'a' to append an item
33
+ </77>Press 'i' to insert an item
34
+ </77>Press 'd' to delete current item
35
+ </77>(don't worry, won't delete your files)
36
+ </77>Press 'enter' or 'tab' to select item
37
+ ------------------------------------------------
38
+ END
32
39
 
33
40
  # Create the scrolling list.
34
- scroll_list = RNDK::SCROLL.new(rndkscreen,
35
- RNDK::CENTER, # x
36
- RNDK::CENTER, # y
37
- RNDK::RIGHT, # scrollbar position
38
- 10, # height
39
- 50, # width
40
- "<C></5>Pick a file", # title
41
- item,
42
- count,
43
- true,
44
- Ncurses::A_REVERSE,
45
- true, # box
46
- false) # shadow
41
+ scroll_list = RNDK::Scroll.new(rndkscreen,
42
+ RNDK::CENTER, # x
43
+ RNDK::CENTER, # y
44
+ RNDK::RIGHT, # scrollbar position
45
+ 50, # width
46
+ 24, # height
47
+ title, # title
48
+ item, # items on the list
49
+ true, # show numbers
50
+ RNDK::Color[:red], # highlight color
51
+ true, # box
52
+ false) # shadow
47
53
 
48
54
  if scroll_list.nil?
49
55
  RNDK::Screen.end_rndk
@@ -54,21 +60,30 @@ begin
54
60
 
55
61
  # These are the functions that will modify the
56
62
  # Scroll List at runtime.
63
+ #
64
+ # The arguments to the block are provided by
65
+ # default, you can ignore them right now.
66
+ #
67
+ # The only thing you need to know is that `widget` is
68
+ # the scroll - widget that we attach the callback to.
69
+ $counter = 0
57
70
 
58
- addItemCB = lambda do |type, widget, client_data, input|
59
- widget.addItem(ScrollExample.newLabel("add"))
71
+ add_item_callback = lambda do |type, widget, client_data, input|
72
+ widget.addItem "add_#{$counter}"
73
+ $counter += 1
60
74
  widget.screen.refresh
61
75
  return true
62
76
  end
63
77
 
64
- insItemCB = lambda do |type, widget, client_data, input|
65
- widget.insertItem(ScrollExample.newLabel("insert"))
78
+ insert_item_callback = lambda do |type, widget, client_data, input|
79
+ widget.insertItem "insert_#{$counter}"
80
+ $counter += 1
66
81
  widget.screen.refresh
67
82
  return true
68
83
  end
69
84
 
70
- delItemCB = lambda do |type, widget, client_data, input|
71
- widget.deleteItem(widget.getCurrentItem)
85
+ delete_item_callback = lambda do |type, widget, client_data, input|
86
+ widget.deleteItem widget.getCurrentItem
72
87
  widget.screen.refresh
73
88
  return true
74
89
  end
@@ -77,30 +92,41 @@ begin
77
92
  #
78
93
  # It only accepts lambdas.
79
94
 
80
- scroll_list.bind(:SCROLL, 'a', addItemCB, nil)
81
- scroll_list.bind(:SCROLL, 'i', insItemCB, nil);
82
- scroll_list.bind(:SCROLL, 'd', delItemCB, nil);
95
+ scroll_list.bind(:scroll, 'a', add_item_callback, nil)
96
+ scroll_list.bind(:scroll, 'i', insert_item_callback, nil)
97
+ scroll_list.bind(:scroll, 'd', delete_item_callback, nil)
83
98
 
84
99
  # Activate the scrolling list.
85
- selection = scroll_list.activate('')
100
+ selection = scroll_list.activate
101
+
102
+ # Now, we'll determine how the widget was exited
103
+ # and pop-up the user with it's choice
86
104
 
87
- # Determine how the widget was exited
88
105
  msg = []
89
106
  if scroll_list.exit_type == :ESCAPE_HIT
90
107
  msg = ['<C>You hit escape. No file selected',
91
- '',
92
108
  '<C>Press any key to continue.']
93
109
 
94
110
  elsif scroll_list.exit_type == :NORMAL
95
111
  the_item = RNDK.chtype2Char scroll_list.item[selection]
96
112
 
97
113
  msg = ['<C>You selected the following file',
98
- "<C>%.*s" % [236, the_item], # FIXME magic number
114
+ "<C></77>#{the_item}",
99
115
  "<C>Press any key to continue."]
100
116
  end
117
+
118
+ # A quick widget - see example 'quick-widgets.rb'
101
119
  rndkscreen.popup_label msg
102
120
 
103
- # Exit
104
121
  RNDK::Screen.end_rndk
122
+
123
+ # Just in case something bad happens.
124
+ rescue Exception => e
125
+ RNDK::Screen.end_rndk
126
+
127
+ puts e
128
+ puts e.inspect
129
+ puts e.backtrace
130
+ exit 1
105
131
  end
106
132
 
@@ -0,0 +1,70 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Shows a slider bar that goes from 1 to 100.
4
+
5
+ require 'rndk/slider'
6
+
7
+ begin
8
+ # Markup-happy labels
9
+ title = '<C></U>Enter a value'
10
+ label = '</B>Current Value:'
11
+
12
+ # Set up RNDK
13
+ rndkscreen = RNDK::Screen.new
14
+ RNDK::Color.init
15
+
16
+ # Create the widget
17
+ widget = RNDK::Slider.new(rndkscreen,
18
+ RNDK::CENTER,
19
+ RNDK::CENTER,
20
+ title,
21
+ label,
22
+ Ncurses::A_REVERSE | RNDK::Color[:white_blue] | ' '.ord,
23
+ 50,
24
+ 1,
25
+ 1,
26
+ 100,
27
+ 1,
28
+ 2,
29
+ true,
30
+ false)
31
+
32
+ if widget.nil?
33
+ RNDK::Screen.end_rndk
34
+
35
+ puts "Cannot make the widget. Is the window too small?"
36
+ exit 1
37
+ end
38
+
39
+ # Activate the widget.
40
+ selection = widget.activate
41
+
42
+ # Check the exit value of the widget.
43
+ mesg = []
44
+
45
+ if widget.exit_type == :ESCAPE_HIT
46
+ mesg = ["<C>You hit escape. No value selected.",
47
+ "<C>Press any key to continue."]
48
+
49
+ elsif widget.exit_type == :NORMAL
50
+ mesg = ["<C>You selected #{selection}",
51
+ "<C>Press any key to continue."]
52
+ end
53
+
54
+ # A quick popup widget! Check out the
55
+ # example file 'quick-widgets.rb'
56
+ rndkscreen.popup_label mesg
57
+
58
+ # Clean up
59
+ RNDK::Screen.end_rndk
60
+
61
+ # Just in case something bad happens.
62
+ rescue Exception => e
63
+ RNDK::Screen.end_rndk
64
+
65
+ puts e
66
+ puts e.inspect
67
+ puts e.backtrace
68
+ exit 1
69
+ end
70
+