Skip to content

Commit 84b3b48

Browse files
committed
Added CanvasConfig.passthrough
1 parent f2221ae commit 84b3b48

File tree

5 files changed

+74
-2
lines changed

5 files changed

+74
-2
lines changed

src/chafa/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from .enums import TermSeq
88
from .enums import ColorSpace
99
from .enums import ColorExtractor
10+
from .enums import Passthrough
1011

1112
from .symbol_map import SymbolMap
1213
from .symbol_map import ReadOnlySymbolMap

src/chafa/canvas_config.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,15 @@ def bg_color(self) -> Tuple[int, int, int]:
361361
return packed_8bit_to_tuple(color)
362362

363363

364+
@property
365+
def passthrough(self) -> Passthrough:
366+
# Get passthrough
367+
through = self._get_passthrough()
368+
369+
# Convert to enum
370+
return Passthrough(through)
371+
372+
364373
def get_geometry(self) -> Tuple[int, int]:
365374
"""
366375
Get the config's canvas geometry in character cells.
@@ -647,6 +656,21 @@ def _get_optimizations(self) -> int:
647656

648657
return _Chafa.chafa_canvas_config_get_optimizations(self._canvas_config)
649658

659+
660+
def _get_passthrough(self) -> int:
661+
"""
662+
Wrapper for chafa_canvas_config_get_passthrough
663+
"""
664+
665+
# Specify types
666+
_Chafa.chafa_canvas_config_get_passthrough.argtypes = [
667+
ctypes.c_void_p
668+
]
669+
670+
_Chafa.chafa_canvas_config_get_passthrough.restype = ctypes.c_uint
671+
672+
return _Chafa.chafa_canvas_config_get_passthrough(self._canvas_config)
673+
650674

651675
def peek_symbol_map(self) -> ReadOnlySymbolMap:
652676
"""
@@ -877,6 +901,13 @@ def bg_color(self, bg_color: Tuple[int, int, int]):
877901

878902
self._set_bg_color(color)
879903

904+
905+
@ReadOnlyCanvasConfig.passthrough.setter
906+
def passthrough(self, through: Passthrough):
907+
through = Passthrough(through)
908+
909+
self._set_passthrough(through)
910+
880911

881912

882913
def copy(self) -> CanvasConfig:
@@ -1164,6 +1195,24 @@ def _set_optimizations(self, optimizations: int):
11641195
)
11651196

11661197

1198+
def _set_passthrough(self, through: Passthrough):
1199+
"""
1200+
Wrapper for chafa_canvas_config_set_passthrough
1201+
"""
1202+
1203+
# Specify types
1204+
_Chafa.chafa_canvas_config_set_passthrough.argtypes = [
1205+
ctypes.c_void_p,
1206+
ctypes.c_uint
1207+
]
1208+
1209+
# Set passthrough
1210+
_Chafa.chafa_canvas_config_set_passthrough(
1211+
self._canvas_config,
1212+
through
1213+
)
1214+
1215+
11671216
def set_symbol_map(self, symbol_map: SymbolMap):
11681217
"""
11691218
Assigns a copy of symbol_map to config.

src/chafa/chafa.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
import sys
33
import platform
44
from io import UnsupportedOperation
5-
import asyncio
65

76
if platform.system() == "Linux":
87
import termios
9-
import select
108

119

1210
def get_device_attributes():

src/chafa/enums.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,3 +214,14 @@ class TermSeq(IntEnum):
214214
CHAFA_TERM_SEQ_SET_COLOR_FGBG_8 = 54
215215

216216
CHAFA_TERM_SEQ_MAX = 55
217+
218+
219+
#
220+
# === Passthrough ===
221+
#
222+
223+
class Passthrough(IntEnum):
224+
CHAFA_PASSTHROUGH_NONE = 0
225+
CHAFA_PASSTHROUGH_SCREEN = 1
226+
CHAFA_PASSTHROUGH_TMUX = 2
227+
CHAFA_PASSTHROUGH_MAX = 3

tests/5_passthrough_test.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from chafa import *
2+
3+
def test_passthrough():
4+
config = CanvasConfig()
5+
6+
through = config.passthrough
7+
print("Before:", through)
8+
9+
config.passthrough = Passthrough.CHAFA_PASSTHROUGH_SCREEN
10+
11+
print("After:", config.passthrough)
12+
13+
assert config.passthrough != through

0 commit comments

Comments
 (0)