Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
mikutter用縦書きプラグイン
# -*- coding: utf-8 -*-
Plugin.create :tategaki do
def to_tategaki(str)
result = ""
halfs = ('0'..'9').to_a + ('A'..'Z').to_a + ('a'..'z').to_a
fulls = ('0'..'9').to_a + ('A'..'Z').to_a + ('a'..'z').to_a
half_symbols = ' !""#$%&''\'''\'()*+,-./:;<=>?@[\\]^_`{|}~'.split('')
full_symbols = ' !“”#$%&‘’()*+,−./:;<=>?@[\]^_`{|}〜'.split('')
halfs += half_symbols
fulls += full_symbols
table = Hash[halfs.zip(fulls)]
chars_from = '→↓←↑ー/\,、。…‥(){}〔〕【】《》〈〉「」『』[]↓←↑→|\/︐︑︒︙︰︵︶︷︸︹︺︻︼︽︾︿﹀﹁﹂﹃﹄﹇﹈'.split('')
chars_to = '↓←↑→|\/︐︑︒︙︰︵︶︷︸︹︺︻︼︽︾︿﹀﹁﹂﹃﹄﹇﹈←↑→↓ー/\,、。…‥)(}{〕〔】【》《〉〈」「』『]['.split('')
str = str.gsub(/[#{Regexp.escape(halfs.join)}]/u, table)
str = str.gsub(/[#{Regexp.escape(chars_from.join)}]/u, Hash[chars_from.zip(chars_to)])
str = str.split("\n").reverse
max_len = 0
str.each do |s|
max_len = s.length if max_len < s.length
end
max_len.times do |n|
str.each do |s|
if n < s.length
result += s[n]
else
result += ' '
end
end
result += "\n"
end
result.gsub(/ +$/,'').chop
end
command(:convert_tategaki,
name: '縦書きに変換',
condition: lambda{ |opt| true },
visible: true,
role: :postbox) do |opt|
Plugin.create(:gtk).widgetof(opt.widget).widget_post.buffer.text =
to_tategaki(Plugin.create(:gtk).widgetof(opt.widget).widget_post.buffer.text)
end
command(:convert_yokogaki,
name: 'このツイートを横書きに変換',
condition: lambda{ |opt| true },
visible: true,
role: :timeline) do |opt|
opt.messages.each do |m|
Plugin.call(:update, nil, [Message.new(message: to_tategaki(to_tategaki(to_tategaki(m.message.to_s))), system: true)])
end
end
command(:copy_paste_with_tategaki,
name: '縦書きにしてパクる',
condition: lambda{ |opt| true },
visible: true,
role: :timeline) do |opt|
opt.messages.each do |m|
Service.primary.post :message => to_tategaki(m.message.to_s)
end
end
command(:nanameyomi,
name: '斜め読みにする',
condition: lambda{ |opt| true },
visible: true,
role: :postbox) do |opt|
str = to_tategaki(Plugin.create(:gtk).widgetof(opt.widget).widget_post.buffer.text)
Plugin.create(:gtk).widgetof(opt.widget).widget_post.buffer.text =
((0..str.split("\n").size-1).to_a.zip str.split("\n")).map{|ar| " " * ar[0] + ar[1]}.join("\n")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.