Skip to content

Instantly share code, notes, and snippets.

@syusui-s
Created April 13, 2013 06:05
Show Gist options
  • Save syusui-s/5377219 to your computer and use it in GitHub Desktop.
Save syusui-s/5377219 to your computer and use it in GitHub Desktop.
突然の死
# -*- 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