Sha256: 9eca71e343385da2f8fb37973f45b449117cdb618a8264790d6f741e39ff1ddf

Contents?: true

Size: 1.39 KB

Versions: 8

Compression:

Stored size: 1.39 KB

Contents

require 'yaml'
require 'cocoapods-mtxx-bin/config/config'

module CBin
  class Config
    class Asker
      def show_prompt
        print ' > '.green
      end

      def ask_with_answer(question, pre_answer, selection)
        print "\n#{question}\n"

        print_selection_info = lambda {
          print "可选值:[ #{selection.join(' / ')} ]\n" if selection
        }
        print_selection_info.call
        print "旧值:#{pre_answer}\n" unless pre_answer.nil?

        answer = ''
        loop do
          show_prompt
          answer = STDIN.gets.chomp.strip

          if answer == '' && !pre_answer.nil?
            answer = pre_answer
            print answer.yellow
            print "\n"
          end

          next if answer.empty?
          break if !selection || selection.include?(answer)

          print_selection_info.call
        end

        answer
      end

      def wellcome_message
        print <<~EOF

          设置插件配置信息.
          所有的信息都会保存在 #{CBin.config.config_file} 文件中.
          你可以在对应目录下手动添加编辑该文件. 
          文件包含的配置信息样式如下:

          #{CBin.config.default_config.to_yaml}
        EOF
      end

      def done_message
        print "\n设置完成.\n".green
      end
      def done_message_update
        print "\n更新完成.\n".green
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
cocoapods-mtxx-bin-0.0.13 lib/cocoapods-mtxx-bin/config/config_asker.rb
cocoapods-mtxx-bin-0.0.12 lib/cocoapods-mtxx-bin/config/config_asker.rb
cocoapods-mtxx-bin-0.0.10 lib/cocoapods-mtxx-bin/config/config_asker.rb
cocoapods-mtxx-bin-0.0.9.1 lib/cocoapods-mtxx-bin/config/config_asker.rb
cocoapods-mtxx-bin-0.0.9 lib/cocoapods-mtxx-bin/config/config_asker.rb
cocoapods-mtxx-bin-0.0.8 lib/cocoapods-mtxx-bin/config/config_asker.rb
cocoapods-mtxx-bin-0.0.7 lib/cocoapods-mtxx-bin/config/config_asker.rb
cocoapods-mtxx-bin-0.0.6 lib/cocoapods-mtxx-bin/config/config_asker.rb