Class: FFmpegProgress::Theme
- Inherits:
-
Object
- Object
- FFmpegProgress::Theme
- 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
-
#bars ⇒ Integer
The length of the progress bar.
-
#block_fg ⇒ Integer
The color of the optional block return value.
-
#cancel_fg ⇒ Integer
The color of the time position info on an interrupted task.
-
#empty_chr ⇒ String
The string to be used to draw the remaining part of the bar.
-
#empty_fg ⇒ Integer
The color of the remaining part of the bar.
-
#end_fg ⇒ Integer
The color of the beginning and end of a section.
-
#finish_fg ⇒ Integer
The color of the time position info on a completed task.
-
#full_chr ⇒ String
The string to be used to draw the filled part of the bar.
-
#full_fg ⇒ Integer
The color of the filled part of the bar.
-
#head_chr ⇒ String
The string to be used as the start of a section.
-
#tail_chr ⇒ String
The string to be used as the end of a section.
-
#time_fg ⇒ Integer
The color of the current time position info.
Class Method Summary collapse
-
.from(object) ⇒ Theme
Generates a new instance of Theme.
Instance Method Summary collapse
-
#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.
-
#initialize(theme_hash = DEFAULT_THEME) ⇒ Theme
constructor
Generates a new instance of Theme from a theme hash.
Constructor Details
#initialize(theme_hash = DEFAULT_THEME) ⇒ Theme
Generates a new instance of Theme from a theme hash.
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
#bars ⇒ Integer
The length of the progress bar.
15 16 17 |
# File 'lib/ffmpeg_progress/theme.rb', line 15 def @bars end |
#block_fg ⇒ Integer
The color of the optional block return value.
60 61 62 |
# File 'lib/ffmpeg_progress/theme.rb', line 60 def block_fg @block_fg end |
#cancel_fg ⇒ Integer
The color of the time position info on an interrupted task.
70 71 72 |
# File 'lib/ffmpeg_progress/theme.rb', line 70 def cancel_fg @cancel_fg end |
#empty_chr ⇒ String
The string to be used to draw the remaining part of the bar.
30 31 32 |
# File 'lib/ffmpeg_progress/theme.rb', line 30 def empty_chr @empty_chr end |
#empty_fg ⇒ Integer
The color of the remaining part of the bar.
50 51 52 |
# File 'lib/ffmpeg_progress/theme.rb', line 50 def empty_fg @empty_fg end |
#end_fg ⇒ Integer
The color of the beginning and end of a section.
40 41 42 |
# File 'lib/ffmpeg_progress/theme.rb', line 40 def end_fg @end_fg end |
#finish_fg ⇒ Integer
The color of the time position info on a completed task.
65 66 67 |
# File 'lib/ffmpeg_progress/theme.rb', line 65 def finish_fg @finish_fg end |
#full_chr ⇒ String
The string to be used to draw the filled part of the bar.
25 26 27 |
# File 'lib/ffmpeg_progress/theme.rb', line 25 def full_chr @full_chr end |
#full_fg ⇒ Integer
The color of the filled part of the bar.
45 46 47 |
# File 'lib/ffmpeg_progress/theme.rb', line 45 def full_fg @full_fg end |
#head_chr ⇒ String
The string to be used as the start of a section.
20 21 22 |
# File 'lib/ffmpeg_progress/theme.rb', line 20 def head_chr @head_chr end |
#tail_chr ⇒ String
The string to be used as the end of a section.
35 36 37 |
# File 'lib/ffmpeg_progress/theme.rb', line 35 def tail_chr @tail_chr end |
#time_fg ⇒ Integer
The color of the current time position info.
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.
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.
104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/ffmpeg_progress/theme.rb', line 104 def (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 |