@@ -17,8 +17,12 @@ def output_helper(prompt, choices, active, selected, options = {})
17
17
out = [ ]
18
18
out << "\e [?25l" if init
19
19
out << prompt << " "
20
- out << "(min. #{ options [ :min ] } ) " if options [ :min ]
21
- out << "(max. #{ options [ :max ] } ) " if options [ :max ]
20
+ if options [ :min ] && options [ :max ]
21
+ out << "(min. #{ options [ :min ] } , max. #{ options [ :max ] } ) "
22
+ else
23
+ out << "(min. #{ options [ :min ] } ) " if options [ :min ]
24
+ out << "(max. #{ options [ :max ] } ) " if options [ :max ]
25
+ end
22
26
out << selected . join ( ", " )
23
27
out << " " if ( init || hint ) && !selected . empty?
24
28
out << "\e [90m(#{ hint } )\e [0m" if hint
@@ -905,4 +909,32 @@ def exit_message(prompt, choices)
905
909
expect ( prompt . output . string ) . to eq ( expected_output )
906
910
end
907
911
end
912
+
913
+ context "with :min and :max" do
914
+ let ( :choices ) { %w[ A B C ] }
915
+ let ( :keydown ) { "j" }
916
+ let ( :spacebar ) { " " }
917
+ let ( :enter ) { "\r " }
918
+ before do
919
+ prompt . on ( :keypress ) { |e | prompt . trigger ( :keydown ) if e . value == keydown }
920
+ end
921
+ it "requires a min number of choices" do
922
+ prompt . input << spacebar << enter << keydown << spacebar << enter
923
+ prompt . input . rewind
924
+
925
+ value = prompt . multi_select ( "What letter?" , choices , min : 2 , max : 2 , per_page : choices . count )
926
+ expect ( value ) . to eq ( %w[ A B ] )
927
+
928
+ expected_output =
929
+ output_helper ( "What letter?" , choices , "A" , [ ] , init : true , min : 2 , max : 2 ,
930
+ hint : "Press #{ up_down } arrow to move, Space to select and Enter to finish" ) +
931
+ output_helper ( "What letter?" , choices , "A" , %w[ A ] , min : 2 , max : 2 ) +
932
+ output_helper ( "What letter?" , choices , "A" , %w[ A ] , min : 2 , max : 2 ) +
933
+ output_helper ( "What letter?" , choices , "B" , %w[ A ] , min : 2 , max : 2 ) +
934
+ output_helper ( "What letter?" , choices , "B" , %w[ A B ] , min : 2 , max : 2 ) +
935
+ exit_message ( "What letter?" , %w[ A B ] )
936
+
937
+ expect ( prompt . output . string ) . to eq ( expected_output )
938
+ end
939
+ end
908
940
end
0 commit comments