From: Rich Lane <rlane@club.cc.cmu.edu>
To: sup-devel@rubyforge.org
Subject: [sup-devel] [PATCH] add a mouse-enabled colorpicker to contrib
Date: Sun, 3 Jan 2010 07:33:28 -0800 [thread overview]
Message-ID: <1262532808-19401-1-git-send-email-rlane@club.cc.cmu.edu> (raw)
Intended to make colorscheme creation easier.
---
contrib/colorpicker.rb | 104 ++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 104 insertions(+), 0 deletions(-)
create mode 100644 contrib/colorpicker.rb
diff --git a/contrib/colorpicker.rb b/contrib/colorpicker.rb
new file mode 100644
index 0000000..c981a23
--- /dev/null
+++ b/contrib/colorpicker.rb
@@ -0,0 +1,104 @@
+require 'rubygems'
+
+begin
+ require 'ncursesw'
+rescue LoadError
+ require 'ncurses'
+end
+
+Ncurses.initscr
+Ncurses.noecho
+Ncurses.cbreak
+Ncurses.start_color
+
+Ncurses.curs_set 0
+Ncurses.move 0, 0
+Ncurses.clear
+Ncurses.refresh
+cc = Ncurses.COLORS
+
+Ncurses::keypad(Ncurses::stdscr, 1)
+Ncurses::mousemask(Ncurses::ALL_MOUSE_EVENTS | Ncurses::REPORT_MOUSE_POSITION, [])
+
+fail "color count is #{cc}, expected 256" unless cc == 256
+
+1.upto(255) do |c|
+ Ncurses.init_pair(c, 0, c)
+end
+
+def cell y, x, c
+ @map[[y,x]] = c
+ Ncurses.attron(Ncurses.COLOR_PAIR(c))
+ Ncurses.mvaddstr(y, x, " ")
+ Ncurses.attroff(Ncurses.COLOR_PAIR(c))
+end
+
+def handle_click y, x
+ c = @map[[y,x]] or return
+ name = case c
+ when 0...16
+ c.to_s
+ when 16...232
+ 'c' + (c-16).to_s(6).rjust(3,'0')
+ when 232...256
+ 'g' + (c-232).to_s
+ end
+
+ Ncurses.mvaddstr 11, 0, "#{name} "
+
+ Ncurses.attron(Ncurses.COLOR_PAIR(c))
+ 10.times do |i|
+ 20.times do |j|
+ y = 13 + i
+ x = j
+ Ncurses.mvaddstr(y, x, " ")
+ end
+ end
+ Ncurses.attroff(Ncurses.COLOR_PAIR(c))
+end
+
+@map = {}
+@fg = @bg = 0
+
+begin
+ 16.times do |i|
+ cell 0, i, i
+ end
+
+ 6.times do |i|
+ 6.times do |j|
+ 6.times do |k|
+ c = 16 + 6*6*i + 6*j + k
+ y = 2 + j
+ x = 7*i + k
+ cell y, x, c
+ end
+ end
+ end
+
+ 16.times do |i|
+ c = 16 + 6*6*6 + i
+ cell 9, i, c
+ end
+
+ handle_click 0, 0
+ Ncurses.refresh
+
+ while (c = Ncurses.getch)
+ case c
+ when 113 #q
+ break
+ when Ncurses::KEY_MOUSE
+ mev = Ncurses::MEVENT.new
+ Ncurses.getmouse(mev)
+ case(mev.bstate)
+ when Ncurses::BUTTON1_CLICKED
+ handle_click mev.y, mev.x
+ end
+ end
+ Ncurses.refresh
+ end
+
+ensure
+ Ncurses.endwin
+end
--
1.6.3.3
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel
next reply other threads:[~2010-01-03 15:36 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-03 15:33 Rich Lane [this message]
2010-01-05 21:04 ` William Morgan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1262532808-19401-1-git-send-email-rlane@club.cc.cmu.edu \
--to=rlane@club.cc.cmu.edu \
--cc=sup-devel@rubyforge.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox