Skip to content

Instantly share code, notes, and snippets.

@no6v
Last active December 15, 2015 02:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save no6v/5187616 to your computer and use it in GitHub Desktop.
Save no6v/5187616 to your computer and use it in GitHub Desktop.
# 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