The character color of terminal is controlled by escape sequence, it is the system display function in text mode, and the specific language is independent, Shell,python,perl and so on can be called.
The escape sequence starts with the ESC and can do the same with \033 (the ASCII code for ESC is in decimal notation is 27, = 33 in octal).
\033[display mode; background color m "background color can not be used, behind must end with m "
Display mode: 0 (default), 1 (highlight), 22 (not bold), 4 (underscore), 24 (non-underlined), 5 (blinking), 25 (non-flashing), 7 (inverted), 27 (non-inverting)
Foreground color: 30 (Black), 31 (red), 32 (green), 33 (yellow), 34 (blue), 35 (magenta), 36 (cyan), 37 (white)
Background color: 40 (Black), 41 (red), 42 (green), 43 (yellow), 44 (blue), 45 (magenta), 46 (cyan), 47 (white)
#!/usr/bin/env pythonsearch_name = ' Zhao ' name_list = [' Zhao ', ' Zhao ', ' Qian ', ' Sun ', ' du ', ' qi ', ' Wang ', ' Wei ', ' Li ', ' Wan G ', ' Zhao ', ' Zhou ', ' Wu ', ' Zhen ']if search_name in name_list: print "Find it", search_name first_num = 0 for n Ame_count in Xrange (Name_list.count (search_name)): next_num = Name_list[first_num:].index (search_name) Print "Times%d, the element is \033[2;31;40m%s \033[0m, and the index is%d"% (Name_count, Search_name, (Next_num + first_ num)) First_num + = Next_num + 1else: print "can ' t find it", search_name
Bash Shell terminal character color display