Skip to content

Instantly share code, notes, and snippets.

@fumieval
Created December 28, 2011 13:48
Show Gist options
  • Save fumieval/1527996 to your computer and use it in GitHub Desktop.
Save fumieval/1527996 to your computer and use it in GitHub Desktop.
import curtana.lib.parser as P
def withcolor(color):
return lambda text: '\033[1;%dm%s\033[1;m' % (color, text)
def is_hashtag_char(c):
return c == "_" or c.isalnum() or 12353 <= ord(c) <= 12534 or 20124 <= ord(c) <= 40657
SCREEN_NAME = P.StringA ** P.Char("@") * P.join ** +(P.alnum | P.Char("_"))
HASHTAG = P.StringA ** P.Char("#") * P.join ** +P.Sat(is_hashtag_char)
def arrangetext():
return P.Null() | withcolor(35) ** HASHTAG | \
P.StringA ** (P.Char("&") >> (P.String("gt;") >> P.Return(">")
| P.String("lt;") >> P.Return("<"))
| withcolor(36) ** SCREEN_NAME
| P.StringA ** P.Char(" ") * withcolor(35) ** HASHTAG
| P.AnyChar()
) * P.Delay(arrangetext)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment