shoes-core 4.0.0.pre8 → 4.0.0.pre9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. checksums.yaml +4 -4
  2. data/bin/shoes-picker +1 -0
  3. data/lib/shoes.rb +1 -0
  4. data/lib/shoes/animation.rb +1 -0
  5. data/lib/shoes/app.rb +7 -1
  6. data/lib/shoes/arc.rb +2 -3
  7. data/lib/shoes/arrow.rb +2 -3
  8. data/lib/shoes/background.rb +2 -2
  9. data/lib/shoes/border.rb +2 -2
  10. data/lib/shoes/builtin_methods.rb +2 -2
  11. data/lib/shoes/button.rb +2 -2
  12. data/lib/shoes/check_button.rb +2 -2
  13. data/lib/shoes/color.rb +1 -0
  14. data/lib/shoes/color/dsl.rb +1 -0
  15. data/lib/shoes/color/dsl_helpers.rb +1 -0
  16. data/lib/shoes/color/hex_converter.rb +1 -0
  17. data/lib/shoes/common/art_element.rb +6 -9
  18. data/lib/shoes/common/attachable.rb +1 -0
  19. data/lib/shoes/common/background_element.rb +2 -11
  20. data/lib/shoes/common/changeable.rb +1 -0
  21. data/lib/shoes/common/clickable.rb +1 -0
  22. data/lib/shoes/common/fill.rb +1 -0
  23. data/lib/shoes/common/hover.rb +2 -1
  24. data/lib/shoes/common/inspect.rb +1 -0
  25. data/lib/shoes/common/link_finder.rb +1 -0
  26. data/lib/shoes/common/positioning.rb +1 -0
  27. data/lib/shoes/common/registration.rb +1 -0
  28. data/lib/shoes/common/remove.rb +1 -0
  29. data/lib/shoes/common/rotate.rb +1 -0
  30. data/lib/shoes/common/safely_evaluate.rb +13 -0
  31. data/lib/shoes/common/state.rb +4 -10
  32. data/lib/shoes/common/stroke.rb +1 -0
  33. data/lib/shoes/common/style.rb +13 -3
  34. data/lib/shoes/common/style_normalizer.rb +1 -0
  35. data/lib/shoes/common/translate.rb +1 -0
  36. data/lib/shoes/common/ui_element.rb +67 -5
  37. data/lib/shoes/common/visibility.rb +7 -6
  38. data/lib/shoes/configuration.rb +5 -16
  39. data/lib/shoes/console.rb +91 -0
  40. data/lib/shoes/core.rb +1 -1
  41. data/lib/shoes/core/version.rb +1 -1
  42. data/lib/shoes/dialog.rb +1 -0
  43. data/lib/shoes/dimension.rb +1 -0
  44. data/lib/shoes/dimensions.rb +1 -0
  45. data/lib/shoes/download.rb +1 -0
  46. data/lib/shoes/dsl.rb +28 -588
  47. data/lib/shoes/dsl/animate.rb +51 -0
  48. data/lib/shoes/dsl/art.rb +256 -0
  49. data/lib/shoes/dsl/element.rb +56 -0
  50. data/lib/shoes/dsl/interaction.rb +76 -0
  51. data/lib/shoes/dsl/media.rb +38 -0
  52. data/lib/shoes/dsl/setup.rb +42 -0
  53. data/lib/shoes/dsl/style.rb +81 -0
  54. data/lib/shoes/dsl/text.rb +50 -0
  55. data/lib/shoes/file_not_found_error.rb +1 -0
  56. data/lib/shoes/font.rb +2 -1
  57. data/lib/shoes/gradient.rb +1 -0
  58. data/lib/shoes/image.rb +2 -2
  59. data/lib/shoes/image_pattern.rb +1 -0
  60. data/lib/shoes/input_box.rb +11 -2
  61. data/lib/shoes/internal_app.rb +16 -3
  62. data/lib/shoes/key_event.rb +1 -0
  63. data/lib/shoes/line.rb +2 -3
  64. data/lib/shoes/link.rb +2 -0
  65. data/lib/shoes/list_box.rb +3 -3
  66. data/lib/shoes/logger_collection.rb +38 -0
  67. data/lib/shoes/mock.rb +1 -0
  68. data/lib/shoes/mock/animation.rb +1 -0
  69. data/lib/shoes/mock/app.rb +1 -0
  70. data/lib/shoes/mock/arc.rb +1 -0
  71. data/lib/shoes/mock/arrow.rb +1 -0
  72. data/lib/shoes/mock/background.rb +1 -0
  73. data/lib/shoes/mock/border.rb +1 -0
  74. data/lib/shoes/mock/button.rb +1 -0
  75. data/lib/shoes/mock/check.rb +1 -0
  76. data/lib/shoes/mock/clickable.rb +1 -0
  77. data/lib/shoes/mock/common_methods.rb +1 -0
  78. data/lib/shoes/mock/dialog.rb +1 -0
  79. data/lib/shoes/mock/download.rb +1 -0
  80. data/lib/shoes/mock/font.rb +1 -0
  81. data/lib/shoes/mock/image.rb +1 -0
  82. data/lib/shoes/mock/image_pattern.rb +1 -0
  83. data/lib/shoes/mock/input_box.rb +4 -0
  84. data/lib/shoes/mock/keypress.rb +1 -0
  85. data/lib/shoes/mock/keyrelease.rb +1 -0
  86. data/lib/shoes/mock/line.rb +1 -0
  87. data/lib/shoes/mock/link.rb +1 -0
  88. data/lib/shoes/mock/list_box.rb +1 -0
  89. data/lib/shoes/mock/oval.rb +1 -0
  90. data/lib/shoes/mock/packager.rb +3 -0
  91. data/lib/shoes/mock/progress.rb +1 -0
  92. data/lib/shoes/mock/radio.rb +1 -0
  93. data/lib/shoes/mock/rect.rb +1 -0
  94. data/lib/shoes/mock/shape.rb +1 -0
  95. data/lib/shoes/mock/slot.rb +1 -0
  96. data/lib/shoes/mock/sound.rb +1 -0
  97. data/lib/shoes/mock/star.rb +1 -0
  98. data/lib/shoes/mock/text_block.rb +1 -0
  99. data/lib/shoes/mock/timer.rb +1 -0
  100. data/lib/shoes/not_implemented_error.rb +1 -0
  101. data/lib/shoes/oval.rb +2 -3
  102. data/lib/shoes/packager.rb +13 -0
  103. data/lib/shoes/point.rb +1 -0
  104. data/lib/shoes/progress.rb +2 -3
  105. data/lib/shoes/radio.rb +1 -0
  106. data/lib/shoes/rect.rb +2 -3
  107. data/lib/shoes/renamed_delegate.rb +1 -0
  108. data/lib/shoes/shape.rb +2 -4
  109. data/lib/shoes/slot.rb +3 -3
  110. data/lib/shoes/slot_contents.rb +1 -0
  111. data/lib/shoes/sound.rb +1 -0
  112. data/lib/shoes/span.rb +1 -0
  113. data/lib/shoes/standard_logger.rb +14 -0
  114. data/lib/shoes/star.rb +2 -3
  115. data/lib/shoes/text.rb +1 -0
  116. data/lib/shoes/text_block.rb +4 -4
  117. data/lib/shoes/text_block_dimensions.rb +1 -0
  118. data/lib/shoes/timer.rb +1 -0
  119. data/lib/shoes/ui/cli.rb +5 -0
  120. data/lib/shoes/ui/picker.rb +2 -1
  121. data/lib/shoes/url.rb +1 -0
  122. data/lib/shoes/version.rb +1 -1
  123. data/lib/shoes/widget.rb +1 -0
  124. data/lib/shoes/window.rb +1 -0
  125. metadata +14 -5
  126. data/lib/shoes/common/initialization.rb +0 -71
  127. data/lib/shoes/logger.rb +0 -65
  128. data/lib/shoes/logger/ruby.rb +0 -15
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+ class Shoes
3
+ class << self
4
+ # To ease the upgrade path from Shoes 3 we warn users they need to install
5
+ # and require gems themselves.
6
+ #
7
+ # @example
8
+ # Shoes.setup do
9
+ # gem 'bluecloth =2.0.6'
10
+ # gem 'metaid'
11
+ # end
12
+ #
13
+ # @param block [Proc] The block that describes the gems that are needed
14
+ # @deprecated
15
+ def setup(&block)
16
+ Shoes.logger.warn "The Shoes.setup method is deprecated, you need to install gems yourself.\n" \
17
+ "You can do this using the 'gem install' command or bundler and a Gemfile."
18
+ DeprecatedShoesGemSetup.new.instance_eval(&block)
19
+ end
20
+
21
+ # Load the backend in memory. This does not set any configuration.
22
+ #
23
+ # @param name [String|Symbol] The name, such as :swt or :mock
24
+ # @return The backend
25
+ def load_backend(name)
26
+ require "shoes/#{name.to_s.downcase}"
27
+ Shoes.const_get(name.to_s.capitalize)
28
+ rescue LoadError => e
29
+ raise LoadError, "Couldn't load backend Shoes::#{name.capitalize}'. Error: #{e.message}\n#{e.backtrace.join("\n")}"
30
+ end
31
+ end
32
+
33
+ class DeprecatedShoesGemSetup
34
+ def gem(name)
35
+ name, version = name.split
36
+ install_cmd = 'gem install ' + name
37
+ install_cmd += " --version \"#{version}\"" if version
38
+ Shoes.logger.warn "To use the '#{name}' gem, install it with '#{install_cmd}', and put 'require \"#{name}\"' at the top of your Shoes program.\n" \
39
+ "Shoes also supports Bundler, so you can provide a 'Gemfile' in your application directory"
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+ class Shoes
3
+ module DSL
4
+ module Style
5
+ # Set default style for elements of a particular class, or for all
6
+ # elements, or return the current defaults for all elements
7
+ #
8
+ # @overload style(klass, styles)
9
+ # Set default style for elements of a particular class
10
+ # @param [Class] klass a Shoes element class
11
+ # @param [Hash] styles default styles for elements of klass
12
+ # @example
13
+ # style Para, :text_size => 42, :stroke => green
14
+ #
15
+ # @overload style(styles)
16
+ # Set default style for all elements
17
+ # @param [Hash] styles default style for all elements
18
+ # @example
19
+ # style :stroke => alicewhite, :fill => black
20
+ #
21
+ # @overload style()
22
+ # @return [Hash] the default style for all elements
23
+ def style(klass_or_styles = nil, styles = {})
24
+ if klass_or_styles.kind_of? Class
25
+ klass = klass_or_styles
26
+ @__app__.element_styles[klass] = styles
27
+ else
28
+ @__app__.style(klass_or_styles)
29
+ end
30
+ end
31
+
32
+ # Define app-level setter methods
33
+ PATTERN_APP_STYLES = [:fill, :stroke].freeze
34
+ OTHER_APP_STYLES = [:cap, :rotate, :strokewidth, :transform].freeze
35
+
36
+ PATTERN_APP_STYLES.each do |style|
37
+ define_method style do |val|
38
+ @__app__.style[style] = pattern(val)
39
+ end
40
+ end
41
+
42
+ OTHER_APP_STYLES.each do |style|
43
+ define_method style do |val|
44
+ @__app__.style[style] = val
45
+ end
46
+ end
47
+
48
+ def translate(left, top)
49
+ @__app__.style[:translate] = [left, top]
50
+ end
51
+
52
+ def nostroke
53
+ @__app__.style[:stroke] = nil
54
+ end
55
+
56
+ def nofill
57
+ @__app__.style[:fill] = nil
58
+ end
59
+
60
+ private
61
+
62
+ def style_normalizer
63
+ @style_normalizer ||= Common::StyleNormalizer.new
64
+ end
65
+
66
+ def pop_style(opts)
67
+ opts.last.class == Hash ? opts.pop : {}
68
+ end
69
+
70
+ # Default styles for elements of klass
71
+ def style_for_element(klass, styles = {})
72
+ @__app__.element_styles.fetch(klass, {}).merge(styles)
73
+ end
74
+
75
+ def normalize_style_for_element(clazz, texts)
76
+ style = style_normalizer.normalize(pop_style(texts))
77
+ style_for_element(clazz, style)
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+ class Shoes
3
+ module DSL
4
+ module Text
5
+ %w(banner title subtitle tagline caption para inscription).each do |method|
6
+ define_method method do |*texts|
7
+ styles = pop_style(texts)
8
+ klass = Shoes.const_get(method.capitalize)
9
+ create klass, texts, styles
10
+ end
11
+ end
12
+
13
+ TEXT_STYLES = {
14
+ code: { font: "Lucida Console" },
15
+ del: { strikethrough: true },
16
+ em: { emphasis: true },
17
+ ins: { underline: true },
18
+ sub: { rise: -10, size_modifier: 0.8 },
19
+ sup: { rise: 10, size_modifier: 0.8 },
20
+ strong: { weight: true },
21
+ }.freeze
22
+
23
+ TEXT_STYLES.keys.each do |method|
24
+ define_method method do |*texts|
25
+ styles = style_normalizer.normalize(pop_style(texts))
26
+ styles = TEXT_STYLES[method].merge(styles)
27
+ Shoes::Span.new texts, styles
28
+ end
29
+ end
30
+
31
+ def fg(*texts, color)
32
+ Shoes::Span.new texts, stroke: pattern(color)
33
+ end
34
+
35
+ def bg(*texts, color)
36
+ Shoes::Span.new texts, fill: pattern(color)
37
+ end
38
+
39
+ def link(*texts, &blk)
40
+ opts = normalize_style_for_element(Shoes::Link, texts)
41
+ Shoes::Link.new @__app__, texts, opts, blk
42
+ end
43
+
44
+ def span(*texts)
45
+ opts = normalize_style_for_element(Shoes::Span, texts)
46
+ Shoes::Span.new texts, opts
47
+ end
48
+ end
49
+ end
50
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  class Shoes
2
3
  class FileNotFoundError < StandardError
