Tcl
Tcl
Notify the SSH Server of a Terminal Resize
See more SSH Examples
Demonstrates the Chilkat Ssh.SendReqWindowChange method, which tells the server that the terminal dimensions changed. The arguments are the channel number, the new character width and height, and the pixel width and height. It may be sent any time after the PTY is allocated.
Background: When a user resizes a terminal window, full-screen remote programs such as
vi, top, or less need to know the new size or they will keep drawing at the old dimensions. This request delivers that update, causing the server to signal the remote process (SIGWINCH on Unix) so it can redraw correctly.Chilkat Tcl Downloads
load ./chilkat.dll
set success 0
# Demonstrates the Ssh.SendReqWindowChange method, which notifies the server that the terminal
# dimensions changed. The 1st argument is the channel number, the 2nd and 3rd are the new
# character width and height, and the 4th and 5th are the pixel width and height.
set ssh [new_CkSsh]
set sshPort 22
set success [CkSsh_Connect $ssh "ssh.example.com" $sshPort]
if {$success == 0} then {
puts [CkSsh_lastErrorText $ssh]
delete_CkSsh $ssh
exit
}
# Normally you would not hard-code the password in source. You should instead obtain it
# from an interactive prompt, environment variable, or a secrets vault.
set password "mySshPassword"
set success [CkSsh_AuthenticatePw $ssh "mySshLogin" $password]
if {$success == 0} then {
puts [CkSsh_lastErrorText $ssh]
delete_CkSsh $ssh
exit
}
# Open a session channel. A negative return value indicates failure.
set channelNum [CkSsh_OpenSessionChannel $ssh]
if {$channelNum < 0} then {
puts [CkSsh_lastErrorText $ssh]
delete_CkSsh $ssh
exit
}
# Allocate a PTY and start a shell.
set success [CkSsh_SendReqPty $ssh $channelNum "xterm" 80 24 0 0]
if {$success == 0} then {
puts [CkSsh_lastErrorText $ssh]
delete_CkSsh $ssh
exit
}
set success [CkSsh_SendReqShell $ssh $channelNum]
if {$success == 0} then {
puts [CkSsh_lastErrorText $ssh]
delete_CkSsh $ssh
exit
}
# The user resized the terminal window -- tell the server the new dimensions.
set newWidthInChars 132
set newHeightInRows 43
set pixWidth 0
set pixHeight 0
set success [CkSsh_SendReqWindowChange $ssh $channelNum $newWidthInChars $newHeightInRows $pixWidth $pixHeight]
if {$success == 0} then {
puts [CkSsh_lastErrorText $ssh]
delete_CkSsh $ssh
exit
}
puts "Window change sent."
CkSsh_Disconnect $ssh
delete_CkSsh $ssh