Minimalistic module for work with colors in Win32-console
Posted: Sun Jun 12, 2005 9:46 pm
#
# Minimalistic module for work with colors in Win32-console
#
# Tested in Windows 2000
#
------------ file w32cons.lsp -----------------------
(context 'WIN32-CONSOLE)
(import "kernel32.DLL" "GetStdHandle")
(import "kernel32.DLL" "SetConsoleTextAttribute")
(constant 'STD_OUTPUT_HANDLE 0xfffffff5)
(setq cons-color-constans '(BLA BLU GRE CYA RED MAG YEL WHI LBLA LBLU LGRE LCYA LRED LMAG LYEL LWHI) )
(setq cons-color-values '(0x0 0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8 0x9 0xA 0xB 0xC 0xD 0xE 0xF ) )
(map (lambda (x y) (constant x y)) cons-color-constans cons-color-values)
(define (cons-output-handle)
(GetStdHandle STD_OUTPUT_HANDLE))
(define (cons-attr-set attr)
(SetConsoleTextAttribute (cons-output-handle) attr))
(define (color-print foreground background )
(cons-attr-set (| (<< background 4) foreground))
(dolist (x (args)) (print x)))
------------ end file w32cons.lsp -----------------------
#Example-1
#Simple :) programmer can use:
(load "w32cons.lsp")
(WIN32-CONSOLE:color-print WIN32-CONSOLE:LBLU WIN32-CONSOLE:BLA "bla-bla-bla\n")
(WIN32-CONSOLE:color-print WIN32-CONSOLE:LYEL WIN32-CONSOLE:BLA "bla" "-" "bla" "-" "bla\n")
(print "Press any key to continue...\n")
(read-key)
#Example-2
#Lazy :) programmer can use:
(load "w32cons.lsp")
(map (lambda (x y) (constant x y)) WIN32-CONSOLE:cons-color-constans WIN32-CONSOLE:cons-color-values)
(define (cpr) (eval (append '(WIN32-CONSOLE:color-print) (args))) )
(cpr LBLU LBLA "bla-bla-bla1\n")
(cpr LGRE BLA "bla-bla-bla2\n")
(cpr LRED LBLA "bla-bla-bla3\n")
(cpr LCYA BLA "bla" "-" "bla" "-" "bla4\n")
(cpr LBLU CYA "bla" "-" "bla" "-" "bla5\n")
(cpr WHI BLA "Press any key to continue...\n")
(read-key)
# Minimalistic module for work with colors in Win32-console
#
# Tested in Windows 2000
#
------------ file w32cons.lsp -----------------------
(context 'WIN32-CONSOLE)
(import "kernel32.DLL" "GetStdHandle")
(import "kernel32.DLL" "SetConsoleTextAttribute")
(constant 'STD_OUTPUT_HANDLE 0xfffffff5)
(setq cons-color-constans '(BLA BLU GRE CYA RED MAG YEL WHI LBLA LBLU LGRE LCYA LRED LMAG LYEL LWHI) )
(setq cons-color-values '(0x0 0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8 0x9 0xA 0xB 0xC 0xD 0xE 0xF ) )
(map (lambda (x y) (constant x y)) cons-color-constans cons-color-values)
(define (cons-output-handle)
(GetStdHandle STD_OUTPUT_HANDLE))
(define (cons-attr-set attr)
(SetConsoleTextAttribute (cons-output-handle) attr))
(define (color-print foreground background )
(cons-attr-set (| (<< background 4) foreground))
(dolist (x (args)) (print x)))
------------ end file w32cons.lsp -----------------------
#Example-1
#Simple :) programmer can use:
(load "w32cons.lsp")
(WIN32-CONSOLE:color-print WIN32-CONSOLE:LBLU WIN32-CONSOLE:BLA "bla-bla-bla\n")
(WIN32-CONSOLE:color-print WIN32-CONSOLE:LYEL WIN32-CONSOLE:BLA "bla" "-" "bla" "-" "bla\n")
(print "Press any key to continue...\n")
(read-key)
#Example-2
#Lazy :) programmer can use:
(load "w32cons.lsp")
(map (lambda (x y) (constant x y)) WIN32-CONSOLE:cons-color-constans WIN32-CONSOLE:cons-color-values)
(define (cpr) (eval (append '(WIN32-CONSOLE:color-print) (args))) )
(cpr LBLU LBLA "bla-bla-bla1\n")
(cpr LGRE BLA "bla-bla-bla2\n")
(cpr LRED LBLA "bla-bla-bla3\n")
(cpr LCYA BLA "bla" "-" "bla" "-" "bla4\n")
(cpr LBLU CYA "bla" "-" "bla" "-" "bla5\n")
(cpr WHI BLA "Press any key to continue...\n")
(read-key)