| | | 1 | | using System.Collections.Generic; |
| | | 2 | | |
| | | 3 | | using Renci.SshNet.Common; |
| | | 4 | | |
| | | 5 | | namespace Renci.SshNet.Messages.Connection |
| | | 6 | | { |
| | | 7 | | /// <summary> |
| | | 8 | | /// Represents "pty-req" type channel request information. |
| | | 9 | | /// </summary> |
| | | 10 | | internal sealed class PseudoTerminalRequestInfo : RequestInfo |
| | | 11 | | { |
| | | 12 | | /// <summary> |
| | | 13 | | /// Channel request name. |
| | | 14 | | /// </summary> |
| | | 15 | | public const string Name = "pty-req"; |
| | | 16 | | |
| | | 17 | | /// <summary> |
| | | 18 | | /// Gets the name of the request. |
| | | 19 | | /// </summary> |
| | | 20 | | /// <value> |
| | | 21 | | /// The name of the request. |
| | | 22 | | /// </value> |
| | | 23 | | public override string RequestName |
| | | 24 | | { |
| | 39 | 25 | | get { return Name; } |
| | | 26 | | } |
| | | 27 | | |
| | | 28 | | /// <summary> |
| | | 29 | | /// Gets or sets the value of the TERM environment variable (e.g., vt100). |
| | | 30 | | /// </summary> |
| | | 31 | | /// <value> |
| | | 32 | | /// The value of the TERM environment variable. |
| | | 33 | | /// </value> |
| | 41 | 34 | | public string EnvironmentVariable { get; set; } |
| | | 35 | | |
| | | 36 | | /// <summary> |
| | | 37 | | /// Gets or sets the terminal width in columns (e.g., 80). |
| | | 38 | | /// </summary> |
| | | 39 | | /// <value> |
| | | 40 | | /// The terminal width in columns. |
| | | 41 | | /// </value> |
| | 41 | 42 | | public uint Columns { get; set; } |
| | | 43 | | |
| | | 44 | | /// <summary> |
| | | 45 | | /// Gets or sets the terminal width in rows (e.g., 24). |
| | | 46 | | /// </summary> |
| | | 47 | | /// <value> |
| | | 48 | | /// The terminal width in rows. |
| | | 49 | | /// </value> |
| | 41 | 50 | | public uint Rows { get; set; } |
| | | 51 | | |
| | | 52 | | /// <summary> |
| | | 53 | | /// Gets or sets the terminal width in pixels (e.g., 640). |
| | | 54 | | /// </summary> |
| | | 55 | | /// <value> |
| | | 56 | | /// The terminal width in pixels. |
| | | 57 | | /// </value> |
| | 41 | 58 | | public uint PixelWidth { get; set; } |
| | | 59 | | |
| | | 60 | | /// <summary> |
| | | 61 | | /// Gets or sets the terminal height in pixels (e.g., 480). |
| | | 62 | | /// </summary> |
| | | 63 | | /// <value> |
| | | 64 | | /// The terminal height in pixels. |
| | | 65 | | /// </value> |
| | 41 | 66 | | public uint PixelHeight { get; set; } |
| | | 67 | | |
| | | 68 | | /// <summary> |
| | | 69 | | /// Gets or sets the terminal mode. |
| | | 70 | | /// </summary> |
| | | 71 | | /// <value> |
| | | 72 | | /// The terminal mode. |
| | | 73 | | /// </value> |
| | 56 | 74 | | public IDictionary<TerminalModes, uint> TerminalModeValues { get; set; } |
| | | 75 | | |
| | | 76 | | /// <summary> |
| | | 77 | | /// Gets the size of the message in bytes. |
| | | 78 | | /// </summary> |
| | | 79 | | /// <value> |
| | | 80 | | /// <c>-1</c> to indicate that the size of the message cannot be determined, |
| | | 81 | | /// or is too costly to calculate. |
| | | 82 | | /// </value> |
| | | 83 | | protected override int BufferCapacity |
| | | 84 | | { |
| | 48 | 85 | | get { return -1; } |
| | | 86 | | } |
| | | 87 | | |
| | | 88 | | /// <summary> |
| | | 89 | | /// Initializes a new instance of the <see cref="PseudoTerminalRequestInfo"/> class. |
| | | 90 | | /// </summary> |
| | 2826 | 91 | | public PseudoTerminalRequestInfo() |
| | 2826 | 92 | | { |
| | 2826 | 93 | | WantReply = true; |
| | 2826 | 94 | | } |
| | | 95 | | |
| | | 96 | | /// <summary> |
| | | 97 | | /// Initializes a new instance of the <see cref="PseudoTerminalRequestInfo"/> class. |
| | | 98 | | /// </summary> |
| | | 99 | | /// <param name="environmentVariable">The <c>TERM</c> environment variable which a identifier for the text windo |
| | | 100 | | /// <param name="columns">The terminal width in columns.</param> |
| | | 101 | | /// <param name="rows">The terminal width in rows.</param> |
| | | 102 | | /// <param name="width">The terminal width in pixels.</param> |
| | | 103 | | /// <param name="height">The terminal height in pixels.</param> |
| | | 104 | | /// <param name="terminalModeValues">The terminal mode values.</param> |
| | | 105 | | /// <remarks> |
| | | 106 | | /// <para> |
| | | 107 | | /// The <c>TERM</c> environment variable contains an identifier for the text window's capabilities. |
| | | 108 | | /// You can get a detailed list of these cababilities by using the ‘infocmp’ command. |
| | | 109 | | /// </para> |
| | | 110 | | /// <para> |
| | | 111 | | /// The column/row dimensions override the pixel dimensions(when nonzero). Pixel dimensions refer |
| | | 112 | | /// to the drawable area of the window. |
| | | 113 | | /// </para> |
| | | 114 | | /// </remarks> |
| | | 115 | | public PseudoTerminalRequestInfo(string environmentVariable, uint columns, uint rows, uint width, uint height, I |
| | 19 | 116 | | : this() |
| | 19 | 117 | | { |
| | 19 | 118 | | EnvironmentVariable = environmentVariable; |
| | 19 | 119 | | Columns = columns; |
| | 19 | 120 | | Rows = rows; |
| | 19 | 121 | | PixelWidth = width; |
| | 19 | 122 | | PixelHeight = height; |
| | 19 | 123 | | TerminalModeValues = terminalModeValues; |
| | 19 | 124 | | } |
| | | 125 | | |
| | | 126 | | /// <summary> |
| | | 127 | | /// Called when type specific data need to be saved. |
| | | 128 | | /// </summary> |
| | | 129 | | protected override void SaveData() |
| | 16 | 130 | | { |
| | 16 | 131 | | base.SaveData(); |
| | | 132 | | |
| | 16 | 133 | | Write(EnvironmentVariable); |
| | 16 | 134 | | Write(Columns); |
| | 16 | 135 | | Write(Rows); |
| | 16 | 136 | | Write(PixelWidth); |
| | 16 | 137 | | Write(PixelHeight); |
| | | 138 | | |
| | 16 | 139 | | if (TerminalModeValues != null && TerminalModeValues.Count > 0) |
| | 4 | 140 | | { |
| | | 141 | | // write total length of encoded terminal modes, which is 1 bytes for the opcode / terminal mode |
| | | 142 | | // and 4 bytes for the uint argument for each entry; the encoded terminal modes are terminated by |
| | | 143 | | // opcode TTY_OP_END (which is 1 byte) |
| | 4 | 144 | | Write(((uint) TerminalModeValues.Count*(1 + 4)) + 1); |
| | | 145 | | |
| | 26 | 146 | | foreach (var item in TerminalModeValues) |
| | 7 | 147 | | { |
| | 7 | 148 | | Write((byte) item.Key); |
| | 7 | 149 | | Write(item.Value); |
| | 7 | 150 | | } |
| | | 151 | | |
| | 4 | 152 | | Write((byte) TerminalModes.TTY_OP_END); |
| | 4 | 153 | | } |
| | | 154 | | else |
| | 12 | 155 | | { |
| | | 156 | | // when there are no terminal mode, the length of the string is zero |
| | 12 | 157 | | Write(0u); |
| | 12 | 158 | | } |
| | 16 | 159 | | } |
| | | 160 | | } |
| | | 161 | | } |