gloo 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/.DS_Store +0 -0
  3. data/.rubocop.yml +1 -1
  4. data/Gemfile.lock +80 -81
  5. data/Rakefile +1 -0
  6. data/gloo.gemspec +2 -1
  7. data/lib/gloo/app/engine.rb +48 -3
  8. data/lib/gloo/app/info.rb +1 -1
  9. data/lib/gloo/app/settings.rb +12 -5
  10. data/lib/gloo/convert/string_to_datetime.rb +21 -0
  11. data/lib/gloo/convert/string_to_decimal.rb +20 -0
  12. data/lib/gloo/convert/string_to_integer.rb +20 -0
  13. data/lib/gloo/core/event_manager.rb +2 -6
  14. data/lib/gloo/core/factory.rb +58 -1
  15. data/lib/gloo/core/gloo_system.rb +72 -0
  16. data/lib/gloo/core/obj.rb +50 -1
  17. data/lib/gloo/core/parser.rb +3 -1
  18. data/lib/gloo/core/pn.rb +3 -2
  19. data/lib/gloo/exec/dispatch.rb +30 -0
  20. data/lib/gloo/exec/runner.rb +43 -0
  21. data/lib/gloo/expr/expression.rb +1 -0
  22. data/lib/gloo/expr/l_decimal.rb +34 -0
  23. data/lib/gloo/expr/op_div.rb +2 -0
  24. data/lib/gloo/expr/op_minus.rb +2 -0
  25. data/lib/gloo/expr/op_mult.rb +2 -0
  26. data/lib/gloo/expr/op_plus.rb +2 -0
  27. data/lib/gloo/objs/basic/alias.rb +111 -0
  28. data/lib/gloo/objs/basic/container.rb +11 -1
  29. data/lib/gloo/objs/basic/decimal.rb +96 -0
  30. data/lib/gloo/objs/basic/integer.rb +5 -0
  31. data/lib/gloo/objs/basic/string.rb +9 -1
  32. data/lib/gloo/objs/basic/text.rb +27 -2
  33. data/lib/gloo/objs/cli/banner.rb +137 -0
  34. data/lib/gloo/objs/cli/bar.rb +141 -0
  35. data/lib/gloo/objs/cli/colorize.rb +1 -1
  36. data/lib/gloo/objs/cli/menu.rb +236 -0
  37. data/lib/gloo/objs/cli/menu_item.rb +128 -0
  38. data/lib/gloo/objs/cli/pastel.rb +120 -0
  39. data/lib/gloo/objs/cli/prompt.rb +19 -11
  40. data/lib/gloo/objs/cli/select.rb +153 -0
  41. data/lib/gloo/objs/ctrl/each.rb +45 -16
  42. data/lib/gloo/objs/ctrl/repeat.rb +129 -0
  43. data/lib/gloo/objs/data/markdown.rb +109 -0
  44. data/lib/gloo/objs/data/table.rb +168 -0
  45. data/lib/gloo/objs/dt/date.rb +72 -0
  46. data/lib/gloo/objs/dt/datetime.rb +84 -0
  47. data/lib/gloo/objs/dt/time.rb +72 -0
  48. data/lib/gloo/objs/ror/erb.rb +1 -0
  49. data/lib/gloo/objs/system/file_handle.rb +50 -1
  50. data/lib/gloo/objs/web/http_get.rb +24 -4
  51. data/lib/gloo/objs/web/http_post.rb +1 -0
  52. data/lib/gloo/objs/web/json.rb +155 -0
  53. data/lib/gloo/objs/web/uri.rb +160 -0
  54. data/lib/gloo/persist/file_loader.rb +17 -6
  55. data/lib/gloo/persist/line_splitter.rb +7 -2
  56. data/lib/gloo/persist/persist_man.rb +37 -13
  57. data/lib/gloo/verbs/cls.rb +67 -0
  58. data/lib/gloo/verbs/help.rb +9 -0
  59. data/lib/gloo/verbs/if.rb +1 -0
  60. data/lib/gloo/verbs/load.rb +3 -2
  61. data/lib/gloo/verbs/move.rb +128 -0
  62. data/lib/gloo/verbs/run.rb +21 -7
  63. data/lib/gloo/verbs/tell.rb +1 -1
  64. data/lib/gloo/verbs/unless.rb +1 -0
  65. data/lib/gloo/verbs/wait.rb +73 -0
  66. metadata +36 -5
  67. data/lib/gloo/core/runner.rb +0 -26
@@ -13,6 +13,8 @@ module Gloo
13
13
  return left + right.to_s if left.is_a? String
