diff --git a/TermTk/TTkWidgets/TTkTerminal/__init__.py b/TermTk/TTkWidgets/TTkTerminal/__init__.py new file mode 100644 index 00000000..7758c111 --- /dev/null +++ b/TermTk/TTkWidgets/TTkTerminal/__init__.py @@ -0,0 +1,2 @@ +from .terminal import * +from .vt102 import * \ No newline at end of file diff --git a/TermTk/TTkWidgets/TTkTerminal/terminal.py b/TermTk/TTkWidgets/TTkTerminal/terminal.py new file mode 100644 index 00000000..e421261d --- /dev/null +++ b/TermTk/TTkWidgets/TTkTerminal/terminal.py @@ -0,0 +1,171 @@ +# MIT License +# +# Copyright (c) 2023 Eugenio Parodi +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +import os, pty, threading +import re +from select import select +from TermTk.TTkCore.canvas import TTkCanvas + + +from TermTk.TTkCore.color import TTkColor +from TermTk.TTkCore.log import TTkLog +from TermTk.TTkCore.constant import TTkK +from TermTk.TTkCore.cfg import TTkCfg +from TermTk.TTkCore.string import TTkString +from TermTk.TTkCore.signal import pyTTkSignal, pyTTkSlot +from TermTk.TTkCore.helper import TTkHelper +from TermTk.TTkGui.clipboard import TTkClipboard +from TermTk.TTkGui.textwrap1 import TTkTextWrap +from TermTk.TTkGui.textcursor import TTkTextCursor +from TermTk.TTkGui.textdocument import TTkTextDocument +from TermTk.TTkLayouts.gridlayout import TTkGridLayout +from TermTk.TTkAbstract.abstractscrollarea import TTkAbstractScrollArea +from TermTk.TTkAbstract.abstractscrollview import TTkAbstractScrollView, TTkAbstractScrollViewGridLayout +from TermTk.TTkWidgets.widget import TTkWidget + +from .terminal_alt import _TTkTerminalAltScreen +from .terminal_normal import _TTkTerminalNormalScreen + +from .vt102 import TTkVT102 + +__all__ = ['TTkTerminal'] + +class TTkTerminal(TTkWidget): + __slots__ = ('_shell', '_fd', '_inout', '_mode_normal' + '_buffer_lines', '_buffer_screen', + '_screen_current', '_screen_normal', '_screen_alt') + def __init__(self, *args, **kwargs): + self._shell = os.environ.get('SHELL', 'sh') + self._fd = None + self._mode_normal = True + self._buffer_lines = [TTkString()] + self._screen_normal = _TTkTerminalNormalScreen() + self._screen_alt = _TTkTerminalAltScreen() + self._screen_current = self._screen_normal + + super().__init__(*args, **kwargs) + + self.setFocusPolicy(TTkK.ClickFocus + TTkK.TabFocus) + + def runShell(self, program=None): + self._shell = program if program else self._shell + + pid, self._fd = pty.fork() + + if pid == 0: + argv = [self._shell] + env = dict(TERM="screen", DISPLAY=":1") + os.execvpe(argv[0], argv, env) + else: + self._inout = os.fdopen(self._fd, "w+b", 0) + name = os.ttyname(self._fd) + TTkLog.debug(f"{self._fd=} {name}") + + threading.Thread(target=self.loop,args=[self]).start() + + # xterm escape sequences from: + # https://invisible-island.net/xterm/ctlseqs/ctlseqs.html + # https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Functions-using-CSI-_-ordered-by-the-final-character_s_ + re_CURSOR = re.compile('^(\d*)(;?)(\d*)([@ABCDEFGIJKLMPSTXZ^`abcdeginqx])') + # https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Functions-using-CSI-_-ordered-by-the-final-character_s_ + # Basic Re for CSI Ps matches: + # CSI : Control Sequence Introducer "[" = '\033[' + # Ps : A single (usually optional) numeric parameter, composed of one or more digits. + # fn : the single char defining the function + re_CSI_Ps_fu = re.compile('^(\d*)([@ABCDEFGIJKLMPSTXZ^`abcdeginqx])') + re_CSI_Ps_Ps_fu = re.compile('^(\d*);(\d*)([Hf])') + re_DEC_SET_RST = re.compile('^\?(\d+)([lh])') + # re_CURSOR_1 = re.compile(r'^(\d+)([ABCDEFGIJKLMPSTXZHf])') + + def _process_cursor_match(self, m): + y = ps = m.group(1) + sep = m.group(2) + x = m.group(3) + fn = m.group(4) + _ex = self._screen_current._CSI_MAP.get(fn,lambda a,b,c: None) + _ex(self._screen_current,y,x) + + def loop(self, _): + while rs := select( [self._inout], [], [])[0]: + TTkLog.debug(f"Select - {rs=}") + for r in rs: + if r is self._inout: + try: + out = self._inout.read(10240) + except Exception as e: + TTkLog.error(f"Error: {e=}") + return + if out: + # TTkLog.debug(f'Eugenio->{out}') + sout = out.decode('utf-8','ignore') + sout = sout.split('\033[') + self._screen_current.pushLine(sout[0]) + TTkLog.debug(f"{sout[0]=}") + for slice in sout[1:]: + if m := TTkTerminal.re_DEC_SET_RST.match(slice): + # l = len(m.group(0)) + en = m.end() + ps = int(m.group(1)) + sr = m.group(2) + if ps == 1049 and sr == 'l': # NORMAL SCREEN + self._screen_current = self._screen_normal + elif ps == 1049 and sr == 'h': # ALT SCREEN + self._screen_current = self._screen_alt + elif ps == 2004: + # Bracketedpaste ON + # Bracketedpaste OFF + pass + slice = slice[en:] + elif m := TTkTerminal.re_CURSOR.match(slice): + TTkLog.debug(f"{m.group(0)=} {m.group(1)=} {m.group(2)=}") + en = m.end() + self._process_cursor_match(m) + slice[en:] + else: + slice = '\033[' + slice.replace('\r','') + + # TTkLog.debug(f'Eugenio->{slice}') + self._screen_current.pushLine(slice) + slice = slice.replace('\033','').replace('\n','\\n') + TTkLog.debug(f"{slice=}") + self.update() + + def mousePressEvent(self, evt): + return True + + def keyEvent(self, evt): + # TTkLog.debug(f"Key: {evt.code=}") + TTkLog.debug(f"Key: {str(evt)=}") + self._inout.write(evt.code.encode()) + if evt.type == TTkK.SpecialKey: + if evt.key == TTkK.Key_Enter: + TTkLog.debug(f"Key: Enter") + # self._inout.write(b'\n') + # self._inout.write(evt.code.encode()) + else: # Input char + TTkLog.debug(f"Key: {evt.key=}") + # self._inout.write(evt.key.encode()) + return True + + def paintEvent(self, canvas: TTkCanvas): + w,h = self.size() + self._screen_current.paintEvent(canvas,w,h) diff --git a/TermTk/TTkWidgets/TTkTerminal/terminal_alt.py b/TermTk/TTkWidgets/TTkTerminal/terminal_alt.py new file mode 100644 index 00000000..c98d0e94 --- /dev/null +++ b/TermTk/TTkWidgets/TTkTerminal/terminal_alt.py @@ -0,0 +1,1403 @@ + # MIT License + # + # Copyright (c) 2023 Eugenio Parodi + # + # Permission is hereby granted, free of charge, to any person obtaining a copy + # of this software and associated documentation files (the "Software"), to deal + # in the Software without restriction, including without limitation the rights + # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + # copies of the Software, and to permit persons to whom the Software is + # furnished to do so, subject to the following conditions: + # + # The above copyright notice and this permission notice shall be included in all + # copies or substantial portions of the Software. + # + # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + # SOFTWARE. + +import os, pty, threading +import re +from select import select +from TermTk.TTkCore.canvas import TTkCanvas + + +from TermTk.TTkCore.color import TTkColor +from TermTk.TTkCore.log import TTkLog +from TermTk.TTkCore.constant import TTkK +from TermTk.TTkCore.cfg import TTkCfg +from TermTk.TTkCore.string import TTkString +from TermTk.TTkCore.signal import pyTTkSignal, pyTTkSlot +from TermTk.TTkCore.helper import TTkHelper +from TermTk.TTkGui.clipboard import TTkClipboard +from TermTk.TTkGui.textwrap1 import TTkTextWrap +from TermTk.TTkGui.textcursor import TTkTextCursor +from TermTk.TTkGui.textdocument import TTkTextDocument +from TermTk.TTkLayouts.gridlayout import TTkGridLayout +from TermTk.TTkAbstract.abstractscrollarea import TTkAbstractScrollArea +from TermTk.TTkAbstract.abstractscrollview import TTkAbstractScrollView, TTkAbstractScrollViewGridLayout +from TermTk.TTkWidgets.widget import TTkWidget + +class _TTkTerminalAltScreen(): + __slots__ = ('_lines') + def __init__(self) -> None: + self._lines = [TTkString()] + + def pushLine(self, line:str): + lines = line.replace('\r','').split('\n') + for i,l in enumerate(lines): + if i: + self._lines.append(TTkString(l)) + else: + self._lines[-1] += TTkString(l) + + def paintEvent(self, canvas: TTkCanvas, w:int, h:int, ox:int=0, oy:int=0) -> None: + canvas.drawText(text="ALT Screen", pos=(0,0), width=w) + + + # CSI Ps @ Insert Ps (Blank) Character(s) (default = 1) (ICH). + def _CSI___ICH(self, ps, _): pass + + # CSI Ps SP @ (SP = Space) + # Shift left Ps columns(s) (default = 1) (SL), ECMA-48. + def _CSI___SL( self, ps, _): pass + + # CSI Ps A Cursor Up Ps Times (default = 1) (CUU). + def _CSI_A_CUU(self, ps, _): pass + + # CSI Ps SP A (SP = Space) + # Shift right Ps columns(s) (default = 1) (SR), ECMA-48. + def _CSI_A_SR( self, ps, _): pass + + # CSI Ps B Cursor Down Ps Times (default = 1) (CUD). + def _CSI_B_CUD(self, ps, _): pass + + # CSI Ps C Cursor Forward Ps Times (default = 1) (CUF). + def _CSI_C_CUF(self, ps, _): pass + + # CSI Ps D Cursor Backward Ps Times (default = 1) (CUB). + def _CSI_D_CUB(self, ps, _): pass + + # CSI Ps E Cursor Next Line Ps Times (default = 1) (CNL). + def _CSI_E_CNL(self, ps, _): pass + + # CSI Ps F Cursor Preceding Line Ps Times (default = 1) (CPL). + def _CSI_F_CPL(self, ps, _): pass + + # CSI Ps G Cursor Character Absolute [column] (default = [row,1]) (CHA). + def _CSI_G_CHA(self, ps, _): pass + + # CSI Ps ; Ps H + # Cursor Position [row;column] (default = [1,1]) (CUP). + def _CSI_H_CUP(self, row, col): pass + + # CSI Ps I Cursor Forward Tabulation Ps tab stops (default = 1) (CHT). + def _CSI_I_CHT(self, ps, _): pass + + # CSI Ps J Erase in Display (ED), VT100. + # Ps = 0 ⇒ Erase Below (default). + # Ps = 1 ⇒ Erase Above. + # Ps = 2 ⇒ Erase All. + # Ps = 3 ⇒ Erase Saved Lines, xterm. + def _CSI_J_ED(self, ps, _): pass + + # CSI ? Ps J + # Erase in Display (DECSED), VT220. + # Ps = 0 ⇒ Selective Erase Below (default). + # Ps = 1 ⇒ Selective Erase Above. + # Ps = 2 ⇒ Selective Erase All. + # Ps = 3 ⇒ Selective Erase Saved Lines, xterm. + + # CSI Ps K Erase in Line (EL), VT100. + # Ps = 0 ⇒ Erase to Right (default). + # Ps = 1 ⇒ Erase to Left. + # Ps = 2 ⇒ Erase All. + def _CSI_K_el(self, ps, _): pass + + # CSI ? Ps K + # Erase in Line (DECSEL), VT220. + # Ps = 0 ⇒ Selective Erase to Right (default). + # Ps = 1 ⇒ Selective Erase to Left. + # Ps = 2 ⇒ Selective Erase All. + + # CSI Ps L Insert Ps Line(s) (default = 1) (IL). + def _CSI_L_IL(self, ps, _): pass + + # CSI Ps M Delete Ps Line(s) (default = 1) (DL). + def _CSI_M_DL(self, ps, _): pass + + # CSI Ps P Delete Ps Character(s) (default = 1) (DCH). + + # CSI # P + # CSI Pm # P + # Push current dynamic- and ANSI-palette colors onto stack + # (XTPUSHCOLORS), xterm. Parameters (integers in the range 1 + # through 10, since the default 0 will push) may be used to + # store the palette into the stack without pushing. + + # CSI # Q + # CSI Pm # Q + # Pop stack to set dynamic- and ANSI-palette colors + # (XTPOPCOLORS), xterm. Parameters (integers in the range 1 + # through 10, since the default 0 will pop) may be used to + # restore the palette from the stack without popping. + + # CSI # R Report the current entry on the palette stack, and the number + # of palettes stored on the stack, using the same form as + # XTPOPCOLOR (default = 0) (XTREPORTCOLORS), xterm. + + # CSI Ps S Scroll up Ps lines (default = 1) (SU), VT420, ECMA-48. + def _CSI_S_SU(self, ps, _): pass + + # CSI ? Pi ; Pa ; Pv S + # Set or request graphics attribute (XTSMGRAPHICS), xterm. If + # configured to support either Sixel Graphics or ReGIS Graphics, + # xterm accepts a three-parameter control sequence, where Pi, Pa + # and Pv are the item, action and value: + # + # Pi = 1 ⇒ item is number of color registers. + # Pi = 2 ⇒ item is Sixel graphics geometry (in pixels). + # Pi = 3 ⇒ item is ReGIS graphics geometry (in pixels). + # + # Pa = 1 ⇒ read attribute. + # Pa = 2 ⇒ reset to default. + # Pa = 3 ⇒ set to value in Pv. + # Pa = 4 ⇒ read the maximum allowed value. + # + # Pv is ignored by xterm except when setting (Pa == 3 ). + # Pv = n ⇐ A single integer is used for color registers. + # Pv = width ; height ⇐ Two integers for graphics geometry. + # + # xterm replies with a control sequence of the same form: + # + # CSI ? Pi ; Ps ; Pv S + # + # where Ps is the status: + # Ps = 0 ⇐ success. + # Ps = 1 ⇐ error in Pi. + # Ps = 2 ⇐ error in Pa. + # Ps = 3 ⇐ failure. + # + # On success, Pv represents the value read or set. + # + # Notes: + # o The current implementation allows reading the graphics + # sizes, but disallows modifying those sizes because that is + # done once, using resource-values. + # o Graphics geometry is not necessarily the same as "window + # size" (see the dtterm window manipulation extensions). + # XTerm limits the maximum graphics geometry according to + # the maxGraphicSize resource. + # The maxGraphicSize resource can be either an explicit + # heightxwidth (default: 1000x1000 as of version 328) or the + # word "auto" (telling XTerm to use limits the decGraphicsID + # or decTerminalID resource to determine the limits). + # o XTerm uses the minimum of the window size and the graphic + # size to obtain the maximum geometry. + # o While resizing a window will always change the current + # graphics geometry, the reverse is not true. Setting + # graphics geometry does not affect the window size. + # o If xterm is able to support graphics (compile-time), but + # is not configured (runtime) for graphics, these responses + # will indicate a failure. Other implementations which do + # not use the maximum graphics dimensions but are configured + # for graphics should report zeroes for the maximum geometry + # rather than a failure. + + # CSI Ps T Scroll down Ps lines (default = 1) (SD), VT420. + def _CSI_T_SD(self, ps, _): pass + + # CSI Ps ; Ps ; Ps ; Ps ; Ps T + # Initiate highlight mouse tracking (XTHIMOUSE), xterm. + # Parameters are [func;startx;starty;firstrow;lastrow]. See the + # section Mouse Tracking. + + # CSI > Pm T + # Reset title mode features to default value (XTRMTITLE), xterm. + # Normally, "reset" disables the feature. It is possible to + # disable the ability to reset features by compiling a different + # default for the title modes into xterm. + # + # Ps = 0 ⇒ Do not set window/icon labels using hexadecimal. + # Ps = 1 ⇒ Do not query window/icon labels using + # hexadecimal. + # Ps = 2 ⇒ Do not set window/icon labels using UTF-8. + # Ps = 3 ⇒ Do not query window/icon labels using UTF-8. + # + # (See discussion of Title Modes). + + # CSI Ps X Erase Ps Character(s) (default = 1) (ECH). + def _CSI_X_ECH(self, ps, _): pass + + # CSI Ps Z Cursor Backward Tabulation Ps tab stops (default = 1) (CBT). + def _CSI_Z_CBT(self, ps, _): pass + + # CSI Ps ^ Scroll down Ps lines (default = 1) (SD), ECMA-48. + # This was a publication error in the original ECMA-48 5th + # edition (1991) corrected in 2003. + def _CSI___SD(self, ps, _): pass + + # CSI Ps ` Character Position Absolute [column] (default = [row,1]) + # (HPA). + def _CSI___HPA(self, ps, _): pass + + # CSI Ps a Character Position Relative [columns] (default = [row,col+1]) + # (HPR). + def _CSI_a_HPR(self, ps, _): pass + + # CSI Ps b Repeat the preceding graphic character Ps times (REP). + def _CSI_b_REP(self, ps, _): pass + + # CSI Ps c Send Device Attributes (Primary DA). + # Ps = 0 or omitted ⇒ request attributes from terminal. The + # response depends on the decTerminalID resource setting. + # ⇒ CSI ? 1 ; 2 c ("VT100 with Advanced Video Option") + # ⇒ CSI ? 1 ; 0 c ("VT101 with No Options") + # ⇒ CSI ? 4 ; 6 c ("VT132 with Advanced Video and Graphics") + # ⇒ CSI ? 6 c ("VT102") + # ⇒ CSI ? 7 c ("VT131") + # ⇒ CSI ? 1 2 ; Ps c ("VT125") + # ⇒ CSI ? 6 2 ; Ps c ("VT220") + # ⇒ CSI ? 6 3 ; Ps c ("VT320") + # ⇒ CSI ? 6 4 ; Ps c ("VT420") + # + # The VT100-style response parameters do not mean anything by + # themselves. VT220 (and higher) parameters do, telling the + # host what features the terminal supports: + # Ps = 1 ⇒ 132-columns. + # Ps = 2 ⇒ Printer. + # Ps = 3 ⇒ ReGIS graphics. + # Ps = 4 ⇒ Sixel graphics. + # Ps = 6 ⇒ Selective erase. + # Ps = 8 ⇒ User-defined keys. + # Ps = 9 ⇒ National Replacement Character sets. + # Ps = 1 5 ⇒ Technical characters. + # Ps = 1 6 ⇒ Locator port. + # Ps = 1 7 ⇒ Terminal state interrogation. + # Ps = 1 8 ⇒ User windows. + # Ps = 2 1 ⇒ Horizontal scrolling. + # Ps = 2 2 ⇒ ANSI color, e.g., VT525. + # Ps = 2 8 ⇒ Rectangular editing. + # Ps = 2 9 ⇒ ANSI text locator (i.e., DEC Locator mode). + # + # XTerm supports part of the User windows feature, providing a + # single page (which corresponds to its visible window). Rather + # than resizing the font to change the number of lines/columns + # in a fixed-size display, xterm uses the window extension + # controls (DECSNLS, DECSCPP, DECSLPP) to adjust its visible + # window's size. The "cursor coupling" controls (DECHCCM, + # DECPCCM, DECVCCM) are ignored. + def _CSI_c_Pri_DA(self, ps, _): pass + + # CSI = Ps c + # Send Device Attributes (Tertiary DA). + # Ps = 0 ⇒ report Terminal Unit ID (default), VT400. XTerm + # uses zeros for the site code and serial number in its DECRPTUI + # response. + # def _CSI_c_Ter_DA(self, ps, _): pass + + # CSI > Ps c + # Send Device Attributes (Secondary DA). + # Ps = 0 or omitted ⇒ request the terminal's identification + # code. The response depends on the decTerminalID resource + # setting. It should apply only to VT220 and up, but xterm + # extends this to VT100. + # ⇒ CSI > Pp ; Pv ; Pc c + # where Pp denotes the terminal type + # Pp = 0 ⇒ "VT100". + # Pp = 1 ⇒ "VT220". + # Pp = 2 ⇒ "VT240" or "VT241". + # Pp = 1 8 ⇒ "VT330". + # Pp = 1 9 ⇒ "VT340". + # Pp = 2 4 ⇒ "VT320". + # Pp = 3 2 ⇒ "VT382". + # Pp = 4 1 ⇒ "VT420". + # Pp = 6 1 ⇒ "VT510". + # Pp = 6 4 ⇒ "VT520". + # Pp = 6 5 ⇒ "VT525". + # + # and Pv is the firmware version (for xterm, this was originally + # the XFree86 patch number, starting with 95). In a DEC + # terminal, Pc indicates the ROM cartridge registration number + # and is always zero. + # def _CSI_c_DA(self, ps, _): pass + + # CSI Ps d Line Position Absolute [row] (default = [1,column]) (VPA). + def _CSI_d_VPA(self, ps, _): pass + + # CSI Ps e Line Position Relative [rows] (default = [row+1,column]) + # (VPR). + def _CSI_e_VPR(self, ps, _): pass + + # CSI Ps ; Ps f + # Horizontal and Vertical Position [row;column] (default = + # [1,1]) (HVP). + def _CSI_f_HVP(self, row, col): pass + + # CSI Ps g Tab Clear (TBC). ECMA-48 defines additional codes, but the + # VT100 user manual notes that it ignores other codes. DEC's + # later terminals (and xterm) do the same, for compatibility. + # Ps = 0 ⇒ Clear Current Column (default). + # Ps = 3 ⇒ Clear All. + def _CSI_g_TBC(self, ps, _): pass + + # CSI Pm h Set Mode (SM). + # Ps = 2 ⇒ Keyboard Action Mode (KAM). + # Ps = 4 ⇒ Insert Mode (IRM). + # Ps = 1 2 ⇒ Send/receive (SRM). + # Ps = 2 0 ⇒ Automatic Newline (LNM). + def _CSI_h_SM(self, ps, _): pass + + # CSI ? Pm h + # DEC Private Mode Set (DECSET). + # Ps = 1 ⇒ Application Cursor Keys (DECCKM), VT100. + # Ps = 2 ⇒ Designate USASCII for character sets G0-G3 + # (DECANM), VT100, and set VT100 mode. + # Ps = 3 ⇒ 132 Column Mode (DECCOLM), VT100. + # Ps = 4 ⇒ Smooth (Slow) Scroll (DECSCLM), VT100. + # Ps = 5 ⇒ Reverse Video (DECSCNM), VT100. + # Ps = 6 ⇒ Origin Mode (DECOM), VT100. + # Ps = 7 ⇒ Auto-Wrap Mode (DECAWM), VT100. + # Ps = 8 ⇒ Auto-Repeat Keys (DECARM), VT100. + # Ps = 9 ⇒ Send Mouse X & Y on button press. See the + # section Mouse Tracking. This is the X10 xterm mouse protocol. + # Ps = 1 0 ⇒ Show toolbar (rxvt). + # Ps = 1 2 ⇒ Start blinking cursor (AT&T 610). + # Ps = 1 3 ⇒ Start blinking cursor (set only via resource or + # menu). + # Ps = 1 4 ⇒ Enable XOR of blinking cursor control sequence + # and menu. + # Ps = 1 8 ⇒ Print Form Feed (DECPFF), VT220. + # Ps = 1 9 ⇒ Set print extent to full screen (DECPEX), + # VT220. + # Ps = 2 5 ⇒ Show cursor (DECTCEM), VT220. + # Ps = 3 0 ⇒ Show scrollbar (rxvt). + # Ps = 3 5 ⇒ Enable font-shifting functions (rxvt). + # Ps = 3 8 ⇒ Enter Tektronix mode (DECTEK), VT240, xterm. + # Ps = 4 0 ⇒ Allow 80 ⇒ 132 mode, xterm. + # Ps = 4 1 ⇒ more(1) fix (see curses resource). + # Ps = 4 2 ⇒ Enable National Replacement Character sets + # (DECNRCM), VT220. + # Ps = 4 3 ⇒ Enable Graphic Expanded Print Mode (DECGEPM), + # VT340. + # Ps = 4 4 ⇒ Turn on margin bell, xterm. + # Ps = 4 4 ⇒ Enable Graphic Print Color Mode (DECGPCM), + # VT340. + # Ps = 4 5 ⇒ Reverse-wraparound mode (XTREVWRAP), xterm. + # Ps = 4 5 ⇒ Enable Graphic Print Color Syntax (DECGPCS), + # VT340. + # Ps = 4 6 ⇒ Start logging (XTLOGGING), xterm. This is + # normally disabled by a compile-time option. + # Ps = 4 6 ⇒ Graphic Print Background Mode, VT340. + # Ps = 4 7 ⇒ Use Alternate Screen Buffer, xterm. This may + # be disabled by the titeInhibit resource. + # Ps = 4 7 ⇒ Enable Graphic Rotated Print Mode (DECGRPM), + # VT340. + # Ps = 6 6 ⇒ Application keypad mode (DECNKM), VT320. + # Ps = 6 7 ⇒ Backarrow key sends backspace (DECBKM), VT340, + # VT420. This sets the backarrowKey resource to "true". + # Ps = 6 9 ⇒ Enable left and right margin mode (DECLRMM), + # VT420 and up. + # Ps = 8 0 ⇒ Enable Sixel Display Mode (DECSDM), VT330, + # VT340, VT382. + # Ps = 9 5 ⇒ Do not clear screen when DECCOLM is set/reset + # (DECNCSM), VT510 and up. + # Ps = 1 0 0 0 ⇒ Send Mouse X & Y on button press and + # release. See the section Mouse Tracking. This is the X11 + # xterm mouse protocol. + # Ps = 1 0 0 1 ⇒ Use Hilite Mouse Tracking, xterm. + # Ps = 1 0 0 2 ⇒ Use Cell Motion Mouse Tracking, xterm. See + # the section Button-event tracking. + # Ps = 1 0 0 3 ⇒ Use All Motion Mouse Tracking, xterm. See + # the section Any-event tracking. + # Ps = 1 0 0 4 ⇒ Send FocusIn/FocusOut events, xterm. + # Ps = 1 0 0 5 ⇒ Enable UTF-8 Mouse Mode, xterm. + # Ps = 1 0 0 6 ⇒ Enable SGR Mouse Mode, xterm. + # Ps = 1 0 0 7 ⇒ Enable Alternate Scroll Mode, xterm. This + # corresponds to the alternateScroll resource. + # Ps = 1 0 1 0 ⇒ Scroll to bottom on tty output (rxvt). + # This sets the scrollTtyOutput resource to "true". + # Ps = 1 0 1 1 ⇒ Scroll to bottom on key press (rxvt). This + # sets the scrollKey resource to "true". + # Ps = 1 0 1 5 ⇒ Enable urxvt Mouse Mode. + # Ps = 1 0 1 6 ⇒ Enable SGR Mouse PixelMode, xterm. + # Ps = 1 0 3 4 ⇒ Interpret "meta" key, xterm. This sets the + # eighth bit of keyboard input (and enables the eightBitInput + # resource). + # Ps = 1 0 3 5 ⇒ Enable special modifiers for Alt and + # NumLock keys, xterm. This enables the numLock resource. + # Ps = 1 0 3 6 ⇒ Send ESC when Meta modifies a key, xterm. + # This enables the metaSendsEscape resource. + # Ps = 1 0 3 7 ⇒ Send DEL from the editing-keypad Delete + # key, xterm. + # Ps = 1 0 3 9 ⇒ Send ESC when Alt modifies a key, xterm. + # This enables the altSendsEscape resource, xterm. + # Ps = 1 0 4 0 ⇒ Keep selection even if not highlighted, + # xterm. This enables the keepSelection resource. + # Ps = 1 0 4 1 ⇒ Use the CLIPBOARD selection, xterm. This + # enables the selectToClipboard resource. + # Ps = 1 0 4 2 ⇒ Enable Urgency window manager hint when + # Control-G is received, xterm. This enables the bellIsUrgent + # resource. + # Ps = 1 0 4 3 ⇒ Enable raising of the window when Control-G + # is received, xterm. This enables the popOnBell resource. + # Ps = 1 0 4 4 ⇒ Reuse the most recent data copied to + # CLIPBOARD, xterm. This enables the keepClipboard resource. + # Ps = 1 0 4 5 ⇒ Extended Reverse-wraparound mode + # (XTREVWRAP2), xterm. + # Ps = 1 0 4 6 ⇒ Enable switching to/from Alternate Screen + # Buffer, xterm. This works for terminfo-based systems, + # updating the titeInhibit resource. + # Ps = 1 0 4 7 ⇒ Use Alternate Screen Buffer, xterm. This + # may be disabled by the titeInhibit resource. + # Ps = 1 0 4 8 ⇒ Save cursor as in DECSC, xterm. This may + # be disabled by the titeInhibit resource. + # Ps = 1 0 4 9 ⇒ Save cursor as in DECSC, xterm. After + # saving the cursor, switch to the Alternate Screen Buffer, + # clearing it first. This may be disabled by the titeInhibit + # resource. This control combines the effects of the 1 0 4 7 + # and 1 0 4 8 modes. Use this with terminfo-based applications + # rather than the 4 7 mode. + # Ps = 1 0 5 0 ⇒ Set terminfo/termcap function-key mode, + # xterm. + # Ps = 1 0 5 1 ⇒ Set Sun function-key mode, xterm. + # Ps = 1 0 5 2 ⇒ Set HP function-key mode, xterm. + # Ps = 1 0 5 3 ⇒ Set SCO function-key mode, xterm. + # Ps = 1 0 6 0 ⇒ Set legacy keyboard emulation, i.e, X11R6, + # xterm. + # Ps = 1 0 6 1 ⇒ Set VT220 keyboard emulation, xterm. + # Ps = 2 0 0 1 ⇒ Enable readline mouse button-1, xterm. + # Ps = 2 0 0 2 ⇒ Enable readline mouse button-2, xterm. + # Ps = 2 0 0 3 ⇒ Enable readline mouse button-3, xterm. + # Ps = 2 0 0 4 ⇒ Set bracketed paste mode, xterm. + # Ps = 2 0 0 5 ⇒ Enable readline character-quoting, xterm. + # Ps = 2 0 0 6 ⇒ Enable readline newline pasting, xterm. + # def _CSI__(self, ps, _): pass + + # CSI Ps i Media Copy (MC). + # Ps = 0 ⇒ Print screen (default). + # Ps = 4 ⇒ Turn off printer controller mode. + # Ps = 5 ⇒ Turn on printer controller mode. + # Ps = 1 0 ⇒ HTML screen dump, xterm. + # Ps = 1 1 ⇒ SVG screen dump, xterm. + def _CSI_i_MC(self, ps, _): pass + + # CSI ? Ps i + # Media Copy (MC), DEC-specific. + # Ps = 1 ⇒ Print line containing cursor. + # Ps = 4 ⇒ Turn off autoprint mode. + # Ps = 5 ⇒ Turn on autoprint mode. + # Ps = 1 0 ⇒ Print composed display, ignores DECPEX. + # Ps = 1 1 ⇒ Print all pages. + # def _CSI__(self, ps, _): pass + + # CSI Pm l Reset Mode (RM). + # Ps = 2 ⇒ Keyboard Action Mode (KAM). + # Ps = 4 ⇒ Replace Mode (IRM). + # Ps = 1 2 ⇒ Send/receive (SRM). + # Ps = 2 0 ⇒ Normal Linefeed (LNM). + def _CSI_l_RM(self, ps, _): pass + + # CSI ? Pm l + # DEC Private Mode Reset (DECRST). + # Ps = 1 ⇒ Normal Cursor Keys (DECCKM), VT100. + # Ps = 2 ⇒ Designate VT52 mode (DECANM), VT100. + # Ps = 3 ⇒ 80 Column Mode (DECCOLM), VT100. + # Ps = 4 ⇒ Jump (Fast) Scroll (DECSCLM), VT100. + # Ps = 5 ⇒ Normal Video (DECSCNM), VT100. + # Ps = 6 ⇒ Normal Cursor Mode (DECOM), VT100. + # Ps = 7 ⇒ No Auto-Wrap Mode (DECAWM), VT100. + # Ps = 8 ⇒ No Auto-Repeat Keys (DECARM), VT100. + # Ps = 9 ⇒ Don't send Mouse X & Y on button press, xterm. + # Ps = 1 0 ⇒ Hide toolbar (rxvt). + # Ps = 1 2 ⇒ Stop blinking cursor (AT&T 610). + # Ps = 1 3 ⇒ Disable blinking cursor (reset only via + # resource or menu). + # Ps = 1 4 ⇒ Disable XOR of blinking cursor control sequence + # and menu. + # Ps = 1 8 ⇒ Don't Print Form Feed (DECPFF), VT220. + # Ps = 1 9 ⇒ Limit print to scrolling region (DECPEX), + # VT220. + # Ps = 2 5 ⇒ Hide cursor (DECTCEM), VT220. + # Ps = 3 0 ⇒ Don't show scrollbar (rxvt). + # Ps = 3 5 ⇒ Disable font-shifting functions (rxvt). + # Ps = 4 0 ⇒ Disallow 80 ⇒ 132 mode, xterm. + # Ps = 4 1 ⇒ No more(1) fix (see curses resource). + # Ps = 4 2 ⇒ Disable National Replacement Character sets + # (DECNRCM), VT220. + # Ps = 4 3 ⇒ Disable Graphic Expanded Print Mode (DECGEPM), + # VT340. + # Ps = 4 4 ⇒ Turn off margin bell, xterm. + # Ps = 4 4 ⇒ Disable Graphic Print Color Mode (DECGPCM), + # VT340. + # Ps = 4 5 ⇒ No Reverse-wraparound mode (XTREVWRAP), xterm. + # Ps = 4 5 ⇒ Disable Graphic Print Color Syntax (DECGPCS), + # VT340. + # Ps = 4 6 ⇒ Stop logging (XTLOGGING), xterm. This is + # normally disabled by a compile-time option. + # Ps = 4 7 ⇒ Use Normal Screen Buffer, xterm. + # Ps = 4 7 ⇒ Disable Graphic Rotated Print Mode (DECGRPM), + # VT340. + # Ps = 6 6 ⇒ Numeric keypad mode (DECNKM), VT320. + # Ps = 6 7 ⇒ Backarrow key sends delete (DECBKM), VT340, + # VT420. This sets the backarrowKey resource to "false". + # Ps = 6 9 ⇒ Disable left and right margin mode (DECLRMM), + # VT420 and up. + # Ps = 8 0 ⇒ Disable Sixel Display Mode (DECSDM), VT330, + # VT340, VT382. Turns on "Sixel Scrolling". See the section + # Sixel Graphics and mode 8 4 5 2 . + # Ps = 9 5 ⇒ Clear screen when DECCOLM is set/reset + # (DECNCSM), VT510 and up. + # Ps = 1 0 0 0 ⇒ Don't send Mouse X & Y on button press and + # release. See the section Mouse Tracking. + # Ps = 1 0 0 1 ⇒ Don't use Hilite Mouse Tracking, xterm. + # Ps = 1 0 0 2 ⇒ Don't use Cell Motion Mouse Tracking, + # xterm. See the section Button-event tracking. + # Ps = 1 0 0 3 ⇒ Don't use All Motion Mouse Tracking, xterm. + # See the section Any-event tracking. + # Ps = 1 0 0 4 ⇒ Don't send FocusIn/FocusOut events, xterm. + # Ps = 1 0 0 5 ⇒ Disable UTF-8 Mouse Mode, xterm. + # Ps = 1 0 0 6 ⇒ Disable SGR Mouse Mode, xterm. + # Ps = 1 0 0 7 ⇒ Disable Alternate Scroll Mode, xterm. This + # corresponds to the alternateScroll resource. + # Ps = 1 0 1 0 ⇒ Don't scroll to bottom on tty output + # (rxvt). This sets the scrollTtyOutput resource to "false". + # Ps = 1 0 1 1 ⇒ Don't scroll to bottom on key press (rxvt). + # This sets the scrollKey resource to "false". + # Ps = 1 0 1 5 ⇒ Disable urxvt Mouse Mode. + # Ps = 1 0 1 6 ⇒ Disable SGR Mouse Pixel-Mode, xterm. + # Ps = 1 0 3 4 ⇒ Don't interpret "meta" key, xterm. This + # disables the eightBitInput resource. + # Ps = 1 0 3 5 ⇒ Disable special modifiers for Alt and + # NumLock keys, xterm. This disables the numLock resource. + # Ps = 1 0 3 6 ⇒ Don't send ESC when Meta modifies a key, + # xterm. This disables the metaSendsEscape resource. + # Ps = 1 0 3 7 ⇒ Send VT220 Remove from the editing-keypad + # Delete key, xterm. + # Ps = 1 0 3 9 ⇒ Don't send ESC when Alt modifies a key, + # xterm. This disables the altSendsEscape resource. + # Ps = 1 0 4 0 ⇒ Do not keep selection when not highlighted, + # xterm. This disables the keepSelection resource. + # Ps = 1 0 4 1 ⇒ Use the PRIMARY selection, xterm. This + # disables the selectToClipboard resource. + # Ps = 1 0 4 2 ⇒ Disable Urgency window manager hint when + # Control-G is received, xterm. This disables the bellIsUrgent + # resource. + # Ps = 1 0 4 3 ⇒ Disable raising of the window when Control- + # G is received, xterm. This disables the popOnBell resource. + # Ps = 1 0 4 5 ⇒ No Extended Reverse-wraparound mode + # (XTREVWRAP2), xterm. + # Ps = 1 0 4 6 ⇒ Disable switching to/from Alternate Screen + # Buffer, xterm. This works for terminfo-based systems, + # updating the titeInhibit resource. If currently using the + # Alternate Screen Buffer, xterm switches to the Normal Screen + # Buffer. + # Ps = 1 0 4 7 ⇒ Use Normal Screen Buffer, xterm. Clear the + # screen first if in the Alternate Screen Buffer. This may be + # disabled by the titeInhibit resource. + # Ps = 1 0 4 8 ⇒ Restore cursor as in DECRC, xterm. This + # may be disabled by the titeInhibit resource. + # Ps = 1 0 4 9 ⇒ Use Normal Screen Buffer and restore cursor + # as in DECRC, xterm. This may be disabled by the titeInhibit + # resource. This combines the effects of the 1 0 4 7 and 1 0 4 + # 8 modes. Use this with terminfo-based applications rather + # than the 4 7 mode. + # Ps = 1 0 5 0 ⇒ Reset terminfo/termcap function-key mode, + # xterm. + # Ps = 1 0 5 1 ⇒ Reset Sun function-key mode, xterm. + # Ps = 1 0 5 2 ⇒ Reset HP function-key mode, xterm. + # Ps = 1 0 5 3 ⇒ Reset SCO function-key mode, xterm. + # Ps = 1 0 6 0 ⇒ Reset legacy keyboard emulation, i.e, + # X11R6, xterm. + # Ps = 1 0 6 1 ⇒ Reset keyboard emulation to Sun/PC style, + # xterm. + # Ps = 2 0 0 1 ⇒ Disable readline mouse button-1, xterm. + # Ps = 2 0 0 2 ⇒ Disable readline mouse button-2, xterm. + # Ps = 2 0 0 3 ⇒ Disable readline mouse button-3, xterm. + # Ps = 2 0 0 4 ⇒ Reset bracketed paste mode, xterm. + # Ps = 2 0 0 5 ⇒ Disable readline character-quoting, xterm. + # Ps = 2 0 0 6 ⇒ Disable readline newline pasting, xterm. + # def _CSI__(self, ps, _): pass + + # CSI Pm m Character Attributes (SGR). + # Ps = 0 ⇒ Normal (default), VT100. + # Ps = 1 ⇒ Bold, VT100. + # Ps = 2 ⇒ Faint, decreased intensity, ECMA-48 2nd. + # Ps = 3 ⇒ Italicized, ECMA-48 2nd. + # Ps = 4 ⇒ Underlined, VT100. + # Ps = 5 ⇒ Blink, VT100. + # This appears as Bold in X11R6 xterm. + # Ps = 7 ⇒ Inverse, VT100. + # Ps = 8 ⇒ Invisible, i.e., hidden, ECMA-48 2nd, VT300. + # Ps = 9 ⇒ Crossed-out characters, ECMA-48 3rd. + # Ps = 2 1 ⇒ Doubly-underlined, ECMA-48 3rd. + # Ps = 2 2 ⇒ Normal (neither bold nor faint), ECMA-48 3rd. + # Ps = 2 3 ⇒ Not italicized, ECMA-48 3rd. + # Ps = 2 4 ⇒ Not underlined, ECMA-48 3rd. + # Ps = 2 5 ⇒ Steady (not blinking), ECMA-48 3rd. + # Ps = 2 7 ⇒ Positive (not inverse), ECMA-48 3rd. + # Ps = 2 8 ⇒ Visible, i.e., not hidden, ECMA-48 3rd, VT300. + # Ps = 2 9 ⇒ Not crossed-out, ECMA-48 3rd. + # Ps = 3 0 ⇒ Set foreground color to Black. + # Ps = 3 1 ⇒ Set foreground color to Red. + # Ps = 3 2 ⇒ Set foreground color to Green. + # Ps = 3 3 ⇒ Set foreground color to Yellow. + # Ps = 3 4 ⇒ Set foreground color to Blue. + # Ps = 3 5 ⇒ Set foreground color to Magenta. + # Ps = 3 6 ⇒ Set foreground color to Cyan. + # Ps = 3 7 ⇒ Set foreground color to White. + # Ps = 3 9 ⇒ Set foreground color to default, ECMA-48 3rd. + # Ps = 4 0 ⇒ Set background color to Black. + # Ps = 4 1 ⇒ Set background color to Red. + # Ps = 4 2 ⇒ Set background color to Green. + # Ps = 4 3 ⇒ Set background color to Yellow. + # Ps = 4 4 ⇒ Set background color to Blue. + # Ps = 4 5 ⇒ Set background color to Magenta. + # Ps = 4 6 ⇒ Set background color to Cyan. + # Ps = 4 7 ⇒ Set background color to White. + # Ps = 4 9 ⇒ Set background color to default, ECMA-48 3rd. + # + # Some of the above note the edition of ECMA-48 which first + # describes a feature. In its successive editions from 1979 to + # 1991 (2nd 1979, 3rd 1984, 4th 1986, and 5th 1991), ECMA-48 + # listed codes through 6 5 (skipping several toward the end of + # the range). Most of the ECMA-48 codes not implemented in + # xterm were never implemented in a hardware terminal. Several + # (such as 3 9 and 4 9 ) are either noted in ECMA-48 as + # implementation defined, or described in vague terms. + # + # The successive editions of ECMA-48 give little attention to + # changes from one edition to the next, except to comment on + # features which have become obsolete. ECMA-48 1st (1976) is + # unavailable; there is no reliable source of information which + # states whether "ANSI" color was defined in that edition, or + # later (1979). The VT100 (1978) implemented the most commonly + # used non-color video attributes which are given in the 2nd + # edition. + # + # While 8-color support is described in ECMA-48 2nd edition, the + # VT500 series (introduced in 1993) were the first DEC terminals + # implementing "ANSI" color. The DEC terminal's use of color is + # known to differ from xterm; useful documentation on this + # series became available too late to influence xterm. + # + # If 16-color support is compiled, the following aixterm + # controls apply. Assume that xterm's resources are set so that + # the ISO color codes are the first 8 of a set of 16. Then the + # aixterm colors are the bright versions of the ISO colors: + # + # Ps = 9 0 ⇒ Set foreground color to Black. + # Ps = 9 1 ⇒ Set foreground color to Red. + # Ps = 9 2 ⇒ Set foreground color to Green. + # Ps = 9 3 ⇒ Set foreground color to Yellow. + # Ps = 9 4 ⇒ Set foreground color to Blue. + # Ps = 9 5 ⇒ Set foreground color to Magenta. + # Ps = 9 6 ⇒ Set foreground color to Cyan. + # Ps = 9 7 ⇒ Set foreground color to White. + # Ps = 1 0 0 ⇒ Set background color to Black. + # Ps = 1 0 1 ⇒ Set background color to Red. + # Ps = 1 0 2 ⇒ Set background color to Green. + # Ps = 1 0 3 ⇒ Set background color to Yellow. + # Ps = 1 0 4 ⇒ Set background color to Blue. + # Ps = 1 0 5 ⇒ Set background color to Magenta. + # Ps = 1 0 6 ⇒ Set background color to Cyan. + # Ps = 1 0 7 ⇒ Set background color to White. + # + # If xterm is compiled with the 16-color support disabled, it + # supports the following, from rxvt: + # Ps = 1 0 0 ⇒ Set foreground and background color to + # default. + # + # XTerm maintains a color palette whose entries are identified + # by an index beginning with zero. If 88- or 256-color support + # is compiled, the following apply: + # o All parameters are decimal integers. + # o RGB values range from zero (0) to 255. + # o The 88- and 256-color support uses subparameters described + # in ISO-8613-6 for indexed color. ISO-8613-6 also mentions + # direct color, using a similar scheme. xterm supports + # that, too. + # o xterm allows either colons (standard) or semicolons + # (legacy) to separate the subparameters (but after the + # first colon, colons must be used). + # + # The indexed- and direct-color features are summarized in the + # FAQ, which explains why semicolon is accepted as a + # subparameter delimiter: + # + # Can I set a color by its number? + # + # These ISO-8613-6 controls (marked in ECMA-48 5th edition as + # "reserved for future standardization") are supported by xterm: + # Ps = 3 8 : 2 : Pi : Pr : Pg : Pb ⇒ Set foreground color + # using RGB values. If xterm is not compiled with direct-color + # support, it uses the closest match in its palette for the + # given RGB Pr/Pg/Pb. The color space identifier Pi is ignored. + # Ps = 3 8 : 5 : Ps ⇒ Set foreground color to Ps, using + # indexed color. + # Ps = 4 8 : 2 : Pi : Pr : Pg : Pb ⇒ Set background color + # using RGB values. If xterm is not compiled with direct-color + # support, it uses the closest match in its palette for the + # given RGB Pr/Pg/Pb. The color space identifier Pi is ignored. + # Ps = 4 8 : 5 : Ps ⇒ Set background color to Ps, using + # indexed color. + # + # This variation on ISO-8613-6 is supported for compatibility + # with KDE konsole: + # Ps = 3 8 ; 2 ; Pr ; Pg ; Pb ⇒ Set foreground color using + # RGB values. If xterm is not compiled with direct-color + # support, it uses the closest match in its palette for the + # given RGB Pr/Pg/Pb. + # Ps = 4 8 ; 2 ; Pr ; Pg ; Pb ⇒ Set background color using + # RGB values. If xterm is not compiled with direct-color + # support, it uses the closest match in its palette for the + # given RGB Pr/Pg/Pb. + # + # In each case, if xterm is compiled with direct-color support, + # and the resource directColor is true, then rather than + # choosing the closest match, xterm asks the X server to + # directly render a given color. + def _CSI_m_SGR(self, ps, _): pass + + # CSI > Pp ; Pv m + # def _CSI__(self, ps, _): pass + # CSI > Pp m + # Set/reset key modifier options (XTMODKEYS), xterm. Set or + # reset resource-values used by xterm to decide whether to + # construct escape sequences holding information about the + # modifiers pressed with a given key. + # + # The first parameter Pp identifies the resource to set/reset. + # The second parameter Pv is the value to assign to the + # resource. + # + # If the second parameter is omitted, the resource is reset to + # its initial value. Values 3 and 5 are reserved for keypad- + # keys and string-keys. + # + # Pp = 0 ⇒ modifyKeyboard. + # Pp = 1 ⇒ modifyCursorKeys. + # Pp = 2 ⇒ modifyFunctionKeys. + # Pp = 4 ⇒ modifyOtherKeys. + # + # If no parameters are given, all resources are reset to their + # initial values. + # def _CSI__(self, ps, _): pass + + # CSI ? Pp m + # Query key modifier options (XTQMODKEYS), xterm. + # + # The parameter Pp identifies the resource to query. + # + # Pp = 0 ⇒ modifyKeyboard. + # Pp = 1 ⇒ modifyCursorKeys. + # Pp = 2 ⇒ modifyFunctionKeys. + # Pp = 4 ⇒ modifyOtherKeys. + # + # XTerm's response can be used to restore this state, because it + # is formatted as an XTMODKEYS control, i.e., + # + # CSI > Pp m + # + # where + # + # Pp = 0 ⇒ modifyKeyboard. + # Pp = 1 ⇒ modifyCursorKeys. + # Pp = 2 ⇒ modifyFunctionKeys. + # Pp = 4 ⇒ modifyOtherKeys. + + # CSI Ps n Device Status Report (DSR). + # Ps = 5 ⇒ Status Report. + # Result ("OK") is CSI 0 n + # Ps = 6 ⇒ Report Cursor Position (CPR) [row;column]. + # Result is CSI r ; c R + # + # Note: it is possible for this sequence to be sent by a + # function key. For example, with the default keyboard + # configuration the shifted F1 key may send (with shift-, + # control-, alt-modifiers) + # + # CSI 1 ; 2 R , or + # CSI 1 ; 5 R , or + # CSI 1 ; 6 R , etc. + # + # The second parameter encodes the modifiers; values range from + # 2 to 16. See the section PC-Style Function Keys for the + # codes. The modifyFunctionKeys and modifyKeyboard resources + # can change the form of the string sent from the modified F1 + # key. + def _CSI_n_DSR(self, ps, _): pass + + # CSI > Ps n + # Disable key modifier options, xterm. These modifiers may be + # enabled via the CSI > Pm m sequence. This control sequence + # corresponds to a resource value of "-1", which cannot be set + # with the other sequence. + # + # The parameter identifies the resource to be disabled: + # + # Ps = 0 ⇒ modifyKeyboard. + # Ps = 1 ⇒ modifyCursorKeys. + # Ps = 2 ⇒ modifyFunctionKeys. + # Ps = 4 ⇒ modifyOtherKeys. + # + # If the parameter is omitted, modifyFunctionKeys is disabled. + # When modifyFunctionKeys is disabled, xterm uses the modifier + # keys to make an extended sequence of function keys rather than + # adding a parameter to each function key to denote the + # modifiers. + + # CSI ? Ps n + # Device Status Report (DSR, DEC-specific). + # Ps = 6 ⇒ Report Cursor Position (DECXCPR). The response + # [row;column] is returned as + # CSI ? r ; c R + # (assumes the default page, i.e., "1"). + # Ps = 1 5 ⇒ Report Printer status. The response is + # CSI ? 1 0 n (ready). or + # CSI ? 1 1 n (not ready). + # Ps = 2 5 ⇒ Report UDK status. The response is + # CSI ? 2 0 n (unlocked) + # or + # CSI ? 2 1 n (locked). + # Ps = 2 6 ⇒ Report Keyboard status. The response is + # CSI ? 2 7 ; 1 ; 0 ; 0 n (North American). + # + # The last two parameters apply to VT300 & up (keyboard ready) + # and VT400 & up (LK01) respectively. + # + # Ps = 5 3 ⇒ Report Locator status. The response is CSI ? 5 + # 3 n Locator available, if compiled-in, or CSI ? 5 0 n No + # Locator, if not. + # Ps = 5 5 ⇒ Report Locator status. The response is CSI ? 5 + # 3 n Locator available, if compiled-in, or CSI ? 5 0 n No + # Locator, if not. + # Ps = 5 6 ⇒ Report Locator type. The response is CSI ? 5 7 + # ; 1 n Mouse, if compiled-in, or CSI ? 5 7 ; 0 n Cannot + # identify, if not. + # Ps = 6 2 ⇒ Report macro space (DECMSR). The response is + # CSI Pn * { . + # Ps = 6 3 ⇒ Report memory checksum (DECCKSR), VT420 and up. + # The response is DCS Pt ! ~ x x x x ST . + # Pt is the request id (from an optional parameter to the + # request). + # The x's are hexadecimal digits 0-9 and A-F. + # Ps = 7 5 ⇒ Report data integrity. The response is CSI ? 7 + # 0 n (ready, no errors). + # Ps = 8 5 ⇒ Report multi-session configuration. The + # response is CSI ? 8 3 n (not configured for multiple-session + # operation). + + # CSI > Ps p + # Set resource value pointerMode (XTSMPOINTER), xterm. This is + # used by xterm to decide whether to hide the pointer cursor as + # the user types. + # + # Valid values for the parameter: + # Ps = 0 ⇒ never hide the pointer. + # Ps = 1 ⇒ hide if the mouse tracking mode is not enabled. + # Ps = 2 ⇒ always hide the pointer, except when leaving the + # window. + # Ps = 3 ⇒ always hide the pointer, even if leaving/entering + # the window. + # + # If no parameter is given, xterm uses the default, which is 1 . + + # CSI ! p Soft terminal reset (DECSTR), VT220 and up. + + # CSI Pl ; Pc " p + # Set conformance level (DECSCL), VT220 and up. + # + # The first parameter selects the conformance level. Valid + # values are: + # Pl = 6 1 ⇒ level 1, e.g., VT100. + # Pl = 6 2 ⇒ level 2, e.g., VT200. + # Pl = 6 3 ⇒ level 3, e.g., VT300. + # Pl = 6 4 ⇒ level 4, e.g., VT400. + # Pl = 6 5 ⇒ level 5, e.g., VT500. + # + # The second parameter selects the C1 control transmission mode. + # This is an optional parameter, ignored in conformance level 1. + # Valid values are: + # Pc = 0 ⇒ 8-bit controls. + # Pc = 1 ⇒ 7-bit controls (DEC factory default). + # Pc = 2 ⇒ 8-bit controls. + # + # The 7-bit and 8-bit control modes can also be set by S7C1T and + # S8C1T, but DECSCL is preferred. + + # CSI Ps $ p + # Request ANSI mode (DECRQM). For VT300 and up, reply DECRPM is + # CSI Ps; Pm $ y + # where Ps is the mode number as in SM/RM, and Pm is the mode + # value: + # 0 - not recognized + # 1 - set + # 2 - reset + # 3 - permanently set + # 4 - permanently reset + + # CSI ? Ps $ p + # Request DEC private mode (DECRQM). For VT300 and up, reply + # DECRPM is + # CSI ? Ps; Pm $ y + # where Ps is the mode number as in DECSET/DECSET, Pm is the + # mode value as in the ANSI DECRQM. + # Two private modes are read-only (i.e., 1 3 and 1 4 ), + # provided only for reporting their values using this control + # sequence. They correspond to the resources cursorBlink and + # cursorBlinkXOR. + + # CSI # p + + # CSI Pm # p + # Push video attributes onto stack (XTPUSHSGR), xterm. This is + # an alias for CSI # { , used to work around language + # limitations of C#. + + # CSI > Ps q + # Ps = 0 ⇒ Report xterm name and version (XTVERSION). The + # response is a DSR sequence identifying the version: DCS > | + # text ST + + # CSI Ps q Load LEDs (DECLL), VT100. + # Ps = 0 ⇒ Clear all LEDS (default). + # Ps = 1 ⇒ Light Num Lock. + # Ps = 2 ⇒ Light Caps Lock. + # Ps = 3 ⇒ Light Scroll Lock. + # Ps = 2 1 ⇒ Extinguish Num Lock. + # Ps = 2 2 ⇒ Extinguish Caps Lock. + # Ps = 2 3 ⇒ Extinguish Scroll Lock. + def _CSI_q_DECLL(self, ps, _): pass + + # CSI Ps SP q + # Set cursor style (DECSCUSR), VT520. + # Ps = 0 ⇒ blinking block. + # Ps = 1 ⇒ blinking block (default). + # Ps = 2 ⇒ steady block. + # Ps = 3 ⇒ blinking underline. + # Ps = 4 ⇒ steady underline. + # Ps = 5 ⇒ blinking bar, xterm. + # Ps = 6 ⇒ steady bar, xterm. + + # CSI Ps " q + # Select character protection attribute (DECSCA), VT220. Valid + # values for the parameter: + # Ps = 0 ⇒ DECSED and DECSEL can erase (default). + # Ps = 1 ⇒ DECSED and DECSEL cannot erase. + # Ps = 2 ⇒ DECSED and DECSEL can erase. + + # CSI # q Pop video attributes from stack (XTPOPSGR), xterm. This is an + # alias for CSI # } , used to work around language limitations + # of C#. + + # CSI Ps ; Ps r + # Set Scrolling Region [top;bottom] (default = full size of + # window) (DECSTBM), VT100. + + # CSI ? Pm r + # Restore DEC Private Mode Values (XTRESTORE), xterm. The value + # of Ps previously saved is restored. Ps values are the same as + # for DECSET. + # + # Like Restore Cursor (DECRC), this uses a one-level cache. + # Unlike Restore Cursor, specific settings can be saved and + # restored independently. Only those modes listed as parameters + # are restored. + + # CSI Pt ; Pl ; Pb ; Pr ; Pm $ r + # Change Attributes in Rectangular Area (DECCARA), VT400 and up. + # Pt ; Pl ; Pb ; Pr denotes the rectangle. + # Pm denotes the SGR attributes to change: 0, 1, 4, 5, 7. + + # CSI s Save cursor, available only when DECLRMM is disabled (SCOSC, + # also ANSI.SYS). + def _CSI_s_SCOSC(self, _, __): pass + + # CSI Pl ; Pr s + # Set left and right margins (DECSLRM), VT420 and up. This is + # available only when DECLRMM is enabled. + + # CSI > Ps s + # Set/reset shift-escape options (XTSHIFTESCAPE), xterm. This + # corresponds to the shiftEscape resource. + # + # Valid values for the parameter: + # Ps = 0 ⇒ allow shift-key to override mouse protocol. + # Ps = 1 ⇒ conditionally allow shift-key as modifier in + # mouse protocol. + # + # These resource values are disallowed in the control sequence: + # Ps = 2 ⇒ always allow shift-key as modifier in mouse + # protocol. + # Ps = 3 ⇒ never allow shift-key as modifier in mouse + # protocol. + # + # If no parameter is given, xterm uses the default, which is 0 . + + # CSI ? Pm s + # Save DEC Private Mode Values (XTSAVE), xterm. Ps values are + # the same as for DECSET. + # + # Like Save Cursor (DECSC), this uses a one-level cache. Unlike + # Save Cursor, specific settings can be saved and restored + # independently. Only those modes listed as parameters are + # saved. + + # CSI Ps ; Ps ; Ps t + # Window manipulation (XTWINOPS), dtterm, extended by xterm. + # These controls may be disabled using the allowWindowOps + # resource. + # + # xterm uses Extended Window Manager Hints (EWMH) to maximize + # the window. Some window managers have incomplete support for + # EWMH. For instance, fvwm, flwm and quartz-wm advertise + # support for maximizing windows horizontally or vertically, but + # in fact equate those to the maximize operation. + # + # Valid values for the first (and any additional parameters) + # are: + # Ps = 1 ⇒ De-iconify window. + # Ps = 2 ⇒ Iconify window. + # Ps = 3 ; x ; y ⇒ Move window to [x, y]. + # Ps = 4 ; height ; width ⇒ Resize the xterm window to + # given height and width in pixels. Omitted parameters reuse + # the current height or width. Zero parameters use the + # display's height or width. + # Ps = 5 ⇒ Raise the xterm window to the front of the + # stacking order. + # Ps = 6 ⇒ Lower the xterm window to the bottom of the + # stacking order. + # Ps = 7 ⇒ Refresh the xterm window. + # Ps = 8 ; height ; width ⇒ Resize the text area to given + # height and width in characters. Omitted parameters reuse the + # current height or width. Zero parameters use the display's + # height or width. + # Ps = 9 ; 0 ⇒ Restore maximized window. + # Ps = 9 ; 1 ⇒ Maximize window (i.e., resize to screen + # size). + # Ps = 9 ; 2 ⇒ Maximize window vertically. + # Ps = 9 ; 3 ⇒ Maximize window horizontally. + # Ps = 1 0 ; 0 ⇒ Undo full-screen mode. + # Ps = 1 0 ; 1 ⇒ Change to full-screen. + # Ps = 1 0 ; 2 ⇒ Toggle full-screen. + # Ps = 1 1 ⇒ Report xterm window state. + # If the xterm window is non-iconified, it returns CSI 1 t . + # If the xterm window is iconified, it returns CSI 2 t . + # Ps = 1 3 ⇒ Report xterm window position. + # Note: X Toolkit positions can be negative, but the reported + # values are unsigned, in the range 0-65535. Negative values + # correspond to 32768-65535. + # Result is CSI 3 ; x ; y t + # Ps = 1 3 ; 2 ⇒ Report xterm text-area position. + # Result is CSI 3 ; x ; y t + # Ps = 1 4 ⇒ Report xterm text area size in pixels. + # Result is CSI 4 ; height ; width t + # Ps = 1 4 ; 2 ⇒ Report xterm window size in pixels. + # Normally xterm's window is larger than its text area, since it + # includes the frame (or decoration) applied by the window + # manager, as well as the area used by a scroll-bar. + # Result is CSI 4 ; height ; width t + # Ps = 1 5 ⇒ Report size of the screen in pixels. + # Result is CSI 5 ; height ; width t + # Ps = 1 6 ⇒ Report xterm character cell size in pixels. + # Result is CSI 6 ; height ; width t + # Ps = 1 8 ⇒ Report the size of the text area in characters. + # Result is CSI 8 ; height ; width t + # Ps = 1 9 ⇒ Report the size of the screen in characters. + # Result is CSI 9 ; height ; width t + # Ps = 2 0 ⇒ Report xterm window's icon label. + # Result is OSC L label ST + # Ps = 2 1 ⇒ Report xterm window's title. + # Result is OSC l label ST + # Ps = 2 2 ; 0 ⇒ Save xterm icon and window title on stack. + # Ps = 2 2 ; 1 ⇒ Save xterm icon title on stack. + # Ps = 2 2 ; 2 ⇒ Save xterm window title on stack. + # Ps = 2 3 ; 0 ⇒ Restore xterm icon and window title from + # stack. + # Ps = 2 3 ; 1 ⇒ Restore xterm icon title from stack. + # Ps = 2 3 ; 2 ⇒ Restore xterm window title from stack. + # Ps >= 2 4 ⇒ Resize to Ps lines (DECSLPP), VT340 and VT420. + # xterm adapts this by resizing its window. + + # CSI > Pm t + # This xterm control sets one or more features of the title + # modes (XTSMTITLE), xterm. Each parameter enables a single + # feature. + # Ps = 0 ⇒ Set window/icon labels using hexadecimal. + # Ps = 1 ⇒ Query window/icon labels using hexadecimal. + # Ps = 2 ⇒ Set window/icon labels using UTF-8. + # Ps = 3 ⇒ Query window/icon labels using UTF-8. (See + # discussion of Title Modes) + + # CSI Ps SP t + # Set warning-bell volume (DECSWBV), VT520. + # Ps = 0 or 1 ⇒ off. + # Ps = 2 , 3 or 4 ⇒ low. + # Ps = 5 , 6 , 7 , or 8 ⇒ high. + + # CSI Pt ; Pl ; Pb ; Pr ; Pm $ t + # Reverse Attributes in Rectangular Area (DECRARA), VT400 and + # up. + # Pt ; Pl ; Pb ; Pr denotes the rectangle. + # Pm denotes the attributes to reverse, i.e., 1, 4, 5, 7. + + # CSI u Restore cursor (SCORC, also ANSI.SYS). + def _CSI_u_SCORC(self, _, __): pass + + # CSI Ps SP u + # Set margin-bell volume (DECSMBV), VT520. + # Ps = 0 , 5 , 6 , 7 , or 8 ⇒ high. + # Ps = 1 ⇒ off. + # Ps = 2 , 3 or 4 ⇒ low. + + # CSI Pt ; Pl ; Pb ; Pr ; Pp ; Pt ; Pl ; Pp $ v + # Copy Rectangular Area (DECCRA), VT400 and up. + # Pt ; Pl ; Pb ; Pr denotes the rectangle. + # Pp denotes the source page. + # Pt ; Pl denotes the target location. + # Pp denotes the target page. + + # CSI Ps $ w + # Request presentation state report (DECRQPSR), VT320 and up. + # Ps = 0 ⇒ error. + # Ps = 1 ⇒ cursor information report (DECCIR). + # Response is + # DCS 1 $ u Pt ST + # Refer to the VT420 programming manual, which requires six + # pages to document the data string Pt, + # Ps = 2 ⇒ tab stop report (DECTABSR). + # Response is + # DCS 2 $ u Pt ST + # The data string Pt is a list of the tab-stops, separated by + # "/" characters. + + # CSI Pt ; Pl ; Pb ; Pr ' w + # Enable Filter Rectangle (DECEFR), VT420 and up. + # Parameters are [top;left;bottom;right]. + # Defines the coordinates of a filter rectangle and activates + # it. Anytime the locator is detected outside of the filter + # rectangle, an outside rectangle event is generated and the + # rectangle is disabled. Filter rectangles are always treated + # as "one-shot" events. Any parameters that are omitted default + # to the current locator position. If all parameters are + # omitted, any locator motion will be reported. DECELR always + # cancels any previous rectangle definition. + + # CSI Ps x Request Terminal Parameters (DECREQTPARM). + # if Ps is a "0" (default) or "1", and xterm is emulating VT100, + # the control sequence elicits a response of the same form whose + # parameters describe the terminal: + # Ps ⇒ the given Ps incremented by 2. + # Pn = 1 ⇐ no parity. + # Pn = 1 ⇐ eight bits. + # Pn = 1 ⇐ 2 8 transmit 38.4k baud. + # Pn = 1 ⇐ 2 8 receive 38.4k baud. + # Pn = 1 ⇐ clock multiplier. + # Pn = 0 ⇐ STP flags. + def _CSI_x_DECREQTPARM(self, x, __): pass + + # CSI Ps * x + # Select Attribute Change Extent (DECSACE), VT420 and up. + # Ps = 0 ⇒ from start to end position, wrapped. + # Ps = 1 ⇒ from start to end position, wrapped. + # Ps = 2 ⇒ rectangle (exact). + + # CSI Pc ; Pt ; Pl ; Pb ; Pr $ x + # Fill Rectangular Area (DECFRA), VT420 and up. + # Pc is the character to use. + # Pt ; Pl ; Pb ; Pr denotes the rectangle. + + # CSI Ps # y + # Select checksum extension (XTCHECKSUM), xterm. The bits of Ps + # modify the calculation of the checksum returned by DECRQCRA: + # 0 ⇒ do not negate the result. + # 1 ⇒ do not report the VT100 video attributes. + # 2 ⇒ do not omit checksum for blanks. + # 3 ⇒ omit checksum for cells not explicitly initialized. + # 4 ⇒ do not mask cell value to 8 bits or ignore combining + # characters. + # 5 ⇒ do not mask cell value to 7 bits. + + # CSI Pi ; Pg ; Pt ; Pl ; Pb ; Pr * y + # Request Checksum of Rectangular Area (DECRQCRA), VT420 and up. + # Response is + # DCS Pi ! ~ x x x x ST + # Pi is the request id. + # Pg is the page number. + # Pt ; Pl ; Pb ; Pr denotes the rectangle. + # The x's are hexadecimal digits 0-9 and A-F. + + # CSI Ps ; Pu ' z + # Enable Locator Reporting (DECELR). + # Valid values for the first parameter: + # Ps = 0 ⇒ Locator disabled (default). + # Ps = 1 ⇒ Locator enabled. + # Ps = 2 ⇒ Locator enabled for one report, then disabled. + # The second parameter specifies the coordinate unit for locator + # reports. + # Valid values for the second parameter: + # Pu = 0 or omitted ⇒ default to character cells. + # Pu = 1 ⇐ device physical pixels. + # Pu = 2 ⇐ character cells. + + # CSI Pt ; Pl ; Pb ; Pr $ z + # Erase Rectangular Area (DECERA), VT400 and up. + # Pt ; Pl ; Pb ; Pr denotes the rectangle. + + # CSI Pm ' { + # Select Locator Events (DECSLE). + # Valid values for the first (and any additional parameters) + # are: + # Ps = 0 ⇒ only respond to explicit host requests (DECRQLP). + # This is default. It also cancels any filter rectangle. + # Ps = 1 ⇒ report button down transitions. + # Ps = 2 ⇒ do not report button down transitions. + # Ps = 3 ⇒ report button up transitions. + # Ps = 4 ⇒ do not report button up transitions. + + # CSI # { + # CSI Pm # { + # Push video attributes onto stack (XTPUSHSGR), xterm. The + # optional parameters correspond to the SGR encoding for video + # attributes, except for colors (which do not have a unique SGR + # code): + # Ps = 1 ⇒ Bold. + # Ps = 2 ⇒ Faint. + # Ps = 3 ⇒ Italicized. + # Ps = 4 ⇒ Underlined. + # Ps = 5 ⇒ Blink. + # Ps = 7 ⇒ Inverse. + # Ps = 8 ⇒ Invisible. + # Ps = 9 ⇒ Crossed-out characters. + # Ps = 2 1 ⇒ Doubly-underlined. + # Ps = 3 0 ⇒ Foreground color. + # Ps = 3 1 ⇒ Background color. + # + # If no parameters are given, all of the video attributes are + # saved. The stack is limited to 10 levels. + + # CSI Pt ; Pl ; Pb ; Pr $ { + # Selective Erase Rectangular Area (DECSERA), VT400 and up. + # Pt ; Pl ; Pb ; Pr denotes the rectangle. + + # CSI Pt ; Pl ; Pb ; Pr # | + # Report selected graphic rendition (XTREPORTSGR), xterm. The + # response is an SGR sequence which contains the attributes + # which are common to all cells in a rectangle. + # Pt ; Pl ; Pb ; Pr denotes the rectangle. + + # CSI Ps $ | + # Select columns per page (DECSCPP), VT340. + # Ps = 0 ⇒ 80 columns, default if Ps omitted. + # Ps = 8 0 ⇒ 80 columns. + # Ps = 1 3 2 ⇒ 132 columns. + + # CSI Ps ' | + # Request Locator Position (DECRQLP). + # Valid values for the parameter are: + # Ps = 0 , 1 or omitted ⇒ transmit a single DECLRP locator + # report. + # + # If Locator Reporting has been enabled by a DECELR, xterm will + # respond with a DECLRP Locator Report. This report is also + # generated on button up and down events if they have been + # enabled with a DECSLE, or when the locator is detected outside + # of a filter rectangle, if filter rectangles have been enabled + # with a DECEFR. + # + # ⇐ CSI Pe ; Pb ; Pr ; Pc ; Pp & w + # + # Parameters are [event;button;row;column;page]. + # Valid values for the event: + # Pe = 0 ⇐ locator unavailable - no other parameters sent. + # Pe = 1 ⇐ request - xterm received a DECRQLP. + # Pe = 2 ⇐ left button down. + # Pe = 3 ⇐ left button up. + # Pe = 4 ⇐ middle button down. + # Pe = 5 ⇐ middle button up. + # Pe = 6 ⇐ right button down. + # Pe = 7 ⇐ right button up. + # Pe = 8 ⇐ M4 button down. + # Pe = 9 ⇐ M4 button up. + # Pe = 1 0 ⇐ locator outside filter rectangle. + # The "button" parameter is a bitmask indicating which buttons + # are pressed: + # Pb = 0 ⇐ no buttons down. + # Pb & 1 ⇐ right button down. + # Pb & 2 ⇐ middle button down. + # Pb & 4 ⇐ left button down. + # Pb & 8 ⇐ M4 button down. + # The "row" and "column" parameters are the coordinates of the + # locator position in the xterm window, encoded as ASCII + # decimal. + # The "page" parameter is not used by xterm. + + # CSI Ps * | + # Select number of lines per screen (DECSNLS), VT420 and up. + + # CSI # } Pop video attributes from stack (XTPOPSGR), xterm. Popping + # restores the video-attributes which were saved using XTPUSHSGR + # to their previous state. + + # CSI Ps ' } + # Insert Ps Column(s) (default = 1) (DECIC), VT420 and up. + + # CSI Ps $ } + # Select active status display (DECSASD), VT320 and up. + # Ps = 0 ⇒ main (default) + # Ps = 1 ⇒ status line + + # CSI Ps ' ~ + # Delete Ps Column(s) (default = 1) (DECDC), VT420 and up. + + # CSI Ps $ ~ + # Select status line type (DECSSDT), VT320 and up. + # Ps = 0 ⇒ none + # Ps = 1 ⇒ indicator (default) + # Ps = 2 ⇒ host-writable. + + _CSI_MAP = { + '@': _CSI___ICH, + # '@': _CSI___SL, + 'A': _CSI_A_CUU, + 'A': _CSI_A_SR, + 'B': _CSI_B_CUD, + 'C': _CSI_C_CUF, + 'D': _CSI_D_CUB, + 'E': _CSI_E_CNL, + 'F': _CSI_F_CPL, + 'G': _CSI_G_CHA, + 'H': _CSI_H_CUP, + 'I': _CSI_I_CHT, + 'J': _CSI_J_ED, + 'K': _CSI_K_el, + 'L': _CSI_L_IL, + 'M': _CSI_M_DL, + 'S': _CSI_S_SU, + 'T': _CSI_T_SD, + 'X': _CSI_X_ECH, + 'Z': _CSI_Z_CBT, + '^': _CSI___SD, + '`': _CSI___HPA, + 'a': _CSI_a_HPR, + 'b': _CSI_b_REP, + 'c': _CSI_c_Pri_DA, + 'd': _CSI_d_VPA, + 'e': _CSI_e_VPR, + 'f': _CSI_f_HVP, + 'g': _CSI_g_TBC, + 'h': _CSI_h_SM, + 'i': _CSI_i_MC, + 'l': _CSI_l_RM, + 'm': _CSI_m_SGR, + 'n': _CSI_n_DSR, + 'q': _CSI_q_DECLL, + 's': _CSI_s_SCOSC, + 'u': _CSI_u_SCORC, + 'x': _CSI_x_DECREQTPARM + } diff --git a/TermTk/TTkWidgets/TTkTerminal/terminal_normal.py b/TermTk/TTkWidgets/TTkTerminal/terminal_normal.py new file mode 100644 index 00000000..9ebe6df3 --- /dev/null +++ b/TermTk/TTkWidgets/TTkTerminal/terminal_normal.py @@ -0,0 +1,1429 @@ +# MIT License +# +# Copyright (c) 2023 Eugenio Parodi +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +import os, pty, threading +import re +from select import select +from TermTk.TTkCore.canvas import TTkCanvas + + +from TermTk.TTkCore.color import TTkColor +from TermTk.TTkCore.log import TTkLog +from TermTk.TTkCore.constant import TTkK +from TermTk.TTkCore.cfg import TTkCfg +from TermTk.TTkCore.string import TTkString +from TermTk.TTkCore.signal import pyTTkSignal, pyTTkSlot +from TermTk.TTkCore.helper import TTkHelper +from TermTk.TTkGui.clipboard import TTkClipboard +from TermTk.TTkGui.textwrap1 import TTkTextWrap +from TermTk.TTkGui.textcursor import TTkTextCursor +from TermTk.TTkGui.textdocument import TTkTextDocument +from TermTk.TTkLayouts.gridlayout import TTkGridLayout +from TermTk.TTkAbstract.abstractscrollarea import TTkAbstractScrollArea +from TermTk.TTkAbstract.abstractscrollview import TTkAbstractScrollView, TTkAbstractScrollViewGridLayout +from TermTk.TTkWidgets.widget import TTkWidget + +from .vt102 import TTkVT102 + +class _TTkTerminalNormalScreen(): + __slots__ = ('_lines', '_cursor') + def __init__(self) -> None: + self._lines = [TTkString()] + self._cursor = (0,0) + + def _pushTxt(self, txt): + x,y = self._cursor + self._cursor = (x+len(txt),y) + l = self._lines[y] + if x < len(l): + self._lines[y] = l.substring(to=x) + txt + l.substring(fr=x+len(txt)) + else: + self._lines[y] += txt + + def pushLine(self, line:str): + lines = line.split('\n') + for i,l in enumerate(lines): + if i: + self._lines.append(TTkString(color=self._lines[-1]._baseColor)) + self._cursor = (0,len(self._lines)-1) + ls = l.split('\r') + for ii,ll in enumerate(ls): + if ii: + self._cursor=(0,len(self._lines)-1) + lls = ll.split('\b') + for iii,lll in enumerate(lls): + if iii: + x,y = self._cursor + self._cursor = (max(0,x-1),y) + self._pushTxt(lll) + + + + def paintEvent(self, canvas:TTkCanvas, w:int, h:int, ox:int=0, oy:int=0) -> None: + canvas.drawText(text="NORMAL Screen", pos=(0,0), width=w) + for y,l in enumerate(self._lines[-h:]): + canvas.drawTTkString(text=l, pos=(0,y), width=w) + + + + # CSI Ps @ Insert Ps (Blank) Character(s) (default = 1) (ICH). + def _CSI___ICH(self, ps, _): pass + + # CSI Ps SP @ (SP = Space) + # Shift left Ps columns(s) (default = 1) (SL), ECMA-48. + def _CSI___SL( self, ps, _): pass + + # CSI Ps A Cursor Up Ps Times (default = 1) (CUU). + def _CSI_A_CUU(self, ps, _): pass + + # CSI Ps SP A (SP = Space) + # Shift right Ps columns(s) (default = 1) (SR), ECMA-48. + def _CSI_A_SR( self, ps, _): pass + + # CSI Ps B Cursor Down Ps Times (default = 1) (CUD). + def _CSI_B_CUD(self, ps, _): pass + + # CSI Ps C Cursor Forward Ps Times (default = 1) (CUF). + def _CSI_C_CUF(self, ps, _): pass + + # CSI Ps D Cursor Backward Ps Times (default = 1) (CUB). + def _CSI_D_CUB(self, ps, _): pass + + # CSI Ps E Cursor Next Line Ps Times (default = 1) (CNL). + def _CSI_E_CNL(self, ps, _): pass + + # CSI Ps F Cursor Preceding Line Ps Times (default = 1) (CPL). + def _CSI_F_CPL(self, ps, _): pass + + # CSI Ps G Cursor Character Absolute [column] (default = [row,1]) (CHA). + def _CSI_G_CHA(self, ps, _): pass + + # CSI Ps ; Ps H + # Cursor Position [row;column] (default = [1,1]) (CUP). + def _CSI_H_CUP(self, row, col): pass + + # CSI Ps I Cursor Forward Tabulation Ps tab stops (default = 1) (CHT). + def _CSI_I_CHT(self, ps, _): pass + + # CSI Ps J Erase in Display (ED), VT100. + # Ps = 0 ⇒ Erase Below (default). + # Ps = 1 ⇒ Erase Above. + # Ps = 2 ⇒ Erase All. + # Ps = 3 ⇒ Erase Saved Lines, xterm. + def _CSI_J_ED(self, ps, _): pass + + # CSI ? Ps J + # Erase in Display (DECSED), VT220. + # Ps = 0 ⇒ Selective Erase Below (default). + # Ps = 1 ⇒ Selective Erase Above. + # Ps = 2 ⇒ Selective Erase All. + # Ps = 3 ⇒ Selective Erase Saved Lines, xterm. + + # CSI Ps K Erase in Line (EL), VT100. + # Ps = 0 ⇒ Erase to Right (default). + # Ps = 1 ⇒ Erase to Left. + # Ps = 2 ⇒ Erase All. + def _CSI_K_el(self, ps, _): pass + + # CSI ? Ps K + # Erase in Line (DECSEL), VT220. + # Ps = 0 ⇒ Selective Erase to Right (default). + # Ps = 1 ⇒ Selective Erase to Left. + # Ps = 2 ⇒ Selective Erase All. + + # CSI Ps L Insert Ps Line(s) (default = 1) (IL). + def _CSI_L_IL(self, ps, _): pass + + # CSI Ps M Delete Ps Line(s) (default = 1) (DL). + def _CSI_M_DL(self, ps, _): pass + + # CSI Ps P Delete Ps Character(s) (default = 1) (DCH). + + # CSI # P + # CSI Pm # P + # Push current dynamic- and ANSI-palette colors onto stack + # (XTPUSHCOLORS), xterm. Parameters (integers in the range 1 + # through 10, since the default 0 will push) may be used to + # store the palette into the stack without pushing. + + # CSI # Q + # CSI Pm # Q + # Pop stack to set dynamic- and ANSI-palette colors + # (XTPOPCOLORS), xterm. Parameters (integers in the range 1 + # through 10, since the default 0 will pop) may be used to + # restore the palette from the stack without popping. + + # CSI # R Report the current entry on the palette stack, and the number + # of palettes stored on the stack, using the same form as + # XTPOPCOLOR (default = 0) (XTREPORTCOLORS), xterm. + + # CSI Ps S Scroll up Ps lines (default = 1) (SU), VT420, ECMA-48. + def _CSI_S_SU(self, ps, _): pass + + # CSI ? Pi ; Pa ; Pv S + # Set or request graphics attribute (XTSMGRAPHICS), xterm. If + # configured to support either Sixel Graphics or ReGIS Graphics, + # xterm accepts a three-parameter control sequence, where Pi, Pa + # and Pv are the item, action and value: + # + # Pi = 1 ⇒ item is number of color registers. + # Pi = 2 ⇒ item is Sixel graphics geometry (in pixels). + # Pi = 3 ⇒ item is ReGIS graphics geometry (in pixels). + # + # Pa = 1 ⇒ read attribute. + # Pa = 2 ⇒ reset to default. + # Pa = 3 ⇒ set to value in Pv. + # Pa = 4 ⇒ read the maximum allowed value. + # + # Pv is ignored by xterm except when setting (Pa == 3 ). + # Pv = n ⇐ A single integer is used for color registers. + # Pv = width ; height ⇐ Two integers for graphics geometry. + # + # xterm replies with a control sequence of the same form: + # + # CSI ? Pi ; Ps ; Pv S + # + # where Ps is the status: + # Ps = 0 ⇐ success. + # Ps = 1 ⇐ error in Pi. + # Ps = 2 ⇐ error in Pa. + # Ps = 3 ⇐ failure. + # + # On success, Pv represents the value read or set. + # + # Notes: + # o The current implementation allows reading the graphics + # sizes, but disallows modifying those sizes because that is + # done once, using resource-values. + # o Graphics geometry is not necessarily the same as "window + # size" (see the dtterm window manipulation extensions). + # XTerm limits the maximum graphics geometry according to + # the maxGraphicSize resource. + # The maxGraphicSize resource can be either an explicit + # heightxwidth (default: 1000x1000 as of version 328) or the + # word "auto" (telling XTerm to use limits the decGraphicsID + # or decTerminalID resource to determine the limits). + # o XTerm uses the minimum of the window size and the graphic + # size to obtain the maximum geometry. + # o While resizing a window will always change the current + # graphics geometry, the reverse is not true. Setting + # graphics geometry does not affect the window size. + # o If xterm is able to support graphics (compile-time), but + # is not configured (runtime) for graphics, these responses + # will indicate a failure. Other implementations which do + # not use the maximum graphics dimensions but are configured + # for graphics should report zeroes for the maximum geometry + # rather than a failure. + + # CSI Ps T Scroll down Ps lines (default = 1) (SD), VT420. + def _CSI_T_SD(self, ps, _): pass + + # CSI Ps ; Ps ; Ps ; Ps ; Ps T + # Initiate highlight mouse tracking (XTHIMOUSE), xterm. + # Parameters are [func;startx;starty;firstrow;lastrow]. See the + # section Mouse Tracking. + + # CSI > Pm T + # Reset title mode features to default value (XTRMTITLE), xterm. + # Normally, "reset" disables the feature. It is possible to + # disable the ability to reset features by compiling a different + # default for the title modes into xterm. + # + # Ps = 0 ⇒ Do not set window/icon labels using hexadecimal. + # Ps = 1 ⇒ Do not query window/icon labels using + # hexadecimal. + # Ps = 2 ⇒ Do not set window/icon labels using UTF-8. + # Ps = 3 ⇒ Do not query window/icon labels using UTF-8. + # + # (See discussion of Title Modes). + + # CSI Ps X Erase Ps Character(s) (default = 1) (ECH). + def _CSI_X_ECH(self, ps, _): pass + + # CSI Ps Z Cursor Backward Tabulation Ps tab stops (default = 1) (CBT). + def _CSI_Z_CBT(self, ps, _): pass + + # CSI Ps ^ Scroll down Ps lines (default = 1) (SD), ECMA-48. + # This was a publication error in the original ECMA-48 5th + # edition (1991) corrected in 2003. + def _CSI___SD(self, ps, _): pass + + # CSI Ps ` Character Position Absolute [column] (default = [row,1]) + # (HPA). + def _CSI___HPA(self, ps, _): pass + + # CSI Ps a Character Position Relative [columns] (default = [row,col+1]) + # (HPR). + def _CSI_a_HPR(self, ps, _): pass + + # CSI Ps b Repeat the preceding graphic character Ps times (REP). + def _CSI_b_REP(self, ps, _): pass + + # CSI Ps c Send Device Attributes (Primary DA). + # Ps = 0 or omitted ⇒ request attributes from terminal. The + # response depends on the decTerminalID resource setting. + # ⇒ CSI ? 1 ; 2 c ("VT100 with Advanced Video Option") + # ⇒ CSI ? 1 ; 0 c ("VT101 with No Options") + # ⇒ CSI ? 4 ; 6 c ("VT132 with Advanced Video and Graphics") + # ⇒ CSI ? 6 c ("VT102") + # ⇒ CSI ? 7 c ("VT131") + # ⇒ CSI ? 1 2 ; Ps c ("VT125") + # ⇒ CSI ? 6 2 ; Ps c ("VT220") + # ⇒ CSI ? 6 3 ; Ps c ("VT320") + # ⇒ CSI ? 6 4 ; Ps c ("VT420") + # + # The VT100-style response parameters do not mean anything by + # themselves. VT220 (and higher) parameters do, telling the + # host what features the terminal supports: + # Ps = 1 ⇒ 132-columns. + # Ps = 2 ⇒ Printer. + # Ps = 3 ⇒ ReGIS graphics. + # Ps = 4 ⇒ Sixel graphics. + # Ps = 6 ⇒ Selective erase. + # Ps = 8 ⇒ User-defined keys. + # Ps = 9 ⇒ National Replacement Character sets. + # Ps = 1 5 ⇒ Technical characters. + # Ps = 1 6 ⇒ Locator port. + # Ps = 1 7 ⇒ Terminal state interrogation. + # Ps = 1 8 ⇒ User windows. + # Ps = 2 1 ⇒ Horizontal scrolling. + # Ps = 2 2 ⇒ ANSI color, e.g., VT525. + # Ps = 2 8 ⇒ Rectangular editing. + # Ps = 2 9 ⇒ ANSI text locator (i.e., DEC Locator mode). + # + # XTerm supports part of the User windows feature, providing a + # single page (which corresponds to its visible window). Rather + # than resizing the font to change the number of lines/columns + # in a fixed-size display, xterm uses the window extension + # controls (DECSNLS, DECSCPP, DECSLPP) to adjust its visible + # window's size. The "cursor coupling" controls (DECHCCM, + # DECPCCM, DECVCCM) are ignored. + def _CSI_c_Pri_DA(self, ps, _): pass + + # CSI = Ps c + # Send Device Attributes (Tertiary DA). + # Ps = 0 ⇒ report Terminal Unit ID (default), VT400. XTerm + # uses zeros for the site code and serial number in its DECRPTUI + # response. + # def _CSI_c_Ter_DA(self, ps, _): pass + + # CSI > Ps c + # Send Device Attributes (Secondary DA). + # Ps = 0 or omitted ⇒ request the terminal's identification + # code. The response depends on the decTerminalID resource + # setting. It should apply only to VT220 and up, but xterm + # extends this to VT100. + # ⇒ CSI > Pp ; Pv ; Pc c + # where Pp denotes the terminal type + # Pp = 0 ⇒ "VT100". + # Pp = 1 ⇒ "VT220". + # Pp = 2 ⇒ "VT240" or "VT241". + # Pp = 1 8 ⇒ "VT330". + # Pp = 1 9 ⇒ "VT340". + # Pp = 2 4 ⇒ "VT320". + # Pp = 3 2 ⇒ "VT382". + # Pp = 4 1 ⇒ "VT420". + # Pp = 6 1 ⇒ "VT510". + # Pp = 6 4 ⇒ "VT520". + # Pp = 6 5 ⇒ "VT525". + # + # and Pv is the firmware version (for xterm, this was originally + # the XFree86 patch number, starting with 95). In a DEC + # terminal, Pc indicates the ROM cartridge registration number + # and is always zero. + # def _CSI_c_DA(self, ps, _): pass + + # CSI Ps d Line Position Absolute [row] (default = [1,column]) (VPA). + def _CSI_d_VPA(self, ps, _): pass + + # CSI Ps e Line Position Relative [rows] (default = [row+1,column]) + # (VPR). + def _CSI_e_VPR(self, ps, _): pass + + # CSI Ps ; Ps f + # Horizontal and Vertical Position [row;column] (default = + # [1,1]) (HVP). + def _CSI_f_HVP(self, row, col): pass + + # CSI Ps g Tab Clear (TBC). ECMA-48 defines additional codes, but the + # VT100 user manual notes that it ignores other codes. DEC's + # later terminals (and xterm) do the same, for compatibility. + # Ps = 0 ⇒ Clear Current Column (default). + # Ps = 3 ⇒ Clear All. + def _CSI_g_TBC(self, ps, _): pass + + # CSI Pm h Set Mode (SM). + # Ps = 2 ⇒ Keyboard Action Mode (KAM). + # Ps = 4 ⇒ Insert Mode (IRM). + # Ps = 1 2 ⇒ Send/receive (SRM). + # Ps = 2 0 ⇒ Automatic Newline (LNM). + def _CSI_h_SM(self, ps, _): pass + + # CSI ? Pm h + # DEC Private Mode Set (DECSET). + # Ps = 1 ⇒ Application Cursor Keys (DECCKM), VT100. + # Ps = 2 ⇒ Designate USASCII for character sets G0-G3 + # (DECANM), VT100, and set VT100 mode. + # Ps = 3 ⇒ 132 Column Mode (DECCOLM), VT100. + # Ps = 4 ⇒ Smooth (Slow) Scroll (DECSCLM), VT100. + # Ps = 5 ⇒ Reverse Video (DECSCNM), VT100. + # Ps = 6 ⇒ Origin Mode (DECOM), VT100. + # Ps = 7 ⇒ Auto-Wrap Mode (DECAWM), VT100. + # Ps = 8 ⇒ Auto-Repeat Keys (DECARM), VT100. + # Ps = 9 ⇒ Send Mouse X & Y on button press. See the + # section Mouse Tracking. This is the X10 xterm mouse protocol. + # Ps = 1 0 ⇒ Show toolbar (rxvt). + # Ps = 1 2 ⇒ Start blinking cursor (AT&T 610). + # Ps = 1 3 ⇒ Start blinking cursor (set only via resource or + # menu). + # Ps = 1 4 ⇒ Enable XOR of blinking cursor control sequence + # and menu. + # Ps = 1 8 ⇒ Print Form Feed (DECPFF), VT220. + # Ps = 1 9 ⇒ Set print extent to full screen (DECPEX), + # VT220. + # Ps = 2 5 ⇒ Show cursor (DECTCEM), VT220. + # Ps = 3 0 ⇒ Show scrollbar (rxvt). + # Ps = 3 5 ⇒ Enable font-shifting functions (rxvt). + # Ps = 3 8 ⇒ Enter Tektronix mode (DECTEK), VT240, xterm. + # Ps = 4 0 ⇒ Allow 80 ⇒ 132 mode, xterm. + # Ps = 4 1 ⇒ more(1) fix (see curses resource). + # Ps = 4 2 ⇒ Enable National Replacement Character sets + # (DECNRCM), VT220. + # Ps = 4 3 ⇒ Enable Graphic Expanded Print Mode (DECGEPM), + # VT340. + # Ps = 4 4 ⇒ Turn on margin bell, xterm. + # Ps = 4 4 ⇒ Enable Graphic Print Color Mode (DECGPCM), + # VT340. + # Ps = 4 5 ⇒ Reverse-wraparound mode (XTREVWRAP), xterm. + # Ps = 4 5 ⇒ Enable Graphic Print Color Syntax (DECGPCS), + # VT340. + # Ps = 4 6 ⇒ Start logging (XTLOGGING), xterm. This is + # normally disabled by a compile-time option. + # Ps = 4 6 ⇒ Graphic Print Background Mode, VT340. + # Ps = 4 7 ⇒ Use Alternate Screen Buffer, xterm. This may + # be disabled by the titeInhibit resource. + # Ps = 4 7 ⇒ Enable Graphic Rotated Print Mode (DECGRPM), + # VT340. + # Ps = 6 6 ⇒ Application keypad mode (DECNKM), VT320. + # Ps = 6 7 ⇒ Backarrow key sends backspace (DECBKM), VT340, + # VT420. This sets the backarrowKey resource to "true". + # Ps = 6 9 ⇒ Enable left and right margin mode (DECLRMM), + # VT420 and up. + # Ps = 8 0 ⇒ Enable Sixel Display Mode (DECSDM), VT330, + # VT340, VT382. + # Ps = 9 5 ⇒ Do not clear screen when DECCOLM is set/reset + # (DECNCSM), VT510 and up. + # Ps = 1 0 0 0 ⇒ Send Mouse X & Y on button press and + # release. See the section Mouse Tracking. This is the X11 + # xterm mouse protocol. + # Ps = 1 0 0 1 ⇒ Use Hilite Mouse Tracking, xterm. + # Ps = 1 0 0 2 ⇒ Use Cell Motion Mouse Tracking, xterm. See + # the section Button-event tracking. + # Ps = 1 0 0 3 ⇒ Use All Motion Mouse Tracking, xterm. See + # the section Any-event tracking. + # Ps = 1 0 0 4 ⇒ Send FocusIn/FocusOut events, xterm. + # Ps = 1 0 0 5 ⇒ Enable UTF-8 Mouse Mode, xterm. + # Ps = 1 0 0 6 ⇒ Enable SGR Mouse Mode, xterm. + # Ps = 1 0 0 7 ⇒ Enable Alternate Scroll Mode, xterm. This + # corresponds to the alternateScroll resource. + # Ps = 1 0 1 0 ⇒ Scroll to bottom on tty output (rxvt). + # This sets the scrollTtyOutput resource to "true". + # Ps = 1 0 1 1 ⇒ Scroll to bottom on key press (rxvt). This + # sets the scrollKey resource to "true". + # Ps = 1 0 1 5 ⇒ Enable urxvt Mouse Mode. + # Ps = 1 0 1 6 ⇒ Enable SGR Mouse PixelMode, xterm. + # Ps = 1 0 3 4 ⇒ Interpret "meta" key, xterm. This sets the + # eighth bit of keyboard input (and enables the eightBitInput + # resource). + # Ps = 1 0 3 5 ⇒ Enable special modifiers for Alt and + # NumLock keys, xterm. This enables the numLock resource. + # Ps = 1 0 3 6 ⇒ Send ESC when Meta modifies a key, xterm. + # This enables the metaSendsEscape resource. + # Ps = 1 0 3 7 ⇒ Send DEL from the editing-keypad Delete + # key, xterm. + # Ps = 1 0 3 9 ⇒ Send ESC when Alt modifies a key, xterm. + # This enables the altSendsEscape resource, xterm. + # Ps = 1 0 4 0 ⇒ Keep selection even if not highlighted, + # xterm. This enables the keepSelection resource. + # Ps = 1 0 4 1 ⇒ Use the CLIPBOARD selection, xterm. This + # enables the selectToClipboard resource. + # Ps = 1 0 4 2 ⇒ Enable Urgency window manager hint when + # Control-G is received, xterm. This enables the bellIsUrgent + # resource. + # Ps = 1 0 4 3 ⇒ Enable raising of the window when Control-G + # is received, xterm. This enables the popOnBell resource. + # Ps = 1 0 4 4 ⇒ Reuse the most recent data copied to + # CLIPBOARD, xterm. This enables the keepClipboard resource. + # Ps = 1 0 4 5 ⇒ Extended Reverse-wraparound mode + # (XTREVWRAP2), xterm. + # Ps = 1 0 4 6 ⇒ Enable switching to/from Alternate Screen + # Buffer, xterm. This works for terminfo-based systems, + # updating the titeInhibit resource. + # Ps = 1 0 4 7 ⇒ Use Alternate Screen Buffer, xterm. This + # may be disabled by the titeInhibit resource. + # Ps = 1 0 4 8 ⇒ Save cursor as in DECSC, xterm. This may + # be disabled by the titeInhibit resource. + # Ps = 1 0 4 9 ⇒ Save cursor as in DECSC, xterm. After + # saving the cursor, switch to the Alternate Screen Buffer, + # clearing it first. This may be disabled by the titeInhibit + # resource. This control combines the effects of the 1 0 4 7 + # and 1 0 4 8 modes. Use this with terminfo-based applications + # rather than the 4 7 mode. + # Ps = 1 0 5 0 ⇒ Set terminfo/termcap function-key mode, + # xterm. + # Ps = 1 0 5 1 ⇒ Set Sun function-key mode, xterm. + # Ps = 1 0 5 2 ⇒ Set HP function-key mode, xterm. + # Ps = 1 0 5 3 ⇒ Set SCO function-key mode, xterm. + # Ps = 1 0 6 0 ⇒ Set legacy keyboard emulation, i.e, X11R6, + # xterm. + # Ps = 1 0 6 1 ⇒ Set VT220 keyboard emulation, xterm. + # Ps = 2 0 0 1 ⇒ Enable readline mouse button-1, xterm. + # Ps = 2 0 0 2 ⇒ Enable readline mouse button-2, xterm. + # Ps = 2 0 0 3 ⇒ Enable readline mouse button-3, xterm. + # Ps = 2 0 0 4 ⇒ Set bracketed paste mode, xterm. + # Ps = 2 0 0 5 ⇒ Enable readline character-quoting, xterm. + # Ps = 2 0 0 6 ⇒ Enable readline newline pasting, xterm. + # def _CSI__(self, ps, _): pass + + # CSI Ps i Media Copy (MC). + # Ps = 0 ⇒ Print screen (default). + # Ps = 4 ⇒ Turn off printer controller mode. + # Ps = 5 ⇒ Turn on printer controller mode. + # Ps = 1 0 ⇒ HTML screen dump, xterm. + # Ps = 1 1 ⇒ SVG screen dump, xterm. + def _CSI_i_MC(self, ps, _): pass + + # CSI ? Ps i + # Media Copy (MC), DEC-specific. + # Ps = 1 ⇒ Print line containing cursor. + # Ps = 4 ⇒ Turn off autoprint mode. + # Ps = 5 ⇒ Turn on autoprint mode. + # Ps = 1 0 ⇒ Print composed display, ignores DECPEX. + # Ps = 1 1 ⇒ Print all pages. + # def _CSI__(self, ps, _): pass + + # CSI Pm l Reset Mode (RM). + # Ps = 2 ⇒ Keyboard Action Mode (KAM). + # Ps = 4 ⇒ Replace Mode (IRM). + # Ps = 1 2 ⇒ Send/receive (SRM). + # Ps = 2 0 ⇒ Normal Linefeed (LNM). + def _CSI_l_RM(self, ps, _): pass + + # CSI ? Pm l + # DEC Private Mode Reset (DECRST). + # Ps = 1 ⇒ Normal Cursor Keys (DECCKM), VT100. + # Ps = 2 ⇒ Designate VT52 mode (DECANM), VT100. + # Ps = 3 ⇒ 80 Column Mode (DECCOLM), VT100. + # Ps = 4 ⇒ Jump (Fast) Scroll (DECSCLM), VT100. + # Ps = 5 ⇒ Normal Video (DECSCNM), VT100. + # Ps = 6 ⇒ Normal Cursor Mode (DECOM), VT100. + # Ps = 7 ⇒ No Auto-Wrap Mode (DECAWM), VT100. + # Ps = 8 ⇒ No Auto-Repeat Keys (DECARM), VT100. + # Ps = 9 ⇒ Don't send Mouse X & Y on button press, xterm. + # Ps = 1 0 ⇒ Hide toolbar (rxvt). + # Ps = 1 2 ⇒ Stop blinking cursor (AT&T 610). + # Ps = 1 3 ⇒ Disable blinking cursor (reset only via + # resource or menu). + # Ps = 1 4 ⇒ Disable XOR of blinking cursor control sequence + # and menu. + # Ps = 1 8 ⇒ Don't Print Form Feed (DECPFF), VT220. + # Ps = 1 9 ⇒ Limit print to scrolling region (DECPEX), + # VT220. + # Ps = 2 5 ⇒ Hide cursor (DECTCEM), VT220. + # Ps = 3 0 ⇒ Don't show scrollbar (rxvt). + # Ps = 3 5 ⇒ Disable font-shifting functions (rxvt). + # Ps = 4 0 ⇒ Disallow 80 ⇒ 132 mode, xterm. + # Ps = 4 1 ⇒ No more(1) fix (see curses resource). + # Ps = 4 2 ⇒ Disable National Replacement Character sets + # (DECNRCM), VT220. + # Ps = 4 3 ⇒ Disable Graphic Expanded Print Mode (DECGEPM), + # VT340. + # Ps = 4 4 ⇒ Turn off margin bell, xterm. + # Ps = 4 4 ⇒ Disable Graphic Print Color Mode (DECGPCM), + # VT340. + # Ps = 4 5 ⇒ No Reverse-wraparound mode (XTREVWRAP), xterm. + # Ps = 4 5 ⇒ Disable Graphic Print Color Syntax (DECGPCS), + # VT340. + # Ps = 4 6 ⇒ Stop logging (XTLOGGING), xterm. This is + # normally disabled by a compile-time option. + # Ps = 4 7 ⇒ Use Normal Screen Buffer, xterm. + # Ps = 4 7 ⇒ Disable Graphic Rotated Print Mode (DECGRPM), + # VT340. + # Ps = 6 6 ⇒ Numeric keypad mode (DECNKM), VT320. + # Ps = 6 7 ⇒ Backarrow key sends delete (DECBKM), VT340, + # VT420. This sets the backarrowKey resource to "false". + # Ps = 6 9 ⇒ Disable left and right margin mode (DECLRMM), + # VT420 and up. + # Ps = 8 0 ⇒ Disable Sixel Display Mode (DECSDM), VT330, + # VT340, VT382. Turns on "Sixel Scrolling". See the section + # Sixel Graphics and mode 8 4 5 2 . + # Ps = 9 5 ⇒ Clear screen when DECCOLM is set/reset + # (DECNCSM), VT510 and up. + # Ps = 1 0 0 0 ⇒ Don't send Mouse X & Y on button press and + # release. See the section Mouse Tracking. + # Ps = 1 0 0 1 ⇒ Don't use Hilite Mouse Tracking, xterm. + # Ps = 1 0 0 2 ⇒ Don't use Cell Motion Mouse Tracking, + # xterm. See the section Button-event tracking. + # Ps = 1 0 0 3 ⇒ Don't use All Motion Mouse Tracking, xterm. + # See the section Any-event tracking. + # Ps = 1 0 0 4 ⇒ Don't send FocusIn/FocusOut events, xterm. + # Ps = 1 0 0 5 ⇒ Disable UTF-8 Mouse Mode, xterm. + # Ps = 1 0 0 6 ⇒ Disable SGR Mouse Mode, xterm. + # Ps = 1 0 0 7 ⇒ Disable Alternate Scroll Mode, xterm. This + # corresponds to the alternateScroll resource. + # Ps = 1 0 1 0 ⇒ Don't scroll to bottom on tty output + # (rxvt). This sets the scrollTtyOutput resource to "false". + # Ps = 1 0 1 1 ⇒ Don't scroll to bottom on key press (rxvt). + # This sets the scrollKey resource to "false". + # Ps = 1 0 1 5 ⇒ Disable urxvt Mouse Mode. + # Ps = 1 0 1 6 ⇒ Disable SGR Mouse Pixel-Mode, xterm. + # Ps = 1 0 3 4 ⇒ Don't interpret "meta" key, xterm. This + # disables the eightBitInput resource. + # Ps = 1 0 3 5 ⇒ Disable special modifiers for Alt and + # NumLock keys, xterm. This disables the numLock resource. + # Ps = 1 0 3 6 ⇒ Don't send ESC when Meta modifies a key, + # xterm. This disables the metaSendsEscape resource. + # Ps = 1 0 3 7 ⇒ Send VT220 Remove from the editing-keypad + # Delete key, xterm. + # Ps = 1 0 3 9 ⇒ Don't send ESC when Alt modifies a key, + # xterm. This disables the altSendsEscape resource. + # Ps = 1 0 4 0 ⇒ Do not keep selection when not highlighted, + # xterm. This disables the keepSelection resource. + # Ps = 1 0 4 1 ⇒ Use the PRIMARY selection, xterm. This + # disables the selectToClipboard resource. + # Ps = 1 0 4 2 ⇒ Disable Urgency window manager hint when + # Control-G is received, xterm. This disables the bellIsUrgent + # resource. + # Ps = 1 0 4 3 ⇒ Disable raising of the window when Control- + # G is received, xterm. This disables the popOnBell resource. + # Ps = 1 0 4 5 ⇒ No Extended Reverse-wraparound mode + # (XTREVWRAP2), xterm. + # Ps = 1 0 4 6 ⇒ Disable switching to/from Alternate Screen + # Buffer, xterm. This works for terminfo-based systems, + # updating the titeInhibit resource. If currently using the + # Alternate Screen Buffer, xterm switches to the Normal Screen + # Buffer. + # Ps = 1 0 4 7 ⇒ Use Normal Screen Buffer, xterm. Clear the + # screen first if in the Alternate Screen Buffer. This may be + # disabled by the titeInhibit resource. + # Ps = 1 0 4 8 ⇒ Restore cursor as in DECRC, xterm. This + # may be disabled by the titeInhibit resource. + # Ps = 1 0 4 9 ⇒ Use Normal Screen Buffer and restore cursor + # as in DECRC, xterm. This may be disabled by the titeInhibit + # resource. This combines the effects of the 1 0 4 7 and 1 0 4 + # 8 modes. Use this with terminfo-based applications rather + # than the 4 7 mode. + # Ps = 1 0 5 0 ⇒ Reset terminfo/termcap function-key mode, + # xterm. + # Ps = 1 0 5 1 ⇒ Reset Sun function-key mode, xterm. + # Ps = 1 0 5 2 ⇒ Reset HP function-key mode, xterm. + # Ps = 1 0 5 3 ⇒ Reset SCO function-key mode, xterm. + # Ps = 1 0 6 0 ⇒ Reset legacy keyboard emulation, i.e, + # X11R6, xterm. + # Ps = 1 0 6 1 ⇒ Reset keyboard emulation to Sun/PC style, + # xterm. + # Ps = 2 0 0 1 ⇒ Disable readline mouse button-1, xterm. + # Ps = 2 0 0 2 ⇒ Disable readline mouse button-2, xterm. + # Ps = 2 0 0 3 ⇒ Disable readline mouse button-3, xterm. + # Ps = 2 0 0 4 ⇒ Reset bracketed paste mode, xterm. + # Ps = 2 0 0 5 ⇒ Disable readline character-quoting, xterm. + # Ps = 2 0 0 6 ⇒ Disable readline newline pasting, xterm. + # def _CSI__(self, ps, _): pass + + # CSI Pm m Character Attributes (SGR). + # Ps = 0 ⇒ Normal (default), VT100. + # Ps = 1 ⇒ Bold, VT100. + # Ps = 2 ⇒ Faint, decreased intensity, ECMA-48 2nd. + # Ps = 3 ⇒ Italicized, ECMA-48 2nd. + # Ps = 4 ⇒ Underlined, VT100. + # Ps = 5 ⇒ Blink, VT100. + # This appears as Bold in X11R6 xterm. + # Ps = 7 ⇒ Inverse, VT100. + # Ps = 8 ⇒ Invisible, i.e., hidden, ECMA-48 2nd, VT300. + # Ps = 9 ⇒ Crossed-out characters, ECMA-48 3rd. + # Ps = 2 1 ⇒ Doubly-underlined, ECMA-48 3rd. + # Ps = 2 2 ⇒ Normal (neither bold nor faint), ECMA-48 3rd. + # Ps = 2 3 ⇒ Not italicized, ECMA-48 3rd. + # Ps = 2 4 ⇒ Not underlined, ECMA-48 3rd. + # Ps = 2 5 ⇒ Steady (not blinking), ECMA-48 3rd. + # Ps = 2 7 ⇒ Positive (not inverse), ECMA-48 3rd. + # Ps = 2 8 ⇒ Visible, i.e., not hidden, ECMA-48 3rd, VT300. + # Ps = 2 9 ⇒ Not crossed-out, ECMA-48 3rd. + # Ps = 3 0 ⇒ Set foreground color to Black. + # Ps = 3 1 ⇒ Set foreground color to Red. + # Ps = 3 2 ⇒ Set foreground color to Green. + # Ps = 3 3 ⇒ Set foreground color to Yellow. + # Ps = 3 4 ⇒ Set foreground color to Blue. + # Ps = 3 5 ⇒ Set foreground color to Magenta. + # Ps = 3 6 ⇒ Set foreground color to Cyan. + # Ps = 3 7 ⇒ Set foreground color to White. + # Ps = 3 9 ⇒ Set foreground color to default, ECMA-48 3rd. + # Ps = 4 0 ⇒ Set background color to Black. + # Ps = 4 1 ⇒ Set background color to Red. + # Ps = 4 2 ⇒ Set background color to Green. + # Ps = 4 3 ⇒ Set background color to Yellow. + # Ps = 4 4 ⇒ Set background color to Blue. + # Ps = 4 5 ⇒ Set background color to Magenta. + # Ps = 4 6 ⇒ Set background color to Cyan. + # Ps = 4 7 ⇒ Set background color to White. + # Ps = 4 9 ⇒ Set background color to default, ECMA-48 3rd. + # + # Some of the above note the edition of ECMA-48 which first + # describes a feature. In its successive editions from 1979 to + # 1991 (2nd 1979, 3rd 1984, 4th 1986, and 5th 1991), ECMA-48 + # listed codes through 6 5 (skipping several toward the end of + # the range). Most of the ECMA-48 codes not implemented in + # xterm were never implemented in a hardware terminal. Several + # (such as 3 9 and 4 9 ) are either noted in ECMA-48 as + # implementation defined, or described in vague terms. + # + # The successive editions of ECMA-48 give little attention to + # changes from one edition to the next, except to comment on + # features which have become obsolete. ECMA-48 1st (1976) is + # unavailable; there is no reliable source of information which + # states whether "ANSI" color was defined in that edition, or + # later (1979). The VT100 (1978) implemented the most commonly + # used non-color video attributes which are given in the 2nd + # edition. + # + # While 8-color support is described in ECMA-48 2nd edition, the + # VT500 series (introduced in 1993) were the first DEC terminals + # implementing "ANSI" color. The DEC terminal's use of color is + # known to differ from xterm; useful documentation on this + # series became available too late to influence xterm. + # + # If 16-color support is compiled, the following aixterm + # controls apply. Assume that xterm's resources are set so that + # the ISO color codes are the first 8 of a set of 16. Then the + # aixterm colors are the bright versions of the ISO colors: + # + # Ps = 9 0 ⇒ Set foreground color to Black. + # Ps = 9 1 ⇒ Set foreground color to Red. + # Ps = 9 2 ⇒ Set foreground color to Green. + # Ps = 9 3 ⇒ Set foreground color to Yellow. + # Ps = 9 4 ⇒ Set foreground color to Blue. + # Ps = 9 5 ⇒ Set foreground color to Magenta. + # Ps = 9 6 ⇒ Set foreground color to Cyan. + # Ps = 9 7 ⇒ Set foreground color to White. + # Ps = 1 0 0 ⇒ Set background color to Black. + # Ps = 1 0 1 ⇒ Set background color to Red. + # Ps = 1 0 2 ⇒ Set background color to Green. + # Ps = 1 0 3 ⇒ Set background color to Yellow. + # Ps = 1 0 4 ⇒ Set background color to Blue. + # Ps = 1 0 5 ⇒ Set background color to Magenta. + # Ps = 1 0 6 ⇒ Set background color to Cyan. + # Ps = 1 0 7 ⇒ Set background color to White. + # + # If xterm is compiled with the 16-color support disabled, it + # supports the following, from rxvt: + # Ps = 1 0 0 ⇒ Set foreground and background color to + # default. + # + # XTerm maintains a color palette whose entries are identified + # by an index beginning with zero. If 88- or 256-color support + # is compiled, the following apply: + # o All parameters are decimal integers. + # o RGB values range from zero (0) to 255. + # o The 88- and 256-color support uses subparameters described + # in ISO-8613-6 for indexed color. ISO-8613-6 also mentions + # direct color, using a similar scheme. xterm supports + # that, too. + # o xterm allows either colons (standard) or semicolons + # (legacy) to separate the subparameters (but after the + # first colon, colons must be used). + # + # The indexed- and direct-color features are summarized in the + # FAQ, which explains why semicolon is accepted as a + # subparameter delimiter: + # + # Can I set a color by its number? + # + # These ISO-8613-6 controls (marked in ECMA-48 5th edition as + # "reserved for future standardization") are supported by xterm: + # Ps = 3 8 : 2 : Pi : Pr : Pg : Pb ⇒ Set foreground color + # using RGB values. If xterm is not compiled with direct-color + # support, it uses the closest match in its palette for the + # given RGB Pr/Pg/Pb. The color space identifier Pi is ignored. + # Ps = 3 8 : 5 : Ps ⇒ Set foreground color to Ps, using + # indexed color. + # Ps = 4 8 : 2 : Pi : Pr : Pg : Pb ⇒ Set background color + # using RGB values. If xterm is not compiled with direct-color + # support, it uses the closest match in its palette for the + # given RGB Pr/Pg/Pb. The color space identifier Pi is ignored. + # Ps = 4 8 : 5 : Ps ⇒ Set background color to Ps, using + # indexed color. + # + # This variation on ISO-8613-6 is supported for compatibility + # with KDE konsole: + # Ps = 3 8 ; 2 ; Pr ; Pg ; Pb ⇒ Set foreground color using + # RGB values. If xterm is not compiled with direct-color + # support, it uses the closest match in its palette for the + # given RGB Pr/Pg/Pb. + # Ps = 4 8 ; 2 ; Pr ; Pg ; Pb ⇒ Set background color using + # RGB values. If xterm is not compiled with direct-color + # support, it uses the closest match in its palette for the + # given RGB Pr/Pg/Pb. + # + # In each case, if xterm is compiled with direct-color support, + # and the resource directColor is true, then rather than + # choosing the closest match, xterm asks the X server to + # directly render a given color. + def _CSI_m_SGR(self, ps, _): pass + + # CSI > Pp ; Pv m + # def _CSI__(self, ps, _): pass + # CSI > Pp m + # Set/reset key modifier options (XTMODKEYS), xterm. Set or + # reset resource-values used by xterm to decide whether to + # construct escape sequences holding information about the + # modifiers pressed with a given key. + # + # The first parameter Pp identifies the resource to set/reset. + # The second parameter Pv is the value to assign to the + # resource. + # + # If the second parameter is omitted, the resource is reset to + # its initial value. Values 3 and 5 are reserved for keypad- + # keys and string-keys. + # + # Pp = 0 ⇒ modifyKeyboard. + # Pp = 1 ⇒ modifyCursorKeys. + # Pp = 2 ⇒ modifyFunctionKeys. + # Pp = 4 ⇒ modifyOtherKeys. + # + # If no parameters are given, all resources are reset to their + # initial values. + # def _CSI__(self, ps, _): pass + + # CSI ? Pp m + # Query key modifier options (XTQMODKEYS), xterm. + # + # The parameter Pp identifies the resource to query. + # + # Pp = 0 ⇒ modifyKeyboard. + # Pp = 1 ⇒ modifyCursorKeys. + # Pp = 2 ⇒ modifyFunctionKeys. + # Pp = 4 ⇒ modifyOtherKeys. + # + # XTerm's response can be used to restore this state, because it + # is formatted as an XTMODKEYS control, i.e., + # + # CSI > Pp m + # + # where + # + # Pp = 0 ⇒ modifyKeyboard. + # Pp = 1 ⇒ modifyCursorKeys. + # Pp = 2 ⇒ modifyFunctionKeys. + # Pp = 4 ⇒ modifyOtherKeys. + + # CSI Ps n Device Status Report (DSR). + # Ps = 5 ⇒ Status Report. + # Result ("OK") is CSI 0 n + # Ps = 6 ⇒ Report Cursor Position (CPR) [row;column]. + # Result is CSI r ; c R + # + # Note: it is possible for this sequence to be sent by a + # function key. For example, with the default keyboard + # configuration the shifted F1 key may send (with shift-, + # control-, alt-modifiers) + # + # CSI 1 ; 2 R , or + # CSI 1 ; 5 R , or + # CSI 1 ; 6 R , etc. + # + # The second parameter encodes the modifiers; values range from + # 2 to 16. See the section PC-Style Function Keys for the + # codes. The modifyFunctionKeys and modifyKeyboard resources + # can change the form of the string sent from the modified F1 + # key. + def _CSI_n_DSR(self, ps, _): pass + + # CSI > Ps n + # Disable key modifier options, xterm. These modifiers may be + # enabled via the CSI > Pm m sequence. This control sequence + # corresponds to a resource value of "-1", which cannot be set + # with the other sequence. + # + # The parameter identifies the resource to be disabled: + # + # Ps = 0 ⇒ modifyKeyboard. + # Ps = 1 ⇒ modifyCursorKeys. + # Ps = 2 ⇒ modifyFunctionKeys. + # Ps = 4 ⇒ modifyOtherKeys. + # + # If the parameter is omitted, modifyFunctionKeys is disabled. + # When modifyFunctionKeys is disabled, xterm uses the modifier + # keys to make an extended sequence of function keys rather than + # adding a parameter to each function key to denote the + # modifiers. + + # CSI ? Ps n + # Device Status Report (DSR, DEC-specific). + # Ps = 6 ⇒ Report Cursor Position (DECXCPR). The response + # [row;column] is returned as + # CSI ? r ; c R + # (assumes the default page, i.e., "1"). + # Ps = 1 5 ⇒ Report Printer status. The response is + # CSI ? 1 0 n (ready). or + # CSI ? 1 1 n (not ready). + # Ps = 2 5 ⇒ Report UDK status. The response is + # CSI ? 2 0 n (unlocked) + # or + # CSI ? 2 1 n (locked). + # Ps = 2 6 ⇒ Report Keyboard status. The response is + # CSI ? 2 7 ; 1 ; 0 ; 0 n (North American). + # + # The last two parameters apply to VT300 & up (keyboard ready) + # and VT400 & up (LK01) respectively. + # + # Ps = 5 3 ⇒ Report Locator status. The response is CSI ? 5 + # 3 n Locator available, if compiled-in, or CSI ? 5 0 n No + # Locator, if not. + # Ps = 5 5 ⇒ Report Locator status. The response is CSI ? 5 + # 3 n Locator available, if compiled-in, or CSI ? 5 0 n No + # Locator, if not. + # Ps = 5 6 ⇒ Report Locator type. The response is CSI ? 5 7 + # ; 1 n Mouse, if compiled-in, or CSI ? 5 7 ; 0 n Cannot + # identify, if not. + # Ps = 6 2 ⇒ Report macro space (DECMSR). The response is + # CSI Pn * { . + # Ps = 6 3 ⇒ Report memory checksum (DECCKSR), VT420 and up. + # The response is DCS Pt ! ~ x x x x ST . + # Pt is the request id (from an optional parameter to the + # request). + # The x's are hexadecimal digits 0-9 and A-F. + # Ps = 7 5 ⇒ Report data integrity. The response is CSI ? 7 + # 0 n (ready, no errors). + # Ps = 8 5 ⇒ Report multi-session configuration. The + # response is CSI ? 8 3 n (not configured for multiple-session + # operation). + + # CSI > Ps p + # Set resource value pointerMode (XTSMPOINTER), xterm. This is + # used by xterm to decide whether to hide the pointer cursor as + # the user types. + # + # Valid values for the parameter: + # Ps = 0 ⇒ never hide the pointer. + # Ps = 1 ⇒ hide if the mouse tracking mode is not enabled. + # Ps = 2 ⇒ always hide the pointer, except when leaving the + # window. + # Ps = 3 ⇒ always hide the pointer, even if leaving/entering + # the window. + # + # If no parameter is given, xterm uses the default, which is 1 . + + # CSI ! p Soft terminal reset (DECSTR), VT220 and up. + + # CSI Pl ; Pc " p + # Set conformance level (DECSCL), VT220 and up. + # + # The first parameter selects the conformance level. Valid + # values are: + # Pl = 6 1 ⇒ level 1, e.g., VT100. + # Pl = 6 2 ⇒ level 2, e.g., VT200. + # Pl = 6 3 ⇒ level 3, e.g., VT300. + # Pl = 6 4 ⇒ level 4, e.g., VT400. + # Pl = 6 5 ⇒ level 5, e.g., VT500. + # + # The second parameter selects the C1 control transmission mode. + # This is an optional parameter, ignored in conformance level 1. + # Valid values are: + # Pc = 0 ⇒ 8-bit controls. + # Pc = 1 ⇒ 7-bit controls (DEC factory default). + # Pc = 2 ⇒ 8-bit controls. + # + # The 7-bit and 8-bit control modes can also be set by S7C1T and + # S8C1T, but DECSCL is preferred. + + # CSI Ps $ p + # Request ANSI mode (DECRQM). For VT300 and up, reply DECRPM is + # CSI Ps; Pm $ y + # where Ps is the mode number as in SM/RM, and Pm is the mode + # value: + # 0 - not recognized + # 1 - set + # 2 - reset + # 3 - permanently set + # 4 - permanently reset + + # CSI ? Ps $ p + # Request DEC private mode (DECRQM). For VT300 and up, reply + # DECRPM is + # CSI ? Ps; Pm $ y + # where Ps is the mode number as in DECSET/DECSET, Pm is the + # mode value as in the ANSI DECRQM. + # Two private modes are read-only (i.e., 1 3 and 1 4 ), + # provided only for reporting their values using this control + # sequence. They correspond to the resources cursorBlink and + # cursorBlinkXOR. + + # CSI # p + + # CSI Pm # p + # Push video attributes onto stack (XTPUSHSGR), xterm. This is + # an alias for CSI # { , used to work around language + # limitations of C#. + + # CSI > Ps q + # Ps = 0 ⇒ Report xterm name and version (XTVERSION). The + # response is a DSR sequence identifying the version: DCS > | + # text ST + + # CSI Ps q Load LEDs (DECLL), VT100. + # Ps = 0 ⇒ Clear all LEDS (default). + # Ps = 1 ⇒ Light Num Lock. + # Ps = 2 ⇒ Light Caps Lock. + # Ps = 3 ⇒ Light Scroll Lock. + # Ps = 2 1 ⇒ Extinguish Num Lock. + # Ps = 2 2 ⇒ Extinguish Caps Lock. + # Ps = 2 3 ⇒ Extinguish Scroll Lock. + def _CSI_q_DECLL(self, ps, _): pass + + # CSI Ps SP q + # Set cursor style (DECSCUSR), VT520. + # Ps = 0 ⇒ blinking block. + # Ps = 1 ⇒ blinking block (default). + # Ps = 2 ⇒ steady block. + # Ps = 3 ⇒ blinking underline. + # Ps = 4 ⇒ steady underline. + # Ps = 5 ⇒ blinking bar, xterm. + # Ps = 6 ⇒ steady bar, xterm. + + # CSI Ps " q + # Select character protection attribute (DECSCA), VT220. Valid + # values for the parameter: + # Ps = 0 ⇒ DECSED and DECSEL can erase (default). + # Ps = 1 ⇒ DECSED and DECSEL cannot erase. + # Ps = 2 ⇒ DECSED and DECSEL can erase. + + # CSI # q Pop video attributes from stack (XTPOPSGR), xterm. This is an + # alias for CSI # } , used to work around language limitations + # of C#. + + # CSI Ps ; Ps r + # Set Scrolling Region [top;bottom] (default = full size of + # window) (DECSTBM), VT100. + + # CSI ? Pm r + # Restore DEC Private Mode Values (XTRESTORE), xterm. The value + # of Ps previously saved is restored. Ps values are the same as + # for DECSET. + # + # Like Restore Cursor (DECRC), this uses a one-level cache. + # Unlike Restore Cursor, specific settings can be saved and + # restored independently. Only those modes listed as parameters + # are restored. + + # CSI Pt ; Pl ; Pb ; Pr ; Pm $ r + # Change Attributes in Rectangular Area (DECCARA), VT400 and up. + # Pt ; Pl ; Pb ; Pr denotes the rectangle. + # Pm denotes the SGR attributes to change: 0, 1, 4, 5, 7. + + # CSI s Save cursor, available only when DECLRMM is disabled (SCOSC, + # also ANSI.SYS). + def _CSI_s_SCOSC(self, _, __): pass + + # CSI Pl ; Pr s + # Set left and right margins (DECSLRM), VT420 and up. This is + # available only when DECLRMM is enabled. + + # CSI > Ps s + # Set/reset shift-escape options (XTSHIFTESCAPE), xterm. This + # corresponds to the shiftEscape resource. + # + # Valid values for the parameter: + # Ps = 0 ⇒ allow shift-key to override mouse protocol. + # Ps = 1 ⇒ conditionally allow shift-key as modifier in + # mouse protocol. + # + # These resource values are disallowed in the control sequence: + # Ps = 2 ⇒ always allow shift-key as modifier in mouse + # protocol. + # Ps = 3 ⇒ never allow shift-key as modifier in mouse + # protocol. + # + # If no parameter is given, xterm uses the default, which is 0 . + + # CSI ? Pm s + # Save DEC Private Mode Values (XTSAVE), xterm. Ps values are + # the same as for DECSET. + # + # Like Save Cursor (DECSC), this uses a one-level cache. Unlike + # Save Cursor, specific settings can be saved and restored + # independently. Only those modes listed as parameters are + # saved. + + # CSI Ps ; Ps ; Ps t + # Window manipulation (XTWINOPS), dtterm, extended by xterm. + # These controls may be disabled using the allowWindowOps + # resource. + # + # xterm uses Extended Window Manager Hints (EWMH) to maximize + # the window. Some window managers have incomplete support for + # EWMH. For instance, fvwm, flwm and quartz-wm advertise + # support for maximizing windows horizontally or vertically, but + # in fact equate those to the maximize operation. + # + # Valid values for the first (and any additional parameters) + # are: + # Ps = 1 ⇒ De-iconify window. + # Ps = 2 ⇒ Iconify window. + # Ps = 3 ; x ; y ⇒ Move window to [x, y]. + # Ps = 4 ; height ; width ⇒ Resize the xterm window to + # given height and width in pixels. Omitted parameters reuse + # the current height or width. Zero parameters use the + # display's height or width. + # Ps = 5 ⇒ Raise the xterm window to the front of the + # stacking order. + # Ps = 6 ⇒ Lower the xterm window to the bottom of the + # stacking order. + # Ps = 7 ⇒ Refresh the xterm window. + # Ps = 8 ; height ; width ⇒ Resize the text area to given + # height and width in characters. Omitted parameters reuse the + # current height or width. Zero parameters use the display's + # height or width. + # Ps = 9 ; 0 ⇒ Restore maximized window. + # Ps = 9 ; 1 ⇒ Maximize window (i.e., resize to screen + # size). + # Ps = 9 ; 2 ⇒ Maximize window vertically. + # Ps = 9 ; 3 ⇒ Maximize window horizontally. + # Ps = 1 0 ; 0 ⇒ Undo full-screen mode. + # Ps = 1 0 ; 1 ⇒ Change to full-screen. + # Ps = 1 0 ; 2 ⇒ Toggle full-screen. + # Ps = 1 1 ⇒ Report xterm window state. + # If the xterm window is non-iconified, it returns CSI 1 t . + # If the xterm window is iconified, it returns CSI 2 t . + # Ps = 1 3 ⇒ Report xterm window position. + # Note: X Toolkit positions can be negative, but the reported + # values are unsigned, in the range 0-65535. Negative values + # correspond to 32768-65535. + # Result is CSI 3 ; x ; y t + # Ps = 1 3 ; 2 ⇒ Report xterm text-area position. + # Result is CSI 3 ; x ; y t + # Ps = 1 4 ⇒ Report xterm text area size in pixels. + # Result is CSI 4 ; height ; width t + # Ps = 1 4 ; 2 ⇒ Report xterm window size in pixels. + # Normally xterm's window is larger than its text area, since it + # includes the frame (or decoration) applied by the window + # manager, as well as the area used by a scroll-bar. + # Result is CSI 4 ; height ; width t + # Ps = 1 5 ⇒ Report size of the screen in pixels. + # Result is CSI 5 ; height ; width t + # Ps = 1 6 ⇒ Report xterm character cell size in pixels. + # Result is CSI 6 ; height ; width t + # Ps = 1 8 ⇒ Report the size of the text area in characters. + # Result is CSI 8 ; height ; width t + # Ps = 1 9 ⇒ Report the size of the screen in characters. + # Result is CSI 9 ; height ; width t + # Ps = 2 0 ⇒ Report xterm window's icon label. + # Result is OSC L label ST + # Ps = 2 1 ⇒ Report xterm window's title. + # Result is OSC l label ST + # Ps = 2 2 ; 0 ⇒ Save xterm icon and window title on stack. + # Ps = 2 2 ; 1 ⇒ Save xterm icon title on stack. + # Ps = 2 2 ; 2 ⇒ Save xterm window title on stack. + # Ps = 2 3 ; 0 ⇒ Restore xterm icon and window title from + # stack. + # Ps = 2 3 ; 1 ⇒ Restore xterm icon title from stack. + # Ps = 2 3 ; 2 ⇒ Restore xterm window title from stack. + # Ps >= 2 4 ⇒ Resize to Ps lines (DECSLPP), VT340 and VT420. + # xterm adapts this by resizing its window. + + # CSI > Pm t + # This xterm control sets one or more features of the title + # modes (XTSMTITLE), xterm. Each parameter enables a single + # feature. + # Ps = 0 ⇒ Set window/icon labels using hexadecimal. + # Ps = 1 ⇒ Query window/icon labels using hexadecimal. + # Ps = 2 ⇒ Set window/icon labels using UTF-8. + # Ps = 3 ⇒ Query window/icon labels using UTF-8. (See + # discussion of Title Modes) + + # CSI Ps SP t + # Set warning-bell volume (DECSWBV), VT520. + # Ps = 0 or 1 ⇒ off. + # Ps = 2 , 3 or 4 ⇒ low. + # Ps = 5 , 6 , 7 , or 8 ⇒ high. + + # CSI Pt ; Pl ; Pb ; Pr ; Pm $ t + # Reverse Attributes in Rectangular Area (DECRARA), VT400 and + # up. + # Pt ; Pl ; Pb ; Pr denotes the rectangle. + # Pm denotes the attributes to reverse, i.e., 1, 4, 5, 7. + + # CSI u Restore cursor (SCORC, also ANSI.SYS). + def _CSI_u_SCORC(self, _, __): pass + + # CSI Ps SP u + # Set margin-bell volume (DECSMBV), VT520. + # Ps = 0 , 5 , 6 , 7 , or 8 ⇒ high. + # Ps = 1 ⇒ off. + # Ps = 2 , 3 or 4 ⇒ low. + + # CSI Pt ; Pl ; Pb ; Pr ; Pp ; Pt ; Pl ; Pp $ v + # Copy Rectangular Area (DECCRA), VT400 and up. + # Pt ; Pl ; Pb ; Pr denotes the rectangle. + # Pp denotes the source page. + # Pt ; Pl denotes the target location. + # Pp denotes the target page. + + # CSI Ps $ w + # Request presentation state report (DECRQPSR), VT320 and up. + # Ps = 0 ⇒ error. + # Ps = 1 ⇒ cursor information report (DECCIR). + # Response is + # DCS 1 $ u Pt ST + # Refer to the VT420 programming manual, which requires six + # pages to document the data string Pt, + # Ps = 2 ⇒ tab stop report (DECTABSR). + # Response is + # DCS 2 $ u Pt ST + # The data string Pt is a list of the tab-stops, separated by + # "/" characters. + + # CSI Pt ; Pl ; Pb ; Pr ' w + # Enable Filter Rectangle (DECEFR), VT420 and up. + # Parameters are [top;left;bottom;right]. + # Defines the coordinates of a filter rectangle and activates + # it. Anytime the locator is detected outside of the filter + # rectangle, an outside rectangle event is generated and the + # rectangle is disabled. Filter rectangles are always treated + # as "one-shot" events. Any parameters that are omitted default + # to the current locator position. If all parameters are + # omitted, any locator motion will be reported. DECELR always + # cancels any previous rectangle definition. + + # CSI Ps x Request Terminal Parameters (DECREQTPARM). + # if Ps is a "0" (default) or "1", and xterm is emulating VT100, + # the control sequence elicits a response of the same form whose + # parameters describe the terminal: + # Ps ⇒ the given Ps incremented by 2. + # Pn = 1 ⇐ no parity. + # Pn = 1 ⇐ eight bits. + # Pn = 1 ⇐ 2 8 transmit 38.4k baud. + # Pn = 1 ⇐ 2 8 receive 38.4k baud. + # Pn = 1 ⇐ clock multiplier. + # Pn = 0 ⇐ STP flags. + def _CSI_x_DECREQTPARM(self, x, __): pass + + # CSI Ps * x + # Select Attribute Change Extent (DECSACE), VT420 and up. + # Ps = 0 ⇒ from start to end position, wrapped. + # Ps = 1 ⇒ from start to end position, wrapped. + # Ps = 2 ⇒ rectangle (exact). + + # CSI Pc ; Pt ; Pl ; Pb ; Pr $ x + # Fill Rectangular Area (DECFRA), VT420 and up. + # Pc is the character to use. + # Pt ; Pl ; Pb ; Pr denotes the rectangle. + + # CSI Ps # y + # Select checksum extension (XTCHECKSUM), xterm. The bits of Ps + # modify the calculation of the checksum returned by DECRQCRA: + # 0 ⇒ do not negate the result. + # 1 ⇒ do not report the VT100 video attributes. + # 2 ⇒ do not omit checksum for blanks. + # 3 ⇒ omit checksum for cells not explicitly initialized. + # 4 ⇒ do not mask cell value to 8 bits or ignore combining + # characters. + # 5 ⇒ do not mask cell value to 7 bits. + + # CSI Pi ; Pg ; Pt ; Pl ; Pb ; Pr * y + # Request Checksum of Rectangular Area (DECRQCRA), VT420 and up. + # Response is + # DCS Pi ! ~ x x x x ST + # Pi is the request id. + # Pg is the page number. + # Pt ; Pl ; Pb ; Pr denotes the rectangle. + # The x's are hexadecimal digits 0-9 and A-F. + + # CSI Ps ; Pu ' z + # Enable Locator Reporting (DECELR). + # Valid values for the first parameter: + # Ps = 0 ⇒ Locator disabled (default). + # Ps = 1 ⇒ Locator enabled. + # Ps = 2 ⇒ Locator enabled for one report, then disabled. + # The second parameter specifies the coordinate unit for locator + # reports. + # Valid values for the second parameter: + # Pu = 0 or omitted ⇒ default to character cells. + # Pu = 1 ⇐ device physical pixels. + # Pu = 2 ⇐ character cells. + + # CSI Pt ; Pl ; Pb ; Pr $ z + # Erase Rectangular Area (DECERA), VT400 and up. + # Pt ; Pl ; Pb ; Pr denotes the rectangle. + + # CSI Pm ' { + # Select Locator Events (DECSLE). + # Valid values for the first (and any additional parameters) + # are: + # Ps = 0 ⇒ only respond to explicit host requests (DECRQLP). + # This is default. It also cancels any filter rectangle. + # Ps = 1 ⇒ report button down transitions. + # Ps = 2 ⇒ do not report button down transitions. + # Ps = 3 ⇒ report button up transitions. + # Ps = 4 ⇒ do not report button up transitions. + + # CSI # { + # CSI Pm # { + # Push video attributes onto stack (XTPUSHSGR), xterm. The + # optional parameters correspond to the SGR encoding for video + # attributes, except for colors (which do not have a unique SGR + # code): + # Ps = 1 ⇒ Bold. + # Ps = 2 ⇒ Faint. + # Ps = 3 ⇒ Italicized. + # Ps = 4 ⇒ Underlined. + # Ps = 5 ⇒ Blink. + # Ps = 7 ⇒ Inverse. + # Ps = 8 ⇒ Invisible. + # Ps = 9 ⇒ Crossed-out characters. + # Ps = 2 1 ⇒ Doubly-underlined. + # Ps = 3 0 ⇒ Foreground color. + # Ps = 3 1 ⇒ Background color. + # + # If no parameters are given, all of the video attributes are + # saved. The stack is limited to 10 levels. + + # CSI Pt ; Pl ; Pb ; Pr $ { + # Selective Erase Rectangular Area (DECSERA), VT400 and up. + # Pt ; Pl ; Pb ; Pr denotes the rectangle. + + # CSI Pt ; Pl ; Pb ; Pr # | + # Report selected graphic rendition (XTREPORTSGR), xterm. The + # response is an SGR sequence which contains the attributes + # which are common to all cells in a rectangle. + # Pt ; Pl ; Pb ; Pr denotes the rectangle. + + # CSI Ps $ | + # Select columns per page (DECSCPP), VT340. + # Ps = 0 ⇒ 80 columns, default if Ps omitted. + # Ps = 8 0 ⇒ 80 columns. + # Ps = 1 3 2 ⇒ 132 columns. + + # CSI Ps ' | + # Request Locator Position (DECRQLP). + # Valid values for the parameter are: + # Ps = 0 , 1 or omitted ⇒ transmit a single DECLRP locator + # report. + # + # If Locator Reporting has been enabled by a DECELR, xterm will + # respond with a DECLRP Locator Report. This report is also + # generated on button up and down events if they have been + # enabled with a DECSLE, or when the locator is detected outside + # of a filter rectangle, if filter rectangles have been enabled + # with a DECEFR. + # + # ⇐ CSI Pe ; Pb ; Pr ; Pc ; Pp & w + # + # Parameters are [event;button;row;column;page]. + # Valid values for the event: + # Pe = 0 ⇐ locator unavailable - no other parameters sent. + # Pe = 1 ⇐ request - xterm received a DECRQLP. + # Pe = 2 ⇐ left button down. + # Pe = 3 ⇐ left button up. + # Pe = 4 ⇐ middle button down. + # Pe = 5 ⇐ middle button up. + # Pe = 6 ⇐ right button down. + # Pe = 7 ⇐ right button up. + # Pe = 8 ⇐ M4 button down. + # Pe = 9 ⇐ M4 button up. + # Pe = 1 0 ⇐ locator outside filter rectangle. + # The "button" parameter is a bitmask indicating which buttons + # are pressed: + # Pb = 0 ⇐ no buttons down. + # Pb & 1 ⇐ right button down. + # Pb & 2 ⇐ middle button down. + # Pb & 4 ⇐ left button down. + # Pb & 8 ⇐ M4 button down. + # The "row" and "column" parameters are the coordinates of the + # locator position in the xterm window, encoded as ASCII + # decimal. + # The "page" parameter is not used by xterm. + + # CSI Ps * | + # Select number of lines per screen (DECSNLS), VT420 and up. + + # CSI # } Pop video attributes from stack (XTPOPSGR), xterm. Popping + # restores the video-attributes which were saved using XTPUSHSGR + # to their previous state. + + # CSI Ps ' } + # Insert Ps Column(s) (default = 1) (DECIC), VT420 and up. + + # CSI Ps $ } + # Select active status display (DECSASD), VT320 and up. + # Ps = 0 ⇒ main (default) + # Ps = 1 ⇒ status line + + # CSI Ps ' ~ + # Delete Ps Column(s) (default = 1) (DECDC), VT420 and up. + + # CSI Ps $ ~ + # Select status line type (DECSSDT), VT320 and up. + # Ps = 0 ⇒ none + # Ps = 1 ⇒ indicator (default) + # Ps = 2 ⇒ host-writable. + + _CSI_MAP = { + '@': _CSI___ICH, + # '@': _CSI___SL, + 'A': _CSI_A_CUU, + 'A': _CSI_A_SR, + 'B': _CSI_B_CUD, + 'C': _CSI_C_CUF, + 'D': _CSI_D_CUB, + 'E': _CSI_E_CNL, + 'F': _CSI_F_CPL, + 'G': _CSI_G_CHA, + 'H': _CSI_H_CUP, + 'I': _CSI_I_CHT, + 'J': _CSI_J_ED, + 'K': _CSI_K_el, + 'L': _CSI_L_IL, + 'M': _CSI_M_DL, + 'S': _CSI_S_SU, + 'T': _CSI_T_SD, + 'X': _CSI_X_ECH, + 'Z': _CSI_Z_CBT, + '^': _CSI___SD, + '`': _CSI___HPA, + 'a': _CSI_a_HPR, + 'b': _CSI_b_REP, + 'c': _CSI_c_Pri_DA, + 'd': _CSI_d_VPA, + 'e': _CSI_e_VPR, + 'f': _CSI_f_HVP, + 'g': _CSI_g_TBC, + 'h': _CSI_h_SM, + 'i': _CSI_i_MC, + 'l': _CSI_l_RM, + 'm': _CSI_m_SGR, + 'n': _CSI_n_DSR, + 'q': _CSI_q_DECLL, + 's': _CSI_s_SCOSC, + 'u': _CSI_u_SCORC, + 'x': _CSI_x_DECREQTPARM + } diff --git a/TermTk/TTkWidgets/TTkTerminal/vt102.py b/TermTk/TTkWidgets/TTkTerminal/vt102.py new file mode 100644 index 00000000..6b6f20df --- /dev/null +++ b/TermTk/TTkWidgets/TTkTerminal/vt102.py @@ -0,0 +1,46 @@ +# MIT License +# +# Copyright (c) 2023 Eugenio Parodi +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +from TermTk.TTkCore.color import TTkColor +from TermTk.TTkCore.log import TTkLog +from TermTk.TTkCore.constant import TTkK +from TermTk.TTkCore.cfg import TTkCfg +from TermTk.TTkCore.string import TTkString +from TermTk.TTkCore.signal import pyTTkSignal, pyTTkSlot +from TermTk.TTkCore.helper import TTkHelper +from TermTk.TTkGui.clipboard import TTkClipboard +from TermTk.TTkGui.textwrap1 import TTkTextWrap +from TermTk.TTkGui.textcursor import TTkTextCursor +from TermTk.TTkGui.textdocument import TTkTextDocument +from TermTk.TTkLayouts.gridlayout import TTkGridLayout +from TermTk.TTkAbstract.abstractscrollarea import TTkAbstractScrollArea +from TermTk.TTkAbstract.abstractscrollview import TTkAbstractScrollView, TTkAbstractScrollViewGridLayout +from TermTk.TTkWidgets.widget import TTkWidget + +__all__ = ['TTkVT102'] + +class TTkVT102(): + CLEAR = "\033[2J\033[0;0f" # Clear screen and set cursor to position 0,0 + ALT_SCREEN = "\033[?1049h" #* Switch to alternate screen + NORMAL_SCREEN = "\033[?1049l" #* Switch to normal screen + + diff --git a/TermTk/TTkWidgets/__init__.py b/TermTk/TTkWidgets/__init__.py index 5cb7a80d..47488eaf 100644 --- a/TermTk/TTkWidgets/__init__.py +++ b/TermTk/TTkWidgets/__init__.py @@ -28,3 +28,5 @@ from .texedit import TTkTextEdit, TTkTextEditView from .TTkModelView import * from .TTkPickers import * from .window import TTkWindow + +from .TTkTerminal import * diff --git a/tests/test.pty.005.fork.py b/tests/test.pty.005.fork.py index 875f799d..964d88e9 100755 --- a/tests/test.pty.005.fork.py +++ b/tests/test.pty.005.fork.py @@ -79,10 +79,11 @@ class TermThread(threading.Thread): ttk.TTkLog.error(f"Error: {e=}") return if o: - # ttk.TTkLog.debug(f'Eugenio->{o}') + ttk.TTkLog.debug(f'Eugenio->{o}') # self.textEdit.append(o.decode('utf-8').replace('\r','').replace('\033[?2004h','').replace('\033[?2004l','')) cursor = self.textEdit.textCursor() cursor.insertText(o.decode('utf-8').replace('\r','').replace('\033[?2004h','').replace('\033[?2004l','')) + # cursor.insertText(o.decode('utf-8').replace('\r','<-r->').replace('\033','<-ESC->')) cursor.movePosition(ttk.TTkTextCursor.End) self.textEdit.textEditView()._updateSize() self.textEdit.textEditView().viewMoveTo(0, cursor.position().line) diff --git a/tests/test.pty.006.terminal.py b/tests/test.pty.006.terminal.py new file mode 100755 index 00000000..94c894ae --- /dev/null +++ b/tests/test.pty.006.terminal.py @@ -0,0 +1,66 @@ +#!/usr/bin/env python3 + +# MIT License +# +# Copyright (c) 2023 Eugenio Parodi +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the"Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED"AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +# This test is based on: +# pyte - In memory VTXXX-compatible terminal emulator. +# Terminal Emulator Example +# https://github.com/selectel/pyte/blob/master/examples/terminal_emulator.py +# +# pty — Pseudo-terminal utilities¶ +# https://docs.python.org/3/library/pty.html#example +# +# Using a pseudo-terminal to interact with interactive Python in a subprocess +# by Thomas Billinger +# https://gist.github.com/thomasballinger/7979808 +# +# Run interactive Bash with popen and a dedicated TTY Python +# https://stackoverflow.com/questions/41542960/run-interactive-bash-with-popen-and-a-dedicated-tty-python + +import os +import pty +import sys +import threading +from select import select + + +sys.path.append(os.path.join(sys.path[0],'..')) +import TermTk as ttk + +ttk.TTkLog.use_default_file_logging() +root = ttk.TTk() + +wlog = ttk.TTkWindow(parent=root,pos = (32,12), size=(90,20), title="Log Window", flags=ttk.TTkK.WindowFlag.WindowCloseButtonHint|ttk.TTkK.WindowFlag.WindowMinMaxButtonsHint) +wlog.setLayout(ttk.TTkHBoxLayout()) +ttk.TTkLogViewer(parent=wlog, follow=False ) + +win1 = ttk.TTkWindow(parent=root, pos=(1,1), size=(70,15), title="Terminallo n.1", border=True, layout=ttk.TTkVBoxLayout(), flags = ttk.TTkK.WindowFlag.WindowMinMaxButtonsHint) +term1 = ttk.TTkTerminal(parent=win1) +term1.runShell() + +win2 = ttk.TTkWindow(parent=root, pos=(10,5), size=(70,15), title="Terminallo n.2", border=True, layout=ttk.TTkVBoxLayout(), flags = ttk.TTkK.WindowFlag.WindowMinMaxButtonsHint) +term2 = ttk.TTkTerminal(parent=win2) +term2.runShell() + + +root.mainloop() \ No newline at end of file diff --git a/tests/timeit/15.strings.01.re.loop.py b/tests/timeit/15.strings.01.re.loop.py new file mode 100755 index 00000000..3e1eb454 --- /dev/null +++ b/tests/timeit/15.strings.01.re.loop.py @@ -0,0 +1,224 @@ +#!/usr/bin/env python3 + +# MIT License +# +# Copyright (c) 2023 Eugenio Parodi +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +import sys, os + +import timeit +import re + +sys.path.append(os.path.join(sys.path[0],'../..')) + +# Testing a string contain different kind of matches +# Uppercase the matching pattern +# With the one mimic the VT100 escape codes "A...x" +testString1 = ( + "123456Aabcdef01" + "A[123A" + + "123456Babcdef02" + "A[123B" + + "123456Babcdef03" + "A[12C" + + "123456Babcdef04" + "A[1D" + + "123456Babcdef05" + "A[?123l" + + "123456Babcdef06" + "A[?123h" + + "123456Babcdef07" + "A[?4l" + + "123456Babcdef08" + "A[?5h" + + "123456Babcdef09" + "A[1E" + + "123456Cabcdef10" + "A[1;3H" + + "123456Cabcdef11" + "A[;f" + + "123456Dabcdef12" + "A[123F" + + "123456Eabcdef13" + "A[12;34f" ) + +testString2 = ( + "123456Aabcdef01" + "A[123A" + + "123456Cabcdef10" + "A[1;3H" + + "123456Eabcdef13" ) + +testString3 = ( + "123456Aabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdef01" + "A[123A" + + "123456Eabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdef13" ) + + +re_P1_1 = re.compile(r'^(\d*);(\d*)([Hf])') +re_P1_2 = re.compile(r'^\?(\d+)([lh])') +re_P1_3 = re.compile(r'^(\d+)([ABCDEFGIJKLMPSTXZ])') + +def process1_1(txt): + _lines = [] + _cursor = (1,1) + lines = txt.split('A') + for i,l in enumerate(lines): + if i: + _lines.append("") + _cursor = (0,len(_lines)-1) + ls = l.split('B') + for ii,ll in enumerate(ls): + if ii: + _cursor = (0,len(_lines)-1) + lls = ll.split('C') + for iii,lll in enumerate(lls): + if iii: + x,y = _cursor + _cursor = (max(0,x-1),y) + _lines.append(lll) + return len(lines) +_cursor[0] + _cursor[1] + +def process1(txt): + r = 0 + tmp = [] + sout = txt.split('A[') + r += process1_1(sout[0]) + for slice in sout[1:]: + if m := re_P1_2.match(slice): + l = len(m.group(0)) + ps = int(m.group(1)) + sr = m.group(2) + tmp.append((ps,sr)) + slice = slice[l:] + elif m := re_P1_1.match(slice): + l = len(m.group(0)) + y = m.group(1) + x = m.group(2) + tp = m.group(3) + tmp.append((y,x,tp)) + slice = slice[l:] + elif m := re_P1_3.match(slice): + l = len(m.group(0)) + ps = int(m.group(1)) + sr = m.group(2) + tmp.append((ps,sr)) + slice = slice[l:] + else: + slice = '\033[' + slice.replace('\r','') + r += process1_1(slice) + return r + len(tmp) + +re_P2_1 = re.compile(r'A\[(\d*);(\d*)([Hf])') +re_P2_2 = re.compile(r'A\[\?(\d+)([lh])') +re_P2_3 = re.compile(r'A\[(\d+)([ABCDEFGIJKLMPSTXZ])') +re_P2_4 = re.compile(r'[ABCD]') + +def process2_2(txt): + ret=0 + pos = 0 + prev = 0 + lll = len(txt) + x,y = 0,0 + xxx = { + "A":lambda :(x+1,y), + "B":lambda :(x-1,y), + "C":lambda :(x,y+1), + "D":lambda :(x,y-1), + } + while pos < lll: + if m := re_P2_4.search(txt,pos): + gr = m.group() + ln = 1 + st = m.start() + en = pos = st+1 + _x = xxx.get(gr,lambda :(x,y)) + x,y = _x() + ret += x+y + ret += len(txt[prev:st]) + prev = en + else: + ret += len(txt[prev:]) + break + return ret + +def process2_1(txt): + ret=0 + pos = 0 + prev = 0 + lll = len(txt) + while pos < lll: + if m := re_P2_1.search(txt,pos): + gr = m.group() + ln = len(gr) + st = m.start() + en = pos = m.end() + y = int(vv) if (vv:=m.group(1)) else 0 + x = int(vv) if (vv:=m.group(2)) else 0 + ty = m.group(3) + ret += x+y + ret += process2_2(txt[prev:st]) + prev = en + elif m := re_P2_3.search(txt,pos): + gr = m.group() + ln = len(gr) + st = m.start() + ps = int(m.group(1)) + sr = m.group(2) + en = pos = m.end() + ret += ps + ret += process2_2(txt[prev:st]) + prev = en + else: + ret += process2_2(txt[prev:]) + break + return ret + +def process2(txt): + ret=0 + pos = 0 + prev = 0 + lll = len(txt) + xxx = { + "A[123l":lambda x:len(x)+1, + "A[123l":lambda x:len(x)+2, + } + while pos < lll: + if m := re_P2_2.search(txt,pos): + gr = m.group() + ln = len(gr) + st = m.start() + en = pos = m.end() + _x = xxx.get(gr,lambda x:len(x)+3) + ret += _x(txt[st:en]) + ret += process2_1(txt[prev:st]) + prev = en + else: + ret += process2_1(txt[prev:]) + break + return ret + + +def test1(): return process1(testString1) +def test2(): return process1(testString2) +def test3(): return process1(testString3) +def test4(): return process2(testString1) +def test5(): return process2(testString2) +def test6(): return process2(testString3) +def test7(): return 7 +def test8(): return 8 +def test9(): return 9 + +loop = 10000 + +a={} + +iii = 1 +while (testName := f'test{iii}') and (testName in globals()): + result = timeit.timeit(f'{testName}(*a)', globals=globals(), number=loop) + # print(f"test{iii}) fps {loop / result :.3f} - s {result / loop:.10f} - {result / loop} {globals()[testName](*a)}") + print(f"test{iii:02}) | {result / loop:.10f} sec. | {loop / result : 15.3f} Fps ╞╡-> {globals()[testName](*a)}") + iii+=1 + diff --git a/tests/timeit/15.strings.02.re.py b/tests/timeit/15.strings.02.re.py new file mode 100755 index 00000000..8624e5dc --- /dev/null +++ b/tests/timeit/15.strings.02.re.py @@ -0,0 +1,94 @@ +#!/usr/bin/env python3 + +# MIT License +# +# Copyright (c) 2023 Eugenio Parodi +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +import sys, os + +import timeit +import re + +sys.path.append(os.path.join(sys.path[0],'../..')) + +# Testing a string contain different kind of matches +# Uppercase the matching pattern +# With the one mimic the VT100 escape codes "A...x" +testString1 = "A[12;3H" + "abc" +testString2 = "A[123A" + "abc" +testString3 = "A[;f" + "abc" + +# xterm escape sequences from: +# https://invisible-island.net/xterm/ctlseqs/ctlseqs.html +# https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Functions-using-CSI-_-ordered-by-the-final-character_s_ +re_CURSOR = re.compile('^A\[(\d*);?(\d*)([ABCDEFGIJKLMPSTXZHf@])') +# https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Functions-using-CSI-_-ordered-by-the-final-character_s_ +# Basic Re for CSI Ps matches: +# CSI : Control Sequence Introducer "[" = '\033[' +# Ps : A single (usually optional) numeric parameter, composed of one or more digits. +# fu : the single char defining the function +re_CSI_Ps_fu = re.compile('^A\[(\d*)([ABCDEFGIJKLMPSTXZ@])') +re_CSI_Ps_Ps_fu = re.compile('^A\[(\d*);(\d*)([Hf])') + +re_CSI_Mix = re.compile('^A\[(\d*)([ABCDEFGIJKLMPSTXZ@])|A\[(\d*);(\d*)([Hf])') + + +re_DEC_SET_RST = re.compile('A\[\?(\d+)([lh])') +# re_CURSOR_1 = re.compile(r'^(\d+)([ABCDEFGIJKLMPSTXZHf])') + +def process1(txt): + if m:=re_CURSOR.match(txt): + return 1 + return 3 + +def process2(txt): + if m:=re_CSI_Ps_fu.match(txt): + return 1 + elif m:=re_CSI_Ps_Ps_fu.match(txt): + return 2 + return 3 + +def process3(txt): + if m:=re_CSI_Mix.match(txt): + return 1 + return 3 + +def test1(): return process1(testString1) +def test2(): return process1(testString2) +def test3(): return process1(testString3) +def test4(): return process2(testString1) +def test5(): return process2(testString2) +def test6(): return process2(testString3) +def test7(): return process3(testString1) +def test8(): return process3(testString2) +def test9(): return process3(testString3) + +loop = 100000 + +a={} + +iii = 1 +while (testName := f'test{iii}') and (testName in globals()): + result = timeit.timeit(f'{testName}(*a)', globals=globals(), number=loop) + # print(f"test{iii}) fps {loop / result :.3f} - s {result / loop:.10f} - {result / loop} {globals()[testName](*a)}") + print(f"test{iii:02}) | {result / loop:.10f} sec. | {loop / result : 15.3f} Fps ╞╡-> {globals()[testName](*a)}") + iii+=1 + diff --git a/tests/timeit/16.dict.01.get.py b/tests/timeit/16.dict.01.get.py new file mode 100755 index 00000000..7d2969f6 --- /dev/null +++ b/tests/timeit/16.dict.01.get.py @@ -0,0 +1,151 @@ +#!/usr/bin/env python3 + +# MIT License +# +# Copyright (c) 2023 Eugenio Parodi +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +import sys, os + +import timeit + +sys.path.append(os.path.join(sys.path[0],'../..')) + +D1 = { + 'a' : lambda x, _ : 2*x, + 'b' : lambda x, _ : 2*x, + 'c' : lambda x, _ : 2*x, + 'd' : lambda x, _ : 2*x, + 'e' : lambda x, _ : 2*x, + 'f' : lambda x, _ : 2*x, + 'g' : lambda x, _ : 2*x, + 'h' : lambda x, _ : 2*x, + 'i' : lambda x, _ : 2*x, + 'j' : lambda x, _ : 2*x, + 'k' : lambda x, _ : 2*x, + 'l' : lambda x, y : 2*x+y, + 'm' : lambda x, _ : 2*x, + 'n' : lambda x, _ : 2*x, + 'o' : lambda x, _ : 2*x, + 'p' : lambda x, y : 2*x+y, + 'q' : lambda x, _ : 2*x, + 'r' : lambda x, _ : 2*x, + 's' : lambda x, y : 2*x+y, + 't' : lambda x, _ : 2*x, + 'u' : lambda x, y : 2*x+y, + 'v' : lambda x, _ : 2*x, + 'w' : lambda x, _ : 2*x, + 'x' : lambda x, _ : 2*x, + 'y' : lambda x, _ : 2*x, + 'z' : lambda x, _ : 2*x, +} + +D2_1 = { + 'a' : lambda x: 2*x, + 'b' : lambda x: 2*x, + 'c' : lambda x: 2*x, + 'd' : lambda x: 2*x, + 'e' : lambda x: 2*x, + 'f' : lambda x: 2*x, + 'g' : lambda x: 2*x, + 'h' : lambda x: 2*x, + 'i' : lambda x: 2*x, + 'j' : lambda x: 2*x, + 'k' : lambda x: 2*x, + 'm' : lambda x: 2*x, + 'n' : lambda x: 2*x, + 'o' : lambda x: 2*x, + 'q' : lambda x: 2*x, + 'r' : lambda x: 2*x, + 't' : lambda x: 2*x, + 'v' : lambda x: 2*x, + 'w' : lambda x: 2*x, + 'x' : lambda x: 2*x, + 'y' : lambda x: 2*x, + 'z' : lambda x: 2*x, +} + +D2_2 = { + 'l' : lambda x, y : 2*x+y, + 'p' : lambda x, y : 2*x+y, + 's' : lambda x, y : 2*x+y, + 'u' : lambda x, y : 2*x+y, +} + +test_input_1 = { + 'a' : (2,None), + 'b' : (2,None), + 'c' : (2,None), + 'd' : (2,None), + 'e' : (2,None), + 'l' : (2,2), + 'p' : (2,2), + 's' : (2,2), + 'n' : (2,None), + 'o' : (2,None), + 'z' : (2,None), + 'y' : (2,None), + 'u' : (2,2), +} + +def process1(ttt): + ret = 0 + for i in ttt: + x,y = ttt[i] + _v = D1.get(i,lambda x,y:None) + ret += _v(x,y) + return ret + +def process2(ttt): + ret = 0 + for i in ttt: + x,y = ttt[i] + if y: + _v = D2_2.get(i,lambda x,y:None) + ret += _v(x,y) + else: + _v = D2_1.get(i,lambda x:None) + ret += _v(x) + return ret + +def process3(ttt): + return 3 + +def test1(): return process1(test_input_1) +def test2(): return process1(test_input_1) +def test3(): return process1(test_input_1) +def test4(): return process2(test_input_1) +def test5(): return process2(test_input_1) +def test6(): return process2(test_input_1) +def test7(): return process3(test_input_1) +def test8(): return process3(test_input_1) +def test9(): return process3(test_input_1) + +loop = 100000 + +a={} + +iii = 1 +while (testName := f'test{iii}') and (testName in globals()): + result = timeit.timeit(f'{testName}(*a)', globals=globals(), number=loop) + # print(f"test{iii}) fps {loop / result :.3f} - s {result / loop:.10f} - {result / loop} {globals()[testName](*a)}") + print(f"test{iii:02}) | {result / loop:.10f} sec. | {loop / result : 15.3f} Fps ╞╡-> {globals()[testName](*a)}") + iii+=1 +