-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathsqueezer.rb
74 lines (67 loc) · 1.51 KB
/
squeezer.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
class Squeezer
def initialize(prev_sq, fmt)
@prev_sq = prev_sq
@fmt = fmt
@shown = prev_sq.nil? || $opt_all_ruby_show_dup
@content = String.new
@status = nil
end
attr_reader :prev_sq, :content, :status, :shown
def drop_prev
@prev_sq = nil
end
def difference_found
if @prev_sq
@prev_sq.force_output
end
@shown = true
end
def start
if @prev_sq &&
@prev_sq.prev_sq &&
@prev_sq.prev_sq.prev_sq
if @prev_sq.prev_sq.prev_sq.shown &&
!@prev_sq.prev_sq.shown &&
!@prev_sq.shown
@fmt.output_dots
end
@prev_sq.prev_sq.drop_prev
end
return @fmt.start if @shown
end
def output_data(s)
@content << s
return @fmt.output_data(s) if @shown
return if @prev_sq.content.start_with? @content
difference_found
@fmt.start
@fmt.output_data(@content)
end
def show_status(status)
@status = status
return @fmt.show_status(status) if @shown
return if @prev_sq.content == @content &&
@prev_sq.status == status
difference_found
@fmt.start
@fmt.output_data(@content)
@fmt.show_status(@status)
end
def last_linebreak
return @fmt.last_linebreak if @shown
end
def force_output
return if @shown
if @prev_sq &&
@prev_sq.prev_sq &&
@prev_sq.prev_sq.shown &&
!@prev_sq.shown
@fmt.output_dots
end
@shown = true
@fmt.start
@fmt.output_data(@content)
@fmt.show_status(@status)
@fmt.last_linebreak
end
end