-
-
Save emasaka/303778 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
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
import curses | |
import locale | |
import signal | |
import unicodedata | |
HATO = ( | |
u" _,,_", | |
u" /´o ヽ", | |
u",.ィゝ l ", | |
u" ̄ヽ l", | |
u" l ヽ___", | |
u" / ,,...---`ニニニ==、,,__", | |
u" l / ヽ ヽ ヽ ヽ ヽ ヽ ヽ l三三三>", | |
u" | iヽ ヽ ヽ ヽ ヽ ヽ ヽ/三三/''ー- 、", | |
u" ヽ. ヽ、ヽ ヽ ヽ ヽ ヽ.∠三=‐''´>‐--‐'", | |
u" ヽ、`'''ー‐---‐'''´_,,...--‐'''´", | |
u" `''ーッ--t_,r'''´", | |
u" _/._/ " ) | |
def uni_char_width(c): | |
w = unicodedata.east_asian_width(c) | |
if w == 'F' or w == 'W' or w == "A": | |
return 2 | |
else: | |
return 1 | |
def uni_str_width(str): | |
len = 0 | |
for c in str: | |
len = len + uni_char_width(c) | |
return len | |
def hato_width(hato): | |
mx = 0 | |
for s in hato: | |
sz = uni_str_width(s) | |
if sz > mx: mx = sz | |
return mx | |
def take_col(str, beg, end): | |
s_len = len(str) | |
col = 0 | |
beg_i = 0 | |
while True: | |
if beg_i >= s_len: return "" | |
col = col + uni_char_width(str[beg_i]) | |
if col >= beg: break | |
beg_i = beg_i + 1 | |
end_i = beg_i | |
while True: | |
if end_i >= s_len: break | |
col = col + uni_char_width(str[end_i]) | |
if col >= end: break | |
end_i = end_i + 1 | |
return str[beg_i:end_i].encode('utf-8') | |
def hato(win, hato): | |
rows, cols = win.getmaxyx() | |
y = (rows - len(HATO)) / 2 | |
for i in xrange(1, cols + hato_width(hato)): | |
if i < cols: | |
x = cols - i | |
beg = 0 | |
end = i | |
else: | |
x = 1 | |
beg = i - cols | |
end = cols | |
for j in xrange(0, len(hato)): | |
win.addstr(y + j, x, take_col(hato[j], beg, end)) | |
win.clrtoeol() | |
win.refresh() | |
curses.napms(50) | |
signal.signal(signal.SIGINT, signal.SIG_IGN) | |
locale.setlocale(locale.LC_ALL, "") | |
scrn = curses.initscr() | |
scrn.leaveok(1) | |
hato(scrn, HATO) | |
curses.endwin | |
signal.signal(signal.SIGINT, signal.SIG_DFL) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment