Created
June 29, 2013 14:26
-
-
Save Yamabiko/5891303 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" | |
Curses.init_screen # スクリーンを初期化 | |
Curses.start_color # 色を有効にする | |
Curses.init_pair(1, Curses::COLOR_BLACK, Curses::COLOR_WHITE) | |
Curses.init_pair(2, Curses::COLOR_BLACK, Curses::COLOR_BLUE) | |
Curses.init_pair(3, Curses::COLOR_WHITE, Curses::COLOR_RED) | |
# 色のペアを登録する | |
# init_pair(id,文字色,背景色) | |
# idは1以上の値だけど大きすぎてもダメらしい | |
string = "Hello World!" | |
Curses.setpos(Curses.lines / 2 - 3, Curses.cols / 2 - (string.length / 2)) | |
Curses.attrset(Curses.color_pair(1)) # 色ペアを有効にする | |
# attrset(0)はデフォルト色らしい | |
Curses.addstr(string) | |
Curses.setpos(Curses.lines / 2 - 1, Curses.cols / 2 - (string.length / 2)) | |
Curses.attrset(Curses.color_pair(2)) | |
Curses.addstr(string) | |
Curses.setpos(Curses.lines / 2 + 1, Curses.cols / 2 - (string.length / 2)) | |
Curses.attrset(Curses.color_pair(3)) | |
Curses.addstr(string) | |
Curses.setpos(Curses.lines / 2 + 3, Curses.cols / 2 - (string.length / 2)) | |
Curses.attroff(Curses::A_COLOR) # 色をキャンセルする | |
# どうもA_COLORはデフォルト色な気がする | |
Curses.addstr(string) | |
Curses.refresh | |
Curses.getch | |
Curses.close_screen |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment