Module: Vedeu::Configuration Private

Extended by:
Configuration
Included in:
Configuration
Defined in:
lib/vedeu/configuration/configuration.rb,
lib/vedeu/configuration/api.rb,
lib/vedeu/configuration/cli.rb

Overview

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

Provides access to Vedeu’s configuration, which was set with sensible defaults (influenced by environment variables), overridden by client application settings (via the configuration API), or any command-line arguments provided.

Defined Under Namespace

Classes: API, CLI

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.colour_modeFixnum

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 the chosen colour mode.

Returns:



35
36
37
# File 'lib/vedeu/configuration/configuration.rb', line 35

def colour_mode
  options[:colour_mode]
end

.configure(args = [], &block) ⇒ Hash

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.

Configure Vedeu with sensible defaults. If the client application sets options, override the defaults with those, and if command-line arguments are provided at application invocation, override any options with the arguments provided.

Parameters:

  • args (Array) (defaults to: [])
  • block (Proc)

Returns:

  • (Hash)


24
25
26
27
28
29
30
# File 'lib/vedeu/configuration/configuration.rb', line 24

def configure(args = [], &block)
  options.merge!(API.configure(&block)) if block_given?

  options.merge!(CLI.configure(args)) if args.any?

  options
end

.debug?Boolean Also known as: debug

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 whether debugging is enabled or disabled. Default is false; meaning nothing apart from warnings are written to the log file.

Returns:

  • (Boolean)


43
44
45
# File 'lib/vedeu/configuration/configuration.rb', line 43

def debug?
  options[:debug]
end

.default_system_keysHash

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.

Vedeu’s default system keys. Use #system_keys.

Returns:

  • (Hash)


103
104
105
106
107
108
109
110
# File 'lib/vedeu/configuration/configuration.rb', line 103

def default_system_keys
  {
    exit:        'q',
    focus_next:  :tab,
    focus_prev:  :shift_tab,
    mode_switch: :escape,
  }
end

.defaultsHash (private)

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.

The Vedeu default options, which of course are influenced by environment variables also.

Returns:

  • (Hash)


127
128
129
130
131
132
133
134
135
136
137
# File 'lib/vedeu/configuration/configuration.rb', line 127

def defaults
  {
    colour_mode:   detect_colour_mode,
    debug:         detect_debug_mode,
    interactive:   true,
    once:          false,
    system_keys:   default_system_keys,
    terminal_mode: :raw,
    trace:         detect_trace_mode,
  }
end

.detect_colour_modeFixnum (private)

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.

Attempt to determine the terminal colour mode via environment variables, or be optimistic and settle for 256 colours.

:nocov:

Returns:



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/vedeu/configuration/configuration.rb', line 145

def detect_colour_mode
  return 16777216 if ENV['VEDEU_TESTMODE']

  if ENV['VEDEU_TERM']
    case ENV['VEDEU_TERM']
    when /-256color$/  then 256
    when /-truecolor$/ then 16777216
    else 256
    end

  elsif ENV['TERM']
    case ENV['TERM']
    when /-256color$/, 'xterm' then 256
    when /-color$/, 'rxvt'     then 16
    else 256
    end

  else
    256

  end
end

.detect_debug_modeBoolean (private)

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.

Determine the debug mode via an environment variable.

:nocov:

Returns:

  • (Boolean)


174
175
176
177
178
179
180
# File 'lib/vedeu/configuration/configuration.rb', line 174

def detect_debug_mode
  return false if ENV['VEDEU_TESTMODE']

  return true if ENV['VEDEU_DEBUG']

  false
end

.detect_trace_modeBoolean (private)

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.

Determine the trace mode via an environment variable.

:nocov:

Returns:

  • (Boolean)


188
189
190
191
192
193
194
# File 'lib/vedeu/configuration/configuration.rb', line 188

def detect_trace_mode
  return false if ENV['VEDEU_TESTMODE']

  return true if ENV['VEDEU_TRACE']

  false
end

.interactive?Boolean Also known as: interactive

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 whether the application is interactive (required user input) or standalone (will run until terminates of natural causes.) Default is true; meaning the application will require user input.

Returns:

  • (Boolean)


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

def interactive?
  options[:interactive]
end

.once?Boolean Also known as: once

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 whether the application will run through its main loop once or not. Default is false; meaning the application will loop forever or until terminated by the user.

Returns:

  • (Boolean)


63
64
65
# File 'lib/vedeu/configuration/configuration.rb', line 63

def once?
  options[:once]
end

.optionsHash (private)

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 all the options current configured.

Returns:

  • (Hash)


118
119
120
# File 'lib/vedeu/configuration/configuration.rb', line 118

def options
  @options ||= defaults
end

.resetHash

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.

Resets all options to Vedeu defaults.

Returns:

  • (Hash)


95
96
97
# File 'lib/vedeu/configuration/configuration.rb', line 95

def reset
  @options = defaults
end

.system_keysHash

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

Returns:

  • (Hash)


71
72
73
# File 'lib/vedeu/configuration/configuration.rb', line 71

def system_keys
  options[:system_keys]
end

