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

Discussion in 'Python' started by qwweeeit, Dec 12, 2005.

  1. qwweeeit

    qwweeeit Guest

    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.
     
    qwweeeit, Dec 12, 2005
    #1
    1. Advertising

  2. qwweeeit

    gene tani Guest

    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.
     
    gene tani, Dec 12, 2005
    #2
    1. Advertising

  3. qwweeeit

    qwweeeit Guest

    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.
     
    qwweeeit, Dec 14, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Hunter

    building 2.1 with LFS

    John Hunter, Aug 25, 2004, in forum: Python
    Replies:
    0
    Views:
    307
    John Hunter
    Aug 25, 2004
  2. John Hunter

    lfs confusion

    John Hunter, Sep 23, 2004, in forum: Python
    Replies:
    7
    Views:
    497
    John Hunter
    Sep 24, 2004
  3. qwweeeit

    Colorize expanded tabs

    qwweeeit, Dec 4, 2005, in forum: Python
    Replies:
    2
    Views:
    403
    qwweeeit
    Dec 4, 2005
  4. Mr. Travis

    LFS for Windows apps

    Mr. Travis, Jul 11, 2005, in forum: C Programming
    Replies:
    11
    Views:
    598
    Kenny McCormack
    Jul 12, 2005
  5. ton
    Replies:
    2
    Views:
    2,191
Loading...

Share This Page