Module: CF::Interactive

Includes:
Dots, Interactive::Rewindable
Included in:
Command
Defined in:
lib/cf/cli/command.rb

Defined Under Namespace

Classes: CFState, InteractiveDefault

Constant Summary

Constants included from Dots

Dots::COLOR_CODES, Dots::DOT_COUNT, Dots::DOT_TICK

Instance Method Summary collapse

Methods included from Dots

b, c, #color?, #dots!, #stop_dots!, #with_progress

Instance Method Details

#ask(question, options = {}) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/cf/cli/command.rb', line 34

def ask(question, options = {})
  if force? and options.key?(:default)
    options[:default]
  else
    super
  end
end

#force?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/cf/cli/command.rb', line 30

def force?
  false
end

#handler(which, state) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/cf/cli/command.rb', line 73

def handler(which, state)
  ans = state.answer
  pos = state.position

  if state.default?
    if which.is_a?(Array) and which[0] == :key
      # initial non-movement keypress clears default answer
      clear_input(state)
    else
      # wipe away any coloring
      redraw_input(state)
    end

    state.clear_default!
  end

  super

  print "\n" if which == :enter
end

#input_state(options) ⇒ Object



48
49
50
# File 'lib/cf/cli/command.rb', line 48

def input_state(options)
  CFState.new(options)
end

#list_choices(choices, options) ⇒ Object



42
43
44
45
46
# File 'lib/cf/cli/command.rb', line 42

def list_choices(choices, options)
  choices.each_with_index do |o, i|
    puts "#{c(i + 1, :green)}: #{o}"
  end
end

#prompt(question, options) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/cf/cli/command.rb', line 52

def prompt(question, options)
  value =
    case options[:default]
    when true
      "y"
    when false
      "n"
    when nil
      ""
    else
      options[:default].to_s
    end

  print "#{question}"
  print c("> ", :blue)

  unless value.empty?
    print "#{c(value, :black) + "\b" * value.size}"
  end
end