Class: ITerm2::Window

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client:, id:) ⇒ Window

Returns a new instance of Window.



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

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

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



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

def client
  @client
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

Instance Method Details

#activateObject



12
13
14
# File 'lib/iterm2/window.rb', line 12

def activate
  client.activate_window(id)
end

#create_tab(profile_name: nil) ⇒ Object



21
22
23
24
# File 'lib/iterm2/window.rb', line 21

def create_tab(profile_name: nil)
  result = client.create_tab(window_id: id, profile_name: profile_name)
  Session.new(client: client, id: result[:session_id], window_id: result[:window_id], tab_id: result[:tab_id])
end

#tabsObject



16
17
18
19
# File 'lib/iterm2/window.rb', line 16

def tabs
  tab_ids = client.topology.select { |s| s[:window_id] == id }.map { |s| s[:tab_id] }.uniq
  tab_ids.map { |tab_id| Tab.new(client: client, id: tab_id, window_id: id) }
end

#to_hObject



26
27
28
29
30
31
# File 'lib/iterm2/window.rb', line 26

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