Last active
December 15, 2015 07:09
-
-
Save valvallow/5221622 to your computer and use it in GitHub Desktop.
terminal一杯にランダムに背景色をセットし続けるtputのサンプル
This file contains 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
#!/usr/local/bin/gosh | |
(use gauche.process) | |
(use math.mt-random) | |
(define (main args) | |
(define rand | |
(let1 m (make <mersenne-twister> :seed (sys-time)) | |
(^n (mt-random-integer m n)))) | |
(define (get-tput-val . args) | |
(process-output->string `(tput ,@args))) | |
(define (tput . args) | |
(run-process `(tput ,@args))) | |
(define (make-random-color) | |
#`",(string #\\escape)[4,(+ (rand 8) 1)m ,(string #\\escape)[0m") | |
(let ((cols (x->integer (get-tput-val 'cols))) | |
(lines (x->integer (get-tput-val 'lines)))) | |
(dynamic-wind | |
(^ _ (tput 'civis)(tput 'clear)) | |
(^ _ (let1 size (iota (* cols lines)) | |
(display (apply string-append (map (^_ (make-random-color)) size))) | |
(while #t | |
(for-each (^_ (tput 'cup (rand lines)(rand cols)) | |
(display (make-random-color)) | |
(sys-nanosleep 1000000) | |
(flush)) | |
size)))) | |
(^ _ (tput 'cnorm))))) |
This file contains 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
#!/usr/local/bin/gosh | |
(use gauche.process) | |
(use math.mt-random) | |
(define (main args) | |
(define rand | |
(let1 m (make <mersenne-twister> :seed (sys-time)) | |
(^n (mt-random-integer m n)))) | |
(define (get-tput-val . args) | |
(process-output->string `(tput ,@args))) | |
(define (tput . args) | |
(run-process `(tput ,@args))) | |
(define (make-random-color) | |
#`",(string #\\escape)[4,(+ (rand 8) 1)m ,(string #\\escape)[0m") | |
(let1 cols (x->integer (get-tput-val 'cols)) | |
(while #t | |
(for-each (^_ (display (make-random-color)) | |
(sys-nanosleep 10000000) | |
(flush)) | |
(iota cols)) | |
(display "\r")))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment