Class: Putsplus::Footer

Inherits:
Object
  • Object
show all
Defined in:
lib/putsplus/footer.rb

Overview

Sticks text to last line in console

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text = "") ⇒ Footer



9
10
11
12
13
14
15
16
# File 'lib/putsplus/footer.rb', line 9

def initialize(text = "")
@text = text
@thread = Thread.new {
  while true do
    sticky_footer @text
  end
}
end

Instance Attribute Details

#textObject

Returns the value of attribute text.



7
8
9
# File 'lib/putsplus/footer.rb', line 7

def text
  @text
end

#threadObject (readonly)

Returns the value of attribute thread.



6
7
8
# File 'lib/putsplus/footer.rb', line 6

def thread
  @thread
end

Instance Method Details

#alive?Boolean



29
30
31
# File 'lib/putsplus/footer.rb', line 29

def alive?
  @thread.alive?
end

#killObject



18
19
20
21
22
# File 'lib/putsplus/footer.rb', line 18

def kill
  print " " * `tput cols`.to_i
  $stdout.flush
  Thread.kill(@thread)
end


24
25
26
27
# File 'lib/putsplus/footer.rb', line 24

def sticky_footer text
  print text.to_s + "\r"
  $stdout.flush
end