We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Register.copy()
It seems that Register.copy() does not, in fact, copy a register – it fails to copy the values. Try this:
from sty import fg print(f"{fg.red}Hello!{fg.rs}") fg_copy = fg.copy() print(f"{fg_copy.red}Hello!{fg_copy.rs}")
The latter fails to contain color codes:
This can be confirmed with the Register.as_dict() method:
Register.as_dict()
>>> fg_copy.as_dict() {'black': '', 'blue': '', 'cyan': '', 'da_black': '', 'da_blue': '', 'da_cyan': '', 'da_green': '', 'da_grey': '', 'da_magenta': '', 'da_red': '', 'da_yellow': '', 'green': '', 'grey': '', 'li_blue': '', 'li_cyan': '', 'li_green': '', 'li_grey': '', 'li_magenta': '', 'li_red': '', 'li_yellow': '', 'magenta': '', 'red': '', 'rs': '', 'white': '', 'yellow': ''}
Details on my environment:
For now, the following function can be used as a workaround!
from sty import register def copy_register(register: Register): ret = register.copy() for key, value in register.as_dict().items(): setattr(ret, key, value) return ret
With it, the following now works:
from sty import fg print(f"{fg.red}Hello!{fg.rs}") fg_copy = copy_register(fg) print(f"{fg_copy.red}Hello!{fg_copy.rs}")
The text was updated successfully, but these errors were encountered:
No branches or pull requests
The issue
It seems that
Register.copy()
does not, in fact, copy a register – it fails to copy the values. Try this:The latter fails to contain color codes:
This can be confirmed with the
Register.as_dict()
method:Details on my environment:
A workaround
For now, the following function can be used as a workaround!
With it, the following now works:
The text was updated successfully, but these errors were encountered: