manx.py: man pages in BBS style, with ANSI colours and syntax highlighting, using only the Python standard library.

0 downloads

dbbasic-manx/test_width.py
Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/dbbasic-manx.git
HTTPS
https://gitstable.com/git/askrobots/dbbasic-manx.git
SSH
ssh://git@gitstable.com:2222/askrobots/dbbasic-manx.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

danq9 Initial commit: BBS-style ANSI man page viewer 9414990 1 year, 1 month ago History
test_width.py · 1.5 KB · 59 lines
1#!/usr/bin/env python3
2"""Test script to demonstrate terminal width adaptation."""
3
4import sys
5import os
6
7# Mock different terminal widths
8test_cases = [
9 (200, 120, "Very wide terminal"),
10 (100, 100, "Standard terminal"),
11 (80, 80, "Narrow terminal"),
12 (50, 60, "Very narrow terminal (min 60)"),
13]
14
15print("Terminal Width Adaptation Test")
16print("=" * 60)
17print()
18
19for mock_width, expected, description in test_cases:
20 # Temporarily mock the terminal size
21 old_get = None
22 try:
23 import shutil
24
25 class MockSize:
26 def __init__(self, cols, lines):
27 self.columns = cols
28 self.lines = lines
29
30 # Save original
31 import manx
32 original_get_terminal_size = shutil.get_terminal_size
33
34 # Mock it
35 shutil.get_terminal_size = lambda fallback=None: MockSize(mock_width, 24)
36
37 # Also mock isatty to return True
38 original_isatty = sys.stdout.isatty
39 sys.stdout.isatty = lambda: True
40
41 # Get width
42 from manx import get_term_width, h1
43 width = get_term_width()
44
45 print(f"{description}:")
46 print(f" Input: {mock_width} cols → Output: {width} cols (expected: {expected})")
47 print(f" {h1('Test Header')}")
48 print()
49
50 # Restore
51 shutil.get_terminal_size = original_get_terminal_size
52 sys.stdout.isatty = original_isatty
53
54 except Exception as e:
55 print(f" Error: {e}")
56 print()
57
58print("=" * 60)
59print("✓ All terminal width tests completed!")