Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Brain fried -- Core dumped


devel / comp.lang.python / Re: How to Add ANSI Color to User Response

SubjectAuthor
o Re: How to Add ANSI Color to User ResponseAlan Gauld

1
Re: How to Add ANSI Color to User Response

<mailman.90.1712788887.3468.python-list@python.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=29836&group=comp.lang.python#29836

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: learn2program@gmail.com (Alan Gauld)
Newsgroups: comp.lang.python
Subject: Re: How to Add ANSI Color to User Response
Date: Wed, 10 Apr 2024 23:41:23 +0100
Lines: 37
Message-ID: <mailman.90.1712788887.3468.python-list@python.org>
References: <E07728FE-3599-462D-B572-107C5D53C72F@yahoo.com>
<1b305568-7ba1-4329-9f39-a0d22d769272@yahoo.co.uk>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de cJls+6+sZvb4xiB0Dk50TQE8C2fQAdIziE0kYGmVcdSQ==
Cancel-Lock: sha1:ZGPDdzTKLqDDb+/b+TPTVcyGoUg= sha256:0cNxdhpuRI1dLfAX+X7NXRfmHg6h3sDYAgl2bx4gf2c=
Return-Path: <learn2program@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=fBhtpNoC;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.004
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'def': 0.04; 'subject:Add':
0.04; 'string': 0.07; 'ansi': 0.09; 'else:': 0.09; 'terminal':
0.09; 'import': 0.15; 'flickr': 0.16; 'from:name:alan gauld':
0.16; 'init': 0.16; 'jython': 0.16; 'message-id:@yahoo.co.uk':
0.16; 'photo-blog': 0.16; 'subject:User': 0.16; 'url-
ip:79.170.44.132/32': 0.16; 'url-ip:79.170.44/24': 0.16; 'url-
ip:79.170/16': 0.16; 'url-ip:79/8': 0.16; 'url:alan-g': 0.16;
'url:alan_gauld': 0.16; 'url:alangauldphotos': 0.16; 'wrote:':
0.16; 'url:amazon': 0.19; 'to:addr:python-list': 0.20; 'code':
0.23; 'subject:How': 0.23; "i'd": 0.24; 'to:name:python-
list@python.org': 0.24; 'suspect': 0.26; 'header:User-Agent:1':
0.30; 'program': 0.31; 'python-list': 0.32; 'received:192.168.1':
0.32; 'but': 0.32; 'there': 0.33; 'header:In-Reply-To:1': 0.34;
'received:google.com': 0.34; 'question.': 0.35; 'following': 0.35;
'from:addr:gmail.com': 0.35; 'work,': 0.36; "skip:' 10": 0.37;
'author': 0.37; 'received:192.168': 0.37; 'way': 0.38; 'adding':
0.39; 'text': 0.39; 'use': 0.39; 'alan': 0.40; 'learn': 0.40;
'color': 0.62; 'follow': 0.62; 'look': 0.65; 'coloring': 0.69;
'url:author': 0.69; 'site': 0.70; 'skip:f 20': 0.75; 'choice':
0.76; 'subject:Color': 0.84; 'subject:Response': 0.91; 'colors':
0.93
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20230601; t=1712788885; x=1713393685; darn=python.org;
h=content-transfer-encoding:in-reply-to:content-language:references
:to:subject:user-agent:mime-version:date:message-id:from:from:to:cc
:subject:date:message-id:reply-to;
bh=CES+YHNlIqdqmzZ5330cAxI5kycf6yBzNzvQiGwNzI8=;
b=fBhtpNoCRiKzqZ3YzzTIl93q1OLw7kGjwHAbgif/B22afYPYjr6kTEGCf7i7h1YCXp
pvn9uXk/IJImO5Gblqt1Jr0N2RQj8X9sadHvsP4tm9apCvlZGpri/V1r5AuPs04VVPj9
18JR6LABtMCD52hARCPWri7/5f3/bBjNXKwEg2sYVR+3+iIaD13A833IqUhRoItuF21B
MAsY3cpOKBAbZn6B9Yj7NMBje1iRCeXpg2K98qSAj+6/ywiQhpm2tes9K4FQeboYAQYA
nQj4nHvvraPXroadrDD544h+8rvivp/SImV9EVxhwMMdYgJmcX2zK+/lmwDrnuQKbGKu
dMBA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20230601; t=1712788885; x=1713393685;
h=content-transfer-encoding:in-reply-to:content-language:references
:to:subject:user-agent:mime-version:date:message-id:from
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
bh=CES+YHNlIqdqmzZ5330cAxI5kycf6yBzNzvQiGwNzI8=;
b=WQmC1PeeCfTtNNkg08K/C1cvORHZGXR0cbwO53XBr3VqzsW04tNW/T5vm1Bba46qMt
NjcAsD8Vc44DKVTqkIHjXPPKSVLneLdHwGWrWKkX7H/zDWLC01nt3XHkiLvHsLZwYrU+
Irx/67qnzyUqmPrT/jDKdHNdjBJjhoIeh9hx85oDoXVjp2qvT5TCLj84w2KAeT8vXtnG
bfuzCkcDx0XtJKgW8z8QbxfxgsxcvsVciaxofeyWvxbt6knuI2NdBpD7TyKTd6lWF2Io
w/bJPi6NkqWUMtyMvyKDVGf+Gv1kQHRGZqjvXmgkXFeIGfjJD+Du70GWVuVBGZW0ETcT
NiEA==
X-Forwarded-Encrypted: i=1;
AJvYcCUPZoIZF3cd1pNorORSXrPu8RdjWE5Mw1mYP7ItRNKO1uNrZCYdJAMCk0Lhv3QgBjiHcu6Ze1k5TEC1VVZQeusPQvSQARst
X-Gm-Message-State: AOJu0Yzo28GpNSh31eLifJlBEnQK1C/AP2nu5IsRwrdp9dfHYwja0mCp
pUOnyQRJ+CGmA8WpuQDZfvQCV+in2aUXggWd/eW6H8PXcGsq6cAq
X-Google-Smtp-Source: AGHT+IHGCHuIZ+HXrBCyvQHzOZtf4PgG8T4GAQWE7P2Zjh/85sdli6FKyT2wSyZD7RCAHP+wEzOCNA==
X-Received: by 2002:adf:fcc8:0:b0:33e:a5e1:eccc with SMTP id
f8-20020adffcc8000000b0033ea5e1ecccmr2659231wrs.68.1712788884777;
Wed, 10 Apr 2024 15:41:24 -0700 (PDT)
X-Google-Original-From: Alan Gauld <alan.gauld@yahoo.co.uk>
User-Agent: Mozilla Thunderbird
Content-Language: en-GB
In-Reply-To: <E07728FE-3599-462D-B572-107C5D53C72F@yahoo.com>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <1b305568-7ba1-4329-9f39-a0d22d769272@yahoo.co.uk>
X-Mailman-Original-References: <E07728FE-3599-462D-B572-107C5D53C72F@yahoo.com>
 by: Alan Gauld - Wed, 10 Apr 2024 22:41 UTC

On 10/04/2024 19:50, WordWeaver Evangelist via Python-list wrote:

> I have a simple question. I use the following textPrompt in some of my Jython modules:
> '\nYour choice is? (A B C D E): ', maxChars=1, autoAccept=False, forceUppercase=True)
> Is there a way to add an ANSI color code to the end

Normally, for any kind of fancy terminal work, I'd say use curses.
But I suspect Jython may not support curses?

On the offchance it does do curses it would look like:

import curses

def main(scr):
if curses.has_colors(): # check the terminal supports color
curses.start_color(). # init the color system
curses.init_pair(1,curses.COLOR_YELLOW,curses.COLOR_BLUE)

# Now start adding text coloring as desired...
scr.addstr(0,0,"This string is yellow and blue",
curses.color_pair(1))

scr.refresh(). # make it visible
else: scr.addstr("Sorry, no colors available")

curses.wrapper(main)

HTH
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor