Class: CWG::Print

Inherits:
Object
  • Object
show all
Defined in:
/Users/martyn/cw/cw_clone/lib/cw/print.rb

Defined Under Namespace

Classes: ProgressPrint

Instance Method Summary (collapse)

Constructor Details

- (Print) initialize

Returns a new instance of Print



31
32
33
34
# File '/Users/martyn/cw/cw_clone/lib/cw/print.rb', line 31

def initialize
  update_console_size
  reset
end

Instance Method Details

- (Object) char_result(popped)



95
96
97
98
99
100
101
# File '/Users/martyn/cw/cw_clone/lib/cw/print.rb', line 95

def char_result popped
  unless newline_maybe popped[:value]
    popped[:value] = '_' if((popped[:value] == ' ') && (popped[:success] != true))
    paint_success_failure(popped)
    return true
  end
end

- (Object) console_size



36
37
38
39
40
# File '/Users/martyn/cw/cw_clone/lib/cw/print.rb', line 36

def console_size
  IO.console.winsize
rescue LoadError
  [Integer(`tput li`), Integer(`tput co`)]
end

- (Object) fail(word)



110
111
112
# File '/Users/martyn/cw/cw_clone/lib/cw/print.rb', line 110

def fail word
  print paint("#{word}", fail_colour)
end

- (Object) fail_colour



128
129
130
# File '/Users/martyn/cw/cw_clone/lib/cw/print.rb', line 128

def fail_colour
  Params.fail_colour ||= :red
end

- (Object) force_newline_maybe



57
58
59
60
61
62
# File '/Users/martyn/cw/cw_clone/lib/cw/print.rb', line 57

def force_newline_maybe
  if @print_count >= (@cols - 1)
    newline
    true
  end
end

- (Object) heading



103
104
105
106
107
108
# File '/Users/martyn/cw/cw_clone/lib/cw/print.rb', line 103

def heading
  "Current Sentence is     duration:    secs".length.times do
    print paint('*', list_colour)
    puts
  end
end

- (Object) list(word)



114
115
116
# File '/Users/martyn/cw/cw_clone/lib/cw/print.rb', line 114

def list word
  print paint("#{word}", list_colour)
end

- (Object) list_colour



132
133
134
# File '/Users/martyn/cw/cw_clone/lib/cw/print.rb', line 132

def list_colour
  Params.list_colour ||= :white
end

- (Object) newline



52
53
54
55
# File '/Users/martyn/cw/cw_clone/lib/cw/print.rb', line 52

def newline
  reset
  update_console_size
end

- (Object) newline_maybe(word)



64
65
66
67
68
69
70
71
# File '/Users/martyn/cw/cw_clone/lib/cw/print.rb', line 64

def newline_maybe word
  @print_count += word.size unless force_newline_maybe
  return if((word.size == 1) && (word != ' '))
  if @print_count > (@cols - 10)
    newline
    true
  end
end

- (Object) paint(value, colour)



86
87
88
# File '/Users/martyn/cw/cw_clone/lib/cw/print.rb', line 86

def paint(value, colour)
  Paint[value, colour]
end

- (Object) paint_success_failure(popped)



90
91
92
93
# File '/Users/martyn/cw/cw_clone/lib/cw/print.rb', line 90

def paint_success_failure(popped)
  print paint(popped[:value], success_colour) if popped[:success]
  print paint(popped[:value], fail_colour ) unless popped[:success]
end


136
137
138
# File '/Users/martyn/cw/cw_clone/lib/cw/print.rb', line 136

def print_advice name
  puts "#{name}: Press Q 4 times to Exit"
end

- (Object) reset



47
48
49
50
# File '/Users/martyn/cw/cw_clone/lib/cw/print.rb', line 47

def reset
  @print_count = 0
  puts "\r"
end

- (Object) results(popped, type = :pass_and_fail)



73
74
75
76
77
78
79
80
81
82
83
84
# File '/Users/martyn/cw/cw_clone/lib/cw/print.rb', line 73

def results popped, type = :pass_and_fail
  if popped
    value = popped[:value]
    success = popped[:success]

    newline_maybe value

    print Paint["#{value} ", success_colour] if success
    print Paint["#{value} ", fail_colour ] unless (success || type == :pass_only)
    return true
  end
end

- (Object) success(word)



118
119
120
121
122
# File '/Users/martyn/cw/cw_clone/lib/cw/print.rb', line 118

def success word
  newline_maybe word
  return if(@print_count == 0 && word == ' ')
  print paint("#{word}", success_colour)
end

- (Object) success_colour



124
125
126
# File '/Users/martyn/cw/cw_clone/lib/cw/print.rb', line 124

def success_colour
  Params.success_colour ||= :blue
end

- (Object) update_console_size



42
43
44
45
# File '/Users/martyn/cw/cw_clone/lib/cw/print.rb', line 42

def update_console_size
  @rows, @cols = console_size
  #    printf "%d rows by %d columns\n", @rows, @cols
end