Last active
December 14, 2015 13:58
-
-
Save rummelonp/5096908 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
# -*- coding: utf-8 -*- | |
require 'curses' | |
class TweetReverser | |
include Curses | |
SCREEN_NAME_PATTERN = /@[a-zA-Z0-9_]+/ | |
COLORS = [COLOR_RED, COLOR_GREEN, COLOR_YELLOW, COLOR_BLUE, COLOR_MAGENTA, COLOR_CYAN] | |
def self.start | |
new.start | |
end | |
def initialize | |
@tweets = [] | |
init_screen | |
start_color | |
COLORS.each do |color| | |
init_pair(color, color, COLOR_BLACK) | |
end | |
end | |
def start | |
$stdin.each_line do |line| | |
@tweets << line | |
clear | |
@tweets.reverse.each.with_index do |tweet, index| | |
setpos(index, 0) | |
tweet.split(/(#{SCREEN_NAME_PATTERN})/).each do |word| | |
if word =~ SCREEN_NAME_PATTERN | |
attron(color_pair(COLORS[word.each_byte.map(&:to_i).inject(&:+) % COLORS.size])) | |
else | |
attroff(Curses::A_COLOR) | |
end | |
addstr(word) | |
end | |
refresh | |
end | |
end | |
ensure | |
stop | |
end | |
def stop | |
close_screen | |
end | |
end | |
TweetReverser.start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment