Class: Rex::Ui::Text::Shell::HistoryManager

Inherits:
Object
  • Object
show all
Defined in:
lib/rex/ui/text/shell/history_manager.rb

Constant Summary collapse

@@contexts =
[]

Class Method Summary collapse

Class Method Details

.context_stackObject


16
17
18
# File 'lib/rex/ui/text/shell/history_manager.rb', line 16

def self.context_stack
  @@contexts
end

.inspectObject


12
13
14
# File 'lib/rex/ui/text/shell/history_manager.rb', line 12

def self.inspect
  "#<HistoryManager stack size: #{@@contexts.length}>"
end

.pop_contextObject


28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rex/ui/text/shell/history_manager.rb', line 28

def self.pop_context
  if @@contexts.empty?
    elog("HistoryManager.pop_context called even when the stack was already empty!")
    return
  end

  old_context = @@contexts.pop
  switch_context(@@contexts.last, old_context)

  dlog("HistoryManager.pop_context name: #{old_context&.fetch(:name, nil).inspect}")
end

.push_context(history_file: nil, name: nil) ⇒ Object


20
21
22
23
24
25
26
# File 'lib/rex/ui/text/shell/history_manager.rb', line 20

def self.push_context(history_file: nil, name: nil)
  dlog("HistoryManager.push_context name: #{name.inspect}")
  new_context = { history_file: history_file, name: name }

  switch_context(new_context, @@contexts.last)
  @@contexts.push(new_context)
end

.with_context(**kwargs, &block) ⇒ Object


40
41
42
43
44
45
46
47
48
# File 'lib/rex/ui/text/shell/history_manager.rb', line 40

def self.with_context(**kwargs, &block)
  push_context(**kwargs)

  begin
    block.call
  ensure
    pop_context
  end
end