gloo 3.3.0 → 3.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/gloo.gemspec +8 -3
- data/lib/VERSION +1 -1
- data/lib/VERSION_NOTES +7 -0
- data/lib/gloo/app/engine.rb +1 -1
- data/lib/gloo/app/log.rb +15 -16
- data/lib/gloo/app/platform.rb +11 -90
- data/lib/gloo/app/prompt.rb +90 -0
- data/lib/gloo/app/table.rb +51 -0
- data/lib/gloo/core/gloo_system.rb +7 -14
- data/lib/gloo/objs/basic/container.rb +1 -2
- data/lib/gloo/objs/basic/integer.rb +23 -1
- data/lib/gloo/objs/basic/string.rb +116 -1
- data/lib/gloo/objs/basic/string_generator.rb +49 -0
- data/lib/gloo/objs/basic/text.rb +1 -17
- data/lib/gloo/objs/cli/menu.rb +5 -4
- data/lib/gloo/objs/cli/select.rb +3 -2
- data/lib/gloo/objs/data/markdown.rb +25 -30
- data/lib/gloo/objs/data/mysql.rb +39 -27
- data/lib/gloo/objs/data/pg.rb +1 -1
- data/lib/gloo/objs/data/query_result.rb +4 -9
- data/lib/gloo/objs/data/table.rb +1 -1
- data/lib/gloo/objs/security/cipher.rb +193 -0
- data/lib/gloo/objs/security/password.rb +167 -0
- data/lib/gloo/objs/system/file_handle.rb +1 -3
- data/lib/gloo/objs/web/json.rb +3 -0
- data/lib/gloo/objs/web_svr/page.rb +24 -8
- data/lib/gloo/objs/web_svr/partial.rb +7 -6
- data/lib/gloo/objs/web_svr/svr.rb +267 -14
- data/lib/gloo/verbs/version.rb +1 -1
- data/lib/gloo/web_svr/asset.rb +34 -13
- data/lib/gloo/web_svr/config.rb +1 -1
- data/lib/gloo/web_svr/embedded_renderer.rb +1 -1
- data/lib/gloo/web_svr/handler.rb +6 -4
- data/lib/gloo/web_svr/request.rb +34 -8
- data/lib/gloo/web_svr/response.rb +14 -2
- data/lib/gloo/web_svr/response_code.rb +1 -1
- data/lib/gloo/web_svr/routing/router.rb +1 -2
- data/lib/gloo/web_svr/routing/show_routes.rb +4 -7
- data/lib/gloo/web_svr/server.rb +1 -1
- data/lib/gloo/web_svr/session.rb +161 -0
- data/lib/gloo/web_svr/table_renderer.rb +1 -1
- metadata +58 -25
- data/lib/gloo/objs/cli/banner.rb +0 -118
- data/lib/gloo/objs/cli/bar.rb +0 -133
- data/lib/gloo/objs/cli/pastel.rb +0 -104
@@ -0,0 +1,161 @@
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
+
# Copyright:: Copyright (c) 2024 Eric Crane. All rights reserved.
|
3
|
+
#
|
4
|
+
# Helpers for getting and setting session data.
|
5
|
+
#
|
6
|
+
# Resources:
|
7
|
+
# https://www.rubydoc.info/gems/rack/1.5.5/Rack/Request#cookies-instance_method
|
8
|
+
# https://rubydoc.info/github/rack/rack/Rack/Utils#set_cookie_header-class_method
|
9
|
+
# https://en.wikipedia.org/wiki/HTTP_cookie
|
10
|
+
#
|
11
|
+
require 'base64'
|
12
|
+
|
13
|
+
module Gloo
|
14
|
+
module WebSvr
|
15
|
+
class Session
|
16
|
+
|
17
|
+
SESSION_CONTAINER = 'session'.freeze
|
18
|
+
|
19
|
+
|
20
|
+
# ---------------------------------------------------------------------
|
21
|
+
# Initialization
|
22
|
+
# ---------------------------------------------------------------------
|
23
|
+
|
24
|
+
#
|
25
|
+
# Set up the web server.
|
26
|
+
#
|
27
|
+
def initialize( engine, server_obj )
|
28
|
+
@engine = engine
|
29
|
+
@log = @engine.log
|
30
|
+
|
31
|
+
@server_obj = server_obj
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
# ---------------------------------------------------------------------
|
36
|
+
# Set Session Data for Request
|
37
|
+
# ---------------------------------------------------------------------
|
38
|
+
|
39
|
+
#
|
40
|
+
# Get the session data from the encrypted cookie.
|
41
|
+
# Add it to the session container.
|
42
|
+
#
|
43
|
+
def set_session_data_for_request( env )
|
44
|
+
cookie_hash = Rack::Utils.parse_cookies( env )
|
45
|
+
|
46
|
+
# Are we using sessions?
|
47
|
+
if @server_obj.use_session?
|
48
|
+
data = cookie_hash[ session_name ]
|
49
|
+
|
50
|
+
if data
|
51
|
+
data = decode_decrypt( data )
|
52
|
+
|
53
|
+
data.each do |key, value|
|
54
|
+
@server_obj.set_session_var( key, value )
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
# ---------------------------------------------------------------------
|
63
|
+
# Get Session Data for Response
|
64
|
+
# ---------------------------------------------------------------------
|
65
|
+
|
66
|
+
#
|
67
|
+
# If there is session data, encrypt and add it to the response.
|
68
|
+
# Once done, clear out the session data.
|
69
|
+
#
|
70
|
+
def add_session_for_response( headers )
|
71
|
+
# Are we using sessions?
|
72
|
+
if @server_obj.use_session?
|
73
|
+
# Build and add encrypted session data
|
74
|
+
data = @server_obj.get_session_data
|
75
|
+
unless data.empty?
|
76
|
+
data = encrypt_encode( data )
|
77
|
+
session_hash = {
|
78
|
+
value: data,
|
79
|
+
path: cookie_path,
|
80
|
+
expires: cookie_expires,
|
81
|
+
http_only: true }
|
82
|
+
|
83
|
+
if secure_cookie?
|
84
|
+
session_hash[ :secure ] = true
|
85
|
+
end
|
86
|
+
|
87
|
+
Rack::Utils.set_cookie_header!( headers, session_name, session_hash )
|
88
|
+
end
|
89
|
+
|
90
|
+
# Clear out session data
|
91
|
+
@server_obj.clear_session_data
|
92
|
+
end
|
93
|
+
|
94
|
+
return headers
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
# ---------------------------------------------------------------------
|
99
|
+
# Helper functions
|
100
|
+
# ---------------------------------------------------------------------
|
101
|
+
|
102
|
+
#
|
103
|
+
# Encrypt and encode the session data.
|
104
|
+
#
|
105
|
+
def encrypt_encode( data )
|
106
|
+
return Gloo::Objs::Cipher.encrypt( data.to_json, key, iv )
|
107
|
+
end
|
108
|
+
|
109
|
+
#
|
110
|
+
# Decode and decrypt the session data.
|
111
|
+
#
|
112
|
+
def decode_decrypt( data )
|
113
|
+
data = Gloo::Objs::Cipher.decrypt( data, key, iv )
|
114
|
+
return JSON.parse( data )
|
115
|
+
end
|
116
|
+
|
117
|
+
#
|
118
|
+
# Get the session cookie name.
|
119
|
+
#
|
120
|
+
def session_name
|
121
|
+
return @server_obj.session_name
|
122
|
+
end
|
123
|
+
|
124
|
+
#
|
125
|
+
# Get the key for the encryption cipher.
|
126
|
+
#
|
127
|
+
def key
|
128
|
+
return @server_obj.encryption_key
|
129
|
+
end
|
130
|
+
|
131
|
+
#
|
132
|
+
# Get the initialization vector for the cipher.
|
133
|
+
#
|
134
|
+
def iv
|
135
|
+
return @server_obj.encryption_iv
|
136
|
+
end
|
137
|
+
|
138
|
+
#
|
139
|
+
# Get the path for the session cookie.
|
140
|
+
#
|
141
|
+
def cookie_path
|
142
|
+
return @server_obj.session_cookie_path
|
143
|
+
end
|
144
|
+
|
145
|
+
#
|
146
|
+
# Get the expiration time for the session cookie.
|
147
|
+
#
|
148
|
+
def cookie_expires
|
149
|
+
return @server_obj.session_cookie_expires
|
150
|
+
end
|
151
|
+
|
152
|
+
#
|
153
|
+
# Should the session cookie be secure?
|
154
|
+
#
|
155
|
+
def secure_cookie?
|
156
|
+
return @server_obj.session_cookie_secure
|
157
|
+
end
|
158
|
+
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gloo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Crane
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-09-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -110,40 +110,62 @@ dependencies:
|
|
110
110
|
requirements:
|
111
111
|
- - "~>"
|
112
112
|
- !ruby/object:Gem::Version
|
113
|
-
version:
|
113
|
+
version: 1.1.0
|
114
114
|
- - ">="
|
115
115
|
- !ruby/object:Gem::Version
|
116
|
-
version:
|
116
|
+
version: 1.1.0
|
117
117
|
type: :runtime
|
118
118
|
prerelease: false
|
119
119
|
version_requirements: !ruby/object:Gem::Requirement
|
120
120
|
requirements:
|
121
121
|
- - "~>"
|
122
122
|
- !ruby/object:Gem::Version
|
123
|
-
version:
|
123
|
+
version: 1.1.0
|
124
124
|
- - ">="
|
125
125
|
- !ruby/object:Gem::Version
|
126
|
-
version:
|
126
|
+
version: 1.1.0
|
127
127
|
- !ruby/object:Gem::Dependency
|
128
|
-
name:
|
128
|
+
name: inquirer
|
129
129
|
requirement: !ruby/object:Gem::Requirement
|
130
130
|
requirements:
|
131
|
-
- - "
|
131
|
+
- - ">="
|
132
132
|
- !ruby/object:Gem::Version
|
133
|
-
version: '0
|
133
|
+
version: '0'
|
134
|
+
type: :runtime
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
141
|
+
- !ruby/object:Gem::Dependency
|
142
|
+
name: reline
|
143
|
+
requirement: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
134
145
|
- - ">="
|
135
146
|
- !ruby/object:Gem::Version
|
136
|
-
version: 0
|
147
|
+
version: '0'
|
137
148
|
type: :runtime
|
138
149
|
prerelease: false
|
139
150
|
version_requirements: !ruby/object:Gem::Requirement
|
140
151
|
requirements:
|
141
|
-
- - "
|
152
|
+
- - ">="
|
142
153
|
- !ruby/object:Gem::Version
|
143
|
-
version: '0
|
154
|
+
version: '0'
|
155
|
+
- !ruby/object:Gem::Dependency
|
156
|
+
name: terminal-table
|
157
|
+
requirement: !ruby/object:Gem::Requirement
|
158
|
+
requirements:
|
144
159
|
- - ">="
|
145
160
|
- !ruby/object:Gem::Version
|
146
|
-
version: 0
|
161
|
+
version: '0'
|
162
|
+
type: :runtime
|
163
|
+
prerelease: false
|
164
|
+
version_requirements: !ruby/object:Gem::Requirement
|
165
|
+
requirements:
|
166
|
+
- - ">="
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: '0'
|
147
169
|
- !ruby/object:Gem::Dependency
|
148
170
|
name: json
|
149
171
|
requirement: !ruby/object:Gem::Requirement
|
@@ -168,22 +190,16 @@ dependencies:
|
|
168
190
|
name: openssl
|
169
191
|
requirement: !ruby/object:Gem::Requirement
|
170
192
|
requirements:
|
171
|
-
- - "~>"
|
172
|
-
- !ruby/object:Gem::Version
|
173
|
-
version: '2.1'
|
174
193
|
- - ">="
|
175
194
|
- !ruby/object:Gem::Version
|
176
|
-
version:
|
195
|
+
version: '0'
|
177
196
|
type: :runtime
|
178
197
|
prerelease: false
|
179
198
|
version_requirements: !ruby/object:Gem::Requirement
|
180
199
|
requirements:
|
181
|
-
- - "~>"
|
182
|
-
- !ruby/object:Gem::Version
|
183
|
-
version: '2.1'
|
184
200
|
- - ">="
|
185
201
|
- !ruby/object:Gem::Version
|
186
|
-
version:
|
202
|
+
version: '0'
|
187
203
|
- !ruby/object:Gem::Dependency
|
188
204
|
name: net-ssh
|
189
205
|
requirement: !ruby/object:Gem::Requirement
|
@@ -306,6 +322,20 @@ dependencies:
|
|
306
322
|
- - "~>"
|
307
323
|
- !ruby/object:Gem::Version
|
308
324
|
version: 3.6.0
|
325
|
+
- !ruby/object:Gem::Dependency
|
326
|
+
name: bcrypt
|
327
|
+
requirement: !ruby/object:Gem::Requirement
|
328
|
+
requirements:
|
329
|
+
- - "~>"
|
330
|
+
- !ruby/object:Gem::Version
|
331
|
+
version: 3.1.20
|
332
|
+
type: :runtime
|
333
|
+
prerelease: false
|
334
|
+
version_requirements: !ruby/object:Gem::Requirement
|
335
|
+
requirements:
|
336
|
+
- - "~>"
|
337
|
+
- !ruby/object:Gem::Version
|
338
|
+
version: 3.1.20
|
309
339
|
description: A scripting languge to keep it all together.
|
310
340
|
email:
|
311
341
|
- eric.crane@mac.com
|
@@ -343,8 +373,10 @@ files:
|
|
343
373
|
- lib/gloo/app/log.rb
|
344
374
|
- lib/gloo/app/mode.rb
|
345
375
|
- lib/gloo/app/platform.rb
|
376
|
+
- lib/gloo/app/prompt.rb
|
346
377
|
- lib/gloo/app/running_app.rb
|
347
378
|
- lib/gloo/app/settings.rb
|
379
|
+
- lib/gloo/app/table.rb
|
348
380
|
- lib/gloo/convert/converter.rb
|
349
381
|
- lib/gloo/convert/falseclass_to_integer.rb
|
350
382
|
- lib/gloo/convert/nilclass_to_date.rb
|
@@ -397,15 +429,13 @@ files:
|
|
397
429
|
- lib/gloo/objs/basic/integer.rb
|
398
430
|
- lib/gloo/objs/basic/script.rb
|
399
431
|
- lib/gloo/objs/basic/string.rb
|
432
|
+
- lib/gloo/objs/basic/string_generator.rb
|
400
433
|
- lib/gloo/objs/basic/text.rb
|
401
434
|
- lib/gloo/objs/basic/untyped.rb
|
402
|
-
- lib/gloo/objs/cli/banner.rb
|
403
|
-
- lib/gloo/objs/cli/bar.rb
|
404
435
|
- lib/gloo/objs/cli/colorize.rb
|
405
436
|
- lib/gloo/objs/cli/confirm.rb
|
406
437
|
- lib/gloo/objs/cli/menu.rb
|
407
438
|
- lib/gloo/objs/cli/menu_item.rb
|
408
|
-
- lib/gloo/objs/cli/pastel.rb
|
409
439
|
- lib/gloo/objs/cli/prompt.rb
|
410
440
|
- lib/gloo/objs/cli/select.rb
|
411
441
|
- lib/gloo/objs/ctrl/each.rb
|
@@ -426,6 +456,8 @@ files:
|
|
426
456
|
- lib/gloo/objs/dt/time.rb
|
427
457
|
- lib/gloo/objs/ror/erb.rb
|
428
458
|
- lib/gloo/objs/ror/eval.rb
|
459
|
+
- lib/gloo/objs/security/cipher.rb
|
460
|
+
- lib/gloo/objs/security/password.rb
|
429
461
|
- lib/gloo/objs/snd/play.rb
|
430
462
|
- lib/gloo/objs/snd/say.rb
|
431
463
|
- lib/gloo/objs/system/file_handle.rb
|
@@ -488,6 +520,7 @@ files:
|
|
488
520
|
- lib/gloo/web_svr/routing/router.rb
|
489
521
|
- lib/gloo/web_svr/routing/show_routes.rb
|
490
522
|
- lib/gloo/web_svr/server.rb
|
523
|
+
- lib/gloo/web_svr/session.rb
|
491
524
|
- lib/gloo/web_svr/table_renderer.rb
|
492
525
|
- lib/gloo/web_svr/web_method.rb
|
493
526
|
- lib/run.rb
|
@@ -510,7 +543,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
510
543
|
- !ruby/object:Gem::Version
|
511
544
|
version: '0'
|
512
545
|
requirements: []
|
513
|
-
rubygems_version: 3.
|
546
|
+
rubygems_version: 3.4.19
|
514
547
|
signing_key:
|
515
548
|
specification_version: 4
|
516
549
|
summary: Gloo scripting language. A scripting language built on ruby.
|
data/lib/gloo/objs/cli/banner.rb
DELETED
@@ -1,118 +0,0 @@
|
|
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
|
-
Banner.show_banner( self.text_value, self.style_value, self.color_value )
|
100
|
-
end
|
101
|
-
|
102
|
-
#
|
103
|
-
# Show the banner bar.
|
104
|
-
# text - the text of the banner
|
105
|
-
# style - the style of the banner
|
106
|
-
# color - the color of the banner
|
107
|
-
#
|
108
|
-
def self.show_banner( text, style, color )
|
109
|
-
font = TTY::Font.new style
|
110
|
-
t = font.write( text )
|
111
|
-
pastel = ::Pastel.new
|
112
|
-
c = color.split( ' ' ).map( &:to_sym )
|
113
|
-
puts pastel.decorate( t, *c )
|
114
|
-
end
|
115
|
-
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
data/lib/gloo/objs/cli/bar.rb
DELETED
@@ -1,133 +0,0 @@
|
|
1
|
-
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
-
# Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
|
3
|
-
#
|
4
|
-
# Show a CLI progress bar.
|
5
|
-
#
|
6
|
-
require 'tty-progressbar'
|
7
|
-
|
8
|
-
module Gloo
|
9
|
-
module Objs
|
10
|
-
class Bar < Gloo::Core::Obj
|
11
|
-
|
12
|
-
KEYWORD = 'bar'.freeze
|
13
|
-
KEYWORD_SHORT = 'bar'.freeze
|
14
|
-
NAME = 'name'.freeze
|
15
|
-
TOTAL = 'total'.freeze
|
16
|
-
|
17
|
-
#
|
18
|
-
# The name of the object type.
|
19
|
-
#
|
20
|
-
def self.typename
|
21
|
-
return KEYWORD
|
22
|
-
end
|
23
|
-
|
24
|
-
#
|
25
|
-
# The short name of the object type.
|
26
|
-
#
|
27
|
-
def self.short_typename
|
28
|
-
return KEYWORD_SHORT
|
29
|
-
end
|
30
|
-
|
31
|
-
#
|
32
|
-
# Get the bar's name from the child object.
|
33
|
-
#
|
34
|
-
def name_value
|
35
|
-
o = find_child NAME
|
36
|
-
return '' unless o
|
37
|
-
|
38
|
-
return o.value
|
39
|
-
end
|
40
|
-
|
41
|
-
#
|
42
|
-
# Get the bar's total from the child object.
|
43
|
-
#
|
44
|
-
def total_value
|
45
|
-
o = find_child TOTAL
|
46
|
-
return 100 unless o
|
47
|
-
|
48
|
-
return o.value
|
49
|
-
end
|
50
|
-
|
51
|
-
# ---------------------------------------------------------------------
|
52
|
-
# Children
|
53
|
-
# ---------------------------------------------------------------------
|
54
|
-
|
55
|
-
# Does this object have children to add when an object
|
56
|
-
# is created in interactive mode?
|
57
|
-
# This does not apply during obj load, etc.
|
58
|
-
def add_children_on_create?
|
59
|
-
return true
|
60
|
-
end
|
61
|
-
|
62
|
-
# Add children to this object.
|
63
|
-
# This is used by containers to add children needed
|
64
|
-
# for default configurations.
|
65
|
-
def add_default_children
|
66
|
-
fac = @engine.factory
|
67
|
-
fac.create_string NAME, '', self
|
68
|
-
fac.create_int TOTAL, 100, self
|
69
|
-
end
|
70
|
-
|
71
|
-
# ---------------------------------------------------------------------
|
72
|
-
# Messages
|
73
|
-
# ---------------------------------------------------------------------
|
74
|
-
|
75
|
-
#
|
76
|
-
# Get a list of message names that this object receives.
|
77
|
-
#
|
78
|
-
def self.messages
|
79
|
-
return super + %w[start advance stop run]
|
80
|
-
end
|
81
|
-
|
82
|
-
#
|
83
|
-
# Start the progress bar.
|
84
|
-
#
|
85
|
-
def msg_start
|
86
|
-
msg = "#{name_value} [:bar] :percent"
|
87
|
-
@bar = TTY::ProgressBar.new( msg, total: total_value )
|
88
|
-
end
|
89
|
-
|
90
|
-
#
|
91
|
-
# Finish the progress bar.
|
92
|
-
#
|
93
|
-
def msg_stop
|
94
|
-
@bar.finish
|
95
|
-
end
|
96
|
-
|
97
|
-
#
|
98
|
-
# Advance the progress bar.
|
99
|
-
#
|
100
|
-
def msg_advance
|
101
|
-
x = 1
|
102
|
-
if @params&.token_count&.positive?
|
103
|
-
expr = Gloo::Expr::Expression.new( @engine, @params.tokens )
|
104
|
-
x = expr.evaluate.to_i
|
105
|
-
end
|
106
|
-
|
107
|
-
@bar.advance x
|
108
|
-
end
|
109
|
-
|
110
|
-
#
|
111
|
-
# Run for the given number of seconds advancing
|
112
|
-
# the bar to the end.
|
113
|
-
#
|
114
|
-
def msg_run
|
115
|
-
msg_start
|
116
|
-
|
117
|
-
x = 1
|
118
|
-
if @params&.token_count&.positive?
|
119
|
-
expr = Gloo::Expr::Expression.new( @engine, @params.tokens )
|
120
|
-
x = expr.evaluate.to_i
|
121
|
-
end
|
122
|
-
|
123
|
-
100.times do
|
124
|
-
sleep ( 0.0 + x ) / 100.0
|
125
|
-
@bar.advance 1
|
126
|
-
end
|
127
|
-
|
128
|
-
msg_stop
|
129
|
-
end
|
130
|
-
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
data/lib/gloo/objs/cli/pastel.rb
DELETED
@@ -1,104 +0,0 @@
|
|
1
|
-
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
-
# Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
|
3
|
-
#
|
4
|
-
# Show colorized output with the pastel gem.
|
5
|
-
#
|
6
|
-
require 'pastel'
|
7
|
-
|
8
|
-
module Gloo
|
9
|
-
module Objs
|
10
|
-
class Pastel < Gloo::Core::Obj
|
11
|
-
|
12
|
-
KEYWORD = 'pastel'.freeze
|
13
|
-
KEYWORD_SHORT = 'pastel'.freeze
|
14
|
-
TEXT = 'text'.freeze
|
15
|
-
COLOR = 'color'.freeze
|
16
|
-
|
17
|
-
#
|
18
|
-
# The name of the object type.
|
19
|
-
#
|
20
|
-
def self.typename
|
21
|
-
return KEYWORD
|
22
|
-
end
|
23
|
-
|
24
|
-
#
|
25
|
-
# The short name of the object type.
|
26
|
-
#
|
27
|
-
def self.short_typename
|
28
|
-
return KEYWORD_SHORT
|
29
|
-
end
|
30
|
-
|
31
|
-
#
|
32
|
-
# Get the text from the child object.
|
33
|
-
#
|
34
|
-
def text_value
|
35
|
-
o = find_child TEXT
|
36
|
-
return '' unless o
|
37
|
-
|
38
|
-
return o.value
|
39
|
-
end
|
40
|
-
|
41
|
-
#
|
42
|
-
# Get the color from the child object.
|
43
|
-
#
|
44
|
-
def color_value
|
45
|
-
o = find_child COLOR
|
46
|
-
return '' unless o
|
47
|
-
|
48
|
-
return o.value
|
49
|
-
end
|
50
|
-
|
51
|
-
# ---------------------------------------------------------------------
|
52
|
-
# Children
|
53
|
-
# ---------------------------------------------------------------------
|
54
|
-
|
55
|
-
#
|
56
|
-
# Does this object have children to add when an object
|
57
|
-
# is created in interactive mode?
|
58
|
-
# This does not apply during obj load, etc.
|
59
|
-
#
|
60
|
-
def add_children_on_create?
|
61
|
-
return true
|
62
|
-
end
|
63
|
-
|
64
|
-
#
|
65
|
-
# Add children to this object.
|
66
|
-
# This is used by containers to add children needed
|
67
|
-
# for default configurations.
|
68
|
-
#
|
69
|
-
def add_default_children
|
70
|
-
fac = @engine.factory
|
71
|
-
fac.create_string TEXT, '', self
|
72
|
-
fac.create_string COLOR, '', self
|
73
|
-
end
|
74
|
-
|
75
|
-
# ---------------------------------------------------------------------
|
76
|
-
# Messages
|
77
|
-
# ---------------------------------------------------------------------
|
78
|
-
|
79
|
-
#
|
80
|
-
# Get a list of message names that this object receives.
|
81
|
-
#
|
82
|
-
def self.messages
|
83
|
-
return super + %w[run show]
|
84
|
-
end
|
85
|
-
|
86
|
-
#
|
87
|
-
# Alias to show the banner bar
|
88
|
-
#
|
89
|
-
def msg_run
|
90
|
-
msg_show
|
91
|
-
end
|
92
|
-
|
93
|
-
#
|
94
|
-
# Show the banner bar
|
95
|
-
#
|
96
|
-
def msg_show
|
97
|
-
pastel = ::Pastel.new
|
98
|
-
c = self.color_value.split( ' ' ).map( &:to_sym )
|
99
|
-
puts pastel.decorate( self.text_value, *c )
|
100
|
-
end
|
101
|
-
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|