14
14
 
15
15
  return left + right.to_i if left.is_a? Integer
16
+
17
+ return left + right.to_f if left.is_a? Numeric
16
18
  end
17
19
 
18
20
  end
@@ -0,0 +1,111 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # A String.
5
+ #
6
+
7
+ module Gloo
8
+ module Objs
9
+ class Alias < Gloo::Core::Obj
10
+
11
+ KEYWORD = 'alias'.freeze
12
+ KEYWORD_SHORT = 'ln'.freeze
13
+ ALIAS_REFERENCE = '*'.freeze
14
+
15
+ #
16
+ # The name of the object type.
17
+ #
18
+ def self.typename
19
+ return KEYWORD
20
+ end
21
+
22
+ #
23
+ # The short name of the object type.
24
+ #
25
+ def self.short_typename
26
+ return KEYWORD_SHORT
27
+ end
28
+
29
+ #
30
+ # Set the value with any necessary type conversions.
31
+ #
32
+ def set_value( new_value )
33
+ self.value = new_value.to_s
34
+ end
35
+
36
+ # ---------------------------------------------------------------------
37
+ # Messages
38
+ # ---------------------------------------------------------------------
39
+
40
+ #
41
+ # Get a list of message names that this object receives.
42
+ #
43
+ def self.messages
44
+ return super + %w[resolve]
45
+ end
46
+
47
+ #
48
+ # Check to see if the referenced object exists.
49
+ #
50
+ def msg_resolve
51
+ pn = Gloo::Core::Pn.new( self.value )
52
+ s = pn.exists?
53
+ $engine.heap.it.set_to s
54
+ return s
55
+ end
56
+
57
+ # ---------------------------------------------------------------------
58
+ # Resolve
59
+ # ---------------------------------------------------------------------
60
+
61
+ #
62
+ # Is the object an alias If so, then resolve it.
63
+ # The ref_name is the name used to refer to the object.
64
+ # If it ends with the * then we won't resolve the alias since
65
+ # we are trying to refer to the alias itself.
66
+ #
67
+ def self.resolve_alias( obj, ref_name = nil )
68
+ return nil unless obj
69
+ return obj unless obj.type_display == Gloo::Objs::Alias.typename
70
+ return obj if ref_name&.end_with?( ALIAS_REFERENCE )
71
+
72
+ ln = Gloo::Core::Pn.new( obj.value )
73
+ return ln.resolve
74
+ end
75
+
76
+ # ---------------------------------------------------------------------
77
+ # Help
78
+ # ---------------------------------------------------------------------
79
+
80
+ #
81
+ # Get help for this object type.
82
+ #
83
+ def self.help
84
+ return <<~TEXT
85
+ ALIAS OBJECT TYPE
86
+ NAME: alias
87
+ SHORTCUT: ln
88
+
89
+ DESCRIPTION
90
+ A pointer to another object.
91
+ Normal path-name references will refere to the aliased object.
92
+ To refer to the alias itself, add an * at the end of the path-name.
93
+ This is neeed, for example, to set the value of the alias.
94
+ The value of the alias is merely the path-name of the
95
+ referenced object.
96
+
97
+ CHILDREN
98
+ None
99
+
100
+ MESSAGES
101
+ The alias will reflect the mesages of the object to which
102
+ it points.
103
+ The alias itself can receive the following message:
104
+ resolve - Check to see if the object referenced exists.
105
+ Sets it to true or false.
106
+ TEXT
107
+ end
108
+
109
+ end
110
+ end
111
+ end
@@ -33,16 +33,25 @@ module Gloo
33
33
  # Get a list of message names that this object receives.
34
34
  #
35
35
  def self.messages
36
- return super + [ 'count' ]
36
+ return super + %w[count delete_children]
37
37
  end
38
38
 
39
+ #
39
40
  # Count the number of children in the container.
41
+ #
40
42
  def msg_count
41
43
  i = child_count
42
44
  $engine.heap.it.set_to i
43
45
  return i
44
46
  end
45
47
 
48
+ #
49
+ # Delete all children in the container.
50
+ #
51
+ def msg_delete_children
52
+ self.delete_children
53
+ end
54
+
46
55
  # ---------------------------------------------------------------------
47
56
  # Help
48
57
  # ---------------------------------------------------------------------
@@ -70,6 +79,7 @@ module Gloo
70
79
  MESSAGES
71
80
  count - Count the number of children objects in the container.
72
81
  The result is put in <it>.
82
+ delete_children - Delete all children objects from the container.
73
83
  TEXT
74
84
  end
