gloo-cli 2.1 → 2.2

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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/lib/menu.rb +35 -11
  3. data/lib/shell.rb +4 -1
  4. data/lib/shell_runner.rb +35 -2
  5. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3895372f8e68e7e2a85536a4a8f6ba10706111fcac9424c502a49d47b3bd4722
4
- data.tar.gz: 5a6435ee161245664518dc3df7c9b74ad0bd799b83108f6246dcfb899c1dc9c1
3
+ metadata.gz: 7d03397ae8d5ddcc580deef1c3d0f7acf681493e03fdf77da8034674303f26f8
4
+ data.tar.gz: bf4c226957a48194dde1f52e619a1475b72dc6b67fffcc6d2fe8df0b7122c003
5
5
  SHA512:
6
- metadata.gz: 35bc36bf079647ecf622973e3b8039d52c75420374ab9cfb278dd838c97057d4acc1fe518574f94603b6d64eb82ed130e677a0ad184b24466fada58ff6fb9442
7
- data.tar.gz: fff5950b3c4d76aa72dc28630fbb26203dc19b4cb2e4f0c186ebb0a2e4a0511280134bdc486535b677a67baee4a1a77162273e3dca856ae738cd847cc1781d59
6
+ metadata.gz: a84a16f558144fc05292dadc9e45c73740c8bb88fc1ce5c23e6e9e041ac5f9e5d69dafb52c5d4048e8975e830a70cea7f6e49ddb158d1021e086cd539b0d2b01
7
+ data.tar.gz: 73304154299c9e2f7df0a90387271dfa132506cbdc35835ee32f2b18ffa237e1225a92a82ac3f4711b67c07d8ddc03415fd4c6fcca3ca10b06e9a17d48e767e0
data/lib/menu.rb CHANGED
@@ -19,6 +19,7 @@ class Menu < Gloo::Core::Obj
19
19
  TITLE = 'title'.freeze
20
20
  TITLE_COLOR = 'green'.freeze
21
21
  QUIT_ITEM_NAME = 'q'.freeze
22
+ QUIT_HINT = "Use 'q' to quit this menu.".freeze
22
23
 
23
24
  @@menu_stack = []
24
25
 
@@ -227,21 +228,42 @@ class Menu < Gloo::Core::Obj
227
228
  run_default
228
229
  loop do
229
230
  begin_menu
230
- if prompt_value.empty?
231
- dt = DateTime.now
232
- d = dt.strftime( '%Y.%m.%d' )
233
- t = dt.strftime( '%I:%M:%S' )
234
- theme = @engine.theme
235
- cmd = @engine.platform.prompt.ask( "#{theme.accent( d )} #{theme.emphasis( t )} >" )
236
- else
237
- cmd = @engine.platform.prompt.ask( prompt_value )
238
- end
239
- cmd ? run_command( cmd ) : run_default
231
+ cmd = ask_command
232
+ next if cmd == :interrupted
233
+
234
+ # Ctrl-C stops the command and comes back to this menu.
235
+ @engine.run_interruptible { cmd ? run_command( cmd ) : run_default }
240
236
  break unless loop?
241
237
  end
242
238
  pop_menu self
243
239
  end
244
240
 
241
+ #
242
+ # Show the prompt and read a command: nil at the end of input, or
243
+ # :interrupted if Ctrl-C dropped the line (with the hint, if nothing
244
+ # had been typed).
245
+ #
246
+ def ask_command
247
+ prompt = @engine.platform.prompt
248
+ return prompt.ask( prompt_text )
249
+ rescue Interrupt
250
+ @engine.interrupted_at_prompt( prompt.line_typed, QUIT_HINT )
251
+ return :interrupted
252
+ end
253
+
254
+ #
255
+ # The menu's prompt: its own, or the date and time.
256
+ #
257
+ def prompt_text
258
+ return prompt_value unless prompt_value.empty?
259
+
260
+ dt = DateTime.now
261
+ d = dt.strftime( '%Y.%m.%d' )
262
+ t = dt.strftime( '%I:%M:%S' )
263
+ theme = @engine.theme
264
+ return "#{theme.accent( d )} #{theme.emphasis( t )} >"
265
+ end
266
+
245
267
  # ---------------------------------------------------------------------
