gloo 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.DS_Store +0 -0
- data/.rubocop.yml +1 -1
- data/Gemfile.lock +80 -81
- data/Rakefile +1 -0
- data/gloo.gemspec +2 -1
- data/lib/gloo/app/engine.rb +48 -3
- data/lib/gloo/app/info.rb +1 -1
- data/lib/gloo/app/settings.rb +12 -5
- data/lib/gloo/convert/string_to_datetime.rb +21 -0
- data/lib/gloo/convert/string_to_decimal.rb +20 -0
- data/lib/gloo/convert/string_to_integer.rb +20 -0
- data/lib/gloo/core/event_manager.rb +2 -6
- data/lib/gloo/core/factory.rb +58 -1
- data/lib/gloo/core/gloo_system.rb +72 -0
- data/lib/gloo/core/obj.rb +50 -1
- data/lib/gloo/core/parser.rb +3 -1
- data/lib/gloo/core/pn.rb +3 -2
- data/lib/gloo/exec/dispatch.rb +30 -0
- data/lib/gloo/exec/runner.rb +43 -0
- data/lib/gloo/expr/expression.rb +1 -0
- data/lib/gloo/expr/l_decimal.rb +34 -0
- data/lib/gloo/expr/op_div.rb +2 -0
- data/lib/gloo/expr/op_minus.rb +2 -0
- data/lib/gloo/expr/op_mult.rb +2 -0
- data/lib/gloo/expr/op_plus.rb +2 -0
- data/lib/gloo/objs/basic/alias.rb +111 -0
- data/lib/gloo/objs/basic/container.rb +11 -1
- data/lib/gloo/objs/basic/decimal.rb +96 -0
- data/lib/gloo/objs/basic/integer.rb +5 -0
- data/lib/gloo/objs/basic/string.rb +9 -1
- data/lib/gloo/objs/basic/text.rb +27 -2
- data/lib/gloo/objs/cli/banner.rb +137 -0
- data/lib/gloo/objs/cli/bar.rb +141 -0
- data/lib/gloo/objs/cli/colorize.rb +1 -1
- data/lib/gloo/objs/cli/menu.rb +236 -0
- data/lib/gloo/objs/cli/menu_item.rb +128 -0
- data/lib/gloo/objs/cli/pastel.rb +120 -0
- data/lib/gloo/objs/cli/prompt.rb +19 -11
- data/lib/gloo/objs/cli/select.rb +153 -0
- data/lib/gloo/objs/ctrl/each.rb +45 -16
- data/lib/gloo/objs/ctrl/repeat.rb +129 -0
- data/lib/gloo/objs/data/markdown.rb +109 -0
- data/lib/gloo/objs/data/table.rb +168 -0
- data/lib/gloo/objs/dt/date.rb +72 -0
- data/lib/gloo/objs/dt/datetime.rb +84 -0
- data/lib/gloo/objs/dt/time.rb +72 -0
- data/lib/gloo/objs/ror/erb.rb +1 -0
- data/lib/gloo/objs/system/file_handle.rb +50 -1
- data/lib/gloo/objs/web/http_get.rb +24 -4
- data/lib/gloo/objs/web/http_post.rb +1 -0
- data/lib/gloo/objs/web/json.rb +155 -0
- data/lib/gloo/objs/web/uri.rb +160 -0
- data/lib/gloo/persist/file_loader.rb +17 -6
- data/lib/gloo/persist/line_splitter.rb +7 -2
- data/lib/gloo/persist/persist_man.rb +37 -13
- data/lib/gloo/verbs/cls.rb +67 -0
- data/lib/gloo/verbs/help.rb +9 -0
- data/lib/gloo/verbs/if.rb +1 -0
- data/lib/gloo/verbs/load.rb +3 -2
- data/lib/gloo/verbs/move.rb +128 -0
- data/lib/gloo/verbs/run.rb +21 -7
- data/lib/gloo/verbs/tell.rb +1 -1
- data/lib/gloo/verbs/unless.rb +1 -0
- data/lib/gloo/verbs/wait.rb +73 -0
- metadata +36 -5
- data/lib/gloo/core/runner.rb +0 -26
@@ -0,0 +1,109 @@
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
+
# Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
|
3
|
+
#
|
4
|
+
# Markdown data.
|
5
|
+
#
|
6
|
+
require 'tty-markdown'
|
7
|
+
require 'tty-pager'
|
8
|
+
|
9
|
+
module Gloo
|
10
|
+
module Objs
|
11
|
+
class Markdown < Gloo::Core::Obj
|
12
|
+
|
13
|
+
KEYWORD = 'markdown'.freeze
|
14
|
+
KEYWORD_SHORT = 'md'.freeze
|
15
|
+
|
16
|
+
#
|
17
|
+
# The name of the object type.
|
18
|
+
#
|
19
|
+
def self.typename
|
20
|
+
return KEYWORD
|
21
|
+
end
|
22
|
+
|
23
|
+
#
|
24
|
+
# The short name of the object type.
|
25
|
+
#
|
26
|
+
def self.short_typename
|
27
|
+
return KEYWORD_SHORT
|
28
|
+
end
|
29
|
+
|
30
|
+
#
|
31
|
+
# Set the value with any necessary type conversions.
|
32
|
+
#
|
33
|
+
def set_value( new_value )
|
34
|
+
self.value = new_value.to_s
|
35
|
+
end
|
36
|
+
|
37
|
+
#
|
38
|
+
# Does this object support multi-line values?
|
39
|
+
# Initially only true for scripts.
|
40
|
+
#
|
41
|
+
def multiline_value?
|
42
|
+
return false
|
43
|
+
end
|
44
|
+
|
45
|
+
#
|
46
|
+
# Get the number of lines of text.
|
47
|
+
#
|
48
|
+
def line_count
|
49
|
+
return value.split( "\n" ).count
|
50
|
+
end
|
51
|
+
|
52
|
+
# ---------------------------------------------------------------------
|
53
|
+
# Messages
|
54
|
+
# ---------------------------------------------------------------------
|
55
|
+
|
56
|
+
#
|
57
|
+
# Get a list of message names that this object receives.
|
58
|
+
#
|
59
|
+
def self.messages
|
60
|
+
return super + %w[show page]
|
61
|
+
end
|
62
|
+
|
63
|
+
#
|
64
|
+
# Show the markdown data in the terminal.
|
65
|
+
#
|
66
|
+
def msg_show
|
67
|
+
puts TTY::Markdown.parse self.value
|
68
|
+
end
|
69
|
+
|
70
|
+
#
|
71
|
+
# Show the markdown data in the terminal, paginated.
|
72
|
+
#
|
73
|
+
def msg_page
|
74
|
+
return unless self.value
|
75
|
+
|
76
|
+
md = TTY::Markdown.parse self.value
|
77
|
+
# pager = TTY::Pager::SystemPager.new command: 'less -R'
|
78
|
+
pager = TTY::Pager.new
|
79
|
+
pager.page( md )
|
80
|
+
end
|
81
|
+
|
82
|
+
# ---------------------------------------------------------------------
|
83
|
+
# Help
|
84
|
+
# ---------------------------------------------------------------------
|
85
|
+
|
86
|
+
#
|
87
|
+
# Get help for this object type.
|
88
|
+
#
|
89
|
+
def self.help
|
90
|
+
return <<~TEXT
|
91
|
+
MARKDOWN OBJECT TYPE
|
92
|
+
NAME: markdown
|
93
|
+
SHORTCUT: md
|
94
|
+
|
95
|
+
DESCRIPTION
|
96
|
+
Markdown data in a text string.
|
97
|
+
|
98
|
+
CHILDREN
|
99
|
+
None
|
100
|
+
|
101
|
+
MESSAGES
|
102
|
+
show - Show the markdown data in the terminal.
|
103
|
+
page - Show the markdown data in the terminal, paginated.
|
104
|
+
TEXT
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,168 @@
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
+
# Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
|
3
|
+
#
|
4
|
+
# A data table.
|
5
|
+
# The table container headers and data.
|
6
|
+
#
|
7
|
+
require 'tty-table'
|
8
|
+
require 'pastel'
|
9
|
+
|
10
|
+
module Gloo
|
11
|
+
module Objs
|
12
|
+
class Table < Gloo::Core::Obj
|
13
|
+
|
14
|
+
KEYWORD = 'table'.freeze
|
15
|
+
KEYWORD_SHORT = 'tbl'.freeze
|
16
|
+
HEADERS = 'headers'.freeze
|
17
|
+
DATA = 'data'.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 list of headers.
|
35
|
+
# Returns nil if there is none.
|
36
|
+
#
|
37
|
+
def headers
|
38
|
+
o = find_child HEADERS
|
39
|
+
return [] unless o
|
40
|
+
|
41
|
+
return o.children.map( &:value )
|
42
|
+
end
|
43
|
+
|
44
|
+
#
|
45
|
+
# Get the list of column names.
|
46
|
+
# Returns nil if there is none.
|
47
|
+
#
|
48
|
+
def columns
|
49
|
+
o = find_child HEADERS
|
50
|
+
return [] unless o
|
51
|
+
|
52
|
+
return o.children.map( &:name )
|
53
|
+
end
|
54
|
+
|
55
|
+
#
|
56
|
+
# Get the list of data elements.
|
57
|
+
#
|
58
|
+
def data
|
59
|
+
o = find_child DATA
|
60
|
+
return [] unless o
|
61
|
+
|
62
|
+
o = Gloo::Objs::Alias.resolve_alias( o )
|
63
|
+
cols = self.columns
|
64
|
+
return o.children.map do |e|
|
65
|
+
cols.map { |h| e.find_child( h ).value }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# ---------------------------------------------------------------------
|
70
|
+
# Children
|
71
|
+
# ---------------------------------------------------------------------
|
72
|
+
|
73
|
+
# Does this object have children to add when an object
|
74
|
+
# is created in interactive mode?
|
75
|
+
# This does not apply during obj load, etc.
|
76
|
+
def add_children_on_create?
|
77
|
+
return true
|
78
|
+
end
|
79
|
+
|
80
|
+
# Add children to this object.
|
81
|
+
# This is used by containers to add children needed
|
82
|
+
# for default configurations.
|
83
|
+
def add_default_children
|
84
|
+
fac = $engine.factory
|
85
|
+
fac.create_can HEADERS, self
|
86
|
+
fac.create_can DATA, self
|
87
|
+
end
|
88
|
+
|
89
|
+
# ---------------------------------------------------------------------
|
90
|
+
# Messages
|
91
|
+
# ---------------------------------------------------------------------
|
92
|
+
|
93
|
+
#
|
94
|
+
# Get a list of message names that this object receives.
|
95
|
+
#
|
96
|
+
def self.messages
|
97
|
+
return super + [ 'show' ]
|
98
|
+
end
|
99
|
+
|
100
|
+
#
|
101
|
+
# Show the table in the CLI.
|
102
|
+
#
|
103
|
+
def msg_show
|
104
|
+
title = self.value
|
105
|
+
Gloo::Objs::Table.show headers, data, title
|
106
|
+
end
|
107
|
+
|
108
|
+
# ---------------------------------------------------------------------
|
109
|
+
# Static table helper
|
110
|
+
# ---------------------------------------------------------------------
|
111
|
+
|
112
|
+
#
|
113
|
+
# Show the given table data.
|
114
|
+
#
|
115
|
+
def self.show( headers, data, title = nil )
|
116
|
+
pastel = ::Pastel.new
|
117
|
+
table = TTY::Table.new headers, data
|
118
|
+
pad = [ 0, 1, 0, 1 ]
|
119
|
+
rendered = table.render( :ascii, indent: 2, padding: pad ) do |r|
|
120
|
+
r.border.style = :blue
|
121
|
+
r.filter = proc do |val, row_index, _col_index|
|
122
|
+
# col_index % 2 == 1 ? pastel.red.on_green(val) : val
|
123
|
+
if row_index.zero?
|
124
|
+
pastel.blue( val )
|
125
|
+
else
|
126
|
+
row_index.odd? ? pastel.white( val ) : pastel.yellow( val )
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
puts "\n#{title.white}"
|
131
|
+
puts "#{rendered}\n\n"
|
132
|
+
end
|
133
|
+
|
134
|
+
# ---------------------------------------------------------------------
|
135
|
+
# Help
|
136
|
+
# ---------------------------------------------------------------------
|
137
|
+
|
138
|
+
#
|
139
|
+
# Get help for this object type.
|
140
|
+
#
|
141
|
+
def self.help
|
142
|
+
return <<~TEXT
|
143
|
+
TABLE OBJECT TYPE
|
144
|
+
NAME: table
|
145
|
+
SHORTCUT: tbl
|
146
|
+
|
147
|
+
DESCRIPTION
|
148
|
+
A data table.
|
149
|
+
|
150
|
+
CHILDREN
|
151
|
+
headers - container
|
152
|
+
A list of headers.
|
153
|
+
The name of the header object needs to be the same as the
|
154
|
+
name of the object in the data container.
|
155
|
+
The value of the header is what will be displayed.
|
156
|
+
data - container
|
157
|
+
The table's data.
|
158
|
+
The data container will have one or more containers, each
|
159
|
+
of which represents one row of data.
|
160
|
+
|
161
|
+
MESSAGES
|
162
|
+
show - Show the contents of the table in the CLI.
|
163
|
+
TEXT
|
164
|
+
end
|
165
|
+
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
+
# Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
|
3
|
+
#
|
4
|
+
# A Date object (does not include a time).
|
5
|
+
#
|
6
|
+
|
7
|
+
module Gloo
|
8
|
+
module Objs
|
9
|
+
class Date < Gloo::Core::Obj
|
10
|
+
|
11
|
+
KEYWORD = 'date'.freeze
|
12
|
+
KEYWORD_SHORT = 'date'.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
|
+
# Messages
|
30
|
+
# ---------------------------------------------------------------------
|
31
|
+
|
32
|
+
#
|
33
|
+
# Get a list of message names that this object receives.
|
34
|
+
#
|
35
|
+
def self.messages
|
36
|
+
return super + %w[now]
|
37
|
+
end
|
38
|
+
|
39
|
+
# Get the current working branch.
|
40
|
+
def msg_now
|
41
|
+
t = DateTime.now.strftime( '%Y.%m.%d' )
|
42
|
+
self.value = t
|
43
|
+
$engine.heap.it.set_to t
|
44
|
+
end
|
45
|
+
|
46
|
+
# ---------------------------------------------------------------------
|
47
|
+
# Help
|
48
|
+
# ---------------------------------------------------------------------
|
49
|
+
|
50
|
+
#
|
51
|
+
# Get help for this object type.
|
52
|
+
#
|
53
|
+
def self.help
|
54
|
+
return <<~TEXT
|
55
|
+
DATE OBJECT TYPE
|
56
|
+
NAME: date
|
57
|
+
SHORTCUT: date
|
58
|
+
|
59
|
+
DESCRIPTION
|
60
|
+
A reference to a date, but without time.
|
61
|
+
|
62
|
+
CHILDREN
|
63
|
+
None
|
64
|
+
|
65
|
+
MESSAGES
|
66
|
+
now - Set to the current system date.
|
67
|
+
TEXT
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
+
# Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
|
3
|
+
#
|
4
|
+
# A Date and Time object.
|
5
|
+
#
|
6
|
+
|
7
|
+
module Gloo
|
8
|
+
module Objs
|
9
|
+
class Datetime < Gloo::Core::Obj
|
10
|
+
|
11
|
+
KEYWORD = 'datetime'.freeze
|
12
|
+
KEYWORD_SHORT = 'dt'.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
|
+
unless new_value.is_a? DateTime
|
33
|
+
self.value = $engine.convert( new_value, 'DateTime', nil )
|
34
|
+
return
|
35
|
+
end
|
36
|
+
|
37
|
+
self.value = new_value
|
38
|
+
end
|
39
|
+
|
40
|
+
# ---------------------------------------------------------------------
|
41
|
+
# Messages
|
42
|
+
# ---------------------------------------------------------------------
|
43
|
+
|
44
|
+
#
|
45
|
+
# Get a list of message names that this object receives.
|
46
|
+
#
|
47
|
+
def self.messages
|
48
|
+
return super + %w[now]
|
49
|
+
end
|
50
|
+
|
51
|
+
# Get the current working branch.
|
52
|
+
def msg_now
|
53
|
+
t = DateTime.now.strftime( '%Y.%m.%d %I:%M:%S %P' )
|
54
|
+
self.value = t
|
55
|
+
$engine.heap.it.set_to t
|
56
|
+
end
|
57
|
+
|
58
|
+
# ---------------------------------------------------------------------
|
59
|
+
# Help
|
60
|
+
# ---------------------------------------------------------------------
|
61
|
+
|
62
|
+
#
|
63
|
+
# Get help for this object type.
|
64
|
+
#
|
65
|
+
def self.help
|
66
|
+
return <<~TEXT
|
67
|
+
DATETIME OBJECT TYPE
|
68
|
+
NAME: datetime
|
69
|
+
SHORTCUT: dt
|
70
|
+
|
71
|
+
DESCRIPTION
|
72
|
+
A reference to a date and time.
|
73
|
+
|
74
|
+
CHILDREN
|
75
|
+
None
|
76
|
+
|
77
|
+
MESSAGES
|
78
|
+
now - Set to the current system date and time.
|
79
|
+
TEXT
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
+
# Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
|
3
|
+
#
|
4
|
+
# A Time object (does not include a date).
|
5
|
+
#
|
6
|
+
|
7
|
+
module Gloo
|
8
|
+
module Objs
|
9
|
+
class Time < Gloo::Core::Obj
|
10
|
+
|
11
|
+
KEYWORD = 'time'.freeze
|
12
|
+
KEYWORD_SHORT = 'time'.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
|
+
# Messages
|
30
|
+
# ---------------------------------------------------------------------
|
31
|
+
|
32
|
+
#
|
33
|
+
# Get a list of message names that this object receives.
|
34
|
+
#
|
35
|
+
def self.messages
|
36
|
+
return super + %w[now]
|
37
|
+
end
|
38
|
+
|
39
|
+
# Get the current working branch.
|
40
|
+
def msg_now
|
41
|
+
t = DateTime.now.strftime( '%I:%M:%S %P' )
|
42
|
+
self.value = t
|
43
|
+
$engine.heap.it.set_to t
|
44
|
+
end
|
45
|
+
|
46
|
+
# ---------------------------------------------------------------------
|
47
|
+
# Help
|
48
|
+
# ---------------------------------------------------------------------
|
49
|
+
|
50
|
+
#
|
51
|
+
# Get help for this object type.
|
52
|
+
#
|
53
|
+
def self.help
|
54
|
+
return <<~TEXT
|
55
|
+
TIME OBJECT TYPE
|
56
|
+
NAME: time
|
57
|
+
SHORTCUT: time
|
58
|
+
|
59
|
+
DESCRIPTION
|
60
|
+
A reference to a time, but without a date.
|
61
|
+
|
62
|
+
CHILDREN
|
63
|
+
None
|
64
|
+
|
65
|
+
MESSAGES
|
66
|
+
now - Set to the current system time.
|
67
|
+
TEXT
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|