Class: Yildun::App
- Inherits:
-
Object
- Object
- Yildun::App
- Defined in:
- lib/yildun/app.rb,
sig/yildun.rbs
Instance Attribute Summary collapse
-
#active_index ⇒ Integer
readonly
Returns the value of attribute active_index.
-
#settings ⇒ Settings
readonly
Returns the value of attribute settings.
-
#tabs ⇒ Array[Tab]
readonly
Returns the value of attribute tabs.
Instance Method Summary collapse
- #active_tab ⇒ Tab
- #active_terminal ⇒ Terminal
- #close_active ⇒ Object
-
#initialize(settings: Settings.new, profile: nil, columns: 80, rows: 24) ⇒ App
constructor
A new instance of App.
- #next_tab ⇒ Object
- #open_tab(profile: nil, cwd: Dir.pwd, columns: 80, rows: 24) ⇒ Tab
- #open_tab_here(profile: nil, columns: 80, rows: 24) ⇒ Tab
- #previous_tab ⇒ Object
Constructor Details
#initialize(settings: Settings.new, profile: nil, columns: 80, rows: 24) ⇒ App
Returns a new instance of App.
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.
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.
5 6 7 |
# File 'lib/yildun/app.rb', line 5 def settings @settings end |
#tabs ⇒ Array[Tab] (readonly)
Returns the value of attribute tabs.
5 6 7 |
# File 'lib/yildun/app.rb', line 5 def tabs @tabs end |
Instance Method Details
#active_tab ⇒ Tab
12 |
# File 'lib/yildun/app.rb', line 12 def active_tab = @tabs.fetch(@active_index) |
#active_terminal ⇒ Terminal
13 |
# File 'lib/yildun/app.rb', line 13 def active_terminal = active_tab.terminal |
#close_active ⇒ 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
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
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 |