Dart
Dart
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 Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
// 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.
final ssh = CkSsh();
final sshPort = 22;
try {
ssh.connect('ssh.example.com', sshPort);
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
// 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.
final password = 'mySshPassword';
try {
ssh.authenticatePw('mySshLogin', password);
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
// Open a session channel. A negative return value indicates failure.
final channelNum = ssh.openSessionChannel();
if (channelNum < 0) {
print(ssh.lastErrorText);
return;
}
// Allocate a PTY and start a shell.
try {
ssh.sendReqPty(channelNum, 'xterm', 80, 24, 0, 0);
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
try {
ssh.sendReqShell(channelNum);
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
// The user resized the terminal window -- tell the server the new dimensions.
final newWidthInChars = 132;
final newHeightInRows = 43;
final pixWidth = 0;
final pixHeight = 0;
try {
ssh.sendReqWindowChange(channelNum, newWidthInChars, newHeightInRows, pixWidth, pixHeight);
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
print('Window change sent.');
ssh.disconnect();
}