.terminal_modeSymbol

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 the terminal mode for the application. Default is ‘:raw`.

Returns:

  • (Symbol)


78
79
80
# File 'lib/vedeu/configuration/configuration.rb', line 78

def terminal_mode
  options[:terminal_mode]
end

.trace?Boolean Also known as: trace

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 whether tracing is enabled or disabled. Tracing is very noisy in the log file (logging method calls and events trigger). Default is false; meaning tracing is disabled.

Returns:

  • (Boolean)


87
88
89
# File 'lib/vedeu/configuration/configuration.rb', line 87

def trace?
  options[:trace]
end

Instance Method Details

#colour_modeFixnum

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 the chosen colour mode.

Returns:



35
36
37
# File 'lib/vedeu/configuration/configuration.rb', line 35

def colour_mode
  options[:colour_mode]
end

#configure(args = [], &block) ⇒ Hash

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.

Configure Vedeu with sensible defaults. If the client application sets options, override the defaults with those, and if command-line arguments are provided at application invocation, override any options with the arguments provided.

Parameters:

  • args (Array) (defaults to: [])
  • block (Proc)

Returns:

  • (Hash)


24
25
26
27
28
29
30
# File 'lib/vedeu/configuration/configuration.rb', line 24

def configure(args = [], &block)
  options.merge!(API.configure(&block)) if block_given?

  options.merge!(CLI.configure(args)) if args.any?

  options
end

#debug?Boolean Also known as: debug

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 whether debugging is enabled or disabled. Default is false; meaning nothing apart from warnings are written to the log file.

Returns:

  • (Boolean)


43
44
45
# File 'lib/vedeu/configuration/configuration.rb', line 43

def debug?
  options[:debug]
end

#default_system_keysHash

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.

Vedeu’s default system keys. Use #system_keys.

Returns:

  • (Hash)


103
104
105
106
107
108
109
110
# File 'lib/vedeu/configuration/configuration.rb', line 103

def default_system_keys
  {
    exit:        'q',
    focus_next:  :tab,
    focus_prev:  :shift_tab,
    mode_switch: :escape,
  }
end

#defaultsHash (private)

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.

The Vedeu default options, which of course are influenced by environment variables also.

Returns:

  • (Hash)


127
128
129
130
131
132
133
134
135
136
137
# File 'lib/vedeu/configuration/configuration.rb', line 127

def defaults
  {
    colour_mode:   detect_colour_mode,
    debug:         detect_debug_mode,
    interactive:   true,
    once:          false,
    system_keys:   default_system_keys,
    terminal_mode: :raw,
    trace:         detect_trace_mode,
  }
end

#detect_colour_modeFixnum (private)

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.

Attempt to determine the terminal colour mode via environment variables, or be optimistic and settle for 256 colours.

:nocov:

Returns:



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/vedeu/configuration/configuration.rb', line 145

def detect_colour_mode
  return 16777216 if ENV['VEDEU_TESTMODE']

  if ENV['VEDEU_TERM']
    case ENV['VEDEU_TERM']
    when /-256color$/  then 256
    when /-truecolor$/ then 16777216
    else 256
    end

  elsif ENV['TERM']
    case ENV['TERM']
    when /-256color$/, 'xterm' then 256
    when /-color$/, 'rxvt'     then 16
    else 256
    end

  else
    256

  end
end

#detect_debug_modeBoolean (private)

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.

Determine the debug mode via an environment variable.

:nocov:

Returns:

  • (Boolean)


174
175
176
177
178
179
180
# File 'lib/vedeu/configuration/configuration.rb', line 174

def detect_debug_mode
  return false if ENV['VEDEU_TESTMODE']

  return true if ENV['VEDEU_DEBUG']

  false
end

#detect_trace_modeBoolean (private)

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.

Determine the trace mode via an environment variable.

:nocov:

Returns:

  • (Boolean)


188
189
190
191
192
193
194
# File 'lib/vedeu/configuration/configuration.rb', line 188

def detect_trace_mode
  return false if ENV['VEDEU_TESTMODE']

  return true if ENV['VEDEU_TRACE']

  false
end

#interactive?Boolean Also known as: interactive

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 whether the application is interactive (required user input) or standalone (will run until terminates of natural causes.) Default is true; meaning the application will require user input.

Returns:

  • (Boolean)


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

def interactive?
  options[:interactive]
end

#once?Boolean Also known as: once

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 whether the application will run through its main loop once or not. Default is false; meaning the application will loop forever or until terminated by the user.

Returns:

  • (Boolean)


63
64
65
# File 'lib/vedeu/configuration/configuration.rb', line 63

def once?
  options[:once]
end

#optionsHash (private)

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 all the options current configured.

Returns:

  • (Hash)


118
119
120
# File 'lib/vedeu/configuration/configuration.rb', line 118

def options
  @options ||= defaults
end

#resetHash

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.

Resets all options to Vedeu defaults.

Returns:

  • (Hash)


95
96
97
# File 'lib/vedeu/configuration/configuration.rb', line 95

def reset
  @options = defaults
end

#system_keysHash

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

Returns:

  • (Hash)


71
72
73
# File 'lib/vedeu/configuration/configuration.rb', line 71

def system_keys
  options[:system_keys]
end

#terminal_modeSymbol

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 the terminal mode for the application. Default is ‘:raw`.

Returns:

  • (Symbol)


78
79
80
# File 'lib/vedeu/configuration/configuration.rb', line 78

def terminal_mode
  options[:terminal_mode]
end

#trace?Boolean Also known as: trace

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 whether tracing is enabled or disabled. Tracing is very noisy in the log file (logging method calls and events trigger). Default is false; meaning tracing is disabled.

Returns:

  • (Boolean)


87
88
89
# File 'lib/vedeu/configuration/configuration.rb', line 87

def trace?
  options[:trace]
end