Class: Notiffany::Notifier::Tmux::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/notiffany/notifier/tmux/client.rb

Overview

Class for actually calling TMux to run commands

Constant Summary collapse

CLIENT =
"tmux".freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Client

Returns a new instance of Client.



28
29
30
# File 'lib/notiffany/notifier/tmux/client.rb', line 28

def initialize(client)
  @client = client
end

Class Method Details

._capture(*args) ⇒ Object



19
20
21
# File 'lib/notiffany/notifier/tmux/client.rb', line 19

def _capture(*args)
  Shellany::Sheller.stdout(([CLIENT] + args).join(" "))
end

._run(*args) ⇒ Object



23
24
25
# File 'lib/notiffany/notifier/tmux/client.rb', line 23

def _run(*args)
  Shellany::Sheller.run(([CLIENT] + args).join(" "))
end

.versionObject



11
12
13
14
15
16
17
# 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

Instance Method Details

#clientsObject



32
33
34
35
36
37
38
39
40
# 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) ⇒ Object



49
50
51
52
53
54
55
# 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) ⇒ Object



76
77
78
# File 'lib/notiffany/notifier/tmux/client.rb', line 76

def display_time=(time)
  set("display-time", time)
end

#message_bg=(color) ⇒ Object



72
73
74
# File 'lib/notiffany/notifier/tmux/client.rb', line 72

def message_bg=(color)
  set("message-bg", color)
end

#message_fg=(color) ⇒ Object



68
69
70
# File 'lib/notiffany/notifier/tmux/client.rb', line 68

def message_fg=(color)
  set("message-fg", color)
end

#parse_optionsObject



63
64
65
66
# 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) ⇒ Object



42
43
44
45
46
47
# 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) ⇒ Object



80
81
82
83
# File 'lib/notiffany/notifier/tmux/client.rb', line 80

def title=(string)
  # TODO: properly escape?
  set("set-titles-string", "'#{string}'")
end

#unset(key, value) ⇒ Object



57
58
59
60
61
# 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