On Thursday, September 9, 2021 at 8:57:37 PM UTC+8, Roland Mueller wrote: > Hello > > to 9. syysk. 2021 klo 6.53 hongy...@gmail.com (hongy...@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 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