Created
August 29, 2012 09:12
-
-
Save geta6/3508893 to your computer and use it in GitHub Desktop.
突然のsudden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env coffee | |
String.prototype.repeat = (n) -> | |
b = '' | |
b += @ for num in [1..n] | |
return b | |
util = | |
jplen: (text) -> | |
match = text.match /[ぁ-ヶ亜-黑ー!?:;]/g | |
if match then match.length * 2 else 0 | |
enlen: (text) -> | |
match = text.match /[^ぁ-ヶ亜-黑ー!?:;]/g | |
if match then match.length else 0 | |
line = | |
_txt: {} | |
head: (len) -> | |
if len % 2 | |
len2 = parseInt len/4 | |
@._txt.head = "_#{'人'.repeat len2} #{'人'.repeat if len2 + 0.5 < len / 4 then len2+1 else len2}_" | |
else | |
@._txt.head = "_#{'人'.repeat Math.ceil len/2}_" | |
body: (text) -> | |
@._txt.body = "> #{text} <" | |
foot: (len) -> | |
if len % 2 | |
@._txt.foot = "‾#{'Y^'.repeat len/2}Y‾" | |
else | |
@._txt.foot = "‾#{'Y^'.repeat Math.ceil len/2}‾" | |
pull: -> | |
return "#{@._txt.head}\n#{@._txt.body}\n#{@._txt.foot}" | |
if process.argv[2]? | |
text = "突然の#{process.argv[2]}" | |
else | |
text = "突然のundefined" | |
jpn = util.jplen text | |
eng = util.enlen text | |
len = 2 + jpn + eng | |
line.head len, '' | |
line.body text, '' | |
line.foot len, '' | |
console.log line.pull() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment