Skip to content

Commit

Permalink
Windows and WSL: SI/SO/IBMPC_ON/IBMPC_OFF skip
Browse files Browse the repository at this point in the history
In the case of Windows terminal, output is always Unicode
and escape sequences for charset manipulation are "garbage"
  • Loading branch information
Aleksei Stepanov committed Feb 1, 2024
1 parent 6262189 commit 562a4dc
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions urwid/display/_raw_display_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import contextlib
import functools
import os
import platform
import selectors
import signal
import socket
Expand All @@ -49,6 +50,7 @@
from urwid import Canvas, EventLoop

IS_WINDOWS = sys.platform == "win32"
IS_WSL = (sys.platform == "linux") and ("wsl" in platform.platform().lower())


class Screen(BaseScreen, RealTerminal):
Expand Down Expand Up @@ -640,14 +642,17 @@ def using_standout_or_underline(a: AttrSpec | str) -> bool:
first = True
lasta = lastcs = None
for a, cs, run in row:
if not isinstance(run, bytes): # canvases should render with bytes
if not isinstance(run, bytes): # canvases render with bytes
raise TypeError(run)

if cs != "U":
run = run.translate(UNPRINTABLE_TRANS_TABLE) # noqa: PLW2901

if first or lasta != a:
o.append(attr_to_escape(a))
lasta = a
if first or lastcs != cs:

if not (IS_WINDOWS or IS_WSL) and (first or lastcs != cs):
if cs not in {None, "0", "U"}:
raise ValueError(cs)
if lastcs == "U":
Expand All @@ -660,23 +665,33 @@ def using_standout_or_underline(a: AttrSpec | str) -> bool:
else:
o.append(escape.SO)
lastcs = cs

o.append(run)
first = False

if ins:
(inserta, insertcs, inserttext) = ins
ias = attr_to_escape(inserta)
if insertcs not in {None, "0", "U"}:
raise ValueError(insertcs)
if cs is None:
icss = escape.SI
elif cs == "U":
icss = escape.IBMPC_ON
else:
icss = escape.SO
o += ["\x08" * back, ias, icss, escape.INSERT_ON, inserttext, escape.INSERT_OFF]

if cs == "U":
o.extend(("\x08" * back, ias))

if not (IS_WINDOWS or IS_WSL):
if cs is None:
icss = escape.SI
elif cs == "U":
icss = escape.IBMPC_ON
else:
icss = escape.SO

o.append(icss)

o += [escape.INSERT_ON, inserttext, escape.INSERT_OFF]

if not (IS_WINDOWS or IS_WSL) and cs == "U":
o.append(escape.IBMPC_OFF)

if whitespace_at_end:
o.append(escape.ERASE_IN_LINE_RIGHT)

Expand Down

0 comments on commit 562a4dc

Please sign in to comment.