tv.rb 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/tv.rb +13 -0
- data/lib/tv.rb +146 -0
- metadata +68 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f16cc3d09a424c0658144a173f8a655c23e75407
|
4
|
+
data.tar.gz: b9ee9ab0c13c5d646dfb468adfbb720eeed757b2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9452a246d368524d463d07166719148402492057013fbda5db319a163f449065a700980c59ea1a5f360320070fe516b83a20f2574c4995e9cc139a2a7fff1f5a
|
7
|
+
data.tar.gz: 3b4a8a4ba1b3e2bd9a4d8b6af16e4be3aa7433b4970ad4ad3b4cccb00a2de10f47058bd900c6d0b79f69bd235fa7233f3bbc9316ca1b72be4db8d722ba17c6f7
|
data/bin/tv.rb
ADDED
data/lib/tv.rb
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
require 'terminfo'
|
2
|
+
|
3
|
+
# add colors
|
4
|
+
class String
|
5
|
+
def colorize(bg)
|
6
|
+
"\e[0;0;#{bg}m#{self}\e[0;0m"
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
# TVTVTV
|
12
|
+
class TV
|
13
|
+
@Version = 0.1
|
14
|
+
def initialize(args)
|
15
|
+
setup_colors
|
16
|
+
opts args
|
17
|
+
resize
|
18
|
+
parse args
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
def opts(args)
|
23
|
+
args.select { |arg| arg.chr == "-" }.map do |arg|
|
24
|
+
case arg
|
25
|
+
when "-v", "--version"
|
26
|
+
@vers = true
|
27
|
+
when "--wavy"
|
28
|
+
@wavy = true
|
29
|
+
when "--test"
|
30
|
+
@test = true
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def parse(args)
|
36
|
+
args = args.select { |arg| arg.chr != "-" }
|
37
|
+
|
38
|
+
if @test
|
39
|
+
set_bg args.first unless args.empty?
|
40
|
+
testing
|
41
|
+
|
42
|
+
elsif @vers
|
43
|
+
puts @Version
|
44
|
+
|
45
|
+
else
|
46
|
+
set_bg args.first
|
47
|
+
endless
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def setup_colors
|
52
|
+
blk = 40
|
53
|
+
red = 41
|
54
|
+
grn = 42
|
55
|
+
yel = 43
|
56
|
+
blu = 44
|
57
|
+
ppl = 45
|
58
|
+
cyn = 46
|
59
|
+
gry = 47
|
60
|
+
pnk = 101
|
61
|
+
wht = 107
|
62
|
+
|
63
|
+
# backgrounds
|
64
|
+
@patts = {}
|
65
|
+
@patts['bw'] = [blk, blk, wht, blk, wht, blk, blk, wht, wht]
|
66
|
+
@patts['xmas'] = [grn, grn, red, red, grn, grn, red, red, red]
|
67
|
+
@patts['error'] = [wht, gry, yel, cyn, grn, pnk, red, blu, blk]
|
68
|
+
@patts['rasta'] = [blk, grn, grn, yel, yel, red, red, blk, blk]
|
69
|
+
@patts['pride'] = [blk, ppl, blu, cyn, grn, yel, pnk, red, blk]
|
70
|
+
|
71
|
+
# pride for testing!
|
72
|
+
@patt = @patts['pride']
|
73
|
+
@colors = @patt.length
|
74
|
+
end
|
75
|
+
|
76
|
+
def resize
|
77
|
+
@width = current_width
|
78
|
+
@colorwidth = (@width / @colors).floor
|
79
|
+
@offset = @wavy? offset : [1]
|
80
|
+
end
|
81
|
+
|
82
|
+
def current_width
|
83
|
+
TermInfo.screen_size[1]
|
84
|
+
end
|
85
|
+
|
86
|
+
# makes offset sample avg = offset difference. for example, if we have a final
|
87
|
+
# gap of 3 characters, and a color width of 5, we would want to add 1 to the
|
88
|
+
# width of three colors. on average, we can achieve this by sampling from an
|
89
|
+
# array whose average is 3/5 - or [0,0,1,1,1].
|
90
|
+
#
|
91
|
+
# in general, the array of 0s and 1s whose average is equal to a rational
|
92
|
+
# fraction x/y such that (x/y) < 1 and >= 0 is composed of y-x 0s and x 1s.
|
93
|
+
def offset
|
94
|
+
off = []
|
95
|
+
|
96
|
+
ones = @width % @colorwidth
|
97
|
+
zeros = @colorwidth - ones
|
98
|
+
|
99
|
+
ones.times { |_| off << 1 }
|
100
|
+
zeros.times { |_| off << 0 }
|
101
|
+
|
102
|
+
off
|
103
|
+
end
|
104
|
+
|
105
|
+
def tvline
|
106
|
+
resize unless @width == current_width
|
107
|
+
|
108
|
+
@patt.each do |bg|
|
109
|
+
space = " " * (@colorwidth + @offset.sample)
|
110
|
+
|
111
|
+
print space.colorize bg
|
112
|
+
end
|
113
|
+
|
114
|
+
sleep 0.01 # still tunable...
|
115
|
+
end
|
116
|
+
|
117
|
+
def set_bg(color)
|
118
|
+
if @patts.keys.include? color
|
119
|
+
@patt = @patts[color]
|
120
|
+
else
|
121
|
+
helper
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def helper
|
126
|
+
print "Select a pattern (" << @patts.keys.join(", ") << "): "
|
127
|
+
parse [] << $stdin.gets.chomp
|
128
|
+
end
|
129
|
+
|
130
|
+
def testing
|
131
|
+
100.times { |_| tvline }
|
132
|
+
end
|
133
|
+
|
134
|
+
def endless
|
135
|
+
puts "Turning on the TV... press Ctrl-C to quit."
|
136
|
+
sleep 1
|
137
|
+
|
138
|
+
begin
|
139
|
+
while true do tvline end
|
140
|
+
rescue Interrupt => e
|
141
|
+
puts "\nThanks for watching!"
|
142
|
+
exit 0
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tv.rb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jeremy Warner
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-12-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ruby-terminfo
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.1'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.1.1
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.1'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.1.1
|
33
|
+
description: |-
|
34
|
+
tv.rb (maybe) CLI emulator of a retro tv's fuzzy flashing in
|
35
|
+
the terminal.otherwise just some trippy terminal art that's fun.
|
36
|
+
email: jeremywrnr@gmail.com
|
37
|
+
executables:
|
38
|
+
- tv.rb
|
39
|
+
extensions: []
|
40
|
+
extra_rdoc_files: []
|
41
|
+
files:
|
42
|
+
- bin/tv.rb
|
43
|
+
- lib/tv.rb
|
44
|
+
homepage: http://github.com/jeremywrnr/tv.rb
|
45
|
+
licenses:
|
46
|
+
- MIT
|
47
|
+
metadata: {}
|
48
|
+
post_install_message: Turn on the tv with `tv.rb`
|
49
|
+
rdoc_options: []
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
requirements: []
|
63
|
+
rubyforge_project:
|
64
|
+
rubygems_version: 2.4.5.1
|
65
|
+
signing_key:
|
66
|
+
specification_version: 4
|
67
|
+
summary: CLI emulator of a retro tv's fuzzy flashing patterns.
|
68
|
+
test_files: []
|