CLI for SidePulse
Python
Render compact terminal pairing QR codes
Peter Kuharaeff0f946ee7
diff --git a/src/sidepulse/links.py b/src/sidepulse/links.pyindex 8478ac3..881bdee 100644--- a/src/sidepulse/links.py+++ b/src/sidepulse/links.py@@ -171,7 +171,18 @@ def render_terminal_qr(value: str) -> str:code.add_data(value)code.make(fit=True)matrix = code.get_matrix()- return "\n".join("".join("██" if cell else " " for cell in row) for row in matrix)+ pixels = {+ (False, False): " ",+ (True, False): "▀",+ (False, True): "▄",+ (True, True): "█",+ }+ lines: list[str] = []+ for row_index in range(0, len(matrix), 2):+ top = matrix[row_index]+ bottom = matrix[row_index + 1] if row_index + 1 < len(matrix) else [False] * len(top)+ lines.append("".join(pixels[(top_cell, bottom_cell)] for top_cell, bottom_cell in zip(top, bottom)))+ return "\n".join(lines)def parse_ios_registration(value: str, *, server: str) -> IOSLink:diff --git a/tests/test_links.py b/tests/test_links.pyindex 5358e52..f52053a 100644--- a/tests/test_links.py+++ b/tests/test_links.py@@ -73,7 +73,10 @@ class LinkStorageTests(unittest.TestCase):"Studio Mac",)rendered = render_terminal_qr(url)- self.assertIn("██", rendered)+ lines = rendered.splitlines()+ self.assertTrue(any(character in rendered for character in "▀▄█"))+ self.assertLessEqual(len(lines), 30)+ self.assertLessEqual(max(map(len, lines)), 60)self.assertNotIn("sidepulse://", rendered)def test_sse_parser_returns_complete_data_events(self) -> None: