예제 #1
0
파일: shiowrapper.py 프로젝트: Aareon/stash
# coding: utf-8
"""
The wrappers dispatch io requests based on current thread.

If the thread is an instance of ShBaseThread, the io should be dispatched to ShIO.
Otherwise, it should be dispatched to regular sys io.
"""
import sys
import threading

from stash.lib.libslog import slog
_pyfile_ = __file__.split("/")[-1]
slog(f'_pyfile_: {_pyfile_}')

from stash.system.shcommon import _SYS_STDIN, _SYS_STDOUT, _SYS_STDERR
from stash.system.shthreads import ShBaseThread


class ShStdinWrapper:
    def __getattribute__(self, item):
        thread = threading.currentThread()

        if isinstance(thread, ShBaseThread):
            return getattr(thread.state.sys_stdin, item)
        else:
            return getattr(_SYS_STDIN, item)


class ShStdoutWrapper(object):
    def __getattribute__(self, item):
        thread = threading.currentThread()
예제 #2
0
# coding: utf-8
"""
In-memory screen related code.
"""
import itertools
import logging
import threading
from collections import deque, namedtuple
from contextlib import contextmanager

# noinspection PyPep8Naming
from stash.system.shcommon import Graphics as graphics
from stash.lib.libslog import slog

_pyfile_ = __file__.split("/")[-1]
slog(f'pyfile: {_pyfile_}')


class ShScreenNotLocked(Exception):
    pass


#: A container for a single character, field names are *hopefully*
#: self-explanatory.
_Char = namedtuple("_Char", [
    "data",
    "fg",
    "bg",
    "bold",
    "italics",
    "underscore",