Skip to content

Instantly share code, notes, and snippets.

@rkumar
Created January 23, 2009 06:28
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 rkumar/50914 to your computer and use it in GitHub Desktop.
Save rkumar/50914 to your computer and use it in GitHub Desktop.
# Example ncurses program that should print all combinations of foreground
# color on background color but doesn't work.
# Make your terminal 256 characters wide for best view.
require 'rubygems'
require 'ncurses'
screen = Ncurses.initscr
Ncurses.noecho
Ncurses.cbreak
Ncurses.start_color
screen.addstr(Ncurses.COLORS.to_s)
screen.getch
Ncurses.curs_set 0
Ncurses.move 0, 0
Ncurses.clear
Ncurses.refresh
cc = Ncurses.COLORS
begin
color_count = 0
cc.times do |bg|
cc.times do |fg|
Ncurses.init_pair(color_count, fg, bg)
screen.attron(Ncurses.COLOR_PAIR(color_count))
screen.addstr("#")
screen.attroff(Ncurses.COLOR_PAIR(color_count))
color_count += 1
end
screen.addstr("== #{bg} ===\n")
#if bg % 8 == 0
# Ncurses.refresh
ch = screen.getch
break if ch == ?q
Ncurses.clear
color_count = 0
#end
end
=begin
color_count.times do |i|
screen.attrset(Ncurses.COLOR_PAIR(i))
screen.addstr("#")
end
=end
ensure
Ncurses.endwin
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment