Skip to content

Commit 4fcf604

Browse files
Rasmus715etozherasmusRob-Hagueglenkleidon294797392
authored
Re-introduce ChangeWindow method on ShellStream (#1646)
* Re-introduce ChangeWindow method on ShellStream * Fix pipeline build * Fix pipeline build * tweaks Co-authored-by: Glen Kleidon <glenk@galkam.com.au> Co-authored-by: oheiheiheiheihei <294797392@qq.com> --------- Co-authored-by: Ivan Zaitsev <crackbargains@gmail.com> Co-authored-by: Robert Hague <rh@johnstreetcapital.com> Co-authored-by: Glen Kleidon <glenk@galkam.com.au> Co-authored-by: oheiheiheiheihei <294797392@qq.com>
1 parent f24a5d6 commit 4fcf604

File tree

8 files changed

+55
-50
lines changed

8 files changed

+55
-50
lines changed

src/Renci.SshNet/Channels/ChannelSession.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -239,26 +239,18 @@ public bool SendSubsystemRequest(string subsystem)
239239
/// <param name="rows">The rows.</param>
240240
/// <param name="width">The width.</param>
241241
/// <param name="height">The height.</param>
242-
/// <returns>
243-
/// <see langword="true"/> if request was successful; otherwise <see langword="false"/>.
244-
/// </returns>
245-
public bool SendWindowChangeRequest(uint columns, uint rows, uint width, uint height)
242+
public void SendWindowChangeRequest(uint columns, uint rows, uint width, uint height)
246243
{
247244
SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new WindowChangeRequestInfo(columns, rows, width, height)));
248-
return true;
249245
}
250246

251247
/// <summary>
252248
/// Sends the local flow request.
253249
/// </summary>
254250
/// <param name="clientCanDo">if set to <see langword="true"/> [client can do].</param>
255-
/// <returns>
256-
/// <see langword="true"/> if request was successful; otherwise <see langword="false"/>.
257-
/// </returns>
258-
public bool SendLocalFlowRequest(bool clientCanDo)
251+
public void SendLocalFlowRequest(bool clientCanDo)
259252
{
260253
SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new XonXoffRequestInfo(clientCanDo)));
261-
return true;
262254
}
263255

264256
/// <summary>

src/Renci.SshNet/Channels/IChannelSession.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,13 @@ bool SendPseudoTerminalRequest(string environmentVariable,
9797
/// <param name="rows">The rows.</param>
9898
/// <param name="width">The width.</param>
9999
/// <param name="height">The height.</param>
100-
/// <returns>
101-
/// <see langword="true"/> if request was successful; otherwise <see langword="false"/>.
102-
/// </returns>
103-
bool SendWindowChangeRequest(uint columns, uint rows, uint width, uint height);
100+
void SendWindowChangeRequest(uint columns, uint rows, uint width, uint height);
104101

105102
/// <summary>
106103
/// Sends the local flow request.
107104
/// </summary>
108105
/// <param name="clientCanDo">if set to <see langword="true"/> [client can do].</param>
109-
/// <returns>
110-
/// <see langword="true"/> if request was successful; otherwise <see langword="false"/>.
111-
/// </returns>
112-
bool SendLocalFlowRequest(bool clientCanDo);
106+
void SendLocalFlowRequest(bool clientCanDo);
113107

114108
/// <summary>
115109
/// Sends the signal request.

src/Renci.SshNet/IServiceFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ internal partial interface IServiceFactory
109109
/// <param name="session">The SSH session.</param>
110110
/// <param name="terminalName">The <c>TERM</c> environment variable.</param>
111111
/// <param name="columns">The terminal width in columns.</param>
112-
/// <param name="rows">The terminal width in rows.</param>
112+
/// <param name="rows">The terminal height in rows.</param>
113113
/// <param name="width">The terminal width in pixels.</param>
114114
/// <param name="height">The terminal height in pixels.</param>
115115
/// <param name="terminalModeValues">The terminal mode values.</param>

src/Renci.SshNet/ISshClient.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public interface ISshClient : IBaseClient
186186
/// </summary>
187187
/// <param name="terminalName">The <c>TERM</c> environment variable.</param>
188188
/// <param name="columns">The terminal width in columns.</param>
189-
/// <param name="rows">The terminal width in rows.</param>
189+
/// <param name="rows">The terminal height in rows.</param>
190190
/// <param name="width">The terminal width in pixels.</param>
191191
/// <param name="height">The terminal height in pixels.</param>
192192
/// <param name="bufferSize">The size of the buffer.</param>
@@ -200,7 +200,7 @@ public interface ISshClient : IBaseClient
200200
/// You can get a detailed list of these capabilities by using the ‘infocmp’ command.
201201
/// </para>
202202
/// <para>
203-
/// The column/row dimensions override the pixel dimensions(when nonzero). Pixel dimensions refer
203+
/// The column/row dimensions override the pixel dimensions (when nonzero). Pixel dimensions refer
204204
/// to the drawable area of the window.
205205
/// </para>
206206
/// </remarks>
@@ -211,7 +211,7 @@ public interface ISshClient : IBaseClient
211211
/// </summary>
212212
/// <param name="terminalName">The <c>TERM</c> environment variable.</param>
213213
/// <param name="columns">The terminal width in columns.</param>
214-
/// <param name="rows">The terminal width in rows.</param>
214+
/// <param name="rows">The terminal height in rows.</param>
215215
/// <param name="width">The terminal width in pixels.</param>
216216
/// <param name="height">The terminal height in pixels.</param>
217217
/// <param name="bufferSize">The size of the buffer.</param>
@@ -226,7 +226,7 @@ public interface ISshClient : IBaseClient
226226
/// You can get a detailed list of these capabilities by using the ‘infocmp’ command.
227227
/// </para>
228228
/// <para>
229-
/// The column/row dimensions override the pixel dimensions(when non-zero). Pixel dimensions refer
229+
/// The column/row dimensions override the pixel dimensions (when non-zero). Pixel dimensions refer
230230
/// to the drawable area of the window.
231231
/// </para>
232232
/// </remarks>

src/Renci.SshNet/ServiceFactory.cs

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -177,31 +177,7 @@ public ISftpResponseFactory CreateSftpResponseFactory()
177177
return new SftpResponseFactory();
178178
}
179179

