chore: import official kitty sources from upstream
Bring the kovidgoyal/kitty codebase in as the base of FWS-Kitty, vendored at upstream commit 91fb38a without its git history.
This commit is contained in:
1134 files changed
+433629
No files matched your search
@@ -0,0 +1,59 @@
|
||||
#!/usr/bin/env python
|
||||
# License: GPLv3 Copyright: 2021, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
import os
|
||||
from collections.abc import Generator
|
||||
from contextlib import contextmanager
|
||||
|
||||
_cwd = _home = ''
|
||||
|
||||
|
||||
def abspath(path: str, use_home: bool = False) -> str:
|
||||
base = home_path() if use_home else (_cwd or os.getcwd())
|
||||
return os.path.normpath(os.path.join(base, path))
|
||||
|
||||
|
||||
def home_path() -> str:
|
||||
return _home or os.path.expanduser('~')
|
||||
|
||||
|
||||
def cwd_path() -> str:
|
||||
return _cwd or os.getcwd()
|
||||
|
||||
|
||||
def expand_home(path: str) -> str:
|
||||
if path.startswith('~' + os.sep) or (os.altsep and path.startswith('~' + os.altsep)):
|
||||
return os.path.join(home_path(), path[2:].lstrip(os.sep + (os.altsep or '')))
|
||||
return path
|
||||
|
||||
|
||||
@contextmanager
|
||||
def set_paths(cwd: str = '', home: str = '') -> Generator[None, None, None]:
|
||||
global _cwd, _home
|
||||
orig = _cwd, _home
|
||||
try:
|
||||
_cwd, _home = cwd, home
|
||||
yield
|
||||
finally:
|
||||
_cwd, _home = orig
|
||||
|
||||
|
||||
class IdentityCompressor:
|
||||
def compress(self, data: bytes | memoryview) -> bytes:
|
||||
return bytes(data)
|
||||
|
||||
def flush(self) -> bytes:
|
||||
return b''
|
||||
|
||||
|
||||
class ZlibCompressor:
|
||||
def __init__(self) -> None:
|
||||
import zlib
|
||||
|
||||
self.c = zlib.compressobj()
|
||||
|
||||
def compress(self, data: bytes | memoryview) -> bytes:
|
||||
return self.c.compress(data)
|
||||
|
||||
def flush(self) -> bytes:
|
||||
return self.c.flush()
|
||||
Reference in new issue
Block a user