flippy 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +14 -0
- data/README.md +16 -0
- data/bin/flippy +2 -0
- data/flippy.gemspec +2 -1
- data/lib/flippy.rb +3 -2
- data/lib/flippy/console.rb +94 -0
- data/lib/flippy/version.rb +1 -1
- data/spec/flippy_spec.rb +38 -0
- data/spec/spec_helper.rb +2 -0
- metadata +41 -3
data/History.txt
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
== 0.0.4 / 2013-02-19
|
2
|
+
* Add Flippy::Console module
|
3
|
+
* Add `console` option to flippy command
|
4
|
+
* Bug Fixes
|
5
|
+
|
6
|
+
== 0.0.3 / 2013-02-04
|
7
|
+
* Bug Fixes
|
8
|
+
|
9
|
+
== 0.0.2 / 2013-02-04
|
10
|
+
* Add flippy command
|
11
|
+
* Add Kernel#stnd
|
12
|
+
|
13
|
+
== 0.0.1 / 2013-01-27
|
14
|
+
* Birthday!
|
data/README.md
CHANGED
@@ -80,6 +80,22 @@ Try #unflip this again, then eval it. It will work.
|
|
80
80
|
|
81
81
|
Flippy.table output the mapping table.
|
82
82
|
|
83
|
+
## flippy command
|
84
|
+
It comes with flippy command. Try it with console option to start flippy console.
|
85
|
+
|
86
|
+
Usage:
|
87
|
+
|
88
|
+
flippy [options] text
|
89
|
+
|
90
|
+
where [options] are:
|
91
|
+
|
92
|
+
--flip, --no-flip, -f: Flip given text (default: true)
|
93
|
+
--unflip, -u: Unflip given text
|
94
|
+
--table, -t: Output flippy mapping table
|
95
|
+
--console, -c: Start flippy console
|
96
|
+
--version, -v: Print version and exit
|
97
|
+
--help, -h: Show this message
|
98
|
+
|
83
99
|
## Thank you
|
84
100
|
|
85
101
|
Thank you to Fumiaki Nishihara for disclosing a ASCII mapping table for text upside down as his blog entry;
|
data/bin/flippy
CHANGED
@@ -29,6 +29,7 @@ class OptionParser
|
|
29
29
|
opt :flip, "Flip given text", :default => true
|
30
30
|
opt :unflip, "Unflip given text"
|
31
31
|
opt :table, "Output flippy mapping table"
|
32
|
+
opt :console, "Start flippy console"
|
32
33
|
end
|
33
34
|
end
|
34
35
|
end
|
@@ -40,6 +41,7 @@ puts begin
|
|
40
41
|
case
|
41
42
|
when opts[:table]; Flippy.table
|
42
43
|
when opts[:unflip]; text.unflip
|
44
|
+
when opts[:console]; Flippy::Console.run
|
43
45
|
when opts[:flip]; text.flip
|
44
46
|
end
|
45
47
|
end
|
data/flippy.gemspec
CHANGED
@@ -18,5 +18,6 @@ Gem::Specification.new do |gem|
|
|
18
18
|
gem.require_paths = ["lib"]
|
19
19
|
gem.required_ruby_version = '>=1.9.3'
|
20
20
|
gem.add_dependency 'trollop'
|
21
|
-
|
21
|
+
gem.add_dependency 'ruby-termios'
|
22
|
+
gem.add_development_dependency 'rspec'
|
22
23
|
end
|
data/lib/flippy.rb
CHANGED
@@ -8,6 +8,7 @@
|
|
8
8
|
# http://id.fnshr.info/2013/01/25/upsidedowntext/
|
9
9
|
|
10
10
|
require_relative "flippy/version"
|
11
|
+
require_relative "flippy/console"
|
11
12
|
|
12
13
|
module Flippy
|
13
14
|
T = [[65, 5572], [66, 5626], [67, 390], [68, 5601], [69, 398], [70, 8498], [71, 8513], [72, 72], [73, 73], [74, 5259], [75, 20012], [76, 8514], [77, 87], [78, 78], [79, 79], [80, 1280], [81, 908], [82, 7450], [83, 83], [84, 8869], [85, 1352], [86, 923], [87, 77], [88, 88], [89, 8516], [90, 90], [97, 592], [98, 113], [99, 596], [100, 112], [101, 601], [102, 607], [103, 595], [104, 613], [105, 7433], [106, 638], [107, 670], [108, 108], [109, 623], [110, 117], [111, 111], [112, 100], [113, 98], [114, 633], [115, 115], [116, 647], [117, 110], [118, 652], [119, 653], [120, 120], [121, 654], [122, 122], [48, 48], [49, 8642], [50, 423], [51, 949], [52, 5421], [53, 53], [54, 57], [55, 76], [56, 56], [57, 54], [46, 729], [44, 8216], [45, 45], [58, 58], [59, 1563], [33, 161], [63, 191], [38, 8523], [40, 41], [41, 40], [60, 62], [62, 60], [91, 93], [93, 91], [95, 8254], [8254, 95], [123, 125], [125, 123], [8756, 8757], [8757, 8756]]
|
@@ -45,8 +46,8 @@ module Flippy
|
|
45
46
|
def margin(str)
|
46
47
|
return str unless str.match(/\n|\r/)
|
47
48
|
max = 0
|
48
|
-
str.
|
49
|
-
.map { |l| ' ' * (max-l.size) + l }.join
|
49
|
+
str.split("\n").tap { |ls| max = ls.map(&:size).max }
|
50
|
+
.map { |l| ' ' * (max-l.size) + l.rstrip }.join("\n")
|
50
51
|
end
|
51
52
|
end
|
52
53
|
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require "termios"
|
2
|
+
|
3
|
+
$stdin.extend Termios
|
4
|
+
|
5
|
+
# On your terminal, try `flippy -c` then type normally.
|
6
|
+
# <ESC> key to exit.
|
7
|
+
# ^R, ^G, ^B, ^E are for setting color.
|
8
|
+
|
9
|
+
module Flippy::Console
|
10
|
+
class << self
|
11
|
+
def run
|
12
|
+
buffer = ""
|
13
|
+
terminal do
|
14
|
+
clear
|
15
|
+
move_to_top
|
16
|
+
while chr = $stdin.getc
|
17
|
+
clear
|
18
|
+
case chr
|
19
|
+
when escape_key?
|
20
|
+
exit
|
21
|
+
when back_key?
|
22
|
+
buffer.chop!
|
23
|
+
when *%w(R G B).map { |ch| ctr_with ch }
|
24
|
+
set_color(chr)
|
25
|
+
when ctr_with('E')
|
26
|
+
reset_color
|
27
|
+
else
|
28
|
+
buffer << chr
|
29
|
+
end
|
30
|
+
flipped = buffer.flip
|
31
|
+
print flipped
|
32
|
+
reset_cursor(flipped)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
# Configuire terminal with non-echo & non-canonical
|
39
|
+
def terminal
|
40
|
+
begin
|
41
|
+
term_preset = $stdin.tcgetattr
|
42
|
+
term = term_preset.dup
|
43
|
+
[Termios::ICANON, Termios::ECHO].each { |flag| term.lflag &= ~flag }
|
44
|
+
$stdin.tcsetattr(Termios::TCSANOW, term)
|
45
|
+
yield
|
46
|
+
ensure
|
47
|
+
$stdin.tcsetattr(Termios::TCSANOW, term_preset)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def clear
|
52
|
+
print "\e[2J"
|
53
|
+
end
|
54
|
+
|
55
|
+
def move_to_top
|
56
|
+
print "\e[0;0H"
|
57
|
+
end
|
58
|
+
|
59
|
+
def escape_key?
|
60
|
+
->chr{ chr.ord == 27 } # <ESC>
|
61
|
+
end
|
62
|
+
|
63
|
+
def back_key?
|
64
|
+
->chr{ [127, 8].include?(chr.ord) } # ^H or delete
|
65
|
+
end
|
66
|
+
|
67
|
+
def ctr_with(key)
|
68
|
+
raise 'only A-Z acceptable' unless key.ord.between?(65, 90)
|
69
|
+
->chr{ chr.ord == key.ord-64 }
|
70
|
+
end
|
71
|
+
|
72
|
+
def set_color(key)
|
73
|
+
key = COL( (key.ord+64).chr )
|
74
|
+
print "\e[#{key}m" if key
|
75
|
+
end
|
76
|
+
|
77
|
+
def reset_color
|
78
|
+
print "\e[0m"
|
79
|
+
end
|
80
|
+
|
81
|
+
def reset_cursor(str)
|
82
|
+
lastline = str.split("\n").first || ""
|
83
|
+
print "\e[#{lastline.size}D" # Backward cursor
|
84
|
+
y = str.count("\n")
|
85
|
+
print "\e[#{y}A" if y > 0 # Up cursor
|
86
|
+
end
|
87
|
+
|
88
|
+
def COL(key)
|
89
|
+
t = %w(red green yellow blue magenta cyan white).zip(31..37)
|
90
|
+
t.detect { |k, v| k.start_with?("#{key}".downcase) }
|
91
|
+
.tap { |k, v| break k ? v : nil }
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
data/lib/flippy/version.rb
CHANGED
data/spec/flippy_spec.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require_relative 'spec_helper'
|
3
|
+
|
4
|
+
describe Flippy do
|
5
|
+
describe "#flip" do
|
6
|
+
context "single-line" do
|
7
|
+
subject { "hello, world!".flip }
|
8
|
+
it { should eq "¡plɹoʍ ‘olləɥ" }
|
9
|
+
end
|
10
|
+
|
11
|
+
context "multi-line" do
|
12
|
+
subject { "hello\nworld!".flip }
|
13
|
+
it { should eq "¡plɹoʍ\n olləɥ" }
|
14
|
+
end
|
15
|
+
|
16
|
+
context "multi-line2" do
|
17
|
+
subject { "def ab\n :ab\nend".flip }
|
18
|
+
it { should eq " puə\n qɐ:\nqɐ ɟəp" }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#unflip" do
|
23
|
+
context "single-line" do
|
24
|
+
subject { "¡plɹoʍ ‘olləɥ".unflip }
|
25
|
+
it { should eq "hello, world!" }
|
26
|
+
end
|
27
|
+
|
28
|
+
context "multi-line" do
|
29
|
+
subject { "¡plɹoʍ\n olləɥ".unflip }
|
30
|
+
it { should eq "hello\nworld!" }
|
31
|
+
end
|
32
|
+
|
33
|
+
context "multi-line2" do
|
34
|
+
subject { " puə\n qɐ: \nqɐ ɟəp".unflip }
|
35
|
+
it { should eq "def ab\n :ab\nend" }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flippy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02-
|
12
|
+
date: 2013-02-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: trollop
|
@@ -27,6 +27,38 @@ dependencies:
|
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: ruby-termios
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
30
62
|
description: Fippy makes a text upside down, like "twitter" to "ɹəʇʇᴉʍʇ".
|
31
63
|
email:
|
32
64
|
- postagie@gmail.com
|
@@ -37,13 +69,17 @@ extra_rdoc_files: []
|
|
37
69
|
files:
|
38
70
|
- .gitignore
|
39
71
|
- Gemfile
|
72
|
+
- History.txt
|
40
73
|
- LICENSE.txt
|
41
74
|
- README.md
|
42
75
|
- Rakefile
|
43
76
|
- bin/flippy
|
44
77
|
- flippy.gemspec
|
45
78
|
- lib/flippy.rb
|
79
|
+
- lib/flippy/console.rb
|
46
80
|
- lib/flippy/version.rb
|
81
|
+
- spec/flippy_spec.rb
|
82
|
+
- spec/spec_helper.rb
|
47
83
|
homepage: https://github.com/melborne/flippy
|
48
84
|
licenses: []
|
49
85
|
post_install_message:
|
@@ -68,4 +104,6 @@ rubygems_version: 1.8.25
|
|
68
104
|
signing_key:
|
69
105
|
specification_version: 3
|
70
106
|
summary: Fippy makes a text upside down, like "twitter" to "ɹəʇʇᴉʍʇ".
|
71
|
-
test_files:
|
107
|
+
test_files:
|
108
|
+
- spec/flippy_spec.rb
|
109
|
+
- spec/spec_helper.rb
|