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

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

Constant Summary collapse

MAX_HISTORY =
2000

Instance Method Summary collapse

Constructor Details

#initializeHistoryManager

Returns a new instance of HistoryManager.



14
15
16
17
18
19
20
21
# File 'lib/rex/ui/text/shell/history_manager.rb', line 14

def initialize
  @contexts = []
  @debug = false
  # Values dequeued before work is started
  @write_queue = ::Queue.new
  # Values dequeued after work is completed
  @remaining_work = ::Queue.new
end

Instance Method Details

#_contextsObject



54
55
56
# File 'lib/rex/ui/text/shell/history_manager.rb', line 54

def _contexts
  @contexts
end

#_debug=(value) ⇒ Object



58
59
60
# File 'lib/rex/ui/text/shell/history_manager.rb', line 58

def _debug=(value)
  @debug = value
end

#flushObject

Flush the contents of the write queue to disk. Blocks synchronously.



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

def flush
  until @write_queue.empty? && @remaining_work.empty?
    sleep 0.1
  end

  nil
end

#inspectObject



50
51
52
# File 'lib/rex/ui/text/shell/history_manager.rb', line 50

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

#with_context(history_file: nil, name: nil, &block) ⇒ nil

Create a new history command context when executing the given block

Parameters:

  • history_file (String, nil) (defaults to: nil)

    The file to load and persist commands to

  • name (String) (defaults to: nil)

    Human readable history context name

  • block (Proc)

Returns:

  • (nil)


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

def with_context(history_file: nil, name: nil, &block)
  push_context(history_file: history_file, name: name)

  begin
    block.call
  ensure
    pop_context
  end

  nil
end