Rakefile: handle non-interactive stdin in ask()
STDIN.gets returns nil when stdin is closed/EOF (e.g. after vim/vundle runs during install), causing `nil.chomp` to abort rake install during install_term_theme. Return nil from ask() on EOF and have callers bail out of the iTerm theme prompts gracefully.
This commit is contained in:
11
Rakefile
11
Rakefile
@@ -210,7 +210,7 @@ def install_term_theme
|
||||
message = "Which theme would you like to apply to your iTerm2 profile?"
|
||||
color_scheme = ask message, iTerm_available_themes
|
||||
|
||||
return if color_scheme == 'None'
|
||||
return if color_scheme.nil? || color_scheme == 'None'
|
||||
|
||||
color_scheme_file = File.join('iTerm2', "#{color_scheme}.itermcolors")
|
||||
|
||||
@@ -220,6 +220,8 @@ def install_term_theme
|
||||
profiles << 'All'
|
||||
selected = ask message, profiles
|
||||
|
||||
return if selected.nil?
|
||||
|
||||
if selected == 'All'
|
||||
(profiles.size-1).times { |idx| apply_theme_to_iterm_profile_idx idx, color_scheme_file }
|
||||
else
|
||||
@@ -244,7 +246,12 @@ def ask(message, values)
|
||||
puts message
|
||||
while true
|
||||
values.each_with_index { |val, idx| puts " #{idx+1}. #{val}" }
|
||||
selection = STDIN.gets.chomp
|
||||
input = STDIN.gets
|
||||
if input.nil?
|
||||
puts "(no input available — skipping prompt)"
|
||||
return nil
|
||||
end
|
||||
selection = input.chomp
|
||||
if (Float(selection)==nil rescue true) || selection.to_i < 0 || selection.to_i > values.size+1
|
||||
puts "ERROR: Invalid selection.\n\n"
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user