sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

index.md (2990B)


      1 colored status text
      2 ===================
      3 
      4 Description
      5 -----------
      6 This patch enables colored text in the status bar. It changes the way colors
      7 are defined in config.h, allowing the user to define multiple color
      8 combinations for use in their status script.
      9 
     10 Configuration
     11 -------------
     12 Download the patch and apply it according to the [general instructions](../).
     13 
     14 Modify the colors definition in 'config.h' to suit your needs. Make sure to
     15 define at least 3 colors as they will be used for 'normal', 'selected', and
     16 'urgent' windows, respectively.
     17 
     18 Usage
     19 -----
     20 Add code to your status script to output the raw characters '\x03' to switch to
     21 the 'urgent' color, or '\x04' to switch to the 4th defined color, etc. Note
     22 that the color indices in the status text are +1 from the definition in
     23 'config.h' (because '\0' is the string terminator). To switch back to the
     24 normal text color use '\x01'. To enter the raw character '\x01' in vim, press
     25 ctrl+v followed by x, 0, and 1 in that order. '\x01' gives the first character,
     26 which appears as a bold "A" on the screen to distinguish it from the regular
     27 character A.
     28 
     29 ### Example
     30 
     31 The following definition in 'config.h':
     32 
     33 	#define NUMCOLORS         4
     34 	static const char colors[NUMCOLORS][MAXCOLORS][8] = {
     35 		// border   foreground background
     36 		{ "#000033", "#dddddd", "#000033" },  // normal
     37 		{ "#000088", "#ffffff", "#000088" },  // selected
     38 		{ "#ff0000", "#000000", "#ffff00" },  // urgent/warning  (black on yellow)
     39 		{ "#ff0000", "#ffffff", "#ff0000" },  // error (white on red)
     40 		// add more here
     41 	};
     42 
     43 Coupled with a matching status script produces the following: ![Example Colored
     44 Status Text](statuscolors.png)
     45 
     46 A really silly example:
     47 
     48 	echo -e "normal \x01 selected \x03 warning/urgent \x04 error \x01 back to normal text" | dwm
     49 
     50 An example status script snippet to take advantage of the colors:
     51 
     52 	status=""
     53 	if [$batperc -le 10]; then
     54 		# use "warning" color
     55 		status+="\x03 BAT: $batperc"
     56 	elif [$batperc -le 5]; then
     57 		# use "error" color
     58 		status+="\x04 BAT: $batperc"
     59 	else
     60 		# default is normal color
     61 		status+="BAT: $batperc"
     62 	fi
     63 
     64 	# switch back to normal color for date
     65 	status+="\x01| "+$(date)
     66 
     67 	echo -e $status
     68 
     69 Download
     70 --------
     71 * [dwm-5.7.2-statuscolors.diff](dwm-5.7.2-statuscolors.diff)
     72 * [dwm-5.8.2-statuscolors.diff](dwm-5.8.2-statuscolors.diff)
     73 * [dwm-statuscolors-5.9.diff](dwm-statuscolors-5.9.diff)
     74 * [dwm-statuscolors-6.1.diff](dwm-statuscolors-6.1.diff)
     75 * [dwm-statuscolors-20181008-b69c870.diff](dwm-statuscolors-20181008-b69c870.diff)
     76 * [dwm-statuscolors-20220322-bece862.diff](dwm-statuscolors-20220322-bece862.diff)
     77 Minor update to make Danny's patch apply again.
     78 
     79 Authors
     80 -------
     81 * Jeremy Jay - [(original patch)](//lists.suckless.org/dwm/0812/7023.html)
     82 * Axel Bayerl - (update to 5.7.2)
     83 * Voltaic - (update to 5.8.2, 5.9)
     84 * Daniel Raloff (update to 6.1)
     85 * Dave Kennedy (fixes to 6.1)
     86 * Danny O'Brien - [danny@spesh.com](mailto:danny@spesh.com) (20181008 patch)
     87 * [danso](https://danso.ca) (20220322 patch)