Created
April 13, 2013 06:05
-
-
Save syusui-s/5377219 to your computer and use it in GitHub Desktop.
突然の死
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
# -*- coding: utf-8 -*- | |
Plugin.create :totsuzen_postbox do | |
def charwidth(char) | |
!(char =~ /[ぁ-ん]|[ァ-ヴ]|[一-龠]/) ? 1 : 2 end | |
def decolength(str) | |
str.split(//).map{|t|charwidth(t)}.inject{|sum,n|sum+n} end | |
def totsuzen(str) | |
deco = decolength(str) | |
"_"+"人"*(deco/2+2)+"_\n> "+str+" <\n ̄"+"Y^"*(deco/2)+"Y ̄\n" end | |
command(:totsuzen, | |
name: '>>突然の死<<', | |
condition: lambda{ |opt| true }, | |
visible: true, | |
role: :postbox) do |opt| | |
str = Plugin.create(:gtk).widgetof(opt.widget).widget_post.buffer.text | |
if str.size > 0 | |
result = totsuzen(str) | |
Plugin.create(:gtk).widgetof(opt.widget).widget_post.buffer.text = result[0..139] | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment