Custom vertical bar glyphs (#738)
* refactor make_vertical_bar refactor to use make_glyph under the hood (de-duping code) * Allow pulseaudio module to accept custom vertical bar arrays also added config example
This commit is contained in:
parent
2016addf81
commit
af6d98cb8e
@ -500,24 +500,19 @@ def make_graph(values, lower_limit=0.0, upper_limit=100.0, style="blocks"):
|
|||||||
return graph
|
return graph
|
||||||
|
|
||||||
|
|
||||||
def make_vertical_bar(percentage, width=1):
|
def make_vertical_bar(percentage, width=1, glyphs=None):
|
||||||
"""
|
"""
|
||||||
Draws a vertical bar made of unicode characters.
|
Draws a vertical bar made of unicode characters.
|
||||||
|
|
||||||
:param value: A value between 0 and 100
|
:param percentage: A value between 0 and 100
|
||||||
:param width: How many characters wide the bar should be.
|
:param width: How many characters wide the bar should be.
|
||||||
:returns: Bar as a String
|
:returns: Bar as a String
|
||||||
"""
|
"""
|
||||||
bar = ' _▁▂▃▄▅▆▇█'
|
if glyphs is not None:
|
||||||
percentage //= 10
|
bar = make_glyph(percentage, lower_bound=0, upper_bound=100, glyphs=glyphs)
|
||||||
percentage = int(percentage)
|
|
||||||
if percentage < 0:
|
|
||||||
output = bar[0]
|
|
||||||
elif percentage >= len(bar):
|
|
||||||
output = bar[-1]
|
|
||||||
else:
|
else:
|
||||||
output = bar[percentage]
|
bar = make_glyph(percentage, lower_bound=0, upper_bound=100)
|
||||||
return output * width
|
return bar * width
|
||||||
|
|
||||||
|
|
||||||
def make_bar(percentage):
|
def make_bar(percentage):
|
||||||
@ -532,13 +527,13 @@ def make_bar(percentage):
|
|||||||
tens = int(percentage / 10)
|
tens = int(percentage / 10)
|
||||||
ones = int(percentage) - tens * 10
|
ones = int(percentage) - tens * 10
|
||||||
result = tens * '█'
|
result = tens * '█'
|
||||||
if(ones >= 1):
|
if ones >= 1:
|
||||||
result = result + bars[ones]
|
result = result + bars[ones]
|
||||||
result = result + (10 - len(result)) * ' '
|
result = result + (10 - len(result)) * ' '
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def make_glyph(number, glyphs="▁▂▃▄▅▆▇█", lower_bound=0, upper_bound=100, enable_boundary_glyphs=False):
|
def make_glyph(number, glyphs=" _▁▂▃▄▅▆▇█", lower_bound=0, upper_bound=100, enable_boundary_glyphs=False):
|
||||||
"""
|
"""
|
||||||
Returns a single glyph from the list of glyphs provided relative to where
|
Returns a single glyph from the list of glyphs provided relative to where
|
||||||
the number is in the range (by default a percentage value is expected).
|
the number is in the range (by default a percentage value is expected).
|
||||||
|
@ -15,6 +15,22 @@ class PulseAudio(Module, ColorRangeModule):
|
|||||||
- Requires amixer for toggling mute and incrementing/decrementing volume on scroll.
|
- Requires amixer for toggling mute and incrementing/decrementing volume on scroll.
|
||||||
- Depends on the PyPI colour module - https://pypi.python.org/pypi/colour/0.0.5
|
- Depends on the PyPI colour module - https://pypi.python.org/pypi/colour/0.0.5
|
||||||
|
|
||||||
|
.. rubric:: Example configuration
|
||||||
|
|
||||||
|
The example configuration below uses only unicode to display the volume (tested with otf-font-awesome)
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
status.register(
|
||||||
|
"pulseaudio",
|
||||||
|
color_unmuted='#aa3300,
|
||||||
|
color_muted='#aa0500',
|
||||||
|
format_muted='\uf6a9',
|
||||||
|
format='{volume_bar}',
|
||||||
|
vertical_bar_width=1,
|
||||||
|
vertical_bar_glyphs=['\uf026 ', '\uf027 ', '\uf028']
|
||||||
|
)
|
||||||
|
|
||||||
.. rubric:: Available formatters
|
.. rubric:: Available formatters
|
||||||
|
|
||||||
* `{volume}` — volume in percent (0...100)
|
* `{volume}` — volume in percent (0...100)
|
||||||
@ -37,7 +53,8 @@ class PulseAudio(Module, ColorRangeModule):
|
|||||||
("bar_type", "type of volume bar. Allowed values are 'vertical' or 'horizontal'"),
|
("bar_type", "type of volume bar. Allowed values are 'vertical' or 'horizontal'"),
|
||||||
("multi_colors", "whether or not to change the color from "
|
("multi_colors", "whether or not to change the color from "
|
||||||
"'color_muted' to 'color_unmuted' based on volume percentage"),
|
"'color_muted' to 'color_unmuted' based on volume percentage"),
|
||||||
("vertical_bar_width", "how many characters wide the vertical volume_bar should be")
|
("vertical_bar_width", "how many characters wide the vertical volume_bar should be"),
|
||||||
|
('vertical_bar_glyphs', 'custom array output as vertical bar instead of unicode bars')
|
||||||
)
|
)
|
||||||
|
|
||||||
muted = "M"
|
muted = "M"
|
||||||
@ -49,6 +66,7 @@ class PulseAudio(Module, ColorRangeModule):
|
|||||||
has_amixer = False
|
has_amixer = False
|
||||||
color_muted = "#FF0000"
|
color_muted = "#FF0000"
|
||||||
color_unmuted = "#FFFFFF"
|
color_unmuted = "#FFFFFF"
|
||||||
|
vertical_bar_glyphs = None
|
||||||
|
|
||||||
sink = None
|
sink = None
|
||||||
move_sink_inputs = True
|
move_sink_inputs = True
|
||||||
@ -173,7 +191,7 @@ class PulseAudio(Module, ColorRangeModule):
|
|||||||
output_format = self.format
|
output_format = self.format
|
||||||
|
|
||||||
if self.bar_type == 'vertical':
|
if self.bar_type == 'vertical':
|
||||||
volume_bar = make_vertical_bar(volume_percent, self.vertical_bar_width)
|
volume_bar = make_vertical_bar(volume_percent, self.vertical_bar_width, glyphs=self.vertical_bar_glyphs)
|
||||||
elif self.bar_type == 'horizontal':
|
elif self.bar_type == 'horizontal':
|
||||||
volume_bar = make_bar(volume_percent)
|
volume_bar = make_bar(volume_percent)
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user