ppcurses 0.0.25 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/README.rdoc +50 -11
  3. data/lib/ppcurses/Screen.rb +128 -15
  4. data/lib/ppcurses/actions/BaseAction.rb +1 -2
  5. data/lib/ppcurses/actions/GetBooleanAction.rb +6 -6
  6. data/lib/ppcurses/actions/GetDataAction.rb +4 -4
  7. data/lib/ppcurses/actions/GetEnumeratedStringAction.rb +6 -6
  8. data/lib/ppcurses/actions/GetIntegerAction.rb +2 -2
  9. data/lib/ppcurses/actions/GetStringAction.rb +2 -0
  10. data/lib/ppcurses/actions/PromptAction.rb +2 -2
  11. data/lib/ppcurses/application.rb +219 -0
  12. data/lib/ppcurses/date/meta_month.rb +139 -0
  13. data/lib/ppcurses/form/button.rb +120 -0
  14. data/lib/ppcurses/form/combo_box.rb +93 -0
  15. data/lib/ppcurses/form/date_picker.rb +86 -0
  16. data/lib/ppcurses/form/form.rb +96 -0
  17. data/lib/ppcurses/form/input_element.rb +189 -0
  18. data/lib/ppcurses/form/radio_button_group.rb +56 -0
  19. data/lib/ppcurses/geometry.rb +23 -0
  20. data/lib/ppcurses/menu/BaseMenu.rb +8 -14
  21. data/lib/ppcurses/menu/Menu.rb +5 -8
  22. data/lib/ppcurses/menu/RadioMenu.rb +2 -5
  23. data/lib/ppcurses/menu/choice_menu.rb +33 -0
  24. data/lib/ppcurses/menu/date_menu.rb +97 -0
  25. data/lib/ppcurses/menu_bar.rb +102 -0
  26. data/lib/ppcurses/table_view.rb +58 -0
  27. data/lib/ppcurses/view.rb +45 -0
  28. data/lib/ppcurses/window/pp_window.rb +42 -0
  29. data/lib/ppcurses.rb +57 -3
  30. data/test/application/create_application.rb +23 -0
  31. data/test/date/printMetaMonth.rb +30 -0
  32. data/test/form/menu_opens_form.rb +15 -0
  33. data/test/form/simple_form.rb +48 -0
  34. data/test/form/test_combo.rb +20 -0
  35. data/test/form/test_date_picker.rb +19 -0
  36. data/test/getBooleanAction.rb +1 -1
  37. data/test/getDataAction.rb +6 -6
  38. data/test/getEnumStringAction.rb +4 -4
  39. data/test/getIntegerAction.rb +4 -4
  40. data/test/menu/changeMenuBorder.rb +1 -1
  41. data/test/menu/compositeMenu.rb +2 -2
  42. data/test/menu/displayMenu.rb +1 -1
  43. data/test/raw_screen/display_colours.rb +69 -0
  44. data/test/raw_screen/press_a_key.rb +18 -0
  45. data/test/table_view/testTableView.rb +16 -0
  46. data/test/threads/block_test.rb +63 -0
  47. data/test/threads/handle_resize.rb +43 -0
  48. metadata +37 -12
  49. data/lib/ppcurses/Constants.rb +0 -8
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require_relative '../../lib/ppcurses.rb'
5
+
6
+ @app = PPCurses::Application.new
7
+
8
+ @win = PPCurses::Window.new(9,60,0,0)
9
+
10
+ table_view = PPCurses::TableView.new
11
+
12
+
13
+ @app.content_view = table_view
14
+ @app.launch
15
+
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require_relative '../../lib/ppcurses.rb'
5
+
6
+ @app = PPCurses::Application.new
7
+
8
+ def handle_cancel
9
+ @app.terminate
10
+ @pressed_cancel = true
11
+ end
12
+
13
+ def handle_submit
14
+ @app.terminate
15
+ @pressed_submit = true
16
+ end
17
+
18
+
19
+ form = PPCurses::Form.new
20
+
21
+ first_name = PPCurses::InputElement.new('First Name', 10)
22
+ last_name = PPCurses::InputElement.new(' Last Name', 10)
23
+ age = PPCurses::InputElement.new_integer_only(' Age', 5)
24
+
25
+ gender = PPCurses::RadioButtonGroup.new(' Sex', %w(Male Female))
26
+ button_pair = PPCurses::ButtonPair.new('Submit', 'Cancel')
27
+
28
+ button_pair.button1.action = method(:handle_submit)
29
+ button_pair.button2.action = method(:handle_cancel)
30
+
31
+ form.add(first_name)
32
+ form.add(last_name)
33
+ form.add(age)
34
+ form.add(gender)
35
+ form.add(button_pair)
36
+
37
+
38
+
39
+ @app.content_view = form
40
+ @app.launch
41
+
42
+ if @pressed_cancel
43
+ puts 'The user pressed cancel.'
44
+ end
45
+
46
+ if @pressed_submit
47
+ puts 'The user pressed submit.'
48
+ end
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require_relative '../../lib/ppcurses.rb'
5
+
6
+
7
+ @app = PPCurses::Application.new
8
+
9
+ form = PPCurses::Form.new
10
+
11
+ state_box = PPCurses::ComboBox.new('State',
12
+ ['Maine', 'New York', 'Kansas', 'California'])
13
+ form.add(state_box)
14
+
15
+
16
+ @app.content_view = form
17
+ @app.launch
18
+
19
+
20
+
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require_relative '../../lib/ppcurses.rb'
5
+
6
+
7
+ @app = PPCurses::Application.new
8
+
9
+ form = PPCurses::Form.new
10
+
11
+ date_picker = PPCurses::DatePicker.new('Date')
12
+ form.add(date_picker)
13
+
14
+
15
+ @app.content_view = form
16
+ @app.launch
17
+
18
+
19
+
@@ -13,4 +13,4 @@ end
13
13
  screen = PPCurses::Screen.new
14
14
  screen.run { do_boolean_action(action) }
15
15
 
16
- puts 'Value input was: ' + action.data
16
+ puts "Value input was: #{action.data}"
@@ -3,17 +3,17 @@
3
3
  require 'rubygems'
4
4
  require_relative '../lib/ppcurses.rb'
5
5
 
6
- integer_action = PPCurses::GetIntegerAction.new("Input Integer : ")
7
- string_action = PPCurses::GetStringAction.new("Input your name: ")
6
+ integer_action = PPCurses::GetIntegerAction.new('Input Integer : ')
7
+ string_action = PPCurses::GetStringAction.new('Input your name: ')
8
8
 
9
9
  action = PPCurses::GetDataAction.new( [integer_action, string_action] )
10
10
 
11
11
  def do_integer_action(action)
12
- action.show()
13
- action.execute()
12
+ action.show
13
+ action.execute
14
14
  end
15
15
 
16
- screen = PPCurses::Screen.new()
16
+ screen = PPCurses::Screen.new
17
17
  screen.run { do_integer_action(action) }
18
18
 
19
- puts 'Value input was: ' + action.data().to_s()
19
+ puts 'Value input was: ' + action.data.to_s
@@ -6,11 +6,11 @@ require_relative '../lib/ppcurses.rb'
6
6
  action = PPCurses::GetEnumeratedStringAction.new('Media Type? ', %w(CD Vinyl MP3))
7
7
 
8
8
  def do_action(action)
9
- action.show()
10
- action.execute()
9
+ action.show
10
+ action.execute
11
11
  end
12
12
 
13
- screen = PPCurses::Screen.new()
13
+ screen = PPCurses::Screen.new
14
14
  screen.run { do_action(action) }
15
15
 
16
- puts 'Value input was: ' + action.data()
16
+ puts "Value input was: #{action.data}"
@@ -6,11 +6,11 @@ require_relative '../lib/ppcurses.rb'
6
6
  action = PPCurses::GetIntegerAction.new('Input Integer : ')
7
7
 
8
8
  def do_integer_action(action)
9
- action.show()
10
- action.execute()
9
+ action.show
10
+ action.execute
11
11
  end
12
12
 
13
- screen = PPCurses::Screen.new()
13
+ screen = PPCurses::Screen.new
14
14
  screen.run { do_integer_action(action) }
