chore(xbar/brew-services): update Xbar::Printer class

This commit is contained in:
2025-09-22 09:33:38 +01:00
parent 509b2e89e6
commit 83c7fb10a2

View File

@@ -2,7 +2,7 @@
# frozen_string_literal: true
# <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.github>jimeh</xbar.author.github>
# <xbar.desc>List and manage Homebrew Services</xbar.desc>
@@ -174,9 +174,22 @@ module Xbar
end
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
def separator
@@ -187,22 +200,14 @@ module Xbar
private
def print_item(text, **props)
props = props.dup
alt = props.delete(:alt)
output = [text]
unless props.empty?
props = normalize_props(props)
output << PARAM_SEP
output += props.map { |k, v| "#{k}=\"#{v}\"" }
end
$stdout.print(SUB_STR * nested_level, output.join(' '))
$stdout.puts
return if alt.nil? || alt.empty?
print_item(alt, **props.merge(alternate: true))
end
def plugin_refresh_uri
@@ -262,6 +267,11 @@ module Xbar
end
end
#
# ------------------------------------------------------------------------------
#
# Brew module contains classes for managing Homebrew services.
module Brew
class Common
include Xbar::Service