75
85
 
@@ -0,0 +1,96 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # An object with a decimal value.
5
+ #
6
+
7
+ module Gloo
8
+ module Objs
9
+ class Decimal < Gloo::Core::Obj
10
+
11
+ KEYWORD = 'decimal'.freeze
12
+ KEYWORD_SHORT = 'num'.freeze
13
+
14
+ #
15
+ # The name of the object type.
16
+ #
17
+ def self.typename
18
+ return KEYWORD
19
+ end
20
+
21
+ #
22
+ # The short name of the object type.
23
+ #
24
+ def self.short_typename
25
+ return KEYWORD_SHORT
26
+ end
27
+
28
+ #
29
+ # Set the value with any necessary type conversions.
30
+ #
31
+ def set_value( new_value )
32
+ if new_value.nil?
33
+ self.value = 0.0
34
+ return
35
+ end
36
+
37
+ unless new_value.is_a? Numeric
38
+ self.value = $engine.convert( new_value, 'Decimal', 0.0 )
39
+ return
40
+ end
41
+
42
+ self.value = new_value.to_f
43
+ end
44
+
45
+ # ---------------------------------------------------------------------
46
+ # Messages
47
+ # ---------------------------------------------------------------------
48
+
49
+ #
50
+ # Get a list of message names that this object receives.
51
+ #
52
+ def self.messages
53
+ return super + %w[round]
54
+ end
55
+
56
+ #
57
+ # Round the value to a whole value.
58
+ # If a parameter is included in the message,
59
+ # round to the precision given.
60
+ #
61
+ def msg_round
62
+ i = value + 1
63
+ set_value i
64
+ $engine.heap.it.set_to i
65
+ return i
66
+ end
67
+
68
+ # ---------------------------------------------------------------------
69
+ # Help
70
+ # ---------------------------------------------------------------------
71
+
72
+ #
73
+ # Get help for this object type.
74
+ #
75
+ def self.help
76
+ return <<~TEXT
77
+ DECIMAL OBJECT TYPE
78
+ NAME: decimal
79
+ SHORTCUT: num
80
+
81
+ DESCRIPTION
82
+ A decimal (numeric) value.
83
+
84
+ CHILDREN
85
+ None
86
+
87
+ MESSAGES
88
+ round - Round to the nearest whole value.
89
+ If an optional parameter is included, round to the
90
+ precision specified.
91
+ TEXT
92
+ end
93
+
94
+ end
95
+ end
96
+ end
@@ -29,6 +29,11 @@ module Gloo
29
29
  # Set the value with any necessary type conversions.
30
30
  #
31
31
  def set_value( new_value )
32
+ unless new_value.is_a? Numeric
33
+ self.value = $engine.convert( new_value, 'Integer', 0 )
34
+ return
35
+ end
36
+
32
37
  self.value = new_value.to_i
33
38
  end
34
39
 
@@ -40,7 +40,14 @@ module Gloo
40
40
  # Get a list of message names that this object receives.
41
41
  #
42
42
  def self.messages
43
- return super + %w[up down]
43
+ return super + %w[up down size]
44
+ end
45
+
46
+ # Get the size of the string.
47
+ def msg_size
48
+ s = value.size
49
+ $engine.heap.it.set_to s
50
+ return s
44
51
  end
45
52
 
46
53
  # Convert string to upper case
@@ -81,6 +88,7 @@ module Gloo
81
88
  MESSAGES
82
89
  up - Convert the string to uppercase.
83
90
  down - Convert the string to lowercase.
91
+ size - Get the size of the string.
84
92
  TEXT
85
93
  end
86
94
 
@@ -3,6 +3,8 @@
3
3
  #
4
4
  # A [multiline] block of text.
5
5
  #
6
+ require 'tty-editor'
7
+ require 'tty-pager'
6
8
 
7
9
  module Gloo
8
10
  module Objs
@@ -10,6 +12,7 @@ module Gloo
10
12
 
11
13
  KEYWORD = 'text'.freeze
12
14
  KEYWORD_SHORT = 'txt'.freeze
15
+ DEFAULT_TMP_FILE = 'tmp.txt'.freeze
13
16
 
14
17
  #
15
18
  # The name of the object type.
@@ -55,7 +58,28 @@ module Gloo
55
58
  # Get a list of message names that this object receives.
56
59
  #
57
60
  def self.messages
58
- return super
61
+ return super + %w[edit page]
62
+ end
63
+
64
+ #
65
+ # Show the contents of the file, paginated.
66
+ #
67
+ def msg_page
68
+ return unless value
69
+
70
+ # pager = TTY::Pager::SystemPager.new command: 'less -R'
71
+ pager = TTY::Pager.new
72
+ pager.page( value )
73
+ end
74
+
75
+ #
76
+ # Edit the text in the default editor.
77
+ #
78
+ def msg_edit
79
+ tmp = File.join( $settings.tmp_path, DEFAULT_TMP_FILE )
80
+ File.open( tmp, 'w' ) { |file| file.write( self.value ) }
81
+ TTY::Editor.open( tmp )
82
+ set_value File.read( tmp )
59
83
  end
60
84
 
61
85
  # ---------------------------------------------------------------------
@@ -78,7 +102,8 @@ module Gloo
78
102
  None
79
103
 
80
104
  MESSAGES
81
- None
105
+ edit - Edit the text field in the default editor.
106
+ page - Show the text, paginated.
82
107
  TEXT
83
108
  end
84
109
 
@@ -0,0 +1,137 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # Show a large-text banner.
5
+ #
6
+ require 'tty-font'
7
+ require 'pastel'
8
+
9
+ module Gloo
10
+ module Objs
11
+ class Banner < Gloo::Core::Obj
12
+
13
+ KEYWORD = 'banner'.freeze
14
+ KEYWORD_SHORT = 'ban'.freeze
15
+ TEXT = 'text'.freeze
16
+ STYLE = 'style'.freeze
17
+ COLOR = 'color'.freeze
18
+
19
+ #
20
+ # The name of the object type.
21
+ #
22
+ def self.typename
23
+ return KEYWORD
24
+ end
25
+
26
+ #
27
+ # The short name of the object type.
28
+ #
29
+ def self.short_typename
30
+ return KEYWORD_SHORT
31
+ end
32
+
33
+ #
34
+ # Get the banner text from the child object.
35
+ #
36
+ def text_value
37
+ o = find_child TEXT
38
+ return '' unless o
39
+
40
+ return o.value
41
+ end
42
+
43
+ #
44
+ # Get the banner style from the child object.
45
+ #
46
+ def style_value
47
+ o = find_child STYLE
48
+ return '' unless o
49
+
50
+ return o.value
51
+ end
52
+
53
+ #
54
+ # Get the banner color from the child object.
55
+ #
56
+ def color_value
57
+ o = find_child COLOR
58
+ return '' unless o
59
+
60
+ return o.value
61
+ end
62
+
63
+ # ---------------------------------------------------------------------
64
+ # Children
65
+ # ---------------------------------------------------------------------
66
+
67
+ # Does this object have children to add when an object
68
+ # is created in interactive mode?
69
+ # This does not apply during obj load, etc.
70
+ def add_children_on_create?
71
+ return true
72
+ end
73
+
74
+ # Add children to this object.
75
+ # This is used by containers to add children needed
76
+ # for default configurations.
77
+ def add_default_children
78
+ fac = $engine.factory
79
+ fac.create_string TEXT, '', self
80
+ fac.create_string STYLE, '', self
81
+ fac.create_string COLOR, '', self
82
+ end
83
+
84
+ # ---------------------------------------------------------------------
85
+ # Messages
86
+ # ---------------------------------------------------------------------
87
+
88
+ #
89
+ # Get a list of message names that this object receives.
90
+ #
91
+ def self.messages
92
+ return super + %w[show]
93
+ end
94
+
95
+ #
96
+ # Show the banner bar
97
+ #
98
+ def msg_show
99
+ font = TTY::Font.new self.style_value
100
+ t = font.write( self.text_value )
101
+ pastel = ::Pastel.new
102
+ c = self.color_value.split( ' ' ).map( &:to_sym )
103
+ puts pastel.decorate( t, *c )
104
+ end
105
+
106
+ # ---------------------------------------------------------------------
107
+ # Help
108
+ # ---------------------------------------------------------------------
109
+
110
+ #
111
+ # Get help for this object type.
112
+ #
113
+ def self.help
114
+ return <<~TEXT
115
+ BANNER OBJECT TYPE
116
+ NAME: banner
117
+ SHORTCUT: ban
118
+
119
+ DESCRIPTION
120
+ Banner text in large, colored font.
121
+
122
+ CHILDREN
123
+ text - string
124
+ The text for the banner.
125
+ style - string
126
+ The banner style. See tty-font for options.
127
+ color - string
128
+ The color for the banner. See pastel for options.
129
+
130
+ MESSAGES
131
+ show - Show the text banner.
132
+ TEXT
133
+ end
134
+
135
+ end
136
+ end
137
+ end