Class: Yildun::App

Inherits:
Object
  • Object
show all
Defined in:
lib/yildun/app.rb,
sig/yildun.rbs

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(settings: Settings.new, profile: nil, columns: 80, rows: 24) ⇒ App

Returns a new instance of App.

Parameters:

  • settings: (Settings) (defaults to: Settings.new)
  • profile: (Object) (defaults to: nil)
  • columns: (Integer) (defaults to: 80)
  • rows: (Integer) (defaults to: 24)


7
8
9
10
# File 'lib/yildun/app.rb', line 7

def initialize(settings: Settings.new, profile: nil, columns: 80, rows: 24)
  @settings, @tabs, @active_index = settings, [], 0
  open_tab(profile: profile, columns: columns, rows: rows)
end

Instance Attribute Details

#active_index ⇒ Integer (readonly)

Returns the value of attribute active_index.

Returns:

  • (Integer)


5
6
7
# File 'lib/yildun/app.rb', line 5

def active_index
  @active_index
end

#settings ⇒ Settings (readonly)

Returns the value of attribute settings.

Returns:



5
6
7
# File 'lib/yildun/app.rb', line 5

def settings
  @settings
end

#tabs ⇒ Array[Tab] (readonly)

Returns the value of attribute tabs.

Returns:



5
6
7
# File 'lib/yildun/app.rb', line 5

def tabs
  @tabs
end

Instance Method Details

#active_tab ⇒ Tab

Returns:



12
# File 'lib/yildun/app.rb', line 12

def active_tab = @tabs.fetch(@active_index)

#active_terminal ⇒ Terminal

Returns:



13
# File 'lib/yildun/app.rb', line 13

def active_terminal = active_tab.terminal

#close_active ⇒ Object

Returns:

  • (Object)


28
29
30
31
32
33
34
# File 'lib/yildun/app.rb', line 28

def close_active
  active_tab.close
  @tabs.delete_at(@active_index)
  return @active_index = 0 if @tabs.empty?

  @active_index = [@active_index, @tabs.length - 1].min
end

#next_tab ⇒ Object



36
37
38
# File 'lib/yildun/app.rb', line 36

def next_tab
  @active_index = (@active_index + 1) % @tabs.length if @tabs.any?
end

#open_tab(profile: nil, cwd: Dir.pwd, columns: 80, rows: 24) ⇒ Tab

Parameters:

  • profile: (Object) (defaults to: nil)
  • cwd: (String) (defaults to: Dir.pwd)
  • columns: (Integer) (defaults to: 80)
  • rows: (Integer) (defaults to: 24)

Returns:



15
16
17
18
19
20
21
22
# File 'lib/yildun/app.rb', line 15

def open_tab(profile: nil, cwd: Dir.pwd, columns: 80, rows: 24)
  profile ||= Yildun.profile(@settings)
  terminal = Terminal.new(command: profile.command, env: profile.env, cwd: profile.cwd || cwd,
    columns: columns, rows: rows, scrollback_limit: @settings.fetch("scrollback_limit"))
  @tabs << Tab.new(terminal, title: profile.name)
  @active_index = @tabs.length - 1
  active_tab
end

#open_tab_here(profile: nil, columns: 80, rows: 24) ⇒ Tab

Parameters:

  • profile: (Object) (defaults to: nil)
  • columns: (Integer) (defaults to: 80)
  • rows: (Integer) (defaults to: 24)

Returns:



24
25
26
# File 'lib/yildun/app.rb', line 24

def open_tab_here(profile: nil, columns: 80, rows: 24)
  open_tab(profile: profile, cwd: active_terminal.cwd, columns: columns, rows: rows)
end

#previous_tab ⇒ Object



40
41
42
# File 'lib/yildun/app.rb', line 40

def previous_tab
  @active_index = (@active_index - 1) % @tabs.length if @tabs.any?
end