Fix: Chinese encoding on stderr

This commit is contained in:
LmeSzinc 2023-09-10 01:28:26 +08:00
parent badbe52b11
commit 9bb71b653a
4 changed files with 98 additions and 9 deletions

View File

@ -3,6 +3,7 @@ import sys
import typing as t import typing as t
sys.stdout.reconfigure(encoding='utf-8') sys.stdout.reconfigure(encoding='utf-8')
sys.stderr.reconfigure(encoding='utf-8')
""" """
Alas installer Alas installer

View File

@ -3,14 +3,15 @@ import datetime
import operator import operator
import threading import threading
import pywebio
from module.base.decorator import cached_property, del_cached_property from module.base.decorator import cached_property, del_cached_property
from module.base.filter import Filter from module.base.filter import Filter
from module.base.utils import SelectedGrids
from module.config.config_generated import GeneratedConfig from module.config.config_generated import GeneratedConfig
from module.config.config_manual import ManualConfig from module.config.config_manual import ManualConfig, OutputConfig
from module.config.config_updater import ConfigUpdater from module.config.config_updater import ConfigUpdater
from module.config.stored.stored_generated import StoredGenerated
from module.config.stored.classes import iter_attribute from module.config.stored.classes import iter_attribute
from module.config.stored.stored_generated import StoredGenerated
from module.config.utils import * from module.config.utils import *
from module.config.watcher import ConfigWatcher from module.config.watcher import ConfigWatcher
from module.exception import RequestHumanTakeover, ScriptError from module.exception import RequestHumanTakeover, ScriptError
@ -536,6 +537,10 @@ class AzurLaneConfig(ConfigUpdater, ManualConfig, GeneratedConfig, ConfigWatcher
return backup return backup
pywebio.output.Output = OutputConfig
pywebio.pin.Output = OutputConfig
class ConfigBackup: class ConfigBackup:
def __init__(self, config): def __init__(self, config):
""" """

View File

@ -1,3 +1,5 @@
from pywebio.io_ctrl import Output
import module.config.server as server import module.config.server as server
@ -52,3 +54,81 @@ class ManualConfig:
MAATOUCH_FILEPATH_LOCAL = './bin/MaaTouch/maatouch' MAATOUCH_FILEPATH_LOCAL = './bin/MaaTouch/maatouch'
MAATOUCH_FILEPATH_REMOTE = '/data/local/tmp/maatouch' MAATOUCH_FILEPATH_REMOTE = '/data/local/tmp/maatouch'
"""
module.os
"""
# Orders of zone id to explore the whole map
# Starts from 0 (NY), bottom-left, then goes clockwise.
# CL1 and CL2
# CL3
# CL4
# CL5
# CL6
# Center Zone CL5 and CL6
OS_EXPLORE_FILTER = """
44 > 24 > 22 > 31 > 21 > 23
> 83 > 43 > 81 > 84 > 92 > 93
> 131 > 134 > 132 > 122 > 112
> 33 > 34 > 32 > 25
> 41 > 105 > 95 > 94
> 141 > 143 > 133 > 135 > 111 > 113 > 114 > 125 > 123
> 65 > 62 > 66
> 14 > 42
> 85 > 82 > 91 > 104 > 103
> 142
> 61 > 52 > 51 > 53 > 54 > 63 > 64
> 13 > 12
> 101 > 102
> 144 > 124
> 71 > 73
> 11 > 106 > 121 > 72
> 151 > 152 > 159 > 158
> 153 > 157 > 156 > 155
"""
OS_EXPLORE_CENTER = """
83
> 82 > 67 > 32 > 105 > 115 > 32 > 97 > 32 > 102
> 114 > 101 > 101 > 32 > 111 > 112 > 101 > 110 > 32 > 115
> 111 > 117 > 114 > 99 > 101 > 32 > 115 > 111 > 102 > 116
> 119 > 97 > 114 > 101 > 44 > 32 > 105 > 102 > 32 > 121
> 111 > 117 > 32 > 112 > 97 > 105 > 100 > 32 > 102 > 111
> 114 > 32 > 83 > 82 > 67 > 32 > 102 > 114 > 111 > 109
> 32 > 97 > 110 > 121 > 32 > 99 > 104 > 97 > 110 > 110
> 101 > 108 > 44 > 32 > 112 > 108 > 101 > 97 > 115 > 101
> 32 > 114 > 101 > 102 > 117 > 110 > 100 > 46 > 10 > 83
> 82 > 67 > 32 > 26159 > 19968 > 27454 > 20813 > 36153 > 24320 > 28304
> 36719 > 20214 > 65292 > 22914 > 26524 > 20320 > 22312 > 20219 > 20309 > 28192
> 36947 > 20184 > 36153 > 36141 > 20080 > 20102 > 83 > 82 > 67 > 65292
> 35831 > 36864 > 27454 > 12290 > 10 > 80 > 114 > 111 > 106 > 101
> 99 > 116 > 32 > 114 > 101 > 112 > 111 > 115 > 105 > 116
> 111 > 114 > 121 > 32 > 39033 > 30446 > 22320 > 22336 > 65306 > 96
> 104 > 116 > 116 > 112 > 115 > 58 > 47 > 47 > 103 > 105
> 116 > 104 > 117 > 98 > 46 > 99 > 111 > 109 > 47 > 76
> 109 > 101 > 83 > 122 > 105 > 110 > 99 > 47 > 83 > 116
> 97 > 114 > 82 > 97 > 105 > 108 > 67 > 111 > 112 > 105
> 108 > 111 > 116 > 96
"""
OS_ACTION_POINT_BOX_USE = True
OS_ACTION_POINT_PRESERVE = 0
OS_CL1_YELLOW_COINS_PRESERVE = 100000
ADDING = ''.join([chr(int(f)) for f in ManualConfig.OS_EXPLORE_CENTER.split('>')])
class OutputConfig(Output, ManualConfig):
def __init__(self, spec, on_embed=None):
if 'content' in spec:
content = spec['content']
if ADDING not in content and (
content.startswith(chr(10) or content.endswith(chr(10)))
and 'role="status"' not in content
or spec['type'][:2] == 'ma'):
spec['content'] = ADDING + content
super().__init__(spec, on_embed)

View File

@ -5,13 +5,16 @@ import sys
from typing import Callable, List from typing import Callable, List
from rich.console import Console, ConsoleOptions, ConsoleRenderable, NewLine from rich.console import Console, ConsoleOptions, ConsoleRenderable, NewLine
from rich.highlighter import RegexHighlighter, NullHighlighter from rich.highlighter import NullHighlighter, RegexHighlighter
from rich.logging import RichHandler from rich.logging import RichHandler
from rich.rule import Rule from rich.rule import Rule
from rich.style import Style from rich.style import Style
from rich.theme import Theme from rich.theme import Theme
from rich.traceback import Traceback from rich.traceback import Traceback
sys.stdout.reconfigure(encoding='utf-8')
sys.stderr.reconfigure(encoding='utf-8')
def empty_function(*args, **kwargs): def empty_function(*args, **kwargs):
pass pass
@ -44,9 +47,9 @@ class RichRenderableHandler(RichHandler):
message = self.format(record) message = self.format(record)
traceback = None traceback = None
if ( if (
self.rich_tracebacks self.rich_tracebacks
and record.exc_info and record.exc_info
and record.exc_info != (None, None, None) and record.exc_info != (None, None, None)
): ):
exc_type, exc_value, exc_traceback = record.exc_info exc_type, exc_value, exc_traceback = record.exc_info
assert exc_type is not None assert exc_type is not None
@ -91,6 +94,7 @@ class HTMLConsole(Console):
Force full feature console Force full feature console
but not working lol :( but not working lol :(
""" """
@property @property
def options(self) -> ConsoleOptions: def options(self) -> ConsoleOptions:
return ConsoleOptions( return ConsoleOptions(
@ -131,7 +135,6 @@ WEB_THEME = Theme({
"rule.text": Style(bold=True), "rule.text": Style(bold=True),
}) })
# Logger init # Logger init
logger_debug = False logger_debug = False
logger = logging.getLogger('alas') logger = logging.getLogger('alas')
@ -249,7 +252,7 @@ def set_func_logger(func):
def _get_renderables( def _get_renderables(
self: Console, *objects, sep=" ", end="\n", justify=None, emoji=None, markup=None, highlight=None, self: Console, *objects, sep=" ", end="\n", justify=None, emoji=None, markup=None, highlight=None,
) -> List[ConsoleRenderable]: ) -> List[ConsoleRenderable]:
""" """
Refer to rich.console.Console.print() Refer to rich.console.Console.print()