tmux-ruby 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/.yardopts +1 -0
  2. data/LICENSE +22 -0
  3. data/README.md +23 -0
  4. data/lib/tmux.rb +56 -0
  5. data/lib/tmux/buffer.rb +131 -0
  6. data/lib/tmux/client.rb +193 -0
  7. data/lib/tmux/exception.rb +5 -0
  8. data/lib/tmux/exception/basic_exception.rb +6 -0
  9. data/lib/tmux/exception/in_tmux.rb +9 -0
  10. data/lib/tmux/exception/index_in_use.rb +9 -0
  11. data/lib/tmux/exception/unknown_command.rb +9 -0
  12. data/lib/tmux/exception/unsupported_version.rb +15 -0
  13. data/lib/tmux/filterable_hash.rb +15 -0
  14. data/lib/tmux/options.rb +109 -0
  15. data/lib/tmux/options/attr_option.rb +10 -0
  16. data/lib/tmux/options/bell_action_option.rb +19 -0
  17. data/lib/tmux/options/boolean_option.rb +26 -0
  18. data/lib/tmux/options/char_array_option.rb +26 -0
  19. data/lib/tmux/options/clock_mode_style_option.rb +27 -0
  20. data/lib/tmux/options/color_option.rb +23 -0
  21. data/lib/tmux/options/justification_option.rb +19 -0
  22. data/lib/tmux/options/keymap_option.rb +19 -0
  23. data/lib/tmux/options/number_option.rb +26 -0
  24. data/lib/tmux/options/option.rb +38 -0
  25. data/lib/tmux/options/string_option.rb +26 -0
  26. data/lib/tmux/options/symbol_option.rb +26 -0
  27. data/lib/tmux/options/word_array_option.rb +26 -0
  28. data/lib/tmux/options_list.rb +150 -0
  29. data/lib/tmux/pane.rb +496 -0
  30. data/lib/tmux/server.rb +217 -0
  31. data/lib/tmux/session.rb +312 -0
  32. data/lib/tmux/status_bar.rb +134 -0
  33. data/lib/tmux/status_bar/field.rb +129 -0
  34. data/lib/tmux/version.rb +4 -0
  35. data/lib/tmux/widget.rb +35 -0
  36. data/lib/tmux/widgets/progress_bar.rb +107 -0
  37. data/lib/tmux/window.rb +697 -0
  38. data/lib/tmux/window/status.rb +21 -0
  39. data/lib/tmux/window/status/state.rb +87 -0
  40. metadata +96 -0
