Class: Hiiro::Tmux::Pane
- Inherits:
-
Object
- Object
- Hiiro::Tmux::Pane
- Defined in:
- lib/hiiro/tmux/pane.rb
Constant Summary collapse
- FORMAT =
'#{pane_id}|#{pane_index}|#{pane_active}|#{pane_current_command}|#{pane_current_path}|#{pane_width}|#{pane_height}|#{window_id}|#{session_name}'
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#session_name ⇒ Object
readonly
Returns the value of attribute session_name.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
-
#window_id ⇒ Object
readonly
Returns the value of attribute window_id.
Class Method Summary collapse
Instance Method Summary collapse
- #active? ⇒ Boolean
- #break_out(dest_window: nil) ⇒ Object
- #capture(buffer: nil, start_line: nil, end_line: nil) ⇒ Object
-
#initialize(id:, index:, active: false, command: nil, path: nil, width: 0, height: 0, window_id: nil, session_name: nil) ⇒ Pane
constructor
A new instance of Pane.
- #join_to(dest_target, horizontal: false) ⇒ Object
- #kill ⇒ Object
- #move_to(dest_target) ⇒ Object
- #resize(width: nil, height: nil) ⇒ Object
- #select ⇒ Object
- #swap_with(other_target) ⇒ Object
- #target ⇒ Object
- #to_h ⇒ Object
- #to_s ⇒ Object
- #zoom ⇒ Object
Constructor Details
#initialize(id:, index:, active: false, command: nil, path: nil, width: 0, height: 0, window_id: nil, session_name: nil) ⇒ Pane
Returns a new instance of Pane.
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/hiiro/tmux/pane.rb', line 36 def initialize(id:, index:, active: false, command: nil, path: nil, width: 0, height: 0, window_id: nil, session_name: nil) @id = id @index = index @active = active @command = command @path = path @width = width @height = height @window_id = window_id @session_name = session_name end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
6 7 8 |
# File 'lib/hiiro/tmux/pane.rb', line 6 def command @command end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
6 7 8 |
# File 'lib/hiiro/tmux/pane.rb', line 6 def height @height end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
6 7 8 |
# File 'lib/hiiro/tmux/pane.rb', line 6 def id @id end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
6 7 8 |
# File 'lib/hiiro/tmux/pane.rb', line 6 def index @index end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
6 7 8 |
# File 'lib/hiiro/tmux/pane.rb', line 6 def path @path end |
#session_name ⇒ Object (readonly)
Returns the value of attribute session_name.
6 7 8 |
# File 'lib/hiiro/tmux/pane.rb', line 6 def session_name @session_name end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
6 7 8 |
# File 'lib/hiiro/tmux/pane.rb', line 6 def width @width end |
#window_id ⇒ Object (readonly)
Returns the value of attribute window_id.
6 7 8 |
# File 'lib/hiiro/tmux/pane.rb', line 6 def window_id @window_id end |
Class Method Details
.current ⇒ Object
29 30 31 32 33 34 |
# File 'lib/hiiro/tmux/pane.rb', line 29 def self.current output = `tmux display-message -p '#{FORMAT}' 2>/dev/null`.strip return nil if output.empty? from_format_line(output) end |
.from_format_line(line) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/hiiro/tmux/pane.rb', line 8 def self.from_format_line(line) return nil if line.nil? || line.strip.empty? parts = line.strip.split('|', 9) return nil if parts.size < 7 id, index, active, command, path, width, height, window_id, session_name = parts new( id: id, index: index.to_i, active: active == '1', command: command, path: path, width: width.to_i, height: height.to_i, window_id: window_id, session_name: session_name ) end |
Instance Method Details
#active? ⇒ Boolean
48 49 50 |
# File 'lib/hiiro/tmux/pane.rb', line 48 def active? @active end |
#break_out(dest_window: nil) ⇒ Object
72 73 74 75 76 |
# File 'lib/hiiro/tmux/pane.rb', line 72 def break_out(dest_window: nil) args = ['tmux', 'break-pane', '-s', target] args += ['-t', dest_window] if dest_window system(*args) end |
#capture(buffer: nil, start_line: nil, end_line: nil) ⇒ Object
95 96 97 98 99 100 101 |
# File 'lib/hiiro/tmux/pane.rb', line 95 def capture(buffer: nil, start_line: nil, end_line: nil) args = ['tmux', 'capture-pane', '-t', target, '-p'] args += ['-b', buffer] if buffer args += ['-S', start_line.to_s] if start_line args += ['-E', end_line.to_s] if end_line `#{args.shelljoin}` end |
#join_to(dest_target, horizontal: false) ⇒ Object
78 79 80 81 82 |
# File 'lib/hiiro/tmux/pane.rb', line 78 def join_to(dest_target, horizontal: false) args = ['tmux', 'join-pane', '-s', target, '-t', dest_target] args << '-h' if horizontal system(*args) end |
#kill ⇒ Object
56 57 58 |
# File 'lib/hiiro/tmux/pane.rb', line 56 def kill system('tmux', 'kill-pane', '-t', target) end |
#move_to(dest_target) ⇒ Object
68 69 70 |
# File 'lib/hiiro/tmux/pane.rb', line 68 def move_to(dest_target) system('tmux', 'move-pane', '-s', target, '-t', dest_target) end |
#resize(width: nil, height: nil) ⇒ Object
84 85 86 87 88 89 |
# File 'lib/hiiro/tmux/pane.rb', line 84 def resize(width: nil, height: nil) args = ['tmux', 'resize-pane', '-t', target] args += ['-x', width.to_s] if width args += ['-y', height.to_s] if height system(*args) end |
#select ⇒ Object
60 61 62 |
# File 'lib/hiiro/tmux/pane.rb', line 60 def select system('tmux', 'select-pane', '-t', target) end |
#swap_with(other_target) ⇒ Object
64 65 66 |
# File 'lib/hiiro/tmux/pane.rb', line 64 def swap_with(other_target) system('tmux', 'swap-pane', '-s', target, '-t', other_target) end |
#target ⇒ Object
52 53 54 |
# File 'lib/hiiro/tmux/pane.rb', line 52 def target id end |
#to_h ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/hiiro/tmux/pane.rb', line 103 def to_h { id: id, index: index, active: active?, command: command, path: path, width: width, height: height, window_id: window_id, session_name: session_name }.compact end |
#to_s ⇒ Object
117 118 119 |
# File 'lib/hiiro/tmux/pane.rb', line 117 def to_s "#{session_name}:#{window_id}.#{index} [#{command}] #{path}" end |
#zoom ⇒ Object
91 92 93 |
# File 'lib/hiiro/tmux/pane.rb', line 91 def zoom system('tmux', 'resize-pane', '-Z', '-t', target) end |