List text files showing LFs and expanded tabs (was: Colorize expanded tabs)
gene tani
gene.tani at gmail.com
Mon Dec 12 11:46:23 EST 2005
qwweeeit wrote:
> Hi all,
> in a previous post I asked help for colorizing expanded tab.
> I wanted to list text files showing in colors LFs and the expanded
> tabs.
> I hoped to use only bash but, being impossible, I reverted to Python.
> I programmed a very short script .
> Here it is (... and I ask comments or critics):
>
> # for Linux users
> # starting from a list of all the lines of a text files (lFileList)
>
> nNP=9 # n. of Not Printables characters
> for line in lFileList:
> nTab= line.count('\t')
> if nTab > 0:
> for i in range(nTab):
> nPosTab=line.find('\t')
> line=line.replace('\t',"\033[41m"+\
> (8-(nPosTab-(nNP*i))%8)*' '+"\033[0m",1)
> print line.replace('\n',"\033[7m \033[0m\n"),
> print
>
> The Linux users can also use piping.
> For example:
> python lft.py lft.py|grep range
>
> correctly displays:
> for i in range(nTab):
> + the mark of the LF (a small white rectangle)
>
> Bye.
?? Whatever editor you use for python should do this: (vim, komodo,
textmate)show and convert hard tabs to soft, show CR-LF, etc.
More information about the Python-list
mailing list