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.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.absent?(variable) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether a variable is nil or empty.

Parameters:

  • variable (String|Symbol|Array|Fixnum)

    The variable to check.

Returns:

  • (Boolean)

.cooked_mode!Symbol

Sets the terminal in to ‘cooked` mode.

Returns:

  • (Symbol)


23
24
25
# File 'lib/vedeu/terminal/mode.rb', line 23

def cooked_mode!
  switch_mode!(:cooked)
end

.cooked_mode?Boolean

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

Returns:

  • (Boolean)


16
17
18
# File 'lib/vedeu/terminal/mode.rb', line 16

def cooked_mode?
  mode == :cooked
end

.demodulize(klass) ⇒ String Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Removes the module part from the expression in the string.

Examples:

demodulize('Vedeu::SomeModule::SomeClass') # => "SomeClass"

Parameters:

  • klass (Class|String)

Returns:

  • (String)

.fake_mode!Symbol

Sets the terminal in to ‘fake` mode.

Returns:

  • (Symbol)


38
39
40
# File 'lib/vedeu/terminal/mode.rb', line 38

def fake_mode!
  switch_mode!(:fake)
end

.fake_mode?Boolean

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

Returns:

  • (Boolean)


31
32
33
# File 'lib/vedeu/terminal/mode.rb', line 31

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)


81
82
83
# File 'lib/vedeu/terminal/mode.rb', line 81

def mode
  @mode = Vedeu::Configuration.terminal_mode
end

.present?(variable) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether a variable has a useful value.

Parameters:

  • variable (String|Symbol|Array|Fixnum)

    The variable to check.

Returns:

  • (Boolean)

.raw_mode!Symbol

Sets the terminal in to ‘raw` mode.

Returns:

  • (Symbol)


53
54
55
# File 'lib/vedeu/terminal/mode.rb', line 53

def raw_mode!
  switch_mode!(:raw)
end

.raw_mode?Boolean

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

Returns:

  • (Boolean)


46
47
48
# File 'lib/vedeu/terminal/mode.rb', line 46

def raw_mode?
  mode == :raw
end

.snake_case(name) ⇒ String Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Converts a class name to a lowercase snake case string.

Examples:

snake_case(MyClassName) # => "my_class_name"
snake_case(NameSpaced::ClassName)
# => "name_spaced/class_name"

Parameters:

  • name (String)

Returns:

  • (String)

.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)


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

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:

  • (Boolean)


92
93
94
# File 'lib/vedeu/terminal/mode.rb', line 92

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

.valid_modesArray<Symbol> (private)

Returns:

  • (Array<Symbol>)


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

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

Instance Method Details

#absent?(variable) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether a variable is nil or empty.

Parameters:

  • variable (String|Symbol|Array|Fixnum)

    The variable to check.

Returns:

  • (Boolean)

#cooked_mode!Symbol

Sets the terminal in to ‘cooked` mode.

Returns:

  • (Symbol)


23
24
25
# File 'lib/vedeu/terminal/mode.rb', line 23

def cooked_mode!
  switch_mode!(:cooked)
end

#cooked_mode?Boolean

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

Returns:

  • (Boolean)


16
17
18
# File 'lib/vedeu/terminal/mode.rb', line 16

def cooked_mode?
  mode == :cooked
end

#demodulize(klass) ⇒ String Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Removes the module part from the expression in the string.

Examples:

demodulize('Vedeu::SomeModule::SomeClass') # => "SomeClass"

Parameters:

  • klass (Class|String)

Returns:

  • (String)

#fake_mode!Symbol

Sets the terminal in to ‘fake` mode.

Returns:

  • (Symbol)


38
39
40
# File 'lib/vedeu/terminal/mode.rb', line 38

def fake_mode!
  switch_mode!(:fake)
end

#fake_mode?Boolean

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

Returns:

  • (Boolean)


31
32
33
# File 'lib/vedeu/terminal/mode.rb', line 31

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)


81
82
83
# File 'lib/vedeu/terminal/mode.rb', line 81

def mode
  @mode = Vedeu::Configuration.terminal_mode
end

#present?(variable) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether a variable has a useful value.

Parameters:

  • variable (String|Symbol|Array|Fixnum)

    The variable to check.

Returns:

  • (Boolean)

#raw_mode!Symbol

Sets the terminal in to ‘raw` mode.

Returns:

  • (Symbol)


53
54
55
# File 'lib/vedeu/terminal/mode.rb', line 53

def raw_mode!
  switch_mode!(:raw)
end

#raw_mode?Boolean

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

Returns:

  • (Boolean)


46
47
48
# File 'lib/vedeu/terminal/mode.rb', line 46

def raw_mode?
  mode == :raw
end

#snake_case(name) ⇒ String Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Converts a class name to a lowercase snake case string.

Examples:

snake_case(MyClassName) # => "my_class_name"
snake_case(NameSpaced::ClassName)
# => "name_spaced/class_name"

Parameters:

  • name (String)

Returns:

  • (String)

#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)


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

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:

  • (Boolean)


92
93
94
# File 'lib/vedeu/terminal/mode.rb', line 92

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

#valid_modesArray<Symbol> (private)

Returns:

  • (Array<Symbol>)


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

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