Change the display style of the text on the STACKLINE.

Roland Mueller roland.em0001 at googlemail.com
Fri Sep 10 02:11:58 EDT 2021


pe 10. syysk. 2021 klo 8.53 hongy... at gmail.com (hongyi.zhao at gmail.com)
kirjoitti:

> On Thursday, September 9, 2021 at 8:57:37 PM UTC+8, Roland Mueller wrote:
> > Hello
> >
> > to 9. syysk. 2021 klo 6.53 hongy... at gmail.com (hongy... at gmail.com)
> > kirjoitti:
> > > I'm using the following code in my forked project [1]:
> > >
> > > percol.view.STACKLINE = 'Fold:F1,F2,F3 Push:C-p Pop:M-p Script:M-s
> Dir:M-d
> > > Dircmd:M-b'
> > >
> > > I would like to change the display style of the text mentioned above,
> for
> > > example, to underline some characters in it, as shown below:
> > >
> > > _D_ir:M-d
> > >
> > >
> > You can use e.g. str.replace() or re.sub()
> >
> > >>> percol.view.STACKLINE = percol.view.STACKLINE.replace('D', '_D_')
> > Result: 'Fold:F1,F2,F3 Push:C-p Pop:M-p Script:M-s _D_ir:M-d
> _D_ircmd:M-b'
> >
> > >>> import re
> >
> > Replace D with _D_
> > >>> percol.view.STACKLINE = re.sub(r'([D])',
> > r'_\1_', percol.view.STACKLINE)
> > Result: 'Fold:F1,F2,F3 Push:C-p Pop:M-p Script:M-s _D_ir:M-d
> _D_ircmd:M-b'
> >
> > Replace D and M with _D_, _M_
> > >>> percol.view.STACKLINE = re.sub(r'([DM])', r'_\1_',
> > percol.view.STACKLINE)
> > 'Fold:F1,F2,F3 Push:C-p Pop:_M_-p Script:_M_-s _D_ir:_M_-d
> _D_ircmd:_M_-b'
> >
> > Regards,
> > Roland
>
> I tried with the following, but failed to achieve the expected effect:
>
> class Term:
>     HEADER = '\033[95m'
>     OKBLUE = '\033[94m'
>     OKGREEN = '\033[92m'
>     WARNING = '\033[93m'
>     FAIL = '\033[91m'
>     ENDC = '\033[0m'
>     LIGHTCYAN = '\033[1;36m'
>     LIGHTGRAY = '\033[0;37m'
>     YELLOW = '\033[0;33m'
>     BOLD = '\033[1m'
>     UNDERLINE = '\033[4m'
>
> [...]
>
> percol.view.STACKLINE = percol.view.STACKLINE.replace('D', Term.UNDERLINE
> + 'D' + Term.ENDC)
>
> The result will look like this:
>
> Fold:F1,F2,F3 Push:C-p Pop:M-p Script:M-s ?[4mD?[0mir:M-d
> ?[4mD?[0mircmd:M-b
>
> I cannot repeat that. Are you sure that the '?' shown in your output are
not due to your terminal settings that influence how strings printed by
Python or inside used terminal are shown?

Python 3.9.6 (default, Jul 16 2021, 00:00:00)
[GCC 11.1.1 20210531 (Red Hat 11.1.1-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> UL = '\033[4m'
>>> UL
'\x1b[4m'
>>> ENDC =  '\033[0m'
>>> ENDC
'\x1b[0m'

>>> s = UL + 'D' + ENDC
>>> s
'\x1b[4mD\x1b[0m'

>>> s = 'ABCDE'
>>> s = s.replace('D', UL + 'D' + ENDC)
>>> s
'ABC\x1b[4mD\x1b[0mE'

When I call  print(s) it even shows ABCD and D is underscored. But copying
the output to mail looses the underscore ...
[image: image.png]

BR,
Roland






> Regards,
> HY
>
>




> > > How to achieve this purpose?
> > >
> > > [1]
> > >
> https://github.com/hongyi-zhao/ariadne/blob/838179bb4275ac85f5342d9e7d086d6ade3be1de/rc.py#L55
> > >
> > > Regards,
> > > HY
> > > --
> > > https://mail.python.org/mailman/listinfo/python-list
> > >
> --
> https://mail.python.org/mailman/listinfo/python-list
>


More information about the Python-list mailing list