Deutsch English Français Italiano |
<mailman.95.1712816224.3468.python-list@python.org> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!fu-berlin.de!uni-berlin.de!not-for-mail From: Thomas Passin <list1@tompassin.net> Newsgroups: comp.lang.python Subject: Re: How to Add ANSI Color to User Response Date: Wed, 10 Apr 2024 20:01:51 -0400 Lines: 37 Message-ID: <mailman.95.1712816224.3468.python-list@python.org> References: <E07728FE-3599-462D-B572-107C5D53C72F@yahoo.com> <1b305568-7ba1-4329-9f39-a0d22d769272@yahoo.co.uk> <36bf592b-d202-476f-b6d3-62af691a97cf@tompassin.net> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de AsIuS+g09u9Swmx7LPLNfQzCo0nMhaVHuCp2tUvAJtjg== Cancel-Lock: sha1:5cnYx4tjEwRiSia+PwtJriDsv/k= sha256:pT74Pot8BzcIQARDbS1LiPa8g//bGd72plI2TKSIOXU= Return-Path: <list1@tompassin.net> 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=tompassin.net header.i=@tompassin.net header.b=C9IfVFzR; dkim-adsp=pass; dkim-atps=neutral X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'def': 0.04; 'subject:Add': 0.04; 'library.': 0.05; 'string': 0.07; 'ansi': 0.09; 'else:': 0.09; 'terminal': 0.09; 'import': 0.15; 'colors.': 0.16; 'gauld': 0.16; 'init': 0.16; 'jython': 0.16; 'received:10.0.0': 0.16; 'received:64.90': 0.16; 'received:64.90.62': 0.16; 'received:64.90.62.162': 0.16; 'received:dreamhost.com': 0.16; 'stuck': 0.16; 'subject:User': 0.16; 'things,': 0.16; 'wrote:': 0.16; 'python': 0.16; 'probably': 0.17; 'pm,': 0.19; 'to:addr :python-list': 0.20; 'code': 0.23; 'subject:How': 0.23; "i'd": 0.24; 'interface': 0.26; 'suspect': 0.26; "isn't": 0.27; 'output': 0.28; 'header:User-Agent:1': 0.30; 'python-list': 0.32; 'received:10.0': 0.32; 'received:mailchannels.net': 0.32; 'received:relay.mailchannels.net': 0.32; 'but': 0.32; 'there': 0.33; 'header:In-Reply-To:1': 0.34; 'question.': 0.35; 'following': 0.35; 'work,': 0.36; "skip:' 10": 0.37; 'way': 0.38; 'could': 0.38; 'adding': 0.39; 'text': 0.39; 'mentioned': 0.39; 'use': 0.39; 'alan': 0.40; 'color': 0.62; 'look': 0.65; 'header:Received:6': 0.67; 'received:64': 0.67; 'coloring': 0.69; 'skip:f 20': 0.75; 'choice': 0.76; 'subject:Color': 0.84; 'subject:Response': 0.91; 'colors': 0.93 X-Sender-Id: dreamhost|x-authsender|tpassin@tompassin.net ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1712793712; a=rsa-sha256; cv=none; b=gekNgP8QDm39UyMm2nCQ+GYo36TjXAKzk6poMrKxLol+HtesqCso8oSDR489Yn0eB0m38N rldTQjh9IEGn4mXoR6shBJh3Eg5amO07ZA4spwvWzhDimeR5APiAXG805U8sZJXfAHCyUu 7TcrzXI7kYXdxgZLrsPBFKT+PqRtaEXYNIQLVNeBKlhR1/s2k/AAjvFx1mynZ+lOwr5sKL 29L/vfMQM1OcPMTjWTrVfPLnc7AkiUNmbEtNJ9kZJnDFGR8DLjNtMnnaLcA3wmIxWxbZKz Qtfi5JDUJ7TVC0T8BTzMnm6IRKU8/0gFxAmIdMAIGN/Tuuyxh1WAL6DzVxrbFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1712793712; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=POSzSpGTUvPrcNRF9eb2Y4pMKewqAofp0g8CZ1eYbsw=; b=m1qSByzIVodNkmon6IZ0YQhjpnULzedFhTr4BTJRtf4hORNlMfVkuKRpBuEQ8x3D8iB4o4 k12Q03wLOatq5BY2VhNH21FXEvKW9GS53HQCgrkSxx1vZCR3ZGTBLvW3TTRdl+kFdEITkk p3egwxyPa5xhCw3NZb2ZdTWEVSPdlgUY1QabDD8o02zC8t3UQMzh63fPjWLdDqL0b4ByzO da4pKvtQ+KvWQEAuxLg3hNb5pyBV6YHfIcCDyoykKY1C+IRaX5Dz6ys0xsoOIaSFOdl+T6 ++BOkzOS5WdaUSFkJNO6b9DCrzBXREpCI1G06JuSEpOb9StJqDvKqYTbPkIXeQ== ARC-Authentication-Results: i=1; rspamd-878bcf566-vhh9h; auth=pass smtp.auth=dreamhost smtp.mailfrom=list1@tompassin.net X-Sender-Id: dreamhost|x-authsender|tpassin@tompassin.net X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|tpassin@tompassin.net X-MailChannels-Auth-Id: dreamhost X-Robust-Abiding: 47bd89ae7ecea2fc_1712793712861_293676660 X-MC-Loop-Signature: 1712793712861:700039170 X-MC-Ingress-Time: 1712793712861 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tompassin.net; s=dreamhost; t=1712793712; bh=POSzSpGTUvPrcNRF9eb2Y4pMKewqAofp0g8CZ1eYbsw=; h=Date:Subject:To:From:Content-Type:Content-Transfer-Encoding; b=C9IfVFzRFYFcXyM8q5bFu4Bp6qMvsmlxSY/2Dx6lRVvjZ10VLztFRAj/Pzn/Gp0Dl Teqsry050NYaSoI9ur7BjlMlpaqOeJ7CqXlVs43csy+LqBRmNE236zNO6OHaMahYLl +c+gGcwV5HpU1lScABX47XZHY/FmLmrHcYlLKyjjcEihwARON57mtTJt4X/Gz9Ak5x Hm2Db8stm/VM2esnyvp1Y67CIsAEEkaJnNvIZK54zHbnGZzQ21Wn4ZjhQwixfDborO zxyt3iYQ1wHjEKlivnGq6dlufM50F4Ahx+DX/VxJ8/NC5qSoIgWTX+YuJM1eTOXXlw ER7jjsFYvaJpw== User-Agent: Mozilla Thunderbird Content-Language: en-US In-Reply-To: <1b305568-7ba1-4329-9f39-a0d22d769272@yahoo.co.uk> 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: <36bf592b-d202-476f-b6d3-62af691a97cf@tompassin.net> X-Mailman-Original-References: <E07728FE-3599-462D-B572-107C5D53C72F@yahoo.com> <1b305568-7ba1-4329-9f39-a0d22d769272@yahoo.co.uk> Bytes: 7140 On 4/10/2024 6:41 PM, Alan Gauld via Python-list wrote: > 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: >> '\n[1;33mYour 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 Curses is a C module, and there is a Python interface to it. Jython would have to find an equivalent Java library. Still, isn't the case that the terminal color output commands are pretty standard? They could just be stuck into the output string. Doing more fancy things, like moving the cursor arbitrarily, probably differ but the OP just mentioned colors.