15
15
 
16
- puts 'Value input was: ' + action.data()
16
+ puts "Value input was: #{action.data}"
@@ -4,7 +4,7 @@ require 'rubygems'
4
4
  require_relative '../../lib/ppcurses.rb'
5
5
 
6
6
  def display_menu
7
- menu = PPCurses::Menu.new( [ 'Press', '<ESCAPE>', 'to Quit'], nil )
7
+ menu = PPCurses::Menu.new( [ 'Press', '<ESCAPE>', 'to Quit'] )
8
8
  menu.side_wall_char = '\\'
9
9
  menu.top_bot_wall_char = '='
10
10
 
@@ -4,8 +4,8 @@ require 'rubygems'
4
4
  require_relative '../../lib/ppcurses.rb'
5
5
 
6
6
  def display_menu
7
- center_menu = PPCurses::Menu.new( [ 'Press', '<ESCAPE>', 'to Quit'], nil )
8
- radio_menu = PPCurses::RadioMenu.new( %w(Wow two menus!), nil )
7
+ center_menu = PPCurses::Menu.new( [ 'Press', '<ESCAPE>', 'to Quit'] )
8
+ radio_menu = PPCurses::RadioMenu.new( %w(Wow two menus!) )
9
9
 
10
10
  main_menu = PPCurses::CompositeMenu.new(center_menu, radio_menu)
11
11
 
@@ -4,7 +4,7 @@ require 'rubygems'
4
4
  require_relative '../../lib/ppcurses.rb'
5
5
 
6
6
  def display_menu
7
- main_menu = PPCurses::Menu.new( [ 'Press', '<ESCAPE>', 'to Quit'], nil )
7
+ main_menu = PPCurses::Menu.new( [ 'Press', '<ESCAPE>', 'to Quit'] )
8
8
  main_menu.show
9
9
  main_menu.menu_selection
10
10
  main_menu.close
