Class: FFmpegProgress::Theme

Inherits:
Object
  • Object
show all
Defined in:
lib/ffmpeg_progress/theme.rb

Overview

This is the class that handles progress bar themes and converting them into visual elements. FFmpegProgress expects a 256-color capable terminal.

Constant Summary collapse

DEFAULT_THEME =

The default theme.

{
  bars: 63, head_chr: '[', full_chr: '=', empty_chr: '-', tail_chr: ']',
  end_fg: 202, full_fg: 214, empty_fg: 202,
  time_fg: 214, block_fg: 214, finish_fg: 40, cancel_fg: 1
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(theme_hash = DEFAULT_THEME) ⇒ Theme

Generates a new instance of Theme from a theme hash.

Parameters:

  • theme_hash (Hash) (defaults to: DEFAULT_THEME)


87
88
89
90
91
# File 'lib/ffmpeg_progress/theme.rb', line 87

def initialize(theme_hash = DEFAULT_THEME)
  DEFAULT_THEME.merge(theme_hash).each_pair do |key, value|
    method("#{key}=").call(value) if DEFAULT_THEME.key? key
  end
end

Instance Attribute Details

#barsInteger

The length of the progress bar.

Returns:

  • (Integer)


15
16
17
# File 'lib/ffmpeg_progress/theme.rb', line 15

def bars
  @bars
end

#block_fgInteger

The color of the optional block return value.

Returns:

  • (Integer)


60
61
62
# File 'lib/ffmpeg_progress/theme.rb', line 60

def block_fg
  @block_fg
end

#cancel_fgInteger

The color of the time position info on an interrupted task.

Returns:

  • (Integer)


70
71
72
# File 'lib/ffmpeg_progress/theme.rb', line 70

def cancel_fg
  @cancel_fg
end

#empty_chrString

The string to be used to draw the remaining part of the bar.

Returns:

  • (String)


30
31
32
# File 'lib/ffmpeg_progress/theme.rb', line 30

def empty_chr
  @empty_chr
end

#empty_fgInteger

The color of the remaining part of the bar.

Returns:

  • (Integer)


50
51
52
# File 'lib/ffmpeg_progress/theme.rb', line 50

def empty_fg
  @empty_fg
end

#end_fgInteger

The color of the beginning and end of a section.

Returns:

  • (Integer)


40
41
42
# File 'lib/ffmpeg_progress/theme.rb', line 40

def end_fg
  @end_fg
end

#finish_fgInteger

The color of the time position info on a completed task.

Returns:

  • (Integer)


65
66
67
# File 'lib/ffmpeg_progress/theme.rb', line 65

def finish_fg
  @finish_fg
end

#full_chrString

The string to be used to draw the filled part of the bar.

Returns:

  • (String)


25
26
27
# File 'lib/ffmpeg_progress/theme.rb', line 25

def full_chr
  @full_chr
end

#full_fgInteger

The color of the filled part of the bar.

Returns:

  • (Integer)


45
46
47
# File 'lib/ffmpeg_progress/theme.rb', line 45

def full_fg
  @full_fg
end

#head_chrString

The string to be used as the start of a section.

Returns:

  • (String)


20
21
22
# File 'lib/ffmpeg_progress/theme.rb', line 20

def head_chr
  @head_chr
end

#tail_chrString

The string to be used as the end of a section.

Returns:

  • (String)


35
36
37
# File 'lib/ffmpeg_progress/theme.rb', line 35

def tail_chr
  @tail_chr
end

#time_fgInteger

The color of the current time position info.

Returns:

  • (Integer)


55
56
57
# File 'lib/ffmpeg_progress/theme.rb', line 55

def time_fg
  @time_fg
end

Class Method Details

.from(object) ⇒ Theme

Generates a new instance of Theme. Returns the argument if the argument is a Theme.

Parameters:

Returns:



77
78
79
80
81
# File 'lib/ffmpeg_progress/theme.rb', line 77

def self.from(object)
  return object if object.is_a? Theme
  return new(object) if object.is_a? Hash
  fail 'Argument must be either Theme or Hash.'
end

Instance Method Details

#bar(position, time_string = '00:00:00.00', option_hash = {}) ⇒ String

Returns a progress bar given a fractional position, a time string, and an optional block output string.

Parameters:

  • position (Float)
  • time_string (String) (defaults to: '00:00:00.00')
  • option_hash (Hash) (defaults to: {})

Options Hash (option_hash):

  • :block_output (String)

    the output from the optional block passed to FFmpeg#run, if any.

  • :interrupted (Boolean)

    has the task been canceled?

  • :finished (Boolean)

    has the task finished?

Returns:

  • (String)


104
105
106
107
108
109
110
111
112
113
114
# File 'lib/ffmpeg_progress/theme.rb', line 104

def bar(position, time_string = '00:00:00.00', option_hash = {})
  output = "#{head}#{full(position)}#{empty(position)}#{tail}" \
    "#{head}#{time(time_string, option_hash)}#{tail}"

  if option_hash.fetch :block_output, false
    output << "#{head}#{colorize(option_hash[:block_output], @block_fg)}" \
      "#{tail}"
  end

  output
end