3
4
  end
data/lib/shoes/font.rb CHANGED
@@ -1,8 +1,9 @@
1
+ # frozen_string_literal: true
1
2
  class Shoes
2
3
  FONT_DIR = DIR + "/fonts/"
3
4
 
4
5
  module Font
5
- FONT_TYPES = "{ttf,ttc,otf,fnt,fon,bdf,pcf,snf,mmm,pfb,pfm}".freeze
6
+ FONT_TYPES = "{ttf,ttc,otf,fnt,fon,bdf,pcf,snf,mmm,pfb,pfm}"
6
7
  @loaded_fonts = {}
7
8
 
8
9
  class << self
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  class Shoes
2
3
  class Gradient
3
4
  include Common::Inspect
data/lib/shoes/image.rb CHANGED
@@ -1,6 +1,6 @@
1
+ # frozen_string_literal: true
1
2
  class Shoes
2
- class Image
3
- include Common::UIElement
3
+ class Image < Common::UIElement
4
4
  include Common::Clickable
5
5
  include Common::Hover
6
6
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  class Shoes
2
3
  class ImagePattern
3
4
  include Common::Inspect
@@ -1,6 +1,6 @@
1
+ # frozen_string_literal: true
1
2
  class Shoes
2
- class InputBox
3
- include Common::UIElement
3
+ class InputBox < Common::UIElement
4
4
  include Common::Changeable