@@ -0,0 +1,69 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require_relative '../../lib/ppcurses.rb'
5
+
6
+
7
+ @index = 0
8
+
9
+ @x_loc = 0
10
+ @y_loc = 0
11
+
12
+ def print_value(value, text_color, bg_color)
13
+ pair_index = @index + 1
14
+ Curses.setpos(@y_loc, @x_loc)
15
+ Curses.init_pair(pair_index, text_color, bg_color)
16
+ color_pair = color_pair(pair_index)
17
+ Curses.attron(color_pair)
18
+ out_string = "#{value}"
19
+ @x_loc = @x_loc + 5
20
+
21
+ if @x_loc > Curses.cols
22
+ @x_loc = 0
23
+ @y_loc = @y_loc + 1
24
+ Curses.setpos(@y_loc, @x_loc)
25
+ end
26
+
27
+ Curses.addstr(out_string.ljust(5))
28
+ Curses.attroff(color_pair)
29
+ @index = @index + 1
30
+ end
31
+
32
+
33
+ def wait_for_key
34
+
35
+
36
+ for i in 0..255
37
+ print_value("#{i}", COLOR_BLACK, i )
38
+ end
39
+
40
+
41
+ Curses.getch
42
+
43
+ end
44
+
45
+
46
+
47
+ screen = PPCurses::Screen.new
48
+ screen.run { wait_for_key }
49
+
50
+ =begin
51
+
52
+ There are 8 default defined colors.
53
+
54
+ COLOR_BLACK = 0
55
+ COLOR_RED = 1
56
+ COLOR_GREEN = 2
57
+ COLOR_YELLOW = 3
58
+ COLOR_BLUE = 4
59
+ COLOR_MAGENTA = 5
60
+ COLOR_CYAN = 6
61
+ COLOR_WHITE = 7
62
+
63
+
64
+ =end
65
+
66
+ puts Curses.cols
67
+ puts "blah".length
68
+
69
+
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require_relative '../../lib/ppcurses.rb'
5
+
6
+ def wait_for_key
7
+
8
+ Curses.setpos(0,0)
9
+ Curses.addstr('Press any key')
10
+ Curses.getch
11
+
12
+ end
13
+
14
+
15
+
16
+ screen = PPCurses::Screen.new
17
+ screen.run { wait_for_key }
18
+
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require_relative '../../lib/ppcurses.rb'
5
+
6
+ @app = PPCurses::Application.new
7
+
8
+ table_view = PPCurses::TableView.new
9
+
10
+ values = %w(Music Reading Lifts)
11
+ data_source = PPCurses::SingleColumnDataSource.new(values)
12
+
13
+ table_view.data_source=data_source
14
+
15
+ @app.content_view = table_view
16
+ @app.launch
@@ -0,0 +1,63 @@
1
+ require 'rubygems'
2
+ require 'thread'
3
+
4
+ # This program demonstrates that the curses getch call blocks all Ruby
5
+ # threads.
6
+ #
7
+ # The code comes from a 2009 blog post by William Morgan.
8
+ # http://masanjin.net/blog/ruby-ncurses-and-thread-blocking
9
+ #
10
+ #
11
+ # Morgan is the original developer of Sup, a ruby curse email client (https://github.com/sup-heliotrope/sup)
12
+ # and he works for tweeter now.
13
+ #
14
+ # Here is the original code from the post.
15
+ =begin
16
+ require 'ncurses'
17
+
18
+ Ncurses.initscr
19
+ Ncurses.noecho
20
+ Ncurses.cbreak
21
+ Ncurses.curs_set 0
22
+
23
+ Thread.new do
24
+ sleep 0.1
25
+ Ncurses.stdscr.mvaddstr 0, 0, "library is GOOD."
26
+ end
27
+
28
+ begin
29
+ Ncurses.stdscr.mvaddstr 0, 0, "library is BAD."
30
+ Ncurses.getch
31
+ ensure
32
+ Ncurses.curs_set 1
33
+ Ncurses.endwin
34
+ puts "bye"
35
+ end
36
+ =end
37
+
38
+ # Here is the port.
39
+
40
+ require 'curses'
41
+
42
+ Thread.new do
43
+ sleep 0.1
44
+ Curses.stdscr.setpos(0, 0)
45
+ Curses.stdscr.addstr('library is GOOD')
46
+ end
47
+
48
+
49
+
50
+ Curses.init_screen
51
+ Curses.raw
52
+ Curses.clear
53
+ Curses.curs_set(0)
54
+ Curses.noecho
55
+ Curses.cbreak
56
+ Curses.start_color
57
+
58
+ Curses.stdscr.setpos(0, 0)
59
+ Curses.stdscr.addstr('library is BAD')
60
+ Curses.stdscr.getch
61
+
62
+
63
+ Curses.close_screen
@@ -0,0 +1,43 @@
1
+ require 'curses'
2
+
3
+ #
4
+ # Resizing the window shouldn't cause an error.
5
+ #
6
+ # Currently it does in Curses 1.0.1 because getch is blocking all
7
+ # Ruby threads.
8
+ #
9
+
10
+ @listeners = []
11
+
12
+ def size_changed
13
+
14
+ # Calling the each method on the array will cause the following error:
15
+ # undefined method `call' for []:Array (NoMethodError)
16
+ #
17
+ @listeners.each { |listener|
18
+ # Notify all listeners ...
19
+ }
20
+ end
21
+
22
+
23
+ begin
24
+ Signal.trap('SIGWINCH', size_changed )
25
+
26
+ Curses.init_screen
27
+ Curses.raw
28
+ Curses.clear
29
+ Curses.curs_set(0)
30
+ Curses.noecho
31
+ Curses.cbreak
32
+ Curses.start_color
33
+
34
+ Curses.stdscr.setpos(0, 0)
35
+ Curses.stdscr.addstr("Resizing window shouldn't cause an error ")
36
+ Curses.stdscr.getch
37
+
38
+ rescue SystemExit, Interrupt
39
+ # Empty Catch block so ruby doesn't puke out
40
+ # a stack trace when CTRL-C is used
41
+ ensure
42
+ Curses.close_screen
43
+ end
metadata CHANGED
@@ -1,21 +1,25 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ppcurses
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.25
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthieu Cormier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-13 00:00:00.000000000 Z
11
+ date: 2015-05-12 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Curses abstraction
13
+ description: A curses abstraction layer.
14
14
  email: mcormier@preenandprune.com
