ztk::terminal
Makes a terminal widget: a screen of cells on libghostty-vt that shows text from a script, the shell of ztcl, or a program on a pseudo terminal.
Synopsis
ztk::terminal PATHNAME ?OPTION VALUE ...?
PATHNAME write DATA
PATHNAME send DATA
PATHNAME paste TEXT
PATHNAME copy
PATHNAME get ?FIRST? ?LAST?
PATHNAME size
PATHNAME cursor
PATHNAME title
PATHNAME selection get|clear
PATHNAME selection range LINE COL LINE COL
PATHNAME yview ?moveto FRACTION? ?scroll NUMBER units|pages?
PATHNAME channel
PATHNAME status
PATHNAME kill ?SIGNAL?
PATHNAME cget OPTION
PATHNAME configure ?OPTION VALUE ...?
Arguments
| Name |
Type |
Default |
Meaning |
-width |
integer |
80 |
The count of columns. |
-height |
integer |
24 |
The count of rows. |
-font |
font |
TkFixedFont |
The font of the cells. |
-scrollback |
integer |
10000 |
The count of lines above the screen that the view can scroll to. |
-shell |
boolean |
0 |
1 runs the shell of ztcl in the interpreter of the widget, with no program. |
-command |
list |
empty |
A program and its arguments to run on a pseudo terminal with ztcl::pty spawn. It needs the capability exec. |
-cwd |
folder |
empty |
The working folder of the program of -command. |
-exitcommand |
script |
empty |
Runs when the program ends, with the status of ztcl::pty status appended. |
-inputcommand |
script |
empty |
With no program and no shell, gets the keys and the replies of the terminal, with the bytes appended. |
-background, -foreground |
color |
from the theme |
The default colors of the cells. |
-borderwidth, -relief, -cursor, -takefocus |
|
0, flat, xterm, 1 |
As for other widgets. |
write DATA |
subcommand |
|
Puts text and escape sequences on the screen. |
send DATA |
subcommand |
|
Sends bytes to the program, the shell, or -inputcommand. |
paste TEXT |
subcommand |
|
Sends the text as a paste, with the bracketed paste mode when the program asks for it. |
copy |
subcommand |
|
Puts the selection on the clipboard. |
get ?FIRST? ?LAST? |
subcommand |
all rows of the screen |
Gives the text of lines. 0 is the first row of the screen, and a negative index is a line of the scrollback. One index gives one line. |
size |
subcommand |
|
Gives {COLUMNS ROWS}. |
cursor |
subcommand |
|
Gives {COLUMN ROW} of the cursor, from 0. |
title |
subcommand |
|
Gives the title that the program set. |
selection |
subcommand |
|
get gives the selected text, clear removes the selection, and range selects from one line and column to another, with the lines of get. |
yview |
subcommand |
|
With no argument, gives the top and the bottom of the view as fractions. moveto and scroll move the view, as for a text widget. |
channel |
subcommand |
|
Gives the channel of the pseudo terminal, or an empty string. |
status |
subcommand |
|
Gives none with no program, or the result of ztcl::pty status. |
kill ?SIGNAL? |
subcommand |
|
Stops the program with ztcl::pty kill. With no program it has no effect. |
Return value
ztk::terminal gives PATHNAME. Each subcommand gives the value in the table, or an empty string.
Errors
| Error |
When |
unknown option "-X" |
An unknown option. |
invalid command name "ztcl::pty" |
-command in an interpreter with no capability exec, such as the ztk program. |
ztk::terminal -command is not available on this platform |
-command on a platform with no pseudo terminal. |
ztk::terminal: -shell and -command cannot run together |
-shell 1 while a program runs. |
bad selection option "X": must be clear, get, or range |
An unknown word after selection. |
wrong # args: should be "PATHNAME write data" |
A subcommand with the wrong count of words. Each subcommand has its own message. |
bad option "X": must be cget, configure, channel, copy, cursor, get, kill, paste, selection, send, size, status, title, write, or yview |
An unknown subcommand. |
| Platform |
Works |
| Windows |
-shell and write. -command gives not available on this platform. |
| macOS |
Yes. -command needs exec of the embedder. |
| Linux, Wayland |
Yes. -command needs exec of the embedder. |
| Linux, X11 |
Yes. -command needs exec of the embedder. |
| Web |
-shell and write. A WebAssembly app of ztk::wasm::run has no ztk::terminal. |
| iOS, Android |
-shell and write. |
| Headless |
Yes |
Example
ztk::terminal .t -width 40 -height 6
pack .t -fill both -expand 1
.t write "\x1b\[1;32mready\x1b\[0m\r\n"
.t get 0
See also