5
5
  include Common::State
6
6
 
@@ -33,6 +33,15 @@ class Shoes
33
33
  def caret_to(index)
34
34
  @gui.caret_to(index)
35
35
  end
36
+
37
+ def readonly?
38
+ state.to_s == "readonly"
39
+ end
40
+
41
+ def update_from_state
42
+ super
43
+ @gui.readonly = readonly?
44
+ end
36
45
  end
37
46
 
38
47
  class EditBox < InputBox
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  class Shoes
2
3
  # This is the representation of the app that is used internally by Shoes
3
4
  # objects. It is *NOT* the app object that a user interacts with in a
@@ -9,6 +10,7 @@ class Shoes
9
10
  class InternalApp
10
11
  include Common::Clickable
11
12
  include Common::Style
13
+ include Common::SafelyEvaluate
12
14
  include DimensionsDelegations
13
15
 
14
16
  extend Forwardable
@@ -34,7 +36,9 @@ class Shoes
34
36
 
35
37
  self.current_slot = create_top_slot
36
38
  execution_blk = create_execution_block(blk)
39
+
37
40
  eval_block execution_blk
41
+ eval_block start_block if start_block
38
42
 
39
43
  setup_global_keypresses
40
44
  register_console_keypress
@@ -51,7 +55,8 @@ class Shoes
51
55
  :mouse_motion, :owner, :element_styles, :resize_callbacks
