Skip to content

Commit

Permalink
Added CanvasConfig.passthrough
Browse files Browse the repository at this point in the history
  • Loading branch information
GuardKenzie committed May 24, 2024
1 parent f2221ae commit 84b3b48
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/chafa/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from .enums import TermSeq
from .enums import ColorSpace
from .enums import ColorExtractor
from .enums import Passthrough

from .symbol_map import SymbolMap
from .symbol_map import ReadOnlySymbolMap
Expand Down
49 changes: 49 additions & 0 deletions src/chafa/canvas_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,15 @@ def bg_color(self) -> Tuple[int, int, int]:
return packed_8bit_to_tuple(color)


@property
def passthrough(self) -> Passthrough:
# Get passthrough
through = self._get_passthrough()

# Convert to enum
return Passthrough(through)


def get_geometry(self) -> Tuple[int, int]:
"""
Get the config's canvas geometry in character cells.
Expand Down Expand Up @@ -647,6 +656,21 @@ def _get_optimizations(self) -> int:

return _Chafa.chafa_canvas_config_get_optimizations(self._canvas_config)


def _get_passthrough(self) -> int:
"""
Wrapper for chafa_canvas_config_get_passthrough
"""

# Specify types
_Chafa.chafa_canvas_config_get_passthrough.argtypes = [
ctypes.c_void_p
]

_Chafa.chafa_canvas_config_get_passthrough.restype = ctypes.c_uint

return _Chafa.chafa_canvas_config_get_passthrough(self._canvas_config)


def peek_symbol_map(self) -> ReadOnlySymbolMap:
"""
Expand Down Expand Up @@ -877,6 +901,13 @@ def bg_color(self, bg_color: Tuple[int, int, int]):

self._set_bg_color(color)


@ReadOnlyCanvasConfig.passthrough.setter
def passthrough(self, through: Passthrough):
through = Passthrough(through)

self._set_passthrough(through)



def copy(self) -> CanvasConfig:
Expand Down Expand Up @@ -1164,6 +1195,24 @@ def _set_optimizations(self, optimizations: int):
)


def _set_passthrough(self, through: Passthrough):
"""
Wrapper for chafa_canvas_config_set_passthrough
"""

# Specify types
_Chafa.chafa_canvas_config_set_passthrough.argtypes = [
ctypes.c_void_p,
ctypes.c_uint
]

# Set passthrough
_Chafa.chafa_canvas_config_set_passthrough(
self._canvas_config,
through
)


def set_symbol_map(self, symbol_map: SymbolMap):
"""
Assigns a copy of symbol_map to config.
Expand Down
2 changes: 0 additions & 2 deletions src/chafa/chafa.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
import sys
import platform
from io import UnsupportedOperation
import asyncio

if platform.system() == "Linux":
import termios
import select


def get_device_attributes():
Expand Down
11 changes: 11 additions & 0 deletions src/chafa/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,14 @@ class TermSeq(IntEnum):
CHAFA_TERM_SEQ_SET_COLOR_FGBG_8 = 54

CHAFA_TERM_SEQ_MAX = 55


#
# === Passthrough ===
#

class Passthrough(IntEnum):
CHAFA_PASSTHROUGH_NONE = 0
CHAFA_PASSTHROUGH_SCREEN = 1
CHAFA_PASSTHROUGH_TMUX = 2
CHAFA_PASSTHROUGH_MAX = 3
13 changes: 13 additions & 0 deletions tests/5_passthrough_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from chafa import *

def test_passthrough():
config = CanvasConfig()

through = config.passthrough
print("Before:", through)

config.passthrough = Passthrough.CHAFA_PASSTHROUGH_SCREEN

print("After:", config.passthrough)

assert config.passthrough != through

0 comments on commit 84b3b48

Please sign in to comment.