180-
/// <summary>
181-
/// Creates a shell stream.
182-
/// </summary>
183-
/// <param name="session">The SSH session.</param>
184-
/// <param name="terminalName">The <c>TERM</c> environment variable.</param>
185-
/// <param name="columns">The terminal width in columns.</param>
186-
/// <param name="rows">The terminal width in rows.</param>
187-
/// <param name="width">The terminal width in pixels.</param>
188-
/// <param name="height">The terminal height in pixels.</param>
189-
/// <param name="terminalModeValues">The terminal mode values.</param>
190-
/// <param name="bufferSize">The size of the buffer.</param>
191-
/// <returns>
192-
/// The created <see cref="ShellStream"/> instance.
193-
/// </returns>
194-
/// <exception cref="SshConnectionException">Client is not connected.</exception>
195-
/// <remarks>
196-
/// <para>
197-
/// The <c>TERM</c> environment variable contains an identifier for the text window's capabilities.
198-
/// You can get a detailed list of these capabilities by using the ‘infocmp’ command.
199-
/// </para>
200-
/// <para>
201-
/// The column/row dimensions override the pixel dimensions(when non-zero). Pixel dimensions refer
202-
/// to the drawable area of the window.
203-
/// </para>
204-
/// </remarks>
180+
/// <inheritdoc/>
205181
public ShellStream CreateShellStream(ISession session, string terminalName, uint columns, uint rows, uint width, uint height, IDictionary<TerminalModes, uint> terminalModeValues, int bufferSize)
206182
{
207183
return new ShellStream(session, terminalName, columns, rows, width, height, terminalModeValues, bufferSize);

src/Renci.SshNet/ShellStream.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,25 @@ public override void SetLength(long value)
281281
throw new NotSupportedException();
282282
}
283283

284+
/// <summary>
285+
/// Sends new dimensions of the window (terminal) to the server.
286+
/// </summary>
287+
/// <param name="columns">The terminal width in columns.</param>
288+
/// <param name="rows">The terminal height in rows.</param>
289+
/// <param name="width">The terminal width in pixels.</param>
290+
/// <param name="height">The terminal height in pixels.</param>
291+
/// <remarks>
292+
/// The column/row dimensions override the pixel dimensions (when nonzero). Pixel dimensions refer
293+
/// to the drawable area of the window.
294+
/// </remarks>
295+
/// <exception cref="ObjectDisposedException">The stream is closed.</exception>
296+
public void ChangeWindowSize(uint columns, uint rows, uint width, uint height)
297+
{
298+
ThrowHelper.ThrowObjectDisposedIf(_disposed, this);
299+
300+
_channel.SendWindowChangeRequest(columns, rows, width, height);
301+
}
302+
284303
/// <summary>
285304
/// Expects the specified expression and performs action when one is found.
286305
/// </summary>

test/Renci.SshNet.Tests/Classes/ShellStreamTest.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,30 @@ public void Write_AfterDispose_ThrowsObjectDisposedException()
123123
Assert.ThrowsException<ObjectDisposedException>(() => shellStream.Write(bytes, 0, bytes.Length));
124124
}
125125

126+
[TestMethod]
127+
public void ChangeWindowSize_AfterDispose_ThrowsObjectDisposedException()
128+
{
129+
var shellStream = CreateShellStream();
130+
131+
_channelSessionMock.Setup(p => p.Dispose());
132+
133+
shellStream.Dispose();
134+
135+
Assert.ThrowsException<ObjectDisposedException>(() => shellStream.ChangeWindowSize(80, 25, 0, 0));
136+
}
137+
138+
[TestMethod]
139+
public void ChangeWindowSize_SendsWindowChangeRequest()
140+
{
141+
var shellStream = CreateShellStream();
142+
143+
_channelSessionMock.Setup(s => s.SendWindowChangeRequest(80, 25, 0, 1));
144+
145+
shellStream.ChangeWindowSize(80, 25, 0, 1);
146+
147+
_channelSessionMock.Verify(v => v.SendWindowChangeRequest(80, 25, 0, 1), Times.Once());
148+
}
149+
126150
private ShellStream CreateShellStream()
127151
{
128152
_sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object);

test/Renci.SshNet.Tests/Classes/ShellStreamTest_ReadExpect.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,13 +426,13 @@ public void Open()
426426

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

429-
public bool SendLocalFlowRequest(bool clientCanDo) => throw new NotImplementedException();
429+
public void SendLocalFlowRequest(bool clientCanDo) => throw new NotImplementedException();
430430

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

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

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

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

0 commit comments

Comments
 (0)