Skip to content
Browse files

added missing module

  • Loading branch information...
1 parent 9a88e26 commit f8226b590148b690e532b6c2136a5265cbb7ee62 @bl0b committed May 20, 2011
Showing with 62 additions and 0 deletions.
  1. +62 −0 py/colorterm.py
View
62 py/colorterm.py
@@ -0,0 +1,62 @@
+import sys
+
+__all__=['TC_WHITE', 'TC_BLACK', 'set_palette', 'fg', 'bg', 'vga_palette']
+
+TC_WHITE=15
+TC_BLACK=0
+
+
+vga_palette = [
+ [ 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0xAA ], [ 0x00, 0xAA, 0x00 ], [ 0x00, 0xAA, 0xAA ], [ 0xAA, 0x00, 0x00 ], [ 0xAA, 0x00, 0xAA ], [ 0xAA, 0x55, 0x00 ], [ 0xAA, 0xAA, 0xAA ], [ 0x55, 0x55, 0x55 ], [ 0x55, 0x55, 0xFF ],
+ [ 0x55, 0xFF, 0x55 ], [ 0x55, 0xFF, 0xFF ], [ 0xFF, 0x55, 0x55 ], [ 0xFF, 0x55, 0xFF ], [ 0xFF, 0xFF, 0x55 ], [ 0xFF, 0xFF, 0xFF ], [ 0x00, 0x00, 0x00 ], [ 0x10, 0x10, 0x10 ], [ 0x20, 0x20, 0x20 ], [ 0x35, 0x35, 0x35 ],
+ [ 0x45, 0x45, 0x45 ], [ 0x55, 0x55, 0x55 ], [ 0x65, 0x65, 0x65 ], [ 0x75, 0x75, 0x75 ], [ 0x8A, 0x8A, 0x8A ], [ 0x9A, 0x9A, 0x9A ], [ 0xAA, 0xAA, 0xAA ], [ 0xBA, 0xBA, 0xBA ], [ 0xCA, 0xCA, 0xCA ], [ 0xDF, 0xDF, 0xDF ],
+ [ 0xEF, 0xEF, 0xEF ], [ 0xFF, 0xFF, 0xFF ], [ 0x00, 0x00, 0xFF ], [ 0x41, 0x00, 0xFF ], [ 0x82, 0x00, 0xFF ], [ 0xBE, 0x00, 0xFF ], [ 0xFF, 0x00, 0xFF ], [ 0xFF, 0x00, 0xBE ], [ 0xFF, 0x00, 0x82 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A, 0xBA ], [ 0xFF, 0xCA, 0xBA ],
+ [ 0xFF, 0xDF, 0xBA ], [ 0xFF, 0xEF, 0xBA ], [ 0xFF, 0xFF, 0xBA ], [ 0xEF, 0xFF, 0xBA ], [ 0xDF, 0xFF, 0xBA ], [ 0xCA, 0xFF, 0xBA ], [ 0xBA, 0xFF, 0xBA ], [ 0xBA, 0xFF, 0xCA ], [ 0xBA, 0xFF, 0xDF ], [ 0xBA, 0xFF, 0xEF ],
+ [ 0xBA, 0xFF, 0xFF ], [ 0xBA, 0xEF, 0xFF ], [ 0xBA, 0xDF, 0xFF ], [ 0xBA, 0xCA, 0xFF ], [ 0x00, 0x00, 0x71 ], [ 0x1C, 0x00, 0x71 ], [ 0x39, 0x00, 0x71 ], [ 0x55, 0x00, 0x71 ], [ 0x71, 0x00, 0x71 ], [ 0x71, 0x00, 0x55 ],
+ [ 0x71, 0x00, 0x39 ], [ 0x71, 0x00, 0x1C ], [ 0x71, 0x00, 0x00 ], [ 0x71, 0x1C, 0x00 ], [ 0x71, 0x39, 0x00 ], [ 0x71, 0x55, 0x00 ], [ 0x71, 0x71, 0x00 ], [ 0x55, 0x71, 0x00 ], [ 0x39, 0x71, 0x00 ], [ 0x1C, 0x71, 0x00 ],
+ [ 0x00, 0x71, 0x00 ], [ 0x00, 0x71, 0x1C ], [ 0x00, 0x71, 0x39 ], [ 0x00, 0x71, 0x55 ], [ 0x00, 0x71, 0x71 ], [ 0x00, 0x55, 0x71 ], [ 0x00, 0x39, 0x71 ], [ 0x00, 0x1C, 0x71 ], [ 0x39, 0x39, 0x71 ], [ 0x45, 0x39, 0x71 ],
+ [ 0x55, 0x39, 0x71 ], [ 0x61, 0x39, 0x71 ], [ 0x71, 0x39, 0x71 ], [ 0x71, 0x39, 0x61 ], [ 0x71, 0x39, 0x55 ], [ 0x71, 0x39, 0x45 ], [ 0x71, 0x39, 0x39 ], [ 0x71, 0x45, 0x39 ], [ 0x71, 0x55, 0x39 ], [ 0x71, 0x61, 0x39 ],
+ [ 0x71, 0x71, 0x39 ], [ 0x61, 0x71, 0x39 ], [ 0x55, 0x71, 0x39 ], [ 0x45, 0x71, 0x39 ], [ 0x39, 0x71, 0x39 ], [ 0x39, 0x71, 0x45 ], [ 0x39, 0x71, 0x55 ], [ 0x39, 0x71, 0x61 ], [ 0x39, 0x71, 0x71 ], [ 0x39, 0x61, 0x71 ],
+ [ 0x39, 0x55, 0x71 ], [ 0x39, 0x45, 0x71 ], [ 0x51, 0x51, 0x71 ], [ 0x59, 0x51, 0x71 ], [ 0x61, 0x51, 0x71 ], [ 0x69, 0x51, 0x71 ], [ 0x71, 0x51, 0x71 ], [ 0x71, 0x51, 0x69 ], [ 0x71, 0x51, 0x61 ], [ 0x71, 0x51, 0x59 ],
+ [ 0x71, 0x51, 0x51 ], [ 0x71, 0x59, 0x51 ], [ 0x71, 0x61, 0x51 ], [ 0x71, 0x69, 0x51 ], [ 0x71, 0x71, 0x51 ], [ 0x69, 0x71, 0x51 ], [ 0x61, 0x71, 0x51 ], [ 0x59, 0x71, 0x51 ], [ 0x51, 0x71, 0x51 ], [ 0x51, 0x71, 0x59 ],
+ [ 0x51, 0x71, 0x61 ], [ 0x51, 0x71, 0x69 ], [ 0x51, 0x71, 0x71 ], [ 0x51, 0x69, 0x71 ], [ 0x51, 0x61, 0x71 ], [ 0x51, 0x59, 0x71 ], [ 0x00, 0x00, 0x41 ], [ 0x10, 0x00, 0x41 ], [ 0x20, 0x00, 0x41 ], [ 0x31, 0x00, 0x41 ],
+ [ 0x41, 0x00, 0x41 ], [ 0x41, 0x00, 0x31 ], [ 0x41, 0x00, 0x20 ], [ 0x41, 0x00, 0x10 ], [ 0x41, 0x00, 0x00 ], [ 0x41, 0x10, 0x00 ], [ 0x41, 0x20, 0x00 ], [ 0x41, 0x31, 0x00 ], [ 0x41, 0x41, 0x00 ], [ 0x31, 0x41, 0x00 ],
+ [ 0x20, 0x41, 0x00 ], [ 0x10, 0x41, 0x00 ], [ 0x00, 0x41, 0x00 ], [ 0x00, 0x41, 0x10 ], [ 0x00, 0x41, 0x20 ], [ 0x00, 0x41, 0x31 ], [ 0x00, 0x41, 0x41 ], [ 0x00, 0x31, 0x41 ], [ 0x00, 0x20, 0x41 ], [ 0x00, 0x10, 0x41 ],
+ [ 0x20, 0x20, 0x41 ], [ 0x28, 0x20, 0x41 ], [ 0x31, 0x20, 0x41 ], [ 0x39, 0x20, 0x41 ], [ 0x41, 0x20, 0x41 ], [ 0x41, 0x20, 0x39 ], [ 0x41, 0x20, 0x31 ], [ 0x41, 0x20, 0x28 ], [ 0x41, 0x20, 0x20 ], [ 0x41, 0x28, 0x20 ],
+ [ 0x41, 0x31, 0x20 ], [ 0x41, 0x39, 0x20 ], [ 0x41, 0x41, 0x20 ], [ 0x39, 0x41, 0x20 ], [ 0x31, 0x41, 0x20 ], [ 0x28, 0x41, 0x20 ], [ 0x20, 0x41, 0x20 ], [ 0x20, 0x41, 0x28 ], [ 0x20, 0x41, 0x31 ], [ 0x20, 0x41, 0x39 ],
+ [ 0x20, 0x41, 0x41 ], [ 0x20, 0x39, 0x41 ], [ 0x20, 0x31, 0x41 ], [ 0x20, 0x28, 0x41 ], [ 0x2D, 0x2D, 0x41 ], [ 0x31, 0x2D, 0x41 ], [ 0x35, 0x2D, 0x41 ], [ 0x3D, 0x2D, 0x41 ], [ 0x41, 0x2D, 0x41 ], [ 0x41, 0x2D, 0x3D ],
+ [ 0x41, 0x2D, 0x35 ], [ 0x41, 0x2D, 0x31 ], [ 0x41, 0x2D, 0x2D ], [ 0x41, 0x31, 0x2D ], [ 0x41, 0x35, 0x2D ], [ 0x41, 0x3D, 0x2D ], [ 0x41, 0x41, 0x2D ], [ 0x3D, 0x41, 0x2D ], [ 0x35, 0x41, 0x2D ], [ 0x31, 0x41, 0x2D ],
+ [ 0x2D, 0x41, 0x2D ], [ 0x2D, 0x41, 0x31 ], [ 0x2D, 0x41, 0x35 ], [ 0x2D, 0x41, 0x3D ], [ 0x2D, 0x41, 0x41 ], [ 0x2D, 0x3D, 0x41 ], [ 0x2D, 0x35, 0x41 ], [ 0x2D, 0x31, 0x41 ], [ 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00 ],
+ [ 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00 ],
+]
+
+
+def set_palette(colors, start=0) :
+ for co in colors :
+ r, g, b = co
+ sys.stdout.write("\x1b]4;%i;rgb:%2.2x/%2.2x/%2.2x\x1b\\"%(start, r, g, b))
+ start=start+1
+
+def fg(ci) :
+ return '\x1B[38;5;%im'%int(ci)
+
+def bg(ci) :
+ return '\x1B[48;5;%im'%int(ci)
+
+if __name__=='__main__' :
+ set_palette(vga_palette)
+ print fg(44)+bg(246)+'Hello, color world.'+fg(TC_WHITE)+bg(TC_BLACK)
+ for i in xrange(16) :
+ for j in xrange(16) :
+ print fg(0)+bg(i*16+j)+' %3i '%(i*16+j),
+ print fg(TC_WHITE)+bg(TC_BLACK)
+# set_palette(vga_palette)
+# for i in xrange(16) :
+# for j in xrange(16) :
+# print fg(0)+bg(i*16+j)+' %3i '%(i*16+j),
+# print fg(TC_WHITE)+bg(TC_BLACK)

0 comments on commit f8226b5

Please sign in to comment.
Something went wrong with that request. Please try again.