52
56
  attr_accessor :elements, :current_slot, :opts, :blk, :mouse_button,
53
57
  :mouse_pos, :mouse_hover_controls, :resizable, :app_title,
54
- :width, :height, :start_as_fullscreen, :location
58
+ :width, :height, :start_as_fullscreen, :location,
59
+ :start_block
55
60
 
56
61
  def_delegators :@app, :eval_with_additional_context
57
62
 
@@ -95,7 +100,7 @@ class Shoes
95
100
 
96
101
  delegated_to_gui = %w(
97
102
  fullscreen= fullscreen quit scroll_top= scroll_top
98
- clipboard clipboard= gutter
103
+ clipboard clipboard= gutter focus open?
99
104
  )
100
105
 
101
106
  def_delegators :gui, *delegated_to_gui
@@ -136,6 +141,14 @@ class Shoes
136
141
  @resize_callbacks << blk
137
142
  end
138
143
 
144
+ def trigger_resize_callbacks
145
+ @resize_callbacks.each do |callback|
146
+ safely_evaluate do
147
+ callback.call
148
+ end
149
+ end
150
+ end
151
+
139
152
  def inspect_details
140
153
  "\"#{@app_title}\" #{@dimensions.inspect}"
141
154
  end
@@ -209,7 +222,7 @@ class Shoes
209
222
 
210
223
  def register_console_keypress
211
224
  self.class.add_global_keypress(:"alt_/") do
212
- Logger.setup
225
+ Shoes.console.show
213
226
  end
214
227
  end
215
228
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  class Shoes
2
3
  class KeyEvent
3
4
  def initialize(app, &blk)
data/lib/shoes/line.rb CHANGED
@@ -1,9 +1,8 @@
1
+ # frozen_string_literal: true
1
2
  require 'matrix'
2
3
 
3
4
  class Shoes
4
- class Line
5
- include Common::ArtElement
6
-
5
+ class Line < Common::ArtElement
7
6
  attr_reader :point_a, :point_b
8
7
 
9
8
  style_with :angle, :art_styles, :dimensions, :x2, :y2
data/lib/shoes/link.rb CHANGED
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
1
2
  class Shoes
2
3
  class Link < Span
3
4
  include Common::Fill
4
5
  include Common::Hover
6
+ include Common::SafelyEvaluate
5
7
  include Common::Stroke
6
8
  include Common::Style
7
9
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  class Shoes
2
3
  class ProxyArray < SimpleDelegator
3
4
  attr_accessor :gui
@@ -24,13 +25,12 @@ class Shoes
24
25
  end
25
26
  end
26
27
 
27
- class ListBox
28
- include Common::UIElement
28
+ class ListBox < Common::UIElement
29
29
  include Common::Changeable
30
30
  include Common::State
31
31
 
32
32
  style_with :change, :choose, :common_styles, :dimensions, :items, :state, :text
33
- STYLES = { width: 200, height: 20, items: [""] }.freeze
33
+ STYLES = { width: 200, height: 29, items: [""] }.freeze
34
34
 
35
35
  def handle_block(blk)
36
36
  change(&blk) if blk
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Shoes
4
+ class LoggerCollection
5
+ def initialize
6
+ @loggers = []
7
+ end
8
+
9
+ def <<(logger)
10
+ @loggers << logger
11
+ self
12
+ end
13
+
14
+ def debug(message)
15
+ forward(:debug, message)
16
+ end
17
+
18
+ def info(message)
19
+ forward(:info, message)
20
+ end
21
+
22
+ def warn(message)
23
+ forward(:warn, message)
24
+ end
25
+
26
+ def error(message)
27
+ forward(:error, message)
28
+ end
29
+
30
+ private
31
+
32
+ def forward(meth, message)
33
+ @loggers.each do |logger|
34
+ logger.public_send(meth, message)
35
+ end
36
+ end
37
+ end
38
+ end
data/lib/shoes/mock.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'shoes/mock/common_methods'
2
3
  require 'shoes/mock/clickable'
3
4
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  class Shoes
2
3
  module Mock
3
4
  class Animation
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  class Shoes
2
3
  module Mock
3
4
  class App
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  class Shoes
2
3
  module Mock
3
4
  class Arc
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  class Shoes
2
3
  module Mock
3
4
  class Arrow
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  class Shoes
2
3
  module Mock
3
4
  class Background
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  class Shoes
2
3
  module Mock
3
4
  class Border
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  class Shoes
2
3
  module Mock
3
4
  class Button