@@ -0,0 +1,9 @@
1
+ module Tmux
2
+ module Exception
3
+ class IndexInUse < RuntimeError
4
+ def initialize(args)
5
+ super "Index '%s' in session '%s' in use" % [args.last, args.first.identifier]
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Tmux
2
+ module Exception
3
+ class UnknownCommand < RuntimeError
4
+ def initialize(command)
5
+ super("unknown command: #{command}")
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,15 @@
1
+ module Tmux
2
+ module Exception
3
+ # Raised if a version requirement isn't met
4
+ class UnsupportedVersion < BasicException
5
+ # @param [String] version The required version
6
+ def initialize(version = nil)
7
+ if message
8
+ version = "Required tmux version: #{version}"
9
+ end
10
+
11
+ super
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module Tmux
2
+ # @api private
3
+ module FilterableHash
4
+ # @param [Hash] search
5
+ # @return [Hash]
6
+ # @api private
7
+ def filter(search)
8
+ self.select { |key, value|
9
+ value.all? { |v_key, v_value|
10
+ !search.has_key?(v_key) || v_value == search[v_key]
11
+ }
12
+ }
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,109 @@
1
+ module Tmux
2
+
3
+ module Options
4
+ require "tmux/options/option"
5
+ require "tmux/options/number_option"
6
+ require "tmux/options/string_option"
7
+ require "tmux/options/boolean_option"
8
+ require "tmux/options/word_array_option"
9
+ require "tmux/options/char_array_option"
10
+ require "tmux/options/symbol_option"
11
+ require "tmux/options/bell_action_option"
12
+ require "tmux/options/color_option"
13
+ require "tmux/options/attr_option"
14
+ require "tmux/options/keymap_option"
15
+ require "tmux/options/justification_option"
16
+ require "tmux/options/clock_mode_style_option"
17
+
18
+ # Table with option names and their appropriate typecasts.
19
+ Mapping = {
20
+ "base-index" => NumberOption,
21
+ "bell-action" => BellActionOption,
22
+ "buffer-limit" => NumberOption,
23
+ "default-command" => StringOption,
24
+ "default-path" => StringOption,
25
+ "default-shell" => StringOption,
26
+ "default-terminal" => StringOption,
27
+ "detach-on-destroy" => BooleanOption,
28
+ "display-panes-colour" => ColorOption,
29
+ "display-panes-active-colour" => ColorOption,
30
+ "display-panes-time" => NumberOption,
31
+ "display-time" => NumberOption,
32
+ "history-limit" => NumberOption,
33
+ "lock-after-time" => NumberOption,
34
+ "lock-command" => StringOption,
35
+ "lock-server" => BooleanOption,
36
+ "message-attr" => AttrOption,
37
+ "message-bg" => ColorOption,
38
+ "message-fg" => ColorOption,
39
+ "message-limit" => NumberOption,
40
+ "mouse-select-pane" => BooleanOption,
41
+ "pane-active-border-bg" => ColorOption,
42
+ "pane-active-border-fg" => ColorOption,
43
+ "pane-border-bg" => ColorOption,
44
+ "pane-border-fg" => ColorOption,
45
+ "prefix" => SymbolOption, # C-b # TODO keycombo
46
+ "repeat-time" => NumberOption,
47
+ "set-remain-on-exit" => BooleanOption,
48
+ "set-titles" => BooleanOption,
49
+ "set-titles-string" => StringOption,
50
+ "status" => BooleanOption,
51
+ "status-attr" => AttrOption,
52
+ "status-bg" => ColorOption,
53
+ "status-fg" => ColorOption,
54
+ "status-interval" => NumberOption,
55
+ "status-justify" => JustificationOption,
56
+ "status-keys" => KeymapOption,
57
+ "status-left" => StringOption,
58
+ "status-left-attr" => AttrOption,
59
+ "status-left-bg" => ColorOption,
60
+ "status-left-fg" => ColorOption,
61
+ "status-left-length" => NumberOption,
62
+ "status-right" => StringOption,
63
+ "status-right-attr" => AttrOption,
64
+ "status-right-bg" => ColorOption,
65
+ "status-right-fg" => ColorOption,
66
+ "status-right-length" => NumberOption,
67
+ "status-utf8" => BooleanOption,
68
+ "terminal-overrides" => StringOption, #TODO "*88col*:colors=88,*256col*:colors=256"
69
+ "update-environment" => WordArrayOption,
70
+ "visual-activity" => BooleanOption,
71
+ "visual-bell" => BooleanOption,
72
+ "visual-content" => BooleanOption,
73
+ "escape-time" => NumberOption,
74
+ "quiet" => BooleanOption,
75
+ "aggressive-resize" => BooleanOption,
76
+ "alternate-screen" => BooleanOption,
77
+ "automatic-rename" => BooleanOption,
78
+ "clock-mode-colour" => ColorOption,
79
+ "clock-mode-style" => ClockModeStyleOption,
80
+ "force-height" => NumberOption,
81
+ "force-width" => NumberOption,
82
+ "main-pane-height" => NumberOption,
83
+ "main-pane-width" => NumberOption,
84
+ "mode-attr" => AttrOption,
85
+ "mode-bg" => ColorOption,
86
+ "mode-fg" => ColorOption,
87
+ "mode-keys" => KeymapOption,
88
+ "mode-mouse" => BooleanOption,
89
+ "monitor-activity" => BooleanOption,
90
+ "monitor-content" => StringOption,
91
+ "remain-on-exit" => BooleanOption,
92
+ "synchronize-panes" => BooleanOption,
93
+ "utf8" => BooleanOption,
94
+ "window-status-alert-attr" => AttrOption,
95
+ "window-status-alert-bg" => ColorOption,
96
+ "window-status-alert-fg" => ColorOption,
97
+ "window-status-attr" => AttrOption,
98
+ "window-status-bg" => ColorOption,
99
+ "window-status-current-attr" => AttrOption,
100
+ "window-status-current-bg" => ColorOption,
101
+ "window-status-current-fg" => ColorOption,
102
+ "window-status-current-format" => StringOption,
103
+ "window-status-fg" => ColorOption,
104
+ "window-status-format" => StringOption,
105
+ "word-separators" => CharArrayOption,
106
+ "xterm-keys" => BooleanOption,
107
+ }
108
+ end
109
+ end
@@ -0,0 +1,10 @@
1
+ require "tmux/options/symbol_option"
2
+ module Tmux
3
+ module Options
4
+ # @todo maintain list of valid attributes
5
+ # @api private
6
+ # @see Option
7
+ class AttrOption < SymbolOption
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,19 @@
1
+ require "tmux/options/symbol_option"
2
+ module Tmux
3
+ module Options
4
+ # @api private
5
+ # @see Option
6
+ class BellActionOption < SymbolOption
7
+ class << self
8
+ # @param (see Option.to_tmux)
9
+ # @return (see Option.to_tmux)
10
+ # @see Option.to_tmux
11
+ # @api private
12
+ def to_tmux(value)
13
+ raise ArgumentError unless [:any, :none, :current, :default].include?(value)
14
+ super
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,26 @@
1
+ require "tmux/options/option"
2
+ module Tmux
3
+ module Options
4
+ # @api private
5
+ # @see Option
6
+ class BooleanOption < Option
7
+ class << self
8
+ # @param (see Option.from_tmux)
9
+ # @return [Boolean]
10
+ # @api private
11
+ # @see Option.from_tmux
12
+ def from_tmux(value)
13
+ super || value == "on"
14
+ end
15
+
16
+ # @param (see Option.to_tmux)
17
+ # @return (see Option.to_tmux)
18
+ # @see Option.to_tmux
19
+ # @api private
20
+ def to_tmux(value)
21
+ super || value ? "on" : "off"
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ require "tmux/options/option"
2
+ module Tmux
3
+ module Options
4
+ # @api private
5
+ # @see Option
6
+ class CharArrayOption < Option
7
+ class << self
8
+ # @param (see Option.from_tmux)
9
+ # @return [Array<String>, Symbol]
10
+ # @api private
11
+ # @see Option.from_tmux
12
+ def from_tmux(value)
13
+ super || StringOption.from_tmux(value).split("")
14
+ end
15
+
16
+ # @param (see Option.to_tmux)
17
+ # @return (see Option.to_tmux)
18
+ # @see Option.to_tmux
19
+ # @api private
20
+ def to_tmux(value)
21
+ super || value.join("")
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,27 @@
1
+ require "tmux/options/symbol_option"
2
+ module Tmux
3
+ module Options
4
+ # @api private
5
+ # @see Option
6
+ class ClockModeStyleOption < SymbolOption
7
+ class << self
8
+ # @param (see Option.from_tmux)
9
+ # @return [Symbol]
10
+ # @api private
11
+ # @see Option.from_tmux
12
+ def from_tmux(value)
13
+ super || {12 => :twelve, 24 => :twenty_four}[value]
14
+ end
15
+
16
+ # @param [Symbol<:twelve, :twenty_four>] value
17
+ # @return (see Option.to_tmux)
18
+ # @see Option.to_tmux
19
+ # @api private
20
+ def to_tmux(value)
21
+ raise ArgumentError unless [:twelve, :twenty_four].include?(value)
22
+ super
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,23 @@
1
+ # -*- coding: utf-8 -*-
2
+ require "tmux/options/symbol_option"
3
+ module Tmux
4
+ module Options
5
+ # @api private
6
+ # @see Option
7
+ class ColorOption < SymbolOption
8
+ class << self
9
+ # @param [Symbol<:black, :red, :green, :yellow, :blue, :magenta, :cyan, :white, :colour0 – colour255, :default>] value
10
+ # @return (see Option.to_tmux)
11
+ # @see Option.to_tmux
12
+ # @api private
13
+ def to_tmux(value)
14
+ if ![:black, :red, :green, :yellow, :blue, :magenta, :cyan, :white, :default].include?(value) &&
15
+ value !~ /^colour\d+$/
16
+ raise ArgumentError
17
+ end
18
+ super
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,19 @@
1
+ require "tmux/options/symbol_option"
2
+ module Tmux
3
+ module Options
4
+ # @api private
5
+ # @see Option
6
+ class JustificationOption < SymbolOption
7
+ class << self
8
+ # @param [Symbol<:left, :right, :centre, :default>] value
9
+ # @return (see Option.to_tmux)
10
+ # @see Option.to_tmux
11
+ # @api private
12
+ def to_tmux(value)
13
+ raise ArgumentError unless [:left, :right, :centre, :default].include?(value)
14
+ super
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require "tmux/options/symbol_option"
2
+ module Tmux
3
+ module Options
4
+ # @api private
5
+ # @see Option
6
+ class KeymapOption < SymbolOption
7
+ class << self
8
+ # @param [Symbol<:emacs, :vi, :default>] value
9
+ # @return (see Option.to_tmux)
10
+ # @see Option.to_tmux
11
+ # @api private
12
+ def to_tmux(value)
13
+ raise ArgumentError unless [:emacs, :vi, :default].include?(value)
14
+ super
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,26 @@
1
+ require "tmux/options/option"
2
+ module Tmux
3
+ module Options
4
+ # @api private
5
+ # @see Option
6
+ class NumberOption < Option
7
+ class << self
8
+ # @param (see Option.from_tmux)
9
+ # @return [Number, Symbol]
10
+ # @api private
11
+ # @see Option.from_tmux
12
+ def from_tmux(value)
13
+ super || value.to_i
14
+ end
15
+
16
+ # @param (see Option.to_tmux)
17
+ # @return (see Option.to_tmux)
18
+ # @see Option.to_tmux
19
+ # @api private
20
+ def to_tmux(value)
21
+ super || value.to_s
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,38 @@
1
+ module Tmux
2
+ module Options
3
+ # This class is the base for all typecasting in ruby-tmux. It will
4
+ # handle `default` and `none`. All other conversions have to be
5
+ # done by classes inheriting from this one. You should never have
6
+ # to instantiate or work with any of those classes yourself.
7
+ #
8
+ # @api private
9
+ # @abstract
10
+ class Option
11
+ class << self
12
+ # Takes an option value from tmux and converts it to an appropriate Ruby object.
13
+ #
14
+ # @param [String] value the value to cast
15
+ # @return [Object, Symbol] Either the specific Ruby object, or either `:default` or `:none`
16
+ # @api private
17
+ # @see Subclasses
18
+ def from_tmux(value)
19
+ if [:default, :none].include?(value)
20
+ return value.to_sym
21
+ end
22
+ end
23
+
24
+ # Converts a Ruby object to a value for tmux.
25
+ #
26
+ # @param [Object] value the value to cast
27
+ # @return [String]
28
+ # @api private
29
+ # @see Subclasses
30
+ def to_tmux(value)
31
+ if [:default, :none].include?(value)
32
+ return value.to_s
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,26 @@
1
+ require "tmux/options/option"
2
+ module Tmux
3
+ module Options
4
+ # @api private
5
+ # @see Option
6
+ class StringOption < Option
7
+ class << self
8
+ # @param (see Option.from_tmux)
9
+ # @return [String, Symbol]
10
+ # @api private
11
+ # @see Option.from_tmux
12
+ def from_tmux(value)
13
+ super || value.gsub(/^"|"$/, "")
14
+ end
15
+
16
+ # @param (see Option.to_tmux)
17
+ # @return (see Option.to_tmux)
18
+ # @see Option.to_tmux
19
+ # @api private
20
+ def to_tmux(value)
21
+ super || value.inspect.gsub(/^"|"$/, "")
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ require "tmux/options/option"
2
+ module Tmux
3
+ module Options
4
+ # @api private
5
+ # @see Option
6
+ class SymbolOption < Option
7
+ class << self
8
+ # @param (see Option.from_tmux)
9
+ # @return [Symbol]
10
+ # @api private
11
+ # @see Option.from_tmux
12
+ def from_tmux(value)
13
+ super || value.to_sym
14
+ end
15
+
16
+ # @param (see Option.to_tmux)
17
+ # @return (see Option.to_tmux)
18
+ # @see Option.to_tmux
19
+ # @api private
20
+ def to_tmux(value)
21
+ super || value.to_s
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end