Class: ITerm2::Tab

Inherits:
Object
  • Object
show all
Defined in:
lib/iterm2/tab.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client:, id:, window_id:) ⇒ Tab

Returns a new instance of Tab.



7
8
9
10
11
# File 'lib/iterm2/tab.rb', line 7

def initialize(client:, id:, window_id:)
  @client = client
  @id = id
  @window_id = window_id
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



5
6
7
# File 'lib/iterm2/tab.rb', line 5

def client
  @client
end

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/iterm2/tab.rb', line 5

def id
  @id
end

#window_idObject (readonly)

Returns the value of attribute window_id.



5
6
7
# File 'lib/iterm2/tab.rb', line 5

def window_id
  @window_id
end

Instance Method Details

#activate(order_window_front: true) ⇒ Object



13
14
15
# File 'lib/iterm2/tab.rb', line 13

def activate(order_window_front: true)
  client.activate_tab(id, order_window_front: order_window_front)
end

#close(force: false) ⇒ Object



27
28
29
# File 'lib/iterm2/tab.rb', line 27

def close(force: false)
  client.close_tab(id, force: force)
end

#primary_sessionObject



23
24
25
# File 'lib/iterm2/tab.rb', line 23

def primary_session
  sessions.first
end

#sessionsObject



17
18
19
20
21
# File 'lib/iterm2/tab.rb', line 17

def sessions
  client.topology
        .select { |s| s[:tab_id] == id && s[:window_id] == window_id }
        .map { |s| Session.new(client: client, id: s[:session_id], window_id: s[:window_id], tab_id: s[:tab_id], title: s[:title]) }
end

#to_hObject



31
32
33
34
35
36
37
# File 'lib/iterm2/tab.rb', line 31

def to_h
  {
    window_id: window_id,
    tab_id: id,
    sessions: sessions.map(&:to_h)
  }
end