Module: Vedeu::Terminal::Mode

Extended by:
Mode
Includes:
Common
Included in:
Vedeu::Terminal, Mode
Defined in:
lib/vedeu/terminal/mode.rb

Overview

Store the current mode of the terminal.

Instance Method Summary collapse

Methods included from Common

#absent?, #array?, #boolean, #boolean?, #empty_value?, #escape?, #falsy?, #hash?, #line_model?, #numeric?, #positionable?, #present?, #snake_case, #stream_model?, #string?, #symbol?, #truthy?, #view_model?

Instance Method Details

#cooked_mode!Symbol

Sets the terminal in to ‘cooked` mode.

Returns:

  • (Symbol)


25
26
27
# File 'lib/vedeu/terminal/mode.rb', line 25

def cooked_mode!
  switch_mode!(:cooked)
end

#cooked_mode?Boolean

Returns a boolean indicating whether the terminal is currently in ‘cooked` mode.

Returns:



18
19
20
# File 'lib/vedeu/terminal/mode.rb', line 18

def cooked_mode?
  mode == :cooked
end

#fake_mode!Symbol

Sets the terminal in to ‘fake` mode.

Returns:

  • (Symbol)


40
41
42
# File 'lib/vedeu/terminal/mode.rb', line 40

def fake_mode!
  switch_mode!(:fake)
end

#fake_mode?Boolean

Returns a boolean indicating whether the terminal is currently in ‘fake` mode.

Returns:



33
34
35
# File 'lib/vedeu/terminal/mode.rb', line 33

def fake_mode?
  mode == :fake
end

#modeSymbol

Returns the mode of the terminal, either ‘:cooked`, `:fake` or `:raw`. Can change throughout the lifespan of the client application.

Returns:

  • (Symbol)


83
84
85
# File 'lib/vedeu/terminal/mode.rb', line 83

def mode
  @mode = Vedeu.config.terminal_mode
end

#raw_mode!Symbol

Sets the terminal in to ‘raw` mode.

Returns:

  • (Symbol)


55
56
57
# File 'lib/vedeu/terminal/mode.rb', line 55

def raw_mode!
  switch_mode!(:raw)
end

#raw_mode?Boolean

Returns a boolean indicating whether the terminal is currently in ‘raw` mode.

Returns:



48
49
50
# File 'lib/vedeu/terminal/mode.rb', line 48

def raw_mode?
  mode == :raw
end

#switch_mode!(mode = nil) ⇒ Symbol

Changes the mode of the terminal to the mode given or toggles the terminal mode between ‘cooked`, `fake` and `raw`, depending on the current mode.

Parameters:

  • mode (NilClass|Symbol) (defaults to: nil)

Returns:

  • (Symbol)


65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/vedeu/terminal/mode.rb', line 65

def switch_mode!(mode = nil)
  if present?(mode) && valid_mode?(mode)
    Vedeu.configure { |config| config.terminal_mode = mode }

  else
    return fake_mode!   if raw_mode?
    return cooked_mode! if fake_mode?

    raw_mode!

  end
end

#valid_mode?(mode) ⇒ Boolean (private)

Returns a boolean indicating whether the given mode is valid.

Parameters:

  • mode (Symbol)

    Should be one of the modes listed in #valid_modes.

Returns:



94
95
96
# File 'lib/vedeu/terminal/mode.rb', line 94

def valid_mode?(mode)
  valid_modes.include?(mode)
end

#valid_modesArray<Symbol> (private)

Returns:

  • (Array<Symbol>)


99
100
101
102
103
104
105
# File 'lib/vedeu/terminal/mode.rb', line 99

def valid_modes
  [
    :cooked,
    :fake,
    :raw,
  ]
end