List text files showing LFs and expanded tabs (was: Colorize expanded tabs)

Q

qwweeeit

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.
 
G

gene tani

qwweeeit said:
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.
 
Q

qwweeeit

Hi Gene,
thank you for your reply, also if my post was meant to be only
an exercise to apply color to lfs and expanded tabs in listing
files and not to apply it to an editor.
However your comment has directed me to consider more
deeply other editors (I use kwrite).
I am inclined to change to vim but I haven't found the
vim module for python.
By the way I'm not sure that vim can display lfs and expanded
tabs in color!
Bye.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,832
Latest member
GlennSmall

Latest Threads

Top