Skip to content

Commit 55cc2ec

Browse files
committed
Merge pull request #426 from tjwp-yesware/fix-ask-color
Fix for an array of colors with ask/yes?/no?
2 parents 6e3e795 + 2398e1c commit 55cc2ec

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/thor/shell/basic.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ def as_unicode
391391
def ask_simply(statement, color, options)
392392
default = options[:default]
393393
message = [statement, ("(#{default})" if default), nil].uniq.join(" ")
394-
message = prepare_message(message, color)
394+
message = prepare_message(message, *color)
395395
result = Thor::LineEditor.readline(message, options)
396396

397397
return unless result

spec/shell/color_spec.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ def shell
1818
expect(Thor::LineEditor).to receive(:readline).with("\e[32mIs this green? [Yes, No, Maybe] \e[0m", anything).and_return("Yes")
1919
shell.ask "Is this green?", :green, :limited_to => %w[Yes No Maybe]
2020
end
21+
22+
it "handles an Array of colors" do
23+
expect(Thor::LineEditor).to receive(:readline).with("\e[32m\e[47m\e[1mIs this green on white? \e[0m", anything).and_return("yes")
24+
shell.ask "Is this green on white?", [:green, :on_white, :bold]
25+
end
26+
27+
it "supports the legacy color syntax" do
28+
expect(Thor::LineEditor).to receive(:readline).with("\e[1m\e[34mIs this legacy blue? \e[0m", anything).and_return("yes")
29+
shell.ask "Is this legacy blue?", [:blue, true]
30+
end
2131
end
2232

2333
describe "#say" do
@@ -53,6 +63,15 @@ def shell
5363

5464
expect(out.chomp).to eq("\e[32m\e[41m\e[1mWow! Now we have colors *and* background colors\e[0m")
5565
end
66+
67+
it "supports the legacy color syntax" do
68+
out = capture(:stdout) do
69+
shell.say "Wow! This still works?", [:blue, true]
70+
end
71+
72+
expect(out.chomp).to eq("\e[1m\e[34mWow! This still works?\e[0m")
73+
end
74+
5675
end
5776

5877
describe "#say_status" do

0 commit comments

Comments
 (0)