Skip to content

Re-introduce ChangeWindow method on ShellStream #1646

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions src/Renci.SshNet/Channels/ChannelSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,26 +239,18 @@ public bool SendSubsystemRequest(string subsystem)
/// <param name="rows">The rows.</param>
/// <param name="width">The width.</param>
/// <param name="height">The height.</param>
/// <returns>
/// <see langword="true"/> if request was successful; otherwise <see langword="false"/>.
/// </returns>
public bool SendWindowChangeRequest(uint columns, uint rows, uint width, uint height)
public void SendWindowChangeRequest(uint columns, uint rows, uint width, uint height)
{
SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new WindowChangeRequestInfo(columns, rows, width, height)));
return true;
}

/// <summary>
/// Sends the local flow request.
/// </summary>
/// <param name="clientCanDo">if set to <see langword="true"/> [client can do].</param>
/// <returns>
/// <see langword="true"/> if request was successful; otherwise <see langword="false"/>.
/// </returns>
public bool SendLocalFlowRequest(bool clientCanDo)
public void SendLocalFlowRequest(bool clientCanDo)
{
SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new XonXoffRequestInfo(clientCanDo)));
return true;
}

/// <summary>
Expand Down
10 changes: 2 additions & 8 deletions src/Renci.SshNet/Channels/IChannelSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,13 @@ bool SendPseudoTerminalRequest(string environmentVariable,
/// <param name="rows">The rows.</param>
/// <param name="width">The width.</param>
/// <param name="height">The height.</param>
/// <returns>
/// <see langword="true"/> if request was successful; otherwise <see langword="false"/>.
/// </returns>
bool SendWindowChangeRequest(uint columns, uint rows, uint width, uint height);
void SendWindowChangeRequest(uint columns, uint rows, uint width, uint height);

/// <summary>
/// Sends the local flow request.
/// </summary>
/// <param name="clientCanDo">if set to <see langword="true"/> [client can do].</param>
/// <returns>
/// <see langword="true"/> if request was successful; otherwise <see langword="false"/>.
/// </returns>
bool SendLocalFlowRequest(bool clientCanDo);
void SendLocalFlowRequest(bool clientCanDo);

/// <summary>
/// Sends the signal request.
Expand Down
2 changes: 1 addition & 1 deletion src/Renci.SshNet/IServiceFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ internal partial interface IServiceFactory
/// <param name="session">The SSH session.</param>
/// <param name="terminalName">The <c>TERM</c> environment variable.</param>
/// <param name="columns">The terminal width in columns.</param>
/// <param name="rows">The terminal width in rows.</param>
/// <param name="rows">The terminal height in rows.</param>
/// <param name="width">The terminal width in pixels.</param>
/// <param name="height">The terminal height in pixels.</param>
/// <param name="terminalModeValues">The terminal mode values.</param>
Expand Down
8 changes: 4 additions & 4 deletions src/Renci.SshNet/ISshClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public interface ISshClient : IBaseClient
/// </summary>
/// <param name="terminalName">The <c>TERM</c> environment variable.</param>
/// <param name="columns">The terminal width in columns.</param>
/// <param name="rows">The terminal width in rows.</param>
/// <param name="rows">The terminal height in rows.</param>
/// <param name="width">The terminal width in pixels.</param>
/// <param name="height">The terminal height in pixels.</param>
/// <param name="bufferSize">The size of the buffer.</param>
Expand All @@ -200,7 +200,7 @@ public interface ISshClient : IBaseClient
/// You can get a detailed list of these capabilities by using the ‘infocmp’ command.
/// </para>
/// <para>
/// The column/row dimensions override the pixel dimensions(when nonzero). Pixel dimensions refer
/// The column/row dimensions override the pixel dimensions (when nonzero). Pixel dimensions refer
/// to the drawable area of the window.
/// </para>
/// </remarks>
Expand All @@ -211,7 +211,7 @@ public interface ISshClient : IBaseClient
/// </summary>
/// <param name="terminalName">The <c>TERM</c> environment variable.</param>
/// <param name="columns">The terminal width in columns.</param>
/// <param name="rows">The terminal width in rows.</param>
/// <param name="rows">The terminal height in rows.</param>
/// <param name="width">The terminal width in pixels.</param>
/// <param name="height">The terminal height in pixels.</param>
/// <param name="bufferSize">The size of the buffer.</param>
Expand All @@ -226,7 +226,7 @@ public interface ISshClient : IBaseClient
/// You can get a detailed list of these capabilities by using the ‘infocmp’ command.
/// </para>
/// <para>
/// The column/row dimensions override the pixel dimensions(when non-zero). Pixel dimensions refer
/// The column/row dimensions override the pixel dimensions (when non-zero). Pixel dimensions refer
/// to the drawable area of the window.
/// </para>
/// </remarks>
Expand Down
26 changes: 1 addition & 25 deletions src/Renci.SshNet/ServiceFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,31 +177,7 @@ public ISftpResponseFactory CreateSftpResponseFactory()
return new SftpResponseFactory();
}

