Module: GitRunner::Text

Extended by:
Text
Included in:
Text
Defined in:
lib/git-runner/text.rb

Constant Summary collapse

COLOR_START =
"\033["
COLOR_END =
"m"
COLOR_RESET =
"#{COLOR_START}0#{COLOR_END}"
COLORS =
{
  :black  => 30,
  :red    => 31,
  :green  => 32,
  :yellow => 33,
  :blue   => 34,
  :purple => 35,
  :cyan   => 36,
  :white  => 37
}
STYLES =
{
  :normal    => 0,
  :bold      => 1,
  :underline => 4
}

Instance Method Summary collapse

Instance Method Details

#beginObject



27
28
29
30
# File 'lib/git-runner/text.rb', line 27

def begin
  STDOUT.sync = true
  print("\e[1G       \e[1G")
end

#finishObject



32
33
34
# File 'lib/git-runner/text.rb', line 32

def finish
  print("\n")
end

#indent(spaces = 2) ⇒ Object



47
48
49
50
51
52
53
54
55
# File 'lib/git-runner/text.rb', line 47

def indent(spaces=2)
  @indentation ||= 0
  @indentation  += spaces

  yield

  @indentation -= spaces
  Text.new_line
end

#new_lineObject



43
44
45
# File 'lib/git-runner/text.rb', line 43

def new_line
  out('')
end

#out(str, style = nil) ⇒ Object



36
37
38
39
40
41
# File 'lib/git-runner/text.rb', line 36

def out(str, style=nil)
  # Ensure that new lines overwrite the default 'remote: ' text
  str = str.gsub("\n", "\n\e[1G#{padding(nil)}")

  print "\n\e[1G#{padding(style).ljust(7 + (@indentation || 0))}#{str}"
end