prompts 0.2.1 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 40fa96bdb16258c1e9612971eeea11a1757e82cdbc68e6084000c26c96f2d86c
4
- data.tar.gz: b7a7daee831ca3473aa043bfe0b1f94aff8f12a9aa8e2fa4acdb6a4a75fb0634
3
+ metadata.gz: 3105477fb552d35423f55db2fd9dc67d0187e0ef02fc1ef6e7f1394405787c00
4
+ data.tar.gz: cb9a0a8a247e329fd75f3af7e01c38cbe57b0fdc9f3c584eb310527b6dd51e2b
5
5
  SHA512:
6
- metadata.gz: fb8c9184e577f2e7b9f6c003407e028ee1613db35ee288c0ac914d5a8464f3c2135e22d4e280aab7233aa52418f60fed3ca6cf05c37d4c6907ef5937099f1445
7
- data.tar.gz: cd5e4cb5512224d68c825b28f67398f5366d0d8a5a1026523c3cc431b44efea1ddef5fdb969832af49b2158dc1bb3e94b6a98cb8781c9422c324f02ebbce16c3
6
+ metadata.gz: d6d7e0a75213bbb99c10103b7069ff5be9e4e9113214d800ddc61567a90f4b6f5590c1c9e1cfbe003457d65827650b46ca149187c4fbad312bc5980a7c12c235
7
+ data.tar.gz: 3bbc31709a1eb187dd00b73f70bae8edf829360db4b6cc0a0b275ae01b9c188645b4559afb45fc05ff7232475cb55ebbd223b1f8fa9416175e2ff732029a2e97
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.3.1] - 2024-10-08
4
+
5
+ - Keep past frames in the terminal window ([@fractaledmind](https://github.com/fractaledmind/prompts/pull/10))
6
+ - Allow users to specify a new for form fields ([@fractaledmind](https://github.com/fractaledmind/prompts/pull/11))
7
+
8
+ ## [0.3.0] - 2024-10-08
9
+
10
+ - Update `fmt` gem and use new syntax ([@KonnorRogers](https://github.com/fractaledmind/prompts/pull/9))
11
+
3
12
  ## [0.2.1] - 2024-08-22
4
13
 
5
14
  - Add `Form.submit` method
data/lib/prompts/box.rb CHANGED
@@ -55,16 +55,16 @@ module Prompts
55
55
 
56
56
  def top_border
57
57
  border = @border_parts[:top_left] + @border_parts[:horizontal] * (@width - 2) + @border_parts[:top_right]
58
- Fmt("#{@line_padding}%{border}#{@border_color}", border: border)
58
+ Fmt("#{@line_padding}%{border}|>#{@border_color}", border: border)
59
59
  end
60
60
 
61
61
  def bottom_border
62
62
  border = @border_parts[:bottom_left] + @border_parts[:horizontal] * (@width - 2) + @border_parts[:bottom_right]
63
- Fmt("#{@line_padding}%{border}#{@border_color}", border: border)
63
+ Fmt("#{@line_padding}%{border}|>#{@border_color}", border: border)
64
64
  end
65
65
 
66
66
  def align(text, alignment, between: @border_parts[:vertical])
67
- formatted_boundary = Fmt("%{boundary}#{@border_color}", boundary: between)
67
+ formatted_boundary = Fmt("%{boundary}|>#{@border_color}", boundary: between)
68
68
  wrap_text(text, width: @width, line_prefix: formatted_boundary + SPACE, line_suffix: SPACE + formatted_boundary, alignment: alignment)
69
69
  end
70
70
  end
@@ -64,7 +64,7 @@ module Prompts
64
64
  end
65
65
 
66
66
  def erase_down
67
- OUTPUT.print "\e[J"
67
+ OUTPUT.print "\e[2J\e[H"
68
68
  end
69
69
  end
70
70
  end
data/lib/prompts/form.rb CHANGED
@@ -3,15 +3,16 @@
3
3
  module Prompts
4
4
  class Form
5
5
  def self.submit(&block)
6
- instance = new()
7
- yield instance if block_given?
6
+ instance = new
7
+ yield instance if block
8
8
  instance.submit
9
9
  end
10
10
 
11
11
  def initialize
12
12
  @content = Prompts::Content.new
13
- @prompts = []
14
- @results = []
13
+ @index = 0
14
+ @prompts = {}
15
+ @results = {}
15
16
  end
16
17
 
17
18
  def content(&block)
@@ -19,37 +20,41 @@ module Prompts
19
20
  @content
20
21
  end
21
22
 
22
- def text(label: nil, prompt: "> ", hint: nil, default: nil, required: false, validate: nil, &block)
23
+ def text(label: nil, prompt: "> ", hint: nil, default: nil, required: false, validate: nil, name: nil, &block)
23
24
  prompt = TextPrompt.new(label: label, prompt: prompt, hint: hint, default: default, required: required, validate: validate)
24
- yield(prompt) if block_given?
25
+ yield(prompt) if block
25
26
  prepend_form_content_to_prompt(prompt)
26
- @prompts << prompt
27
+ key = name || (@index += 1)
28
+ @prompts[key] = prompt
27
29
  end
28
30
 
29
- def select(label: nil, options: nil, prompt: "> ", hint: nil, default: nil, validate: nil, &block)
31
+ def select(label: nil, options: nil, prompt: "> ", hint: nil, default: nil, validate: nil, name: nil, &block)
30
32
  prompt = SelectPrompt.new(label: label, options: options, prompt: prompt, hint: hint, default: default, validate: validate)
31
- yield(prompt) if block_given?
33
+ yield(prompt) if block
32
34
  prepend_form_content_to_prompt(prompt)
33
- @prompts << prompt
35
+ key = name || (@index += 1)
36
+ @prompts[key] = prompt
34
37
  end
35
38
 
36
- def pause(label: nil, prompt: "> ", hint: nil, default: nil, required: false, validate: nil, &block)
39
+ def pause(label: nil, prompt: "> ", hint: nil, default: nil, required: false, validate: nil, name: nil, &block)
37
40
  prompt = PausePrompt.new(label: label, prompt: prompt, hint: hint, default: default, required: required, validate: validate)
38
- yield(prompt) if block_given?
41
+ yield(prompt) if block
39
42
  prepend_form_content_to_prompt(prompt)
40
- @prompts << prompt
43
+ key = name || (@index += 1)
44
+ @prompts[key] = prompt
41
45
  end
42
46
 
43
- def confirm(label: nil, prompt: "> ", hint: nil, default: nil, required: false, validate: nil, &block)
47
+ def confirm(label: nil, prompt: "> ", hint: nil, default: nil, required: false, validate: nil, name: nil, &block)
44
48
  prompt = ConfirmPrompt.new(label: label, prompt: prompt, hint: hint, default: default, required: required, validate: validate)
45
- yield(prompt) if block_given?
49
+ yield(prompt) if block
46
50
  prepend_form_content_to_prompt(prompt)
47
- @prompts << prompt
51
+ key = name || (@index += 1)
52
+ @prompts[key] = prompt
48
53
  end
49
54
 
50
55
  def submit
51
- @prompts.each do |prompt|
52
- @results << prompt.ask
56
+ @prompts.each do |key, prompt|
57
+ @results[key] = prompt.ask
53
58
  end
54
59
  @results
55
60
  end
@@ -58,7 +63,7 @@ module Prompts
58
63
 
59
64
  def prepend_form_content_to_prompt(prompt)
60
65
  prompt.prepare_content
61
- @content.gap
66
+ prompt.prepend_content([SPACE])
62
67
  prompt.prepend_content(*@content.slots)
63
68
  end
64
69
  end
@@ -61,7 +61,7 @@ module Prompts
61
61
 
62
62
  if (@error = ensure_validity(response))
63
63
  @content.reset!
64
- @content.paragraph Fmt("%{error}red|bold", error: @error + " Try again (×#{@attempts})...")
64
+ @content.paragraph Fmt("%{error}|>red|>bold", error: @error + " Try again (×#{@attempts})...")
65
65
  @attempts += 1
66
66
  next
67
67
  else
@@ -114,20 +114,20 @@ module Prompts
114
114
 
115
115
  def formatted_prompt
116
116
  prompt_with_space = @prompt.end_with?(SPACE) ? @prompt : @prompt + SPACE
117
- ansi_prompt = Fmt("%{prompt}faint|bold", prompt: prompt_with_space)
117
+ ansi_prompt = Fmt("%{prompt}|>faint|>bold", prompt: prompt_with_space)
118
118
  @formatted_prompt ||= Paragraph.new(ansi_prompt, width: MAX_WIDTH).lines
119
119
  end
120
120
 
121
121
  def formatted_label
122
- Fmt("%{label}cyan|bold %{instructions}faint|italic", label: @label, instructions: @instructions ? "(#{@instructions})" : "")
122
+ Fmt("%{label}|>cyan|>bold %{instructions}|>faint|>italic", label: @label, instructions: @instructions ? "(#{@instructions})" : "")
123
123
  end
124
124
 
125
125
  def formatted_hint
126
- Fmt("%{hint}faint|bold", hint: @hint)
126
+ Fmt("%{hint}|>faint|>bold", hint: @hint)
127
127
  end
128
128
 
129
129
  def formatted_error
130
- Fmt("%{error}red|bold", error: @error + " Try again (×#{@attempts})...")
130
+ Fmt("%{error}|>red|>bold", error: @error + " Try again (×#{@attempts})...")
131
131
  end
132
132
 
133
133
  def ensure_validity(response)
@@ -29,7 +29,7 @@ module Prompts
29
29
  def prepare_content
30
30
  super
31
31
  @options.each_with_index do |(key, value), index|
32
- @content.paragraph Fmt("%{prefix}faint|bold %{option}", prefix: "#{index + 1}.", option: value)
32
+ @content.paragraph Fmt("%{prefix}|>faint|>bold %{option}", prefix: "#{index + 1}.", option: value)
33
33
  end
34
34
  @content
35
35
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Prompts
4
- VERSION = "0.2.1"
4
+ VERSION = "0.3.1"
5
5
  end
data/lib/prompts.rb CHANGED
@@ -2,10 +2,8 @@
2
2
 
3
3
  require "io/console"
4
4
  require "reline"
5
+ require "rainbow" # this needs to come before require "fmt"
5
6
  require "fmt"
6
- require "rainbow"
7
-
8
- Fmt.add_rainbow_filters
9
7
 
10
8
  require_relative "prompts/version"
11
9
  require_relative "prompts/prompt"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prompts
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Margheim
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-08-22 00:00:00.000000000 Z
11
+ date: 2024-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: unicode-display_width
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: 0.3.0
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: 0.3.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rainbow
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -128,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
128
  - !ruby/object:Gem::Version
129
129
  version: '0'
130
130
  requirements: []
131
- rubygems_version: 3.5.17
131
+ rubygems_version: 3.5.11
132
132
  signing_key:
133
133
  specification_version: 4
134
134
  summary: Beautiful and user-friendly forms for your command-line Ruby applications.