File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -142,9 +142,9 @@ anywhere. Use the combination
142142to read a bits dump instead of a hex dump.
143143.TP
144144.IR \- R " " when
145- In the output the hex-value and the value are both colored with the same color
146- depending on the hex-value. Mostly helping to differentiate printable and
147- non-printable characters.
145+ In the output both the data column (hex, or bits with \- b) and the character
146+ column are colored with the same color depending on the byte value. Mostly
147+ helping to differentiate printable and non-printable characters.
148148.I \fI when \fP
149149is
150150.BR never " , " always " , or " auto " (default: auto).
Original file line number Diff line number Diff line change @@ -101,11 +101,12 @@ OPTIONS
101101 instead of a hex dump.
102102
103103 -R when
104- In the output the hex-value and the value are both colored with
105- the same color depending on the hex-value. Mostly helping to
106- differentiate printable and non-printable characters. when is
107- never, always, or auto (default: auto). When the $NO_COLOR en‐
108- vironment variable is set, colorization will be disabled.
104+ In the output both the data column (hex, or bits with -b) and
105+ the character column are colored with the same color depending
106+ on the byte value. Mostly helping to differentiate printable and
107+ non-printable characters. when is never, always, or auto (de‐
108+ fault: auto). When the $NO_COLOR environment variable is set,
109+ colorization will be disabled.
109110
110111 -seek offset
111112 When used after -r: revert with <offset> added to file positions
Original file line number Diff line number Diff line change @@ -663,6 +663,22 @@ call writefile(data,'Xinput')
663663
664664endfunc
665665
666+ func Test_xxd_color_bits ()
667+ " Binary output (-b) should be colored per byte like the hex output,
668+ " see issue #20385. Bytes cover the white/yellow/green/blue color groups.
669+ let s: test = 1
670+ call writefile (0z000941FF , ' Xxxdbits' )
671+
672+ % d
673+ exe ' 0r! ' . s: xxd_cmd . ' -b -R always -c 4 Xxxdbits'
674+ $d
675+ let expected = [
676+ \ " 00000000: \e [1;37m00000000\e [0m \e [1;33m00001001\e [0m \e [1;32m01000001\e [0m \e [1;34m11111111\e [0m \e [1;37m.\e [0m\e [1;33m.\e [0m\e [1;32mA\e [0m\e [1;34m.\e [0m" ]
677+ call assert_equal (expected, getline (1 , ' $' ), s: Mess (s: test ))
678+
679+ call delete (' Xxxdbits' )
680+ endfunc
681+
666682func Test_xxd_color2 ()
667683 CheckScreendump
668684 CheckUnix
Original file line number Diff line number Diff line change @@ -729,6 +729,8 @@ static char *(features[]) =
729729
730730static int included_patches [] =
731731{ /* Add new patch number below this line */
732+ /**/
733+ 580 ,
732734/**/
733735 579 ,
734736/**/
Original file line number Diff line number Diff line change 7575 * 19.03.2026 Add -t option to end output with terminating null
7676 * 25.03.2026 Fix color output issues
7777 * 26.04.2026 Use unsigned long for printing offsets
78+ * 31.05.2026 Colorize binary output
7879 *
7980 * (c) 1990-1998 by Juergen Weigert (jnweiger@gmail.com)
8081 *
@@ -155,7 +156,7 @@ extern void perror __P((char *));
155156# endif
156157#endif
157158
158- char version [] = "xxd 2026-04-26 by Juergen Weigert et al." ;
159+ char version [] = "xxd 2026-05-31 by Juergen Weigert et al." ;
159160#ifdef WIN32
160161char osver [] = " (Win32)" ;
161162#else
@@ -1194,8 +1195,15 @@ main(int argc, char *argv[])
11941195 }
11951196 else /* hextype == HEX_BITS */
11961197 {
1198+ if (color )
1199+ cur_color = get_color_char (e , ebcdic );
1200+
11971201 for (i = 7 ; i >= 0 ; i -- )
1198- l [c ++ ] = (e & (1 << i )) ? '1' : '0' ;
1202+ {
1203+ if (color )
1204+ colors [c ] = cur_color ;
1205+ l [c ++ ] = (e & (1 << i )) ? '1' : '0' ;
1206+ }
11991207 }
12001208 if (e )
12011209 nonzero ++ ;
You can’t perform that action at this time.
0 commit comments