473,598 Members | 3,252 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Colorize expanded tabs

Hi all,
from a string embedding tabs I want to colorize them when expanded:

# Starting from a string:
a= '1234\t5678\t\t 90\nqwerty\nasd fg'
# which embeds both tabs and lfs

# printing it you obtain:
print a
# 1234 5678 90
# qwerty
# asdfg

# print automatically expands tabs and interprets the NL.

# to colorize the expanded tabs, I tried:
print a.replace('\t', "\033[41m\t\033[0m") # 41 = red color
# instead it works (in Linux) for the \n (substituted with a red
space):
print a.replace('\n', "\033[41m \033[0m\n")

Can you help me?
Bye.

Dec 4 '05 #1
2 1533
qwweeeit wrote:
Hi all,
from a string embedding tabs I want to colorize them when expanded:

# Starting from a string:
a= '1234\t5678\t\t 90\nqwerty\nasd fg'
# which embeds both tabs and lfs

# printing it you obtain:
print a
# 1234 5678 90
# qwerty
# asdfg

# print automatically expands tabs and interprets the NL.

# to colorize the expanded tabs, I tried:
print a.replace('\t', "\033[41m\t\033[0m") # 41 = red color
# instead it works (in Linux) for the \n (substituted with a red
space):
print a.replace('\n', "\033[41m \033[0m\n")

Can you help me?
Bye.


If all else fails you can colorize the tabs after converting them to
spaces:

def splititer(text, token):
# A lazy iter(text.split (token)).
# Probably not worth the effort.
start = 0
while True:
try:
end = text.index(toke n, start)
except ValueError:
break
yield text[start:end]
start = end + len(token)
yield text[start:]

def colortabs(text, tabcolor, normcolor, tabwidth=8):
parts = splititer(text, "\t")
part = parts.next()
pos = len(part)
yield part
for part in parts:
width = tabwidth - pos % tabwidth
yield tabcolor
yield " " * width
yield normcolor
yield part
pos += width + len(part)

print "\t1234\t5678\t \t90".replace(" \t", "\033[41m\t\033[0m")
print "".join(colorta bs("\t1234\t567 8\t\t90", "\033[41m", "\033[0m"))

Peter

Dec 4 '05 #2
Hi Peter,
thank you for your replay, but I was looking for a very
short routine. I even had in mind to use Linux & bash
(only one command line).
It seems that tab expansion, made by print, prevents
the working of the escape sequences for colors.
In fact, if you replace tab with a given number of spaces,
all works well.
That is :
print "\t1234\t5678\t \t90".replace(" \t", "\033[41m \033[0m")
correctly colorizes in red the spaces replacing the tabs...
Unfortunately this is not tab expansion!
Bye.

Dec 4 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2524
by: tanpan | last post by:
Hi i'm looking for free php code which will colorize my html source (structure). please help me if u can :) pozdr puipui
0
3039
by: Francois Verbeeck | last post by:
Dear UseNet readers, Does anyone have any idea on how to colorize selected checkbox in checkboxlist control ? I've quite a huge checkboxlist (approximatively one full screen) and, to improve user's experience, i wanted to highlight selected choices. Does anyone know how to that ? I can successfully do that on a datagrid by adding some code during
2
1398
by: qwweeeit | last post by:
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)
0
911
by: Christian Perthen | last post by:
Hi, How do I get Visual Studio 2005 to colorize vbscript syntax as it does in InterDev? I am getting tired of having both apps launched. Thanks Christian
135
7431
by: Xah Lee | last post by:
Tabs versus Spaces in Source Code Xah Lee, 2006-05-13 In coding a computer program, there's often the choices of tabs or spaces for code indentation. There is a large amount of confusion about which is better. It has become what's known as “religious war” — a heated fight over trivia. In this essay, i like to explain what is the situation behind it, and which is proper.
0
887
by: Marius Matioc | last post by:
New in VS2005 is the colorize inactive feature. However, it seems not to be able to handle _DEBUG. Sections of code bracketed by "#ifdef _DEBUG" are grayed out (or not) in an unpredictable fashion. Is this a know problem, or just something wrong with my setup? Thanks, Marius Matioc
4
5206
by: MrNobody | last post by:
Let's say I have an image which is monochrome with areas of white, black and shades of gray. Now I want to turn all the white parts into some RGB color but it also needs to be darkened by the gray areas for the same color. Like say it's an image of a sphere, it is white in the part it is under the light but then as you get away from the light source it becomes darker and darker gray. Now I want to take this image and apply just one RGB...
6
1764
by: Stephen Edwards | last post by:
I am a novice, so bear with me. I designed a website using CSS TABS, all was fine, then I copy and pasted meta name, etc for keywords, tweaking it where necessary for keywords. I did not notice any problems until I looked at the site and although the text for the tabs was showing up the images which make up the tabs weren't. I have no idea why this has happened, can I have some advice as to what to check, and how to fix it, thank...
7
3752
by: Phil Reynolds | last post by:
I'm using a tab control in Access 2000, and the user requested to have buttons in the form header, instead of the built-in tabs (so that when they scroll down, they can still switch tabs). Now, this works fine. However, when I'm in Design View, I can't access the tabs without changing the tab control's Style back to Tabs. But I want to be able to place controls in that space at the top where the tabs used to be. But if I need to turn the...
0
8392
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8397
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
6718
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5850
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5438
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3939
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2412
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1504
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1250
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.