remedy 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 719b3b98ced94d04f1937e0913d29180fb42137c
4
- data.tar.gz: 3bca1cfaedfa329672d828cfd1bd012a1532f0e9
2
+ SHA256:
3
+ metadata.gz: 346c9d17734819cc9516ee578ae4b647e70c13c876c7a84e3ffe74e9cb956e27
4
+ data.tar.gz: 4add78044a3161d6eae52452a6a0bd3f3ba46a18b238af7b533f996ac6599ac6
5
5
  SHA512:
6
- metadata.gz: 432ca50bfc863581eb5d77aae63c66a38097138ff8298db72b02aa7bb51292e4c91bcc653c46a1d89792f07d76bdcc8bf64507f29dce89d4f2edb7f350a7b9c9
7
- data.tar.gz: e9f4045b0038039d5b8196059dbe46e5bc894ed2db5978cf2ac3960d8a77cb3289cf50a74df81647080024e1c4ee0832ff2ec24d8bd1274d1132f882fe27a80b
6
+ metadata.gz: e3a676f7b7df84dc9732aad2518a4bf2d53625736f0928ed3c2dea7f613d727d3fb6539b724939fa83c427cff098d39fcc7ee09412b195d44dca05d3e28dbbbd
7
+ data.tar.gz: a6f5a5cc4a4523b6220b426b4016b6370c814f38a2effc993c729a1456e22f3dd9765c43d62bb1f5a8e0ee351a4e14530a87286b58e87409ba9b5c2968cf46ff
@@ -1 +1 @@
1
- ruby-2
1
+ 2.3.7
@@ -0,0 +1,48 @@
1
+ require 'remedy'
2
+
3
+ include Remedy
4
+
5
+ screen = Viewport.new
6
+
7
+ notice = Content.new
8
+ notice << "You just resized your screen!\n\nBrilliant!"
9
+
10
+ Console.set_console_resized_hook! do
11
+ screen.draw notice
12
+ end
13
+
14
+ user_input = Interaction.new "press any key to continue"
15
+
16
+ joke = Content.new
17
+ joke << "Q: What's the difference between a duck?"
18
+ joke << "A: Purple, because ice cream has no bones!"
19
+
20
+ screen.draw joke
21
+
22
+ user_input.get_key
23
+
24
+ title = Header.new
25
+ title << "Someone Said These Were Good"
26
+
27
+ jokes = Content.new
28
+ jokes << %q{1. A woman gets on a bus with her baby. The bus driver says: 'Ugh, that's the ugliest baby I've ever seen!' The woman walks to the rear of the bus and sits down, fuming. She says to a man next to her: 'The driver just insulted me!' The man says: 'You go up there and tell him off. Go on, I'll hold your monkey for you.'}
29
+ jokes << %q{2. I went to the zoo the other day, there was only one dog in it, it was a shitzu.}
30
+
31
+ disclaimer = Footer.new
32
+ disclaimer << "According to a survey they were funny. I didn't make them."
33
+
34
+ screen.draw jokes, Size.new(0,0), title, disclaimer
35
+
36
+ user_input.get_key
37
+
38
+ ANSI.cursor.next_line!
39
+ loop_demo = Interaction.new "press q to exit, or any other key to display it\n"
40
+ loop_demo.loop do |key|
41
+ ANSI.cursor.beginning_of_line!
42
+ ANSI.command.clear_line!
43
+ puts key
44
+ break if key == ?q
45
+ end
46
+
47
+ Console.cooked!
48
+ ANSI.cursor.show!
@@ -0,0 +1,60 @@
1
+ require 'remedy'
2
+
3
+ class Menu
4
+ include Remedy
5
+
6
+ # will do basic setup and then loop over user input
7
+ def listen
8
+ # if the user resizes the screen we redraw it to fit the new dimensions
9
+ Console.set_console_resized_hook! do
10
+ draw
11
+ end
12
+
13
+ # create an interaction object to handle user input
14
+ interaction = Interaction.new
15
+
16
+ # call draw here because interaction blocks until it gets input
17
+ draw
18
+
19
+ # loop over user input (individual keypresses)
20
+ interaction.loop do |key|
21
+ @last_key = key
22
+ if key == "q" then
23
+ interaction.quit!
24
+ end
25
+ draw
26
+ end
27
+ end
28
+
29
+ # this tells the Viewport to draw to the screen
30
+ def draw
31
+ Viewport.new.draw content, Size([0,0]), header, footer
32
+ end
33
+
34
+ # this is the body of our menu, it will be squished if the terminal is too small
35
+ def content
36
+ c = Partial.new
37
+ c << <<-CONTENT
38
+
39
+ 1. Do the thing
40
+ 2. Do other thing
41
+ 3. Do the third thing
42
+ Q. Quit the thing
43
+
44
+ CONTENT
45
+ c
46
+ end
47
+
48
+ # headers are displayed the top of the viewport
49
+ def header
50
+ Header.new << "The time is: #{Time.now}"
51
+ end
52
+
53
+ # footers are displayed the bottom of the viewport
54
+ def footer
55
+ Footer.new << "You pressed: #{@last_key}"
56
+ end
57
+ end
58
+
59
+ # display menu and accept user input
60
+ Menu.new.listen
@@ -4,7 +4,14 @@ module Remedy
4
4
  module Console
5
5
  require 'io/console'
6
6
 
7
- TIOCGWINSZ = 0x40087468
7
+ TIOCGWINSZ = case RbConfig::CONFIG['host_os']
8
+ when /darwin|mac os/
9
+ 0x40087468
10
+ when /linux/
11
+ 0x5413
12
+ else
13
+ 0x00
14
+ end
8
15
 
9
16
  module_function
10
17
 
@@ -1,3 +1,3 @@
1
1
  module Remedy
2
- VERSION = '0.1.2'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remedy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anthony M. Cook
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-05 00:00:00.000000000 Z
11
+ date: 2019-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -40,6 +40,8 @@ files:
40
40
  - LICENSE.txt
41
41
  - README.markdown
42
42
  - Rakefile
43
+ - examples/from_readme/readme.rb
44
+ - examples/menu/menu.rb
43
45
  - lib/remedy.rb
44
46
  - lib/remedy/ansi.rb
45
47
  - lib/remedy/characters.rb
@@ -81,8 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
83
  - !ruby/object:Gem::Version
82
84
  version: '0'
83
85
  requirements: []
84
- rubyforge_project:
85
- rubygems_version: 2.6.7
86
+ rubygems_version: 3.0.4
86
87
  signing_key:
87
88
  specification_version: 4
88
89
  summary: Pure Ruby Console Interaction Library