colourful xterms

Hi, A couple of days a made a trivial hack that made me very happy, so I want to share the trick here. The trick is to start rxvt-unicode with -bg \\#`randcolor.py` -fg \\#EEEEEE where randcolor is a simple python script that returns a random hex color with rgb random in range(0..100) (to be dark enough for white font): #!/usr/bin/env python from random import * rs=["%X"%(int(uniform(0,100))) for x in range(3)] s='' for x in rs: while len(x)<2: x="0"+x s+=x print s The outcome is that every term you start has slightly different shade of background. This not only makes your screen much more colourful and nice, but also helps with 0 or 1 pixel borders as terminals now clearly separate into areas on the screen of different colors so it is actually very useful! Best, anže phone: +1 (510) 495 2488, mobile: +1 (510) 289 9395, fax: +1 (510) 486 7149 -- "Speaking as a Jew on Christmas, I would be less shocked if Santa Claus showed up to my house than if Bernie Madoff pulled off this fraud alone." [Ron Geffner]

2009/6/4 Anze Slosar
Hi,
A couple of days a made a trivial hack that made me very happy, so I want to share the trick here. The trick is to start rxvt-unicode with
http://www.steike.com/code/xterm-colors/ -- Thomas Adam

On Thu, 4 Jun 2009 13:33:54 -0700 (PDT)
Anze Slosar
A couple of days a made a trivial hack that made me very happy, so I want to share the trick here. The trick is to start rxvt-unicode with
-bg \\#`randcolor.py` -fg \\#EEEEEE
where randcolor is a simple python script that returns a random hex color with rgb random in range(0..100) (to be dark enough for white font): ......
Yeah, I liked that idea several years ago, it was inspired by old OpenWindows by Sun :) Actually to avoid "extra dependency" on python you can use a shell variable: # echo $RANDOM it will print a random number every time you use it. Cheers, Sergey

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA512 On Thu, Jun 4, 2009 at 5:10 PM, Sergey Manucharian wrote: -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEAREKAAYFAkooQtkACgkQvpDo5Pfl1oJn3QCgikW0q5sF7C30XexAzl7/gG9G wlkAnj4x8RIOHPXr8sYc69NC2JYZVxMS =vC9o -----END PGP SIGNATURE-----
Yeah, I liked that idea several years ago, it was inspired by old OpenWindows by Sun :)
Actually to avoid "extra dependency" on python you can use a shell variable: # echo $RANDOM it will print a random number every time you use it.
Cheers, Sergey
Sure, but then he'd need to scale it. $RANDOM outputs between 0 and 32767, not 0-100. -- gwern

Gwern Branwen
Sure, but then he'd need to scale it. $RANDOM outputs between 0 and 32767, not 0-100.
OK, in zsh, something like: printf %d $((RANDOM/327.67)) Of course, none of these are likely to be as good as just using python (or some other suitable language). For example the zsh example's not likely enough to produce 100. (Hmm, actually wouldn't hex be just as good? In which case a shell-based answer might be adequate (use printf %02x)?)

* On Thursday, June 04 2009, Bruce Stephens wrote:
Gwern Branwen
writes: [...]
Sure, but then he'd need to scale it. $RANDOM outputs between 0 and 32767, not 0-100.
OK, in zsh, something like:
printf %d $((RANDOM/327.67))
Of course, none of these are likely to be as good as just using python (or some other suitable language). For example the zsh example's not
Haskell:
import System.Random import Numeric import XMonad import Control.Monad
randomHex :: (Integral a, Random a) => (a, a) -> IO [Char] randomHex = fmap (concatMap $ ensure 2 . ($ "") . showHex) . replicateM 3 . randomRIO where ensure n = reverse . take n . (++repeat '0') . reverse
randomBg :: (Int,Int) -> X () randomBg x = do t <- asks terminal io $ spawn . ((t++" -bg '#")++) . (++"'") =<< randomHex x

I was already betting with myself, when the first Haskell solution would be finally posted ;) Thanks so much! Best, Thomas Adam Vogt wrote:
* On Thursday, June 04 2009, Bruce Stephens wrote:
Gwern Branwen
writes: [...]
Sure, but then he'd need to scale it. $RANDOM outputs between 0 and 32767, not 0-100.
OK, in zsh, something like:
printf %d $((RANDOM/327.67))
Of course, none of these are likely to be as good as just using python (or some other suitable language). For example the zsh example's not
Haskell:
import System.Random import Numeric import XMonad import Control.Monad
randomHex :: (Integral a, Random a) => (a, a) -> IO [Char] randomHex = fmap (concatMap $ ensure 2 . ($ "") . showHex) . replicateM 3 . randomRIO where ensure n = reverse . take n . (++repeat '0') . reverse
randomBg :: (Int,Int) -> X () randomBg x = do t <- asks terminal io $ spawn . ((t++" -bg '#")++) . (++"'") =<< randomHex x
_______________________________________________ xmonad mailing list xmonad@haskell.org http://www.haskell.org/mailman/listinfo/xmonad

On Thu, 4 Jun 2009 17:55:36 -0400
Gwern Branwen
Sure, but then he'd need to scale it. $RANDOM outputs between 0 and 32767, not 0-100. .......
-------------------------8<------------------------- #!/bin/bash R_BASE=32768 G_BASE=32768 B_BASE=32768 `printf "xterm -bg rgb:%04x/%04x/%04x\n" $(($R_BASE+$RANDOM)) $(($G_BASE+$RANDOM)) $(($B_BASE+$RANDOM))` -------------------------8<------------------------- (the last expression must be on the single line, of course) Cheers, Sergey

On Thu, 4 Jun 2009 16:39:38 -0600
Sergey Manucharian
-------------------------8<------------------------- #!/bin/bash R_BASE=32768 G_BASE=32768 B_BASE=32768
`printf "xterm -bg rgb:%04x/%04x/%04x\n" $(($R_BASE+$RANDOM)) $(($G_BASE+$RANDOM)) $(($B_BASE+$RANDOM))` -------------------------8<-------------------------
My previous example is closer to white, to make it darker: -------------------------8<------------------------- #!/bin/bash R_BASE=16384 G_BASE=16384 B_BASE=16384 SC=2 # scale factor, num of bits to shift `printf "xterm -bg rgb:%04x/%04x/%04x\n" $(($R_BASE+($RANDOM>>$SC))) $(($G_BASE+($RANDOM>>$SC))) $(($B_BASE+($RANDOM>>$SC)))` -------------------------8<------------------------- Cheers, Sergey
participants (7)
-
Adam Vogt
-
Anze Slosar
-
Bruce Stephens
-
Gwern Branwen
-
Sergey Manucharian
-
Thomas Adam
-
Thomas Friedrich