Gets the console attribute state. If this is the first call or reset is True or encoding is not None and does not match the current encoding or out is not None and does not match the current out then the state is (re)initialized. Otherwise the current state is returned. This call associa
(encoding=None, reset=False)
| 629 | |
| 630 | |
| 631 | def GetConsoleAttr(encoding=None, reset=False): |
| 632 | """Gets the console attribute state. |
| 633 | |
| 634 | If this is the first call or reset is True or encoding is not None and does |
| 635 | not match the current encoding or out is not None and does not match the |
| 636 | current out then the state is (re)initialized. Otherwise the current state |
| 637 | is returned. |
| 638 | |
| 639 | This call associates the out file stream with the console. All console related |
| 640 | output should go to the same stream. |
| 641 | |
| 642 | Args: |
| 643 | encoding: Encoding override. |
| 644 | ascii -- ASCII. This is the default. |
| 645 | utf8 -- UTF-8 unicode. |
| 646 | win -- Windows code page 437. |
| 647 | reset: Force re-initialization if True. |
| 648 | |
| 649 | Returns: |
| 650 | The global ConsoleAttr state object. |
| 651 | """ |
| 652 | attr = ConsoleAttr._CONSOLE_ATTR_STATE # pylint: disable=protected-access |
| 653 | if not reset: |
| 654 | if not attr: |
| 655 | reset = True |
| 656 | elif encoding and encoding != attr.GetEncoding(): |
| 657 | reset = True |
| 658 | if reset: |
| 659 | attr = ConsoleAttr(encoding=encoding) |
| 660 | ConsoleAttr._CONSOLE_ATTR_STATE = attr # pylint: disable=protected-access |
| 661 | return attr |
| 662 | |
| 663 | |
| 664 | def ResetConsoleAttr(encoding=None): |
no test coverage detected