Last active
December 15, 2015 02:29
-
-
Save no6v/5187616 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# encoding: UTF-8 | |
# basically inspired by melborne@github aka @merborne | |
# https://gist.github.com/melborne/5180832#file-flippy_vertical-rb | |
Earthquake.init do | |
punctuation = "、。,." | |
h = "ー「」→↑←↓=…" | |
v = "|¬∟↓→↑←॥:" | |
hv = (h + v) | |
vh = (v + h) | |
sep = "||--" | |
command :vertical do | |
puts "[input EOF (e.g. Ctrl+D) at the last]".c(:info) | |
text, _, signature = STDIN.gets(nil).rpartition(sep).reject(&:empty?) | |
lines = text.tr(hv, vh).each_line.map{|line| | |
line.chomp.split(/([#{punctuation}]+)/o) | |
}.flat_map{|line| | |
line.each_slice(2).with_object(["", ""]){|(main, punct), (punct_line, main_line)| | |
punct ||= " " | |
punct_line << " " * main.size.pred + punct | |
main_line << main + " " * punct.size.pred | |
} | |
}.each{|line| line.chomp!(" ")} | |
max = lines.map(&:size).max | |
status = lines.map{|line| | |
line.chars.fill(" ", line.size...max) | |
}.transpose.map{|line| line.reverse.join}.join("\n") | |
status.gsub!(/ +$/, "") | |
status += signature.chomp if signature | |
async_e{twitter.update(status)} if confirm(status) | |
end | |
help :vertical, "updating for vertical writing", <<-'HELP' | |
⚡ :vertical[ENTER] | |
[input EOF (e.g. Ctrl+D) at the last] | |
たてがき、 | |
プラグイン。||-- for #earthquakegem | |
プ た | |
ラ て | |
グ が | |
イ き、 | |
ン。 for #earthquakegem | |
[Yn] | |
# (optional) rest part of last ||-- will be as-is | |
HELP | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment