mirror of
https://github.com/jimeh/dotfiles.git
synced 2026-02-19 13:46:41 +00:00
chore(xbar/brew-services): update Xbar::Printer class
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
# <xbar.title>Brew Services</xbar.title>
|
# <xbar.title>Brew Services</xbar.title>
|
||||||
# <xbar.version>v3.2.2</xbar.version>
|
# <xbar.version>v3.2.3</xbar.version>
|
||||||
# <xbar.author>Jim Myhrberg</xbar.author>
|
# <xbar.author>Jim Myhrberg</xbar.author>
|
||||||
# <xbar.author.github>jimeh</xbar.author.github>
|
# <xbar.author.github>jimeh</xbar.author.github>
|
||||||
# <xbar.desc>List and manage Homebrew Services</xbar.desc>
|
# <xbar.desc>List and manage Homebrew Services</xbar.desc>
|
||||||
@@ -174,9 +174,22 @@ module Xbar
|
|||||||
end
|
end
|
||||||
|
|
||||||
def item(label = nil, **props)
|
def item(label = nil, **props)
|
||||||
print_item(label, **props) if !label.nil? && !label.empty?
|
return if label.nil? || label.empty?
|
||||||
|
|
||||||
yield(sub_printer) if block_given?
|
props = normalize_props(props.dup)
|
||||||
|
alt = props.delete(:alt)
|
||||||
|
nested_items = props.delete(:nested) || :both
|
||||||
|
|
||||||
|
yield_main = block_given? && [:main, :both].include?(nested_items)
|
||||||
|
yield_alt = block_given? && [:alt, :both].include?(nested_items)
|
||||||
|
|
||||||
|
print_item(label, **props)
|
||||||
|
yield(sub_printer) if yield_main
|
||||||
|
|
||||||
|
return if alt.nil? || alt.strip.empty?
|
||||||
|
|
||||||
|
print_item(alt, **props.merge(alternate: true))
|
||||||
|
yield(sub_printer) if yield_alt
|
||||||
end
|
end
|
||||||
|
|
||||||
def separator
|
def separator
|
||||||
@@ -187,22 +200,14 @@ module Xbar
|
|||||||
private
|
private
|
||||||
|
|
||||||
def print_item(text, **props)
|
def print_item(text, **props)
|
||||||
props = props.dup
|
|
||||||
alt = props.delete(:alt)
|
|
||||||
|
|
||||||
output = [text]
|
output = [text]
|
||||||
unless props.empty?
|
unless props.empty?
|
||||||
props = normalize_props(props)
|
|
||||||
output << PARAM_SEP
|
output << PARAM_SEP
|
||||||
output += props.map { |k, v| "#{k}=\"#{v}\"" }
|
output += props.map { |k, v| "#{k}=\"#{v}\"" }
|
||||||
end
|
end
|
||||||
|
|
||||||
$stdout.print(SUB_STR * nested_level, output.join(' '))
|
$stdout.print(SUB_STR * nested_level, output.join(' '))
|
||||||
$stdout.puts
|
$stdout.puts
|
||||||
|
|
||||||
return if alt.nil? || alt.empty?
|
|
||||||
|
|
||||||
print_item(alt, **props.merge(alternate: true))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def plugin_refresh_uri
|
def plugin_refresh_uri
|
||||||
@@ -262,6 +267,11 @@ module Xbar
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
|
||||||
|
# Brew module contains classes for managing Homebrew services.
|
||||||
module Brew
|
module Brew
|
||||||
class Common
|
class Common
|
||||||
include Xbar::Service
|
include Xbar::Service
|
||||||
|
|||||||
Reference in New Issue
Block a user