Class: TermDump::Session
- Inherits:
-
Object
- Object
- TermDump::Session
- Defined in:
- lib/termdump/session.rb
Instance Method Summary collapse
- #enqueue(type, name, attributes) ⇒ Object
- #exec ⇒ Object
- #fallback ⇒ Object
-
#initialize(config = {}) ⇒ Session
constructor
Optional Configures: * terminal: The type of terminal * new_window: The key sequence used to open a new window * new_tab: The key sequence used to open a new tab * new_vsplit: The key sequence used to open a new vsplit * new_hsplit: The key sequence used to open a new hsplit.
- #replay(task) ⇒ Object
- #scan(node) ⇒ Object
Constructor Details
#initialize(config = {}) ⇒ Session
Optional Configures:
-
terminal: The type of terminal
-
new_window: The key sequence used to open a new window
-
new_tab: The key sequence used to open a new tab
-
new_vsplit: The key sequence used to open a new vsplit
-
new_hsplit: The key sequence used to open a new hsplit
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/termdump/session.rb', line 11 def initialize config={} if config.has_key?('terminal') begin terminal = config['terminal'] require_relative "terminal/#{terminal}" rescue LoadError puts "Load with terminal #{terminal} error:" puts "Not support #{terminal} yet!" exit 0 end else require_relative "terminal/base/default" end @terminal = Terminal.new(config) @node_queue = [] @support_split = Terminal.public_method_defined?(:vsplit) && Terminal.public_method_defined?(:hsplit) @support_tab = Terminal.public_method_defined?(:tab) end |
Instance Method Details
#enqueue(type, name, attributes) ⇒ Object
37 38 39 40 |
# File 'lib/termdump/session.rb', line 37 def enqueue type, name, attributes @node_queue.push(Node.new(type, name, attributes['cwd'], attributes['command'])) end |
#exec ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/termdump/session.rb', line 71 def exec current_tab = @node_queue.first @terminal.exec current_tab.cwd, current_tab.command @node_queue.shift @node_queue.each do |node| case node.type when :window, :tab, :vsplit, :hsplit @terminal.method(node.type).call(node.name, node.cwd, node.command) end end end |
#fallback ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/termdump/session.rb', line 57 def fallback unless @support_split @node_queue.each_index do |i| if @node_queue[i].type == :vsplit || @node_queue[i].type == :hsplit @node_queue[i].type = :tab end end end unless @support_tab @node_queue.each_index { |i| @node_queue[i].type = :window if @node_queue[i].type == :tab } end end |
#replay(task) ⇒ Object
31 32 33 34 35 |
# File 'lib/termdump/session.rb', line 31 def replay task scan task fallback exec end |
#scan(node) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/termdump/session.rb', line 42 def scan node node.each_pair do |k, v| if k.start_with?('tab') enqueue :tab, k, v elsif k.start_with?('vsplit') enqueue :vsplit, k, v elsif k.start_with?('hsplit') enqueue :hsplit, k, v elsif k.start_with?('window') enqueue :window, k, v end scan v if v.is_a?(Hash) end end |