246
268
  # Menu actions
247
269
  # ---------------------------------------------------------------------
@@ -403,7 +425,9 @@ class Menu < Gloo::Core::Obj
403
425
  'menu (not shown); q! — quit gloo entirely (not shown); ' \
404
426
  ': {command} — run a gloo command not part of the running app; ' \
405
427
  ': (alone) — quit the running app and drop into gloo, keeping ' \
406
- 'loaded app objects in the stack.',
428
+ 'loaded app objects in the stack. Ctrl-C during an item stops ' \
429
+ 'it and comes back to the menu; at an empty prompt it says how ' \
430
+ 'to leave. See doc application, Stopping with Ctrl-C.',
407
431
  :examples => <<~EXAMPLES.strip
408
432
  simple [menu] :
409
433
  on_load [script] :
data/lib/shell.rb CHANGED
@@ -281,7 +281,10 @@ class Shell < Gloo::Core::Obj
281
281
  'sending it the register message with this shell\'s path, or ' \
282
282
  'by calling add_command directly. The underlying tree/REPL ' \
283
283
  'engine here was later ported into dev/gloo itself (as ' \
284
- 'Gloo::Shell::Runner) to power the interactive help shell.'
284
+ 'Gloo::Shell::Runner) to power the interactive help shell. ' \
285
+ 'Ctrl-C during a command stops it and comes back to the ' \
286
+ 'shell\'s prompt; at an empty prompt it says how to leave ' \
287
+ '(with include_quit). See doc application, Stopping with Ctrl-C.'
285
288
  }
286
289
  end
287
290
 
data/lib/shell_runner.rb CHANGED
@@ -10,6 +10,7 @@ class ShellRunner
10
10
 
11
11
  DEFAULT_PROMPT = " -> "
12
12
  UNKNOWN_COMMAND = "Unknown command".freeze
13
+ QUIT_HINT = "Use 'quit' to leave the shell.".freeze
13
14
 
14
15
  #
15
16
  # Initialize the shell runner
@@ -294,15 +295,47 @@ class ShellRunner
294
295
  def repl
295
296
  setup_completion
296
297
 
297
- while ( ! @context.done && (line = Readline.readline(prompt, true)) )
298
+ until @context.done
299
+ line = read_line
300
+ next if line == :interrupted
301
+ break unless line
302
+
298
303
  tokens = line.strip.split(" ")
299
304
  if tokens.empty?
300
305
  handle_empty_command
301
306
  next
302
307
  end
303
308
 
304
- run_tokens( tokens )
309
+ # Ctrl-C stops the command and comes back to this prompt.
310
+ @engine.run_interruptible { run_tokens( tokens ) }
305
311
  end
306
312
  end
307
313
 
314
+ #
315
+ # Read a line at the shell's prompt: nil at the end of input, or
316
+ # :interrupted if Ctrl-C dropped the line (with the hint, if nothing
317
+ # had been typed).
318
+ #
319
+ def read_line
320
+ return Readline.readline( prompt, true )
321
+ rescue Interrupt
322
+ @engine.interrupted_at_prompt( line_typed, quit_hint )
323
+ return :interrupted
324
+ end
325
+
326
+ #
327
+ # What had been typed when Ctrl-C was pressed.
328
+ #
329
+ def line_typed
330
+ return Readline.respond_to?( :line_buffer ) ? Readline.line_buffer.to_s : ''
331
+ end
332
+
333
+ #
334
+ # How to leave the shell, for the Ctrl-C hint: its quit command, if it
335
+ # has one.
336
+ #
337
+ def quit_hint
338
+ return @obj.include_quit? ? QUIT_HINT : nil
339
+ end
340
+
308
341
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gloo-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: '2.1'
4
+ version: '2.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Crane
@@ -15,14 +15,14 @@ dependencies:
15
15
  requirements:
16
16
  - - ">="
17
17
  - !ruby/object:Gem::Version
18
- version: '7.0'
18
+ version: '7.3'
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - ">="
24
24
  - !ruby/object:Gem::Version
25
- version: '7.0'
25
+ version: '7.3'
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: bundler
28
28
  requirement: !ruby/object:Gem::Requirement