Class: Gitloggl::Command

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/gitloggl/command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) {|_self| ... } ⇒ Command

Returns a new instance of Command.

Yields:

  • (_self)

Yield Parameters:



16
17
18
19
# File 'lib/gitloggl/command.rb', line 16

def initialize(options = {})
  @options = options
  yield(self) if block_given?
end

Instance Attribute Details

#backObject

callable back action



14
15
16
# File 'lib/gitloggl/command.rb', line 14

def back
  @back
end

#optionsObject (readonly)

Returns the value of attribute options.



11
12
13
# File 'lib/gitloggl/command.rb', line 11

def options
  @options
end

Instance Method Details

#back?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/gitloggl/command.rb', line 22

def back?
  @back.respond_to?(:call)
end

#capture_backObject



26
27
28
# File 'lib/gitloggl/command.rb', line 26

def capture_back
  -> { self.class.new(options).execute }
end

#command(**options) ⇒ Object

The external commands runner



56
57
58
59
# File 'lib/gitloggl/command.rb', line 56

def command(**options)
  require 'tty-command'
  TTY::Command.new(options)
end

#configObject



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

#cursorObject

The cursor movement



66
67
68
69
# File 'lib/gitloggl/command.rb', line 66

def cursor
  require 'tty-cursor'
  TTY::Cursor
end

#editorObject

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

Returns:

  • (Boolean)

See Also:



146
147
148
149
# File 'lib/gitloggl/command.rb', line 146

def exec_exist?(*args)
  require 'tty-which'
  TTY::Which.exist?(*args)
end

#executeObject

Execute this command

Raises:

  • (NotImplementedError)


44
45
46
47
48
49
# File 'lib/gitloggl/command.rb', line 44

def execute(*)
  raise(
    NotImplementedError,
    "#{self.class}##{__method__} must be implemented"
  )
end

#generatorObject

File manipulation utility methods



86
87
88
89
# File 'lib/gitloggl/command.rb', line 86

def generator
  require 'tty-file'
  TTY::File
end


30
31
32
33
34
# File 'lib/gitloggl/command.rb', line 30

def menu_back(menu, back: back)
  return unless back?

  menu.choice 'Back', back
end

#pager(**options) ⇒ Object

Terminal output paging



96
97
98
99
# File 'lib/gitloggl/command.rb', line 96

def pager(**options)
  require 'tty-pager'
  TTY::Pager.new(options)
end

#pastel(opts = {}) ⇒ Object



155
156
157
# File 'lib/gitloggl/command.rb', line 155

def pastel(opts = {})
  Pastel.new(opts)
end

#platformObject

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(**options)
  require 'tty-prompt'
  TTY::Prompt.new(options)
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

#screenObject

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

Returns:

  • (Boolean)


37
38
39
# File 'lib/gitloggl/command.rb', line 37

def verbose?
  options['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