15
15
  executables: []
16
16
  extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
+ - LICENCE.txt
20
+ - README.rdoc
21
+ - lib/ppcurses.rb
22
+ - lib/ppcurses/Screen.rb
19
23
  - lib/ppcurses/actions/BaseAction.rb
20
24
  - lib/ppcurses/actions/GetBooleanAction.rb
21
25
  - lib/ppcurses/actions/GetDataAction.rb
@@ -26,15 +30,33 @@ files:
26
30
  - lib/ppcurses/actions/NulAction.rb
27
31
  - lib/ppcurses/actions/PromptAction.rb
28
32
  - lib/ppcurses/actions/ShowMenuAction.rb
29
- - lib/ppcurses/Constants.rb
33
+ - lib/ppcurses/application.rb
34
+ - lib/ppcurses/date/meta_month.rb
35
+ - lib/ppcurses/form/button.rb
36
+ - lib/ppcurses/form/combo_box.rb
37
+ - lib/ppcurses/form/date_picker.rb
38
+ - lib/ppcurses/form/form.rb
39
+ - lib/ppcurses/form/input_element.rb
40
+ - lib/ppcurses/form/radio_button_group.rb
41
+ - lib/ppcurses/geometry.rb
30
42
  - lib/ppcurses/menu/BaseMenu.rb
31
- - lib/ppcurses/menu/class_diagram.txt
32
43
  - lib/ppcurses/menu/CompositeMenu.rb
33
44
  - lib/ppcurses/menu/Menu.rb
34
- - lib/ppcurses/menu/menu_item.rb
35
45
  - lib/ppcurses/menu/RadioMenu.rb
36
- - lib/ppcurses/Screen.rb
37
- - lib/ppcurses.rb
46
+ - lib/ppcurses/menu/choice_menu.rb
47
+ - lib/ppcurses/menu/class_diagram.txt
48
+ - lib/ppcurses/menu/date_menu.rb
49
+ - lib/ppcurses/menu/menu_item.rb
50
+ - lib/ppcurses/menu_bar.rb
51
+ - lib/ppcurses/table_view.rb
52
+ - lib/ppcurses/view.rb
53
+ - lib/ppcurses/window/pp_window.rb
54
+ - test/application/create_application.rb
55
+ - test/date/printMetaMonth.rb
56
+ - test/form/menu_opens_form.rb
57
+ - test/form/simple_form.rb
58
+ - test/form/test_combo.rb
59
+ - test/form/test_date_picker.rb
38
60
  - test/getBooleanAction.rb
39
61
  - test/getDataAction.rb
40
62
  - test/getEnumStringAction.rb
@@ -47,8 +69,11 @@ files:
47
69
  - test/menu/menuInMenu.rb
48
70
  - test/menu/menuItemsWTarget.rb
49
71
  - test/menu/menuWmenuItems.rb
50
- - LICENCE.txt
51
- - README.rdoc
72
+ - test/raw_screen/display_colours.rb
73
+ - test/raw_screen/press_a_key.rb
74
+ - test/table_view/testTableView.rb
75
+ - test/threads/block_test.rb
76
+ - test/threads/handle_resize.rb
52
77
  homepage: https://github.com/mcormier/ppcurses
53
78
  licenses:
54
79
  - MIT
@@ -64,7 +89,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
64
89
  requirements:
65
90
  - - ">="
66
91
  - !ruby/object:Gem::Version
67
- version: '0'
92
+ version: 2.1.5
68
93
  required_rubygems_version: !ruby/object:Gem::Requirement
69
94
  requirements:
70
95
  - - ">="
@@ -72,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
72
97
  version: '0'
73
98
  requirements: []
74
99
  rubyforge_project:
75
- rubygems_version: 2.0.3
100
+ rubygems_version: 2.4.3
76
101
  signing_key:
77
102
  specification_version: 4
78
103
  summary: Convenience classes when using curses
@@ -1,8 +0,0 @@
1
- module PPCurses
2
-
3
- ENTER = 10
4
- ESCAPE = 27
5
- SPACE_BAR = ' '
6
-
7
-
8
- end