Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > List text files showing LFs and expanded tabs (was: Colorize expanded tabs)

Reply
Thread Tools

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

 
 
qwweeeit
Guest
Posts: n/a
 
      12-12-2005
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))%*' '+"\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.

 
Reply With Quote
 
 
 
 
gene tani
Guest
Posts: n/a
 
      12-12-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))%*' '+"\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.

 
Reply With Quote
 
 
 
 
qwweeeit
Guest
Posts: n/a
 
      12-14-2005
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
AJAX Treeview How to keep expanded nodes expanded during AJAX postback ton ASP .Net 2 12-10-2008 04:11 PM
Colorize expanded tabs qwweeeit Python 2 12-04-2005 10:06 PM
lfs confusion John Hunter Python 7 09-24-2004 11:22 AM
Copy text from Google groups postings; CRs, LFs are lost (Firefox 0.9.3) L Mehl Firefox 3 09-02-2004 04:39 AM
building 2.1 with LFS John Hunter Python 0 08-25-2004 12:46 PM



Advertisments