diff --git a/TermTk/TTkWidgets/TTkTerminal/terminal.py b/TermTk/TTkWidgets/TTkTerminal/terminal.py index a0ec994a..ac0a0c21 100644 --- a/TermTk/TTkWidgets/TTkTerminal/terminal.py +++ b/TermTk/TTkWidgets/TTkTerminal/terminal.py @@ -20,6 +20,8 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. +__all__ = ['TTkTerminal'] + import os, pty, threading import struct, fcntl, termios @@ -46,16 +48,15 @@ from TermTk.TTkAbstract.abstractscrollarea import TTkAbstractScrollArea from TermTk.TTkAbstract.abstractscrollview import TTkAbstractScrollView, TTkAbstractScrollViewGridLayout from TermTk.TTkWidgets.widget import TTkWidget -from TermTk.TTkWidgets.TTkTerminal.terminal_alt import _TTkTerminalAltScreen -from TermTk.TTkWidgets.TTkTerminal.terminal_normal import _TTkTerminalNormalScreen -from TermTk.TTkWidgets.TTkTerminal.mode import TTkTerminalModes +from TermTk.TTkWidgets.TTkTerminal.terminal_screen import _TTkTerminalScreen +from TermTk.TTkWidgets.TTkTerminal.mode import TTkTerminalModes from TermTk.TTkWidgets.TTkTerminal.vt102 import TTkVT102 from TermTk.TTkCore.TTkTerm.colors import TTkTermColor from TermTk.TTkCore.TTkTerm.colors_ansi_map import ansiMap16, ansiMap256 -__all__ = ['TTkTerminal'] +from .terminal_CSI_DEC import _TTkTerminal_CSI_DEC class _termLog(): # debug = TTkLog.debug @@ -72,7 +73,7 @@ class _termLog(): # fatal = lambda _:None mouse = lambda _:None -class TTkTerminal(TTkWidget): +class TTkTerminal(TTkWidget, _TTkTerminal_CSI_DEC): @dataclass class _Terminal(): bracketedMode: bool = False @@ -111,8 +112,8 @@ class TTkTerminal(TTkWidget): self._mouse = TTkTerminal._Mouse() self._buffer_lines = [TTkString()] # self._screen_normal = _TTkTerminalNormalScreen() - self._screen_normal = _TTkTerminalAltScreen() - self._screen_alt = _TTkTerminalAltScreen() + self._screen_normal = _TTkTerminalScreen() + self._screen_alt = _TTkTerminalScreen() self._screen_current = self._screen_normal self._clipboard = TTkClipboard() @@ -714,6 +715,18 @@ class TTkTerminal(TTkWidget): if not slice: continue + # C1 Escape Codes + # ESC E Next Line + # ESC D Index = '\n' + # ESC M Reverse Index + # ESC H Horizontal Tab Set + elif slice and slice[0] in ('D','E','H','M','O','P','V','W','X','Z'): + # Handle the screen related functions + _ex = self._screen_current._C1_MAP.get( + slice[0], + lambda : _termLog.error(f"Unhandled C1 {slice[0]}")) + _ex(self._screen_current) + slice = slice[1:] ################################################ # Everything else ################################################ @@ -1039,172 +1052,3 @@ class TTkTerminal(TTkWidget): ps, lambda a,b: _termLog.error(f"Unhandled (DEC) [{ps}{'h' if s else 'l'}")) _dec(self, s) - - - - # CSI ? Pm h - # DEC Private Mode Set (DECSET). - # Ps = 1 ⇒ Application Cursor Keys (MODE_DECCKM), VT100. - # UP = \0330A - # DOWN = \0330B - # LEFT = \0330C - # RIGHT = \0330D - # CSI ? Pm l - # DEC Private Mode Reset (DECRST). - # Ps = 1 ⇒ Normal Cursor Keys (MODE_DECCKM), VT100. - # UP = \033[A - # DOWN = \033[B - # LEFT = \033[C - # RIGHT = \033[D - def _CSI_DEC_SR_1_MODE_DECCKM(self, s): - if s: - self._keyboard.flags |= TTkTerminalModes.MODE_DECCKM - else: - self._keyboard.flags &= ~TTkTerminalModes.MODE_DECCKM - - # CSI ? Pm h - # DEC Private Mode Set (DECSET). - # Ps = 2 5 ⇒ Show cursor (DECTCEM), VT220. - # CSI ? Pm l - # DEC Private Mode Reset (DECRST). - # Ps = 2 5 ⇒ Hide cursor (DECTCEM), VT220. - def _CSI_DEC_SR_25_DECTCEM(self, s): - self.enableWidgetCursor(enable=s) - - # CSI ? Pm h - # DEC Private Mode Set (DECSET). - # 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. - # CSI ? Pm l - # DEC Private Mode Reset (DECRST). - # Ps = 1 0 0 0 ⇒ Don't send Mouse X & Y on button press and - # release. See the section Mouse Tracking. - def _CSI_DEC_SR_1000(self, s): - self._mouse.reportPress = s - self._mouse.reportDrag = False - self._mouse.reportMove = False - _termLog.info(f"1000 Mouse Tracking {s=}") - - # CSI ? Pm h - # DEC Private Mode Set (DECSET). - # Ps = 1 0 0 2 ⇒ Use Cell Motion Mouse Tracking, xterm. See - # the section Button-event tracking. - # CSI ? Pm l - # DEC Private Mode Reset (DECRST). - # Ps = 1 0 0 2 ⇒ Don't use Cell Motion Mouse Tracking, - # xterm. See the section Button-event tracking. - def _CSI_DEC_SR_1002(self, s): - self._mouse.reportPress = s - self._mouse.reportDrag = s - self._mouse.reportMove = False - _termLog.info(f"1002 Mouse Tracking {s=}") - - # CSI ? Pm h - # DEC Private Mode Set (DECSET). - # Ps = 1 0 0 3 ⇒ Use All Motion Mouse Tracking, xterm. See - # the section Any-event tracking. - # CSI ? Pm l - # DEC Private Mode Reset (DECRST). - # Ps = 1 0 0 3 ⇒ Don't use All Motion Mouse Tracking, xterm. - # See the section Any-event tracking. - def _CSI_DEC_SR_1003(self, s): - self._mouse.reportPress = s - self._mouse.reportDrag = s - self._mouse.reportMove = s - _termLog.info(f"1003 Mouse Tracking {s=}") - - # CSI ? Pm h - # DEC Private Mode Set (DECSET). - # Ps = 1 0 0 4 ⇒ Send FocusIn/FocusOut events, xterm. - # CSI ? Pm l - # DEC Private Mode Reset (DECRST). - # Ps = 1 0 0 4 ⇒ Don't send FocusIn/FocusOut events, xterm. - def _CSI_DEC_SR_1004(self, s): - _termLog.warn(f"Unhandled 1004 Focus In/Out event {s=}") - - - # CSI ? Pm h - # DEC Private Mode Set (DECSET). - # Ps = 1 0 0 6 ⇒ Enable SGR Mouse Mode, xterm. - # CSI ? Pm l - # DEC Private Mode Reset (DECRST). - # Ps = 1 0 0 6 ⇒ Disable SGR Mouse Mode, xterm. - def _CSI_DEC_SR_1006(self, s): - self._mouse.sgrMode = s - _termLog.info(f"1006 SGR Mouse Mode {s=}") - - # CSI ? Pm h - # DEC Private Mode Set (DECSET). - # Ps = 1 0 1 5 ⇒ Enable urxvt Mouse Mode. - # CSI ? Pm l - # DEC Private Mode Reset (DECRST). - # Ps = 1 0 1 5 ⇒ Disable urxvt Mouse Mode. - def _CSI_DEC_SR_1015(self, s): - _termLog.warn(f"1015 {s=} Unimplemented: _CSI_DEC_SR_1015 urxvt Mouse Mode.") - - # CSI ? Pm h - # DEC Private Mode Set (DECSET). - # Ps = 1 0 4 7 ⇒ Use Alternate Screen Buffer, xterm. This - # may be disabled by the titeInhibit resource. - # CSI ? Pm l - # DEC Private Mode Reset (DECRST). - # 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. - def _CSI_DEC_SR_1047(self, s): - if s: - self._screen_current = self._screen_alt - else: - self._screen_current = self._screen_normal - - # CSI ? Pm h - # DEC Private Mode Set (DECSET). - # Ps = 1 0 4 8 ⇒ Save cursor as in DECSC, xterm. This may - # be disabled by the titeInhibit resource. - # CSI ? Pm l - # DEC Private Mode Reset (DECRST). - # Ps = 1 0 4 8 ⇒ Restore cursor as in DECRC, xterm. This - # may be disabled by the titeInhibit resource. - def _CSI_DEC_SR_1048(self, s): - pass - - # CSI ? Pm h - # DEC Private Mode Set (DECSET). - # 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 - # CSI ? Pm l - # DEC Private Mode Reset (DECRST). - # 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. - def _CSI_DEC_SR_1049(self, s): - self._CSI_DEC_SR_1047(s) - self._CSI_DEC_SR_1048(s) - - # CSI ? Pm h - # DEC Private Mode Set (DECSET). - # Ps = 2 0 0 4 ⇒ Set bracketed paste mode, xterm. - # CSI ? Pm l - # DEC Private Mode Reset (DECRST). - # Ps = 2 0 0 4 ⇒ Reset bracketed paste mode, xterm. - def _CSI_DEC_SR_2004(self, s): - self._terminal.bracketedMode = s - - _CSI_DEC_SET_RST_MAP = { - 1 : _CSI_DEC_SR_1_MODE_DECCKM, - 25 : _CSI_DEC_SR_25_DECTCEM, - 1000: _CSI_DEC_SR_1000, - 1002: _CSI_DEC_SR_1002, - 1003: _CSI_DEC_SR_1003, - 1004: _CSI_DEC_SR_1004, - 1006: _CSI_DEC_SR_1006, - 1015: _CSI_DEC_SR_1015, - 1047: _CSI_DEC_SR_1047, - 1049: _CSI_DEC_SR_1049, - 2004: _CSI_DEC_SR_2004 - } \ No newline at end of file diff --git a/TermTk/TTkWidgets/TTkTerminal/terminal_CSI_DEC.py b/TermTk/TTkWidgets/TTkTerminal/terminal_CSI_DEC.py new file mode 100644 index 00000000..e85943ce --- /dev/null +++ b/TermTk/TTkWidgets/TTkTerminal/terminal_CSI_DEC.py @@ -0,0 +1,241 @@ +# 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. + +__all__ = [''] + +import os, pty, threading +import struct, fcntl, termios + +from dataclasses import dataclass + +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 TermTk.TTkWidgets.TTkTerminal.terminal_screen import _TTkTerminalScreen +from TermTk.TTkWidgets.TTkTerminal.mode import TTkTerminalModes + +from TermTk.TTkWidgets.TTkTerminal.vt102 import TTkVT102 + +from TermTk.TTkCore.TTkTerm.colors import TTkTermColor +from TermTk.TTkCore.TTkTerm.colors_ansi_map import ansiMap16, ansiMap256 + + +class _termLog(): + # debug = TTkLog.debug + # info = TTkLog.info + error = TTkLog.error + warn = TTkLog.warn + fatal = TTkLog.fatal + # mouse = TTkLog.error + + debug = lambda _:None + info = lambda _:None + # error = lambda _:None + # warn = lambda _:None + # fatal = lambda _:None + mouse = lambda _:None + +class _TTkTerminal_CSI_DEC(): + # CSI ? Pm h + # DEC Private Mode Set (DECSET). + # Ps = 1 ⇒ Application Cursor Keys (MODE_DECCKM), VT100. + # UP = \0330A + # DOWN = \0330B + # LEFT = \0330C + # RIGHT = \0330D + # CSI ? Pm l + # DEC Private Mode Reset (DECRST). + # Ps = 1 ⇒ Normal Cursor Keys (MODE_DECCKM), VT100. + # UP = \033[A + # DOWN = \033[B + # LEFT = \033[C + # RIGHT = \033[D + def _CSI_DEC_SR_1_MODE_DECCKM(self, s): + if s: + self._keyboard.flags |= TTkTerminalModes.MODE_DECCKM + else: + self._keyboard.flags &= ~TTkTerminalModes.MODE_DECCKM + + # CSI ? Pm h + # DEC Private Mode Set (DECSET). + # Ps = 2 5 ⇒ Show cursor (DECTCEM), VT220. + # CSI ? Pm l + # DEC Private Mode Reset (DECRST). + # Ps = 2 5 ⇒ Hide cursor (DECTCEM), VT220. + def _CSI_DEC_SR_25_DECTCEM(self, s): + self.enableWidgetCursor(enable=s) + + # CSI ? Pm h + # DEC Private Mode Set (DECSET). + # 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. + # CSI ? Pm l + # DEC Private Mode Reset (DECRST). + # Ps = 1 0 0 0 ⇒ Don't send Mouse X & Y on button press and + # release. See the section Mouse Tracking. + def _CSI_DEC_SR_1000(self, s): + self._mouse.reportPress = s + self._mouse.reportDrag = False + self._mouse.reportMove = False + _termLog.info(f"1000 Mouse Tracking {s=}") + + # CSI ? Pm h + # DEC Private Mode Set (DECSET). + # Ps = 1 0 0 2 ⇒ Use Cell Motion Mouse Tracking, xterm. See + # the section Button-event tracking. + # CSI ? Pm l + # DEC Private Mode Reset (DECRST). + # Ps = 1 0 0 2 ⇒ Don't use Cell Motion Mouse Tracking, + # xterm. See the section Button-event tracking. + def _CSI_DEC_SR_1002(self, s): + self._mouse.reportPress = s + self._mouse.reportDrag = s + self._mouse.reportMove = False + _termLog.info(f"1002 Mouse Tracking {s=}") + + # CSI ? Pm h + # DEC Private Mode Set (DECSET). + # Ps = 1 0 0 3 ⇒ Use All Motion Mouse Tracking, xterm. See + # the section Any-event tracking. + # CSI ? Pm l + # DEC Private Mode Reset (DECRST). + # Ps = 1 0 0 3 ⇒ Don't use All Motion Mouse Tracking, xterm. + # See the section Any-event tracking. + def _CSI_DEC_SR_1003(self, s): + self._mouse.reportPress = s + self._mouse.reportDrag = s + self._mouse.reportMove = s + _termLog.info(f"1003 Mouse Tracking {s=}") + + # CSI ? Pm h + # DEC Private Mode Set (DECSET). + # Ps = 1 0 0 4 ⇒ Send FocusIn/FocusOut events, xterm. + # CSI ? Pm l + # DEC Private Mode Reset (DECRST). + # Ps = 1 0 0 4 ⇒ Don't send FocusIn/FocusOut events, xterm. + def _CSI_DEC_SR_1004(self, s): + _termLog.warn(f"Unhandled 1004 Focus In/Out event {s=}") + + + # CSI ? Pm h + # DEC Private Mode Set (DECSET). + # Ps = 1 0 0 6 ⇒ Enable SGR Mouse Mode, xterm. + # CSI ? Pm l + # DEC Private Mode Reset (DECRST). + # Ps = 1 0 0 6 ⇒ Disable SGR Mouse Mode, xterm. + def _CSI_DEC_SR_1006(self, s): + self._mouse.sgrMode = s + _termLog.info(f"1006 SGR Mouse Mode {s=}") + + # CSI ? Pm h + # DEC Private Mode Set (DECSET). + # Ps = 1 0 1 5 ⇒ Enable urxvt Mouse Mode. + # CSI ? Pm l + # DEC Private Mode Reset (DECRST). + # Ps = 1 0 1 5 ⇒ Disable urxvt Mouse Mode. + def _CSI_DEC_SR_1015(self, s): + _termLog.warn(f"1015 {s=} Unimplemented: _CSI_DEC_SR_1015 urxvt Mouse Mode.") + + # CSI ? Pm h + # DEC Private Mode Set (DECSET). + # Ps = 1 0 4 7 ⇒ Use Alternate Screen Buffer, xterm. This + # may be disabled by the titeInhibit resource. + # CSI ? Pm l + # DEC Private Mode Reset (DECRST). + # 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. + def _CSI_DEC_SR_1047(self, s): + if s: + self._screen_current = self._screen_alt + else: + self._screen_current = self._screen_normal + + # CSI ? Pm h + # DEC Private Mode Set (DECSET). + # Ps = 1 0 4 8 ⇒ Save cursor as in DECSC, xterm. This may + # be disabled by the titeInhibit resource. + # CSI ? Pm l + # DEC Private Mode Reset (DECRST). + # Ps = 1 0 4 8 ⇒ Restore cursor as in DECRC, xterm. This + # may be disabled by the titeInhibit resource. + def _CSI_DEC_SR_1048(self, s): + pass + + # CSI ? Pm h + # DEC Private Mode Set (DECSET). + # 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 + # CSI ? Pm l + # DEC Private Mode Reset (DECRST). + # 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. + def _CSI_DEC_SR_1049(self, s): + self._CSI_DEC_SR_1047(s) + self._CSI_DEC_SR_1048(s) + + # CSI ? Pm h + # DEC Private Mode Set (DECSET). + # Ps = 2 0 0 4 ⇒ Set bracketed paste mode, xterm. + # CSI ? Pm l + # DEC Private Mode Reset (DECRST). + # Ps = 2 0 0 4 ⇒ Reset bracketed paste mode, xterm. + def _CSI_DEC_SR_2004(self, s): + self._terminal.bracketedMode = s + + _CSI_DEC_SET_RST_MAP = { + 1 : _CSI_DEC_SR_1_MODE_DECCKM, + 25 : _CSI_DEC_SR_25_DECTCEM, + 1000: _CSI_DEC_SR_1000, + 1002: _CSI_DEC_SR_1002, + 1003: _CSI_DEC_SR_1003, + 1004: _CSI_DEC_SR_1004, + 1006: _CSI_DEC_SR_1006, + 1015: _CSI_DEC_SR_1015, + 1047: _CSI_DEC_SR_1047, + 1049: _CSI_DEC_SR_1049, + 2004: _CSI_DEC_SR_2004 + } \ No newline at end of file diff --git a/TermTk/TTkWidgets/TTkTerminal/terminal_normal.py b/TermTk/TTkWidgets/TTkTerminal/terminal_normal.py deleted file mode 100644 index f8e39a13..00000000 --- a/TermTk/TTkWidgets/TTkTerminal/terminal_normal.py +++ /dev/null @@ -1,1548 +0,0 @@ -# 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 collections - -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 _TTkTerminalNormalScreen(): - __slots__ = ('_lines', '_terminalCursor', '_w', '_h', '_bufferSize', '_color') - def __init__(self, w=80, h=24, bufferSize=200, color=TTkColor.RST) -> None: - self._lines = collections.deque(maxlen=bufferSize) - self._lines.append(TTkString()) - self._terminalCursor = (0,0) - self._w = w - self._h = h - self._bufferSize = bufferSize - self._color = color - - def setColor(self, color): - self._color = color - - def getCursor(self): - x,y = self._terminalCursor - h = self._h - l = len(self._lines) - y = y if l= len(self._lines): - self._lines.append(TTkString()) - # self._lines = self._lines[-self._bufferSize:] - self._terminalCursor = (x,y) = (0,min(self._bufferSize-1, y)) - ls = l.split('\r') - for ii,ll in enumerate(ls): - if ii: - self._terminalCursor=(0,y) - lls = ll.split('\b') # 0x08 = Backspace - for iii,lll in enumerate(lls): - if iii: - x,y = self._terminalCursor - self._terminalCursor = (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) - di = max(0,len(self._lines)-h) - for i in range(di,len(self._lines)): - canvas.drawTTkString(text=self._lines[i], pos=(0,i-di), width=w) - - - - - # CSI Ps @ Insert Ps (Blank) Character(s) (default = 1) (ICH). - def _CSI___ICH(self, ps, _): - x,y = self._terminalCursor - self._lines[y] = self._lines[y].substring(to=x) + (' '*ps) + self._lines[y].substring(fr=x) - - # CSI Ps SP @ (SP = Space) - # Shift left Ps columns(s) (default = 1) (SL), ECMA-48. - # def _CSI___SL( self, ps, _): - # x,y = self._terminalCursor - # self._lines[y] = self._lines[y].substring(to=x) + (' '*ps) + self._lines[y].substring(fr=x) - - # CSI Ps A Cursor Up Ps Times (default = 1) (CUU). - def _CSI_A_CUU(self, ps, _): - x,y = self._terminalCursor - l = len(self._lines) - y = max(0, l-self._h, y-ps) - self._terminalCursor=(x,y) - - # CSI Ps SP A (SP = Space) - # Shift right Ps columns(s) (default = 1) (SR), ECMA-48. - # def _CSI_A_SR( self, ps, _): - # x,y = self._terminalCursor - # self._terminalCursor=(x,max(0,y-ps)) - - # CSI Ps B Cursor Down Ps Times (default = 1) (CUD). - def _CSI_B_CUD(self, ps, _): - x,y = self._terminalCursor - l = len(self._lines) - y = min(l-1, y+ps) - self._terminalCursor=(x,y) - - # CSI Ps C Cursor Forward Ps Times (default = 1) (CUF). - def _CSI_C_CUF(self, ps, _): - x,y = self._terminalCursor - x = min(self._w-1, x+ps) - self._terminalCursor=(x,y) - - # CSI Ps D Cursor Backward Ps Times (default = 1) (CUB). - def _CSI_D_CUB(self, ps, _): - x,y = self._terminalCursor - x = max(0,x-ps) - self._terminalCursor=(x,y) - - # CSI Ps E Cursor Next Line Ps Times (default = 1) (CNL). - def _CSI_E_CNL(self, ps, _): - x,y = self._terminalCursor - l = len(self._lines) - y = min(l-1, y+ps) - self._terminalCursor=(0,y) - - # CSI Ps F Cursor Preceding Line Ps Times (default = 1) (CPL). - def _CSI_F_CPL(self, ps, _): - x,y = self._terminalCursor - l = len(self._lines) - y = max(0, l-self._h, y-ps) - self._terminalCursor=(0,y) - - # CSI Ps G Cursor Character Absolute [column] (default = [row,1]) (CHA). - def _CSI_G_CHA(self, row, _): - x,y = self._terminalCursor - w = self._w - x = max( 0, min(w-1, row-1)) - self._terminalCursor=(x,y) - - # CSI Ps ; Ps H - # Cursor Position [row;column] (default = [1,1]) (CUP). - def _CSI_H_CUP(self, row, col): - x,y = self._terminalCursor - w,h = self._w, self._h - row, col = row-1, col-1 - l = len(self._lines) - oy = max(0,l-h) # y offset - ny = row + oy # y row - x = max(0, min(w-1, col)) - y = max(oy, min(ny,oy+h)) - self._terminalCursor=(x,y) - if y>=l: - self._lines += [TTkString()]*(y-l+1) - - - # 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, _): - x,y = self._terminalCursor - h = self._h - l = len(self._lines) - # y = max(0,y-l-h) - if ps == 0: - self._lines[-h:y-1] = [TTkString()]*(y-1-l+h) - self._lines[y] = TTkString(' '*x) + self._lines[y].substring(fr=x) - elif ps == 1: - self._lines[y+1:] = [TTkString()]*(l-y-1) - self._lines[y] = self._lines[y].substring(to=x) - elif ps == 2: - self._lines[-h:] = [TTkString()]*(h) - - # 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, _): - x,y = self._terminalCursor - line = self._lines[y] - if ps == 0: - self._lines[y] = line.substring(to=x) - elif ps == 1: - self._lines[y] = TTkString(' '*x) + self._lines[y].substring(fr=x) - elif ps == 2: - self._lines[y] = TTkString() - - # 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. - # def _CSI_K_DeCSEL(self, ps, _): pass - - # CSI Ps L Insert Ps Line(s) (default = 1) (IL). - def _CSI_L_IL(self, ps, _): - x,y = self._terminalCursor - self._lines[y:y] = [TTkString()]*ps - - # CSI Ps M Delete Ps Line(s) (default = 1) (DL). - def _CSI_M_DL(self, ps, _): - x,y = self._terminalCursor - self._lines[y+1:y+1+ps] = [] - - # CSI Ps P Delete Ps Character(s) (default = 1) (DCH). - def _CSI_P_DCH(self, ps, _): - x,y = self._terminalCursor - l = self._lines[y] - self._lines[y] = l.substring(to=x) + l.substring(fr=x+ps) - - # 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, _): - h = self._w - l = len(self._lines) - oy = max(0,l-h) # y offset - screen = self._lines[oy:] - # Rotate up - screen = screen[min(ps,h):]+[TTkString()]*min(ps,h) - self._lines[oy:] = screen[:h] - - # 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, _): - h = self._h - l = len(self._lines) - oy = max(0,l-h) # y offset - screen = self._lines[oy:] - # Rotate down - screen = [TTkString()]*min(ps,h) + screen - self._lines[oy:] = screen[:h] - - # 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, _): - x,y = self._terminalCursor - w = self._w - ps = min(w,ps) - line = self._lines[y] - line = line.substring(to=x) + TTkString(' '*ps) + line.substring(fr=x+ps) - self._lines[y] = line.substring(to=w) - - # 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, - 'P': _CSI_P_DCH, - '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_screen.py b/TermTk/TTkWidgets/TTkTerminal/terminal_screen.py new file mode 100644 index 00000000..04be084e --- /dev/null +++ b/TermTk/TTkWidgets/TTkTerminal/terminal_screen.py @@ -0,0 +1,188 @@ + # 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. + +__all__ = [''] + +import collections +import unicodedata + +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_screen_CSI import _TTkTerminalScreen_CSI +from .terminal_screen_C1 import _TTkTerminalScreen_C1 + +class _TTkTerminalScreen(_TTkTerminalScreen_CSI, _TTkTerminalScreen_C1): + __slots__ = ('_lines', '_terminalCursor', + '_scrollingRegion', + '_bufferSize', '_bufferedLines', + '_w', '_h', '_color', '_canvas', + '_last', + # Signals + 'bell' + ) + def __init__(self, w=80, h=24, bufferSize=1000, color=TTkColor.RST) -> None: + self.bell = pyTTkSignal() + self._w = w + self._h = h + self._last = None + self._bufferSize = bufferSize + self._bufferedLines = collections.deque(maxlen=bufferSize) + self._terminalCursor = (0,0) + self._scrollingRegion = (0,h) + self._color = color + self._canvas = TTkCanvas(width=w, height=h) + + def color(self): + return self._color + + def setColor(self, color): + self._color = color + + def getCursor(self): + return self._terminalCursor + + def resize(self, w, h): + ow, oh = self._w, self._h + self._w, self._h = w, h + st,sb = self._scrollingRegion + # if oh <= h: # Terminal height decreasing + # sb = min(h,oh) + # else:# Terminal height increasing + # sb = h-oh+sb + # self._scrollingRegion = (st,sb) + self._scrollingRegion = (0,h) + newCanvas = TTkCanvas(width=w, height=h) + s = (0,0,w,h) + newCanvas.paintCanvas(self._canvas,s,s,s) + + self._canvas = newCanvas + x,y = self._terminalCursor + self._terminalCursor = (min(x,w-1),min(y,h-1)) + + def _pushTxt(self, txt:str, irm:bool=False): + x,y = self._terminalCursor + w,h = self._w, self._h + st,sb = self._scrollingRegion + self._last = txt[-1] if txt else None + + for bi, tout in enumerate(txt.split('\a')): # grab the bells + if bi: + self.bell.emit() + + # I check the size of each char in order to draw + # it in the correct position + for ch in tout: + if ord(ch) < 0x20: + # TTkLog.error(f"Unhandled ASCII: 0x{ord(ch):02x}") + continue + l = TTkString._getWidthText(ch) + # Scroll up if we are at the right border + if l+x > w: + x=0 + y+=1 + if y >= sb: + self._CSI_S_SU(y-sb+1, None) # scroll up + y=sb-1 + self._terminalCursor = (x,y) + if l==1: # push normal char + if irm: + self._canvas._data[y][x:x] = [ch] + self._canvas._colors[y][x:x] = [self._color] + # self._canvas._data[y].insert(x,ch) + # self._canvas._colors[y].insert(x,self._color) + self._canvas._data[y].pop() + self._canvas._colors[y].pop() + else: + self._canvas._data[y][x] = ch + self._canvas._colors[y][x] = self._color + elif l > 1: # push wide char + if irm: + self._canvas._data[y][x:x] = [ch,''] + self._canvas._colors[y][x:x] = [self._color,self._color] + # self._canvas._data[y].insert(x,ch) + # self._canvas._colors[y].insert(x,self._color) + self._canvas._data[y].pop() + self._canvas._data[y].pop() + self._canvas._colors[y].pop() + self._canvas._colors[y].pop() + else: + self._canvas._data[y][x] = ch + self._canvas._data[y][x+1] = '' + self._canvas._colors[y][x] = self._color + self._canvas._colors[y][x+1] = self._color + else: # l==0 # push zero sized char + if x>0 and self._canvas._data[y][x-1] != '': + self._canvas._data[y][x-1] += ch + elif x>1: + self._canvas._data[y][x-2] += ch + x+=l + self._terminalCursor = (x+l,y) + self._terminalCursor = (x,y) + + def pushLine(self, line:str, irm:bool=False): + if not line: return + w,h = self._w, self._h + st,sb = self._scrollingRegion + + lines = line.split('\n') + for i,l in enumerate(lines): + if i: + x,y = self._terminalCursor + y+=1 + if y >= sb: + self._CSI_S_SU(y-sb+1, None) # scroll up + y=sb-1 + self._terminalCursor = (x,y) + ls = l.split('\r') + for ii,ll in enumerate(ls): + if ii: + x,y = self._terminalCursor + self._terminalCursor = (0,y) + lls = ll.split('\b') # 0x08 = Backspace + for iii,lll in enumerate(lls): + if iii: + x,y = self._terminalCursor + x = max(0,x-1) + self._terminalCursor = (x,y) + self._pushTxt(lll,irm) + + def paintEvent(self, canvas: TTkCanvas, w:int, h:int, ox:int=0, oy:int=0) -> None: + w,h = self._w, self._h + s = (0,0,w,h) + canvas.paintCanvas(self._canvas,s,s,s) + # TTkLog.debug("Paint") diff --git a/TermTk/TTkWidgets/TTkTerminal/terminal_screen_C1.py b/TermTk/TTkWidgets/TTkTerminal/terminal_screen_C1.py new file mode 100644 index 00000000..97896546 --- /dev/null +++ b/TermTk/TTkWidgets/TTkTerminal/terminal_screen_C1.py @@ -0,0 +1,127 @@ + # 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. + +__all__ = [''] + +import collections +import unicodedata + +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 _TTkTerminalScreen_C1(): + # C1 (8-Bit) Control Characters + # + # The xterm program recognizes both 8-bit and 7-bit control characters. + # It generates 7-bit controls (by default) or 8-bit if S8C1T is enabled. + # The following pairs of 7-bit and 8-bit control characters are + # equivalent: + # + # ESC D + # Index (IND is 0x84). + # Move the cursor down and scroll at the edge + def _C1_D(self): + x,y = self._terminalCursor + t,b = self._scrollingRegion + h = self._h + if y < b-1: + self._terminalCursor = (x,y+1) + else: + self._CSI_S_SU(1) + + # ESC E + # Next Line (NEL is 0x85). + # + # ESC H + # Tab Set (HTS is 0x88). + # + # ESC M + # Reverse Index (RI is 0x8d). + # Move the cursor Up and scroll at the edge + def _C1_M(self): + x,y = self._terminalCursor + t,b = self._scrollingRegion + h = self._h + if y > t: + self._terminalCursor = (x,y-1) + else: + self._CSI_T_SD(1) + + # ESC N + # Single Shift Select of G2 Character Set (SS2 is 0x8e), VT220. + # This affects next character only. + # + # ESC O + # Single Shift Select of G3 Character Set (SS3 is 0x8f), VT220. + # This affects next character only. + # + # ESC P + # Device Control String (DCS is 0x90). + # + # ESC V + # Start of Guarded Area (SPA is 0x96). + # + # ESC W + # End of Guarded Area (EPA is 0x97). + # + # ESC X + # Start of String (SOS is 0x98). + # + # ESC Z + # Return Terminal ID (DECID is 0x9a). Obsolete form of CSI c (DA). + # + # ESC [ + # Control Sequence Introducer (CSI is 0x9b). + # + # ESC \ + # String Terminator (ST is 0x9c). + # + # ESC ] + # Operating System Command (OSC is 0x9d). + # + # ESC ^ + # Privacy Message (PM is 0x9e). + # + # ESC _ + # Application Program Command (APC is 0x9f). + # + # + # These control characters are used in the vtXXX emulation. + _C1_MAP = { + 'D' : _C1_D, + 'M' : _C1_M + } diff --git a/TermTk/TTkWidgets/TTkTerminal/terminal_alt.py b/TermTk/TTkWidgets/TTkTerminal/terminal_screen_CSI.py similarity index 93% rename from TermTk/TTkWidgets/TTkTerminal/terminal_alt.py rename to TermTk/TTkWidgets/TTkTerminal/terminal_screen_CSI.py index 9cbcaddb..59967634 100644 --- a/TermTk/TTkWidgets/TTkTerminal/terminal_alt.py +++ b/TermTk/TTkWidgets/TTkTerminal/terminal_screen_CSI.py @@ -20,6 +20,8 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. +__all__ = [''] + import collections import unicodedata @@ -41,149 +43,15 @@ from TermTk.TTkAbstract.abstractscrollarea import TTkAbstractScrollArea from TermTk.TTkAbstract.abstractscrollview import TTkAbstractScrollView, TTkAbstractScrollViewGridLayout from TermTk.TTkWidgets.widget import TTkWidget -class _TTkTerminalAltScreen(): - __slots__ = ('_lines', '_terminalCursor', - '_scrollingRegion', - '_bufferSize', '_bufferedLines', - '_w', '_h', '_color', '_canvas', - '_last', - # Signals - 'bell' - ) - def __init__(self, w=80, h=24, bufferSize=1000, color=TTkColor.RST) -> None: - self.bell = pyTTkSignal() - self._w = w - self._h = h - self._last = None - self._bufferSize = bufferSize - self._bufferedLines = collections.deque(maxlen=bufferSize) - self._terminalCursor = (0,0) - self._scrollingRegion = (0,h) - self._color = color - self._canvas = TTkCanvas(width=w, height=h) - - def color(self): - return self._color - - def setColor(self, color): - self._color = color - - def getCursor(self): - return self._terminalCursor - - def resize(self, w, h): - ow, oh = self._w, self._h - self._w, self._h = w, h - st,sb = self._scrollingRegion - # if oh <= h: # Terminal height decreasing - # sb = min(h,oh) - # else:# Terminal height increasing - # sb = h-oh+sb - # self._scrollingRegion = (st,sb) - self._scrollingRegion = (0,h) - newCanvas = TTkCanvas(width=w, height=h) - s = (0,0,w,h) - newCanvas.paintCanvas(self._canvas,s,s,s) - - self._canvas = newCanvas - x,y = self._terminalCursor - self._terminalCursor = (min(x,w-1),min(y,h-1)) - - def _pushTxt(self, txt:str, irm:bool=False): - x,y = self._terminalCursor - w,h = self._w, self._h - st,sb = self._scrollingRegion - self._last = txt[-1] if txt else None - - for bi, tout in enumerate(txt.split('\a')): # grab the bells - if bi: - self.bell.emit() - - # I check the size of each char in order to draw - # it in the correct position - for ch in tout: - if ord(ch) < 0x20: - # TTkLog.error(f"Unhandled ASCII: 0x{ord(ch):02x}") - continue - l = TTkString._getWidthText(ch) - # Scroll up if we are at the right border - if l+x > w: - x=0 - y+=1 - if y >= sb: - self._CSI_S_SU(y-sb+1, None) # scroll up - y=sb-1 - if l==1: # push normal char - if irm: - self._canvas._data[y][x:x] = [ch] - self._canvas._colors[y][x:x] = [self._color] - # self._canvas._data[y].insert(x,ch) - # self._canvas._colors[y].insert(x,self._color) - self._canvas._data[y].pop() - self._canvas._colors[y].pop() - else: - self._canvas._data[y][x] = ch - self._canvas._colors[y][x] = self._color - elif l > 1: # push wide char - if irm: - self._canvas._data[y][x:x] = [ch,''] - self._canvas._colors[y][x:x] = [self._color,self._color] - # self._canvas._data[y].insert(x,ch) - # self._canvas._colors[y].insert(x,self._color) - self._canvas._data[y].pop() - self._canvas._data[y].pop() - self._canvas._colors[y].pop() - self._canvas._colors[y].pop() - else: - self._canvas._data[y][x] = ch - self._canvas._data[y][x+1] = '' - self._canvas._colors[y][x] = self._color - self._canvas._colors[y][x+1] = self._color - else: # l==0 # push zero sized char - if x>0 and self._canvas._data[y][x-1] != '': - self._canvas._data[y][x-1] += ch - elif x>1: - self._canvas._data[y][x-2] += ch - x+=l - - self._terminalCursor = (x,y) - - def pushLine(self, line:str, irm:bool=False): - if not line: return - x,y = self._terminalCursor - w,h = self._w, self._h - st,sb = self._scrollingRegion - - lines = line.split('\n') - for i,l in enumerate(lines): - if i: - y+=1 - if y >= sb: - self._CSI_S_SU(y-sb+1, None) # scroll up - y=sb-1 - self._terminalCursor = (x,y) - ls = l.split('\r') - for ii,ll in enumerate(ls): - if ii: - self._terminalCursor = (x,y) = (0,y) - lls = ll.split('\b') # 0x08 = Backspace - for iii,lll in enumerate(lls): - if iii: - x,y = self._terminalCursor - x = max(0,x-1) - self._terminalCursor = (x,y) - self._pushTxt(lll,irm) - - def paintEvent(self, canvas: TTkCanvas, w:int, h:int, ox:int=0, oy:int=0) -> None: - w,h = self._w, self._h - s = (0,0,w,h) - canvas.paintCanvas(self._canvas,s,s,s) - # TTkLog.debug("Paint") - +class _TTkTerminalScreen_CSI(): # CSI Ps @ Insert Ps (Blank) Character(s) (default = 1) (ICH). def _CSI___ICH(self, ps, _): x,y = self._terminalCursor - self._canvas.drawText(' '*ps,pos=(x,y)) + w = self._w + self._canvas._data[y][x:x] = ['']*ps + self._canvas._colors[y][x:x] = [self._color]*ps + self._canvas._data[y] = self._canvas._data[y][:w] + self._canvas._colors[y] = self._canvas._colors[y][:w] # CSI Ps SP @ (SP = Space) # Shift left Ps columns(s) (default = 1) (SL), ECMA-48. @@ -367,7 +235,7 @@ class _TTkTerminalAltScreen(): # XTPOPCOLOR (default = 0) (XTREPORTCOLORS), xterm. # CSI Ps S Scroll up Ps lines (default = 1) (SU), VT420, ECMA-48. - def _CSI_S_SU(self, ps, _): + def _CSI_S_SU(self, ps, _=None): t,b = self._scrollingRegion w,h = self._w, self._h #TODO: Avoid this HACK @@ -450,7 +318,7 @@ class _TTkTerminalAltScreen(): # rather than a failure. # CSI Ps T Scroll down Ps lines (default = 1) (SD), VT420. - def _CSI_T_SD(self, ps, _): + def _CSI_T_SD(self, ps, _=None): t,b = self._scrollingRegion w,h = self._w, self._h #TODO: Avoid this HACK diff --git a/tests/timeit/16.dict.03.vs.link.py b/tests/timeit/16.dict.03.vs.link.py new file mode 100755 index 00000000..48ae1a2d --- /dev/null +++ b/tests/timeit/16.dict.03.vs.link.py @@ -0,0 +1,195 @@ +#!/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],'../..')) +from TermTk import TTkTermColor + +testInput = "abcdefghil£££ABCDEFG<£££>!#$()0123459zZ£££" + +testDict1 = { + '!' : lambda x: x*2, + '#' : lambda x: x*2, + '$' : lambda x: x*2, + + '0' : lambda x: x*2, + '1' : lambda x: x*2, + '2' : lambda x: x*2, + '3' : lambda x: x*2, + '4' : lambda x: x*2, + '9' : lambda x: x*2, + + 'A' : lambda x: x*2, + 'B' : lambda x: x*2, + 'C' : lambda x: x*2, + 'D' : lambda x: x*2, + 'E' : lambda x: x*2, + 'F' : lambda x: x*2, + 'G' : lambda x: x*2, + 'H' : lambda x: x*2, + 'I' : lambda x: x*2, + 'Z' : lambda x: x*2, + + 'a' : lambda x: x*2, + 'b' : lambda x: x*2, + 'c' : lambda x: x*2, + 'd' : lambda x: x*2, + 'e' : lambda x: x*2, + 'f' : lambda x: x*2, + 'g' : lambda x: x*2, + 'h' : lambda x: x*2, + 'i' : lambda x: x*2, + 'z' : lambda x: x*2, +} + +testArray1 = [ # Oct Dec Kex Char + lambda x : x*2 , # 041 33 21 ! + None , # 042 34 22 " + lambda x : x*2 , # 043 35 23 # + lambda x : x*2 , # 044 36 24 $ + None , # 045 37 25 % + None , # 046 38 26 & + None , # 047 39 27 ' + None , # 050 40 28 ( + None , # 051 41 29 ) + None , # 052 42 2A * + None , # 053 43 2B + + None , # 054 44 2C , + None , # 055 45 2D - + None , # 056 46 2E . + None , # 057 47 2F / + lambda x : x*2 , # 060 48 30 0 + lambda x : x*2 , # 061 49 31 1 + lambda x : x*2 , # 062 50 32 2 + lambda x : x*2 , # 063 51 33 3 + lambda x : x*2 , # 064 52 34 4 + None , # 065 53 35 5 + None , # 066 54 36 6 + None , # 067 55 37 7 + None , # 070 56 38 8 + lambda x : x*2 , # 071 57 39 9 + None , # 072 58 3A : + None , # 073 59 3B ; + None , # 074 60 3C < + None , # 075 61 3D = + None , # 076 62 3E > + None , # 077 63 3F ? + None , # 100 64 40 @ + lambda x : x*2 , # 101 65 41 A + lambda x : x*2 , # 102 66 42 B + lambda x : x*2 , # 103 67 43 C + lambda x : x*2 , # 104 68 44 D + lambda x : x*2 , # 105 69 45 E + lambda x : x*2 , # 106 70 46 F + lambda x : x*2 , # 107 71 47 G + lambda x : x*2 , # 110 72 48 H + lambda x : x*2 , # 111 73 49 I + None , # 112 74 4A J + None , # 113 75 4B K + None , # 114 76 4C L + None , # 115 77 4D M + None , # 116 78 4E N + None , # 117 79 4F O + None , # 120 80 50 P + None , # 121 81 51 Q + None , # 122 82 52 R + None , # 123 83 53 S + None , # 124 84 54 T + None , # 125 85 55 U + None , # 126 86 56 V + None , # 127 87 57 W + None , # 130 88 58 X + None , # 131 89 59 Y + lambda x : x*2 , # 132 90 5A Z + None , # 133 91 5B [ + None , # 134 92 5C \ '\\' + None , # 135 93 5D ] + None , # 136 94 5E ^ + None , # 137 95 5F _ + None , # 140 96 60 ` + lambda x : x*2 , # 141 97 61 a + lambda x : x*2 , # 142 98 62 b + lambda x : x*2 , # 143 99 63 c + lambda x : x*2 , # 144 100 64 d + lambda x : x*2 , # 145 101 65 e + lambda x : x*2 , # 146 102 66 f + lambda x : x*2 , # 147 103 67 g + lambda x : x*2 , # 150 104 68 h + lambda x : x*2 , # 151 105 69 i + None , # 152 106 6A j + None , # 153 107 6B k + None , # 154 108 6C l + None , # 155 109 6D m + None , # 156 110 6E n + None , # 157 111 6F o + None , # 160 112 70 p + None , # 161 113 71 q + None , # 162 114 72 r + None , # 163 115 73 s + None , # 164 116 74 t + None , # 165 117 75 u + None , # 166 118 76 v + None , # 167 119 77 w + None , # 170 120 78 x + None , # 171 121 79 y + lambda x : x*2 , # 172 122 7A z + lambda x : x*2 , # 173 123 7B { + lambda x : x*2 , # 174 124 7C | + lambda x : x*2 , # 175 125 7D } + lambda x : x*2 , # 176 126 7E ~ + lambda x : x*2 , # 177 127 7F DEL +] + + +def test1(ttt=testInput): + ret = 0 + for ch in ttt: + op = testDict1.get(ch,None) + if op: + ret += op(10) + return ret + +def test2(ttt=testInput): + ret = 0 + for ch in ttt: + if 33 <= (o:=ord(ch)) <= 127: + op = testArray1[o-33] + if op: + ret += op(10) + return ret + +loop = 150000 + +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/19.classes.01 inheritance.py b/tests/timeit/19.classes.01 inheritance.py new file mode 100755 index 00000000..33cf0d00 --- /dev/null +++ b/tests/timeit/19.classes.01 inheritance.py @@ -0,0 +1,103 @@ +#!/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],'../..')) + +testString1 = "1234567890ABCDEFGHI" + +class T1: + def a(self): return 1 + def b(self): return 2 + def c(self): return 3 + def d(self): return 4 + +def process1(txt): + t = T1() + return t.a() + t.b() + t.c() + t.d() + +class T2a: + def a(self): return 1 +class T2b(T2a): + def b(self): return 2 +class T2c(T2b): + def c(self): return 3 +class T2d(T2c): + def d(self): return 4 +class T2(T2d): pass + +def process2(txt): + t = T2() + return t.a() + t.b() + t.c() + t.d() + +class T3a: + def a(self): return 1 +class T3b: + def b(self): return 2 +class T3c: + def c(self): return 3 +class T3d: + def d(self): return 4 +class T3(T3a, T3b, T3c, T3d): pass + +def process3(txt): + t = T3() + return t.a() + t.b() + t.c() + t.d() + +t1 = T1() +t2 = T2() +t3 = T3() +def process4(t): return ( t.a() + t.b() + t.c() + t.d() + + t.a() + t.b() + t.c() + t.d() + + t.a() + t.b() + t.c() + t.d() + + t.a() + t.b() + t.c() + t.d() + + t.a() + t.b() + t.c() + t.d() + + t.a() + t.b() + t.c() + t.d() + + t.a() + t.b() + t.c() + t.d() + + t.a() + t.b() + t.c() + t.d() + + t.a() + t.b() + t.c() + t.d() + + t.a() + t.b() + t.c() + t.d() ) + + +def test1(): return process1(None) +def test2(): return process2(None) +def test3(): return process3(None) +def test4(): return process4(t1) +def test5(): return process4(t2) +def test6(): return process4(t3) + +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 +