Class: Gitloggl::Command
- Inherits:
-
Object
- Object
- Gitloggl::Command
- Extended by:
- Forwardable
- Defined in:
- lib/gitloggl/command.rb
Direct Known Subclasses
Gitloggl::Commands::Main, Gitloggl::Commands::ManageIntegration, Gitloggl::Commands::Sync, Gitloggl::Commands::Update
Instance Attribute Summary collapse
-
#back ⇒ Object
callable back action.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #back? ⇒ Boolean
- #capture_back ⇒ Object
-
#command(**options) ⇒ Object
The external commands runner.
- #config ⇒ Object
-
#cursor ⇒ Object
The cursor movement.
-
#editor ⇒ Object
Open a file or text in the user’s preferred editor.
-
#exec_exist?(*args) ⇒ Boolean
Check if executable exists.
-
#execute ⇒ Object
Execute this command.
-
#generator ⇒ Object
File manipulation utility methods.
-
#initialize(options = {}) {|_self| ... } ⇒ Command
constructor
A new instance of Command.
- #menu_back(menu, back: back) ⇒ Object
-
#pager(**options) ⇒ Object
Terminal output paging.
- #pastel(opts = {}) ⇒ Object
-
#platform ⇒ Object
Terminal platform and OS properties.
-
#prompt(**options) ⇒ Object
The interactive prompt.
- #render_table(table) ⇒ Object
-
#screen ⇒ Object
Get terminal screen properties.
- #verbose? ⇒ Boolean
-
#which(*args) ⇒ Object
The unix which utility.
Constructor Details
#initialize(options = {}) {|_self| ... } ⇒ Command
Returns a new instance of Command.
16 17 18 19 |
# File 'lib/gitloggl/command.rb', line 16 def initialize( = {}) @options = yield(self) if block_given? end |
Instance Attribute Details
#back ⇒ Object
callable back action
14 15 16 |
# File 'lib/gitloggl/command.rb', line 14 def back @back end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
11 12 13 |
# File 'lib/gitloggl/command.rb', line 11 def @options end |
Instance Method Details
#back? ⇒ Boolean
22 23 24 |
# File 'lib/gitloggl/command.rb', line 22 def back? @back.respond_to?(:call) end |
#capture_back ⇒ Object
26 27 28 |
# File 'lib/gitloggl/command.rb', line 26 def capture_back -> { self.class.new().execute } end |
#command(**options) ⇒ Object
The external commands runner
56 57 58 59 |
# File 'lib/gitloggl/command.rb', line 56 def command(**) require 'tty-command' TTY::Command.new() end |
#config ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/gitloggl/command.rb', line 159 def config @config ||= begin require 'tty-config' TTY::Config.new do |c| c.filename = '.gitloggl' c.extname = '.yml' c.prepend_path(Dir.home) c.read if c.exist? end end end |
#cursor ⇒ Object
The cursor movement
66 67 68 69 |
# File 'lib/gitloggl/command.rb', line 66 def cursor require 'tty-cursor' TTY::Cursor end |
#editor ⇒ Object
Open a file or text in the user’s preferred editor
76 77 78 79 |
# File 'lib/gitloggl/command.rb', line 76 def editor require 'tty-editor' TTY::Editor end |
#exec_exist?(*args) ⇒ Boolean
Check if executable exists
146 147 148 149 |
# File 'lib/gitloggl/command.rb', line 146 def exec_exist?(*args) require 'tty-which' TTY::Which.exist?(*args) end |
#execute ⇒ Object
Execute this command
44 45 46 47 48 49 |
# File 'lib/gitloggl/command.rb', line 44 def execute(*) raise( NotImplementedError, "#{self.class}##{__method__} must be implemented" ) end |
#generator ⇒ Object
File manipulation utility methods
86 87 88 89 |
# File 'lib/gitloggl/command.rb', line 86 def generator require 'tty-file' TTY::File end |
#menu_back(menu, back: back) ⇒ Object
30 31 32 33 34 |
# File 'lib/gitloggl/command.rb', line 30 def (, back: back) return unless back? .choice 'Back', back end |
#pager(**options) ⇒ Object
Terminal output paging
96 97 98 99 |
# File 'lib/gitloggl/command.rb', line 96 def pager(**) require 'tty-pager' TTY::Pager.new() end |
#pastel(opts = {}) ⇒ Object
155 156 157 |
# File 'lib/gitloggl/command.rb', line 155 def pastel(opts = {}) Pastel.new(opts) end |
#platform ⇒ Object
Terminal platform and OS properties
106 107 108 109 |
# File 'lib/gitloggl/command.rb', line 106 def platform require 'tty-platform' TTY::Platform.new end |
#prompt(**options) ⇒ Object
The interactive prompt
116 117 118 119 |
# File 'lib/gitloggl/command.rb', line 116 def prompt(**) require 'tty-prompt' TTY::Prompt.new() end |
#render_table(table) ⇒ Object
151 152 153 |
# File 'lib/gitloggl/command.rb', line 151 def render_table(table) table.render :unicode, padding: 1 end |
#screen ⇒ Object
Get terminal screen properties
126 127 128 129 |
# File 'lib/gitloggl/command.rb', line 126 def screen require 'tty-screen' TTY::Screen end |
#verbose? ⇒ Boolean
37 38 39 |
# File 'lib/gitloggl/command.rb', line 37 def verbose? ['verbose'] end |
#which(*args) ⇒ Object
The unix which utility
136 137 138 139 |
# File 'lib/gitloggl/command.rb', line 136 def which(*args) require 'tty-which' TTY::Which.which(*args) end |