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:

.become(klass, attributes) ⇒ Class 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 one class into another.

Parameters:

  • klass (Class)

    The class to become an instance of.

  • attributes (Hash)

    The attributes of klass.

Returns:

  • (Class)

    Returns a new instance of klass.

.boolean(value) ⇒ 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 the value was a boolean.

Parameters:

  • value (void)

Returns:

.boolean?(value) ⇒ 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 the value is a Boolean.

Parameters:

Returns:

.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

.escape?(value) ⇒ 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 the value is an escape sequence object (e.g. Vedeu::Cells::Escape.)

Returns:

.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

.falsy?(value) ⇒ 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 the value should be considered false.

Parameters:

  • value (void)

Returns:

.hash?(value) ⇒ 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 the value is a Hash.

Parameters:

  • value (Hash|void)

Returns:

.line_model?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 the model is a Views::Line.

Returns:

.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

.numeric?(value) ⇒ 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 the value is a Fixnum.

Parameters:

  • value (Fixnum|void)

Returns:

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

.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

.snake_case(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.

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"

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

Parameters:

  • klass (Module|Class|String)

Returns:

  • (String)

.stream_model?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 the model is a Views::Stream.

Returns:

.string?(value) ⇒ 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 the value is a Fixnum.

Parameters:

  • value (String|void)

Returns:

.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

.truthy?(value) ⇒ 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 the value should be considered true.

Parameters:

  • value (void)

Returns:

.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

.view_model?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 the model is a Views::View.

Returns:

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:

#become(klass, attributes) ⇒ Class 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 one class into another.

Parameters:

  • klass (Class)

    The class to become an instance of.

  • attributes (Hash)

    The attributes of klass.

Returns:

  • (Class)

    Returns a new instance of klass.

#boolean(value) ⇒ 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 the value was a boolean.

Parameters:

  • value (void)

Returns:

#boolean?(value) ⇒ 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 the value is a Boolean.

Parameters:

Returns:

#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

#escape?(value) ⇒ 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 the value is an escape sequence object (e.g. Vedeu::Cells::Escape.)

Returns:

#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

#falsy?(value) ⇒ 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 the value should be considered false.

Parameters:

  • value (void)

Returns:

#hash?(value) ⇒ 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 the value is a Hash.

Parameters:

  • value (Hash|void)

Returns:

#line_model?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 the model is a Views::Line.

Returns:

#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

#numeric?(value) ⇒ 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 the value is a Fixnum.

Parameters:

  • value (Fixnum|void)

Returns:

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

#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

#snake_case(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.

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"

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

Parameters:

  • klass (Module|Class|String)

Returns:

  • (String)

#stream_model?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 the model is a Views::Stream.

Returns:

#string?(value) ⇒ 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 the value is a Fixnum.

Parameters:

  • value (String|void)

Returns:

#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

#truthy?(value) ⇒ 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 the value should be considered true.

Parameters:

  • value (void)

Returns:

#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

#view_model?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 the model is a Views::View.

Returns: