<commit_before># Copyright 2017 Mycroft AI Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import sys
import io

# NOTE: The following two lines prevent extra messages from the
# messagebus setup from appearing during startup and while the
# CLI is running (dirtying the screen).  This is normally good.
# But if there is a bug in this .py file, the Python error messages
# are also consumed.  To debug, invoke the CLI with "--debug" as a
# parameter.
if "--debug" not in sys.argv:
    sys.stdout = io.BytesIO()  # capture any output
    sys.stderr = io.BytesIO()  # capture any output

# All of the nopep8 comments below are to avoid E402 errors
import os                                                   # nopep8
import os.path                                              # nopep8
import time                                                 # nopep8
import curses                                               # nopep8
import curses.ascii                                         # nopep8
import textwrap                                             # nopep8
import json                                                 # nopep8
import mycroft.version                                      # nopep8
from threading import Thread, Lock                          # nopep8
from mycroft.messagebus.client.ws import WebsocketClient    # nopep8
from mycroft.messagebus.message import Message              # nopep8
from mycroft.util import get_ipc_directory                  # nopep8
from mycroft.util.log import LOG                            # nopep8

import locale                                               # nopep8
# Curses uses LC_ALL to determine how to display chars set it to system
# default
locale.setlocale(locale.LC_ALL, '.'.join(locale.getdefaultlocale()))

ws = None
mutex = Lock()

utterances = []
chat = []   # chat history, oldest at the lowest index
line = ""
bSimple = '--simple' in sys.argv
scr = None
log_line_offset = 0  # num lines back in logs to show
log_line_lr_scroll = 0  # amount to scroll left/right for long lines
longest_visible_line = 0  # for HOME key
auto_scroll = True

# for debugging odd terminals<commit_msg>Restore captured text on cli exceptions<commit_after># Copyright 2017 Mycroft AI Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
from __future__ import print_function
import sys
import io


def custom_except_hook(exctype, value, traceback):           # noqa
    print(sys.stdout.getvalue(), file=sys.__stdout__)        # noqa
    print(sys.stderr.getvalue(), file=sys.__stderr__)        # noqa
    sys.stdout, sys.stderr = sys.__stdout__, sys.__stderr__  # noqa
    sys.__excepthook__(exctype, value, traceback)            # noqa


sys.excepthook = custom_except_hook  # noqa

# capture any output
sys.stdout = io.BytesIO()  # noqa
sys.stderr = io.BytesIO()  # noqa

import os
import os.path
import time
import curses
import curses.ascii
import textwrap
import json
import mycroft.version
from threading import Thread, Lock
from mycroft.messagebus.client.ws import WebsocketClient
from mycroft.messagebus.message import Message
from mycroft.util import get_ipc_directory
from mycroft.util.log import LOG

import locale
# Curses uses LC_ALL to determine how to display chars set it to system
# default
locale.setlocale(locale.LC_ALL, '.'.join(locale.getdefaultlocale()))

ws = None
mutex = Lock()

utterances = []
chat = []   # chat history, oldest at the lowest index
line = ""
bSimple = '--simple' in sys.argv
scr = None
log_line_offset = 0  # num lines back in logs to show
log_line_lr_scroll = 0  # amount to scroll left/right for long lines
longest_visible_line = 0  # for HOME key
auto_scroll = True

# for debugging odd terminals
{'fraction_non_alphanumeric': 0.0663820704375667, 'fraction_numerical': 0.008537886872998933, 'mean_word_length': 2.5770992366412213, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 17, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3683183', 'n_tokens_mistral': 1272, 'n_tokens_neox': 1221, 'n_words': 520}