/// <summary>
/// Creates a shell stream.
/// </summary>
/// <param name="session">The SSH session.</param>
/// <param name="terminalName">The <c>TERM</c> environment variable.</param>
/// <param name="columns">The terminal width in columns.</param>
/// <param name="rows">The terminal width in rows.</param>
/// <param name="width">The terminal width in pixels.</param>
/// <param name="height">The terminal height in pixels.</param>
/// <param name="terminalModeValues">The terminal mode values.</param>
/// <param name="bufferSize">The size of the buffer.</param>
/// <returns>
/// The created <see cref="ShellStream"/> instance.
/// </returns>
/// <exception cref="SshConnectionException">Client is not connected.</exception>
/// <remarks>
/// <para>
/// The <c>TERM</c> environment variable contains an identifier for the text window's capabilities.
/// You can get a detailed list of these capabilities by using the ‘infocmp’ command.
/// </para>
/// <para>
/// The column/row dimensions override the pixel dimensions(when non-zero). Pixel dimensions refer
/// to the drawable area of the window.
/// </para>
/// </remarks>
/// <inheritdoc/>
public ShellStream CreateShellStream(ISession session, string terminalName, uint columns, uint rows, uint width, uint height, IDictionary<TerminalModes, uint> terminalModeValues, int bufferSize)
{
return new ShellStream(session, terminalName, columns, rows, width, height, terminalModeValues, bufferSize);
Expand Down
19 changes: 19 additions & 0 deletions src/Renci.SshNet/ShellStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,25 @@ public override void SetLength(long value)
throw new NotSupportedException();
}

/// <summary>
/// Sends new dimensions of the window (terminal) to the server.
/// </summary>
/// <param name="columns">The terminal width in columns.</param>
/// <param name="rows">The terminal height in rows.</param>
/// <param name="width">The terminal width in pixels.</param>
/// <param name="height">The terminal height in pixels.</param>
/// <remarks>
/// The column/row dimensions override the pixel dimensions (when nonzero). Pixel dimensions refer
/// to the drawable area of the window.
/// </remarks>
/// <exception cref="ObjectDisposedException">The stream is closed.</exception>
public void ChangeWindowSize(uint columns, uint rows, uint width, uint height)
{
ThrowHelper.ThrowObjectDisposedIf(_disposed, this);

_channel.SendWindowChangeRequest(columns, rows, width, height);
}

/// <summary>
/// Expects the specified expression and performs action when one is found.
/// </summary>
Expand Down
24 changes: 24 additions & 0 deletions test/Renci.SshNet.Tests/Classes/ShellStreamTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,30 @@ public void Write_AfterDispose_ThrowsObjectDisposedException()
Assert.ThrowsException<ObjectDisposedException>(() => shellStream.Write(bytes, 0, bytes.Length));
}

[TestMethod]
public void ChangeWindowSize_AfterDispose_ThrowsObjectDisposedException()
{
var shellStream = CreateShellStream();

_channelSessionMock.Setup(p => p.Dispose());

shellStream.Dispose();

Assert.ThrowsException<ObjectDisposedException>(() => shellStream.ChangeWindowSize(80, 25, 0, 0));
}

[TestMethod]
public void ChangeWindowSize_SendsWindowChangeRequest()
{
var shellStream = CreateShellStream();

_channelSessionMock.Setup(s => s.SendWindowChangeRequest(80, 25, 0, 1));

shellStream.ChangeWindowSize(80, 25, 0, 1);

_channelSessionMock.Verify(v => v.SendWindowChangeRequest(80, 25, 0, 1), Times.Once());
}

private ShellStream CreateShellStream()
{
_sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,13 +426,13 @@ public void Open()

public bool SendKeepAliveRequest() => throw new NotImplementedException();

public bool SendLocalFlowRequest(bool clientCanDo) => throw new NotImplementedException();
public void SendLocalFlowRequest(bool clientCanDo) => throw new NotImplementedException();

public bool SendSignalRequest(string signalName) => throw new NotImplementedException();

public bool SendSubsystemRequest(string subsystem) => throw new NotImplementedException();

public bool SendWindowChangeRequest(uint columns, uint rows, uint width, uint height) => throw new NotImplementedException();
public void SendWindowChangeRequest(uint columns, uint rows, uint width, uint height) => throw new NotImplementedException();

public bool SendX11ForwardingRequest(bool isSingleConnection, string protocol, byte[] cookie, uint screenNumber) => throw new NotImplementedException();
#pragma warning restore IDE0022 // Use block body for method
Expand Down