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
-
#cooked_mode! ⇒ Symbol
Sets the terminal in to
cookedmode. -
#cooked_mode? ⇒ Boolean
Returns a boolean indicating whether the terminal is currently in
cookedmode. -
#fake_mode! ⇒ Symbol
Sets the terminal in to
fakemode. -
#fake_mode? ⇒ Boolean
Returns a boolean indicating whether the terminal is currently in
fakemode. -
#mode ⇒ Symbol
Returns the mode of the terminal, either
:cooked,:fakeor:raw. -
#raw_mode! ⇒ Symbol
Sets the terminal in to
rawmode. -
#raw_mode? ⇒ Boolean
Returns a boolean indicating whether the terminal is currently in
rawmode. -
#switch_mode!(mode = nil) ⇒ Symbol
Changes the mode of the terminal to the mode given or toggles the terminal mode between
cooked,fakeandraw, depending on the current mode. -
#valid_mode?(mode) ⇒ Boolean
private
Returns a boolean indicating whether the given mode is valid.
- #valid_modes ⇒ Array<Symbol> private
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.
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.
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.
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.
33 34 35 |
# File 'lib/vedeu/terminal/mode.rb', line 33 def fake_mode? mode == :fake end |
#mode ⇒ Symbol
Returns the mode of the terminal, either :cooked, :fake or :raw. Can change throughout the lifespan of the client application.
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.
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.
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.
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.
94 95 96 |
# File 'lib/vedeu/terminal/mode.rb', line 94 def valid_mode?(mode) valid_modes.include?(mode) end |
#valid_modes ⇒ Array<Symbol> (private)
99 100 101 102 103 104 105 |
# File 'lib/vedeu/terminal/mode.rb', line 99 def valid_modes [ :cooked, :fake, :raw, ] end |