LinuxTerminal
For conceptual usage, see:
- class pyrogue.pydm.widgets.TerminalPanel(parent=None, *, argv=None, label='Terminal', windowTitle='Rogue Terminal', noun='terminal')[source]
A
LinuxTerminalwith a button to detach it into its own window.Detaching is useful because a tab is only as tall as the window it lives in. A separate window can be sized and placed independently, or moved to another monitor, which makes a long build log or a full screen program readable.
Reparenting does not disturb the shell. The child process is held by a file descriptor and a socket notifier, neither of which is tied to a window, so detaching and reattaching keep the same shell, its working directory, and its scrollback.
- Parameters:
parent (
QWidget|None, default:None) – Parent Qt widget.argv (
list[str] |None, default:None) – Program to run, passed through toLinuxTerminal. Defaults to the user’s login shell.label (
str, default:'Terminal') – Tab label to restore when reattaching.windowTitle (
str, default:'Rogue Terminal') – Title of the detached window.noun (
str, default:'terminal') – What the detach button tooltips call the contents.
- class pyrogue.pydm.widgets.LinuxTerminal(parent=None, *, argv=None)[source]
Interactive local shell rendered into a read-only text view.
A shell is spawned on a pseudo-terminal, its output is fed to a
pytescreen emulator, and that screen is painted into this widget.The shell is a child of the GUI process, so it runs on the machine displaying the GUI as the user who launched it, not on the Rogue server. Anyone who can reach the GUI window gets an interactive shell with that user’s privileges, which is why the feature is opt-in.
The shell starts on first display rather than on construction, so enabling the feature costs nothing until the tab is actually opened.
The view is dark themed and keeps a bounded scrollback above the live screen, so output can be scrolled back through. Scrolling up pins the view in place; new output only follows the bottom when the view is already there.
Rendering is monochrome.
pytedoes not implement the alternate screen buffer, so full screen programs such asvimandhtopwork but leave their last frame behind on exit instead of restoring the previous screen.- Parameters:
- inputMethodEvent(event)[source]
Swallow input method events; composition is not supported.
- Return type:
- keyPressEvent(event)[source]
Forward key presses to the shell instead of editing the view.
- Return type:
- restart()[source]
Discard the current session and start a fresh shell.
Returns the terminal to the state it had when the GUI was opened: an empty screen, no scrollback, and a new prompt.
- Return type:
- sendInput(data)[source]
Send user input to the shell.
Separate from
writeBytes()because the emulator also writes to the pty on its own to answer terminal queries. Only real input shows that the session reached a usable state, which is what distinguishes a user exiting a shell from a shell that never started.
- showEvent(event)[source]
Spawn the shell on first display and take the keyboard.
Clicking a tab in a
QTabWidgetleaves the keyboard focus on the tab bar, so without this the terminal would appear ready but swallow nothing until it was clicked a second time.- Return type:
- pyrogue.pydm.widgets.terminal.keyToBytes(key, modifiers, text)[source]
Translate a Qt key press into the byte sequence a terminal expects.
Kept free of
QKeyEventso it can be unit tested without constructing aQApplication. The sequences follow thextermconventions, matching theTERMvalue exported to the child shell. Changing one requires changing the other.- Parameters:
- Returns:
Bytes to write to the pty, or
b''when the key produces no input.- Return type:
Notes
Ctrl-C has to reach the shell as
ETXso it can interrupt the foreground job, so copy and paste are bound to Ctrl+Shift+C and Ctrl+Shift+V. Those two chords returnb''here and are handled as clipboard actions by the widget.
- pyrogue.pydm.widgets.terminal.resolveColor(value, bright=False)[source]
Map a
pytecolor to aQColor.- Parameters:
value (
str) – Colour as pyte reports it:'default', one of the eight base names, abright-prefixed name, or six hex digits for 256 colour and 24 bit.bright (
bool, default:False) – Select the bright shade of a base name. Bold text is rendered in the bright shade, which is the convention every colorizing tool assumes.
- Returns:
Nonewhen the value is the default or is not recognised, so the caller can fall back to the theme colour. pyte’s own tables contain at least one misspelled name, so unrecognised input has to be tolerated.- Return type:
QColor|None