class Notiffany::Notifier::Tmux::Client
Class for actually calling TMux to run commands
Constants
- CLIENT
Public Class Methods
_capture(*args)
click to toggle source
# File lib/notiffany/notifier/tmux/client.rb, line 19 def _capture(*args) Shellany::Sheller.stdout(([CLIENT] + args).join(" ")) end
_run(*args)
click to toggle source
# File lib/notiffany/notifier/tmux/client.rb, line 23 def _run(*args) Shellany::Sheller.run(([CLIENT] + args).join(" ")) end
new(client)
click to toggle source
# File lib/notiffany/notifier/tmux/client.rb, line 28 def initialize(client) @client = client end
version()
click to toggle source
# File lib/notiffany/notifier/tmux/client.rb, line 11 def version begin Float(_capture("-V")[/\d+\.\d+/]) rescue NoMethodError, TypeError raise Base::UnavailableError, "Could not find tmux" end end
Public Instance Methods
clients()
click to toggle source
# File lib/notiffany/notifier/tmux/client.rb, line 32 def clients return [@client] unless @client == :all ttys = _capture("list-clients", "-F", "'\#{client_tty}'") ttys = ttys.split(/\n/) # if user is running 'tmux -C' remove this client from list ttys.delete("(null)") ttys end
display_message(message)
click to toggle source
# File lib/notiffany/notifier/tmux/client.rb, line 49 def display_message(message) clients.each do |client| args = ["-c", client.strip] if client # TODO: should properly escape message here _run("display", *args, "'#{message}'") end end
display_time=(time)
click to toggle source
# File lib/notiffany/notifier/tmux/client.rb, line 76 def display_time=(time) set("display-time", time) end
message_bg=(color)
click to toggle source
# File lib/notiffany/notifier/tmux/client.rb, line 72 def message_bg=(color) set("message-bg", color) end
message_fg=(color)
click to toggle source
# File lib/notiffany/notifier/tmux/client.rb, line 68 def message_fg=(color) set("message-fg", color) end
parse_options()
click to toggle source
# File lib/notiffany/notifier/tmux/client.rb, line 63 def parse_options output = _capture("show", "-t", @client) Hash[output.lines.map { |line| _parse_option(line) }] end
set(key, value)
click to toggle source
# File lib/notiffany/notifier/tmux/client.rb, line 42 def set(key, value) clients.each do |client| args = client ? ["-t", client.strip] : nil _run("set", "-q", *args, key, value) end end
title=(string)
click to toggle source
# File lib/notiffany/notifier/tmux/client.rb, line 80 def title=(string) # TODO: properly escape? set("set-titles-string", "'#{string}'") end
unset(key, value)
click to toggle source
# File lib/notiffany/notifier/tmux/client.rb, line 57 def unset(key, value) clients.each do |client| _run(*_all_args_for(key, value, client)) end end
Private Instance Methods
_all_args_for(key, value, client)
click to toggle source
# File lib/notiffany/notifier/tmux/client.rb, line 99 def _all_args_for(key, value, client) unset = value ? [] : %w(-u) args = client ? ["-t", client.strip] : [] ["set", "-q", *unset, *args, key, *[value].compact] end
_capture(*args)
click to toggle source
# File lib/notiffany/notifier/tmux/client.rb, line 91 def _capture(*args) self.class._capture(*args) end
_parse_option(line)
click to toggle source
# File lib/notiffany/notifier/tmux/client.rb, line 95 def _parse_option(line) line.partition(" ").map(&:strip).reject(&:empty?) end
_run(*args)
click to toggle source
# File lib/notiffany/notifier/tmux/client.rb, line 87 def _run(*args) self.class._run(*args) end