PseudoTerminalInfo.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. using Renci.SshNet.Common;
  2. using System.Collections.Generic;
  3. namespace Renci.SshNet.Messages.Connection
  4. {
  5. /// <summary>
  6. /// Represents "pty-req" type channel request information
  7. /// </summary>
  8. internal class PseudoTerminalRequestInfo : RequestInfo
  9. {
  10. /// <summary>
  11. /// Channel request name
  12. /// </summary>
  13. public const string NAME = "pty-req";
  14. /// <summary>
  15. /// Gets the name of the request.
  16. /// </summary>
  17. /// <value>
  18. /// The name of the request.
  19. /// </value>
  20. public override string RequestName
  21. {
  22. get { return NAME; }
  23. }
  24. /// <summary>
  25. /// Gets or sets the environment variable (e.g., vt100).
  26. /// </summary>
  27. /// <value>
  28. /// The environment variable.
  29. /// </value>
  30. public string EnvironmentVariable { get; set; }
  31. /// <summary>
  32. /// Gets or sets the terminal width in columns (e.g., 80).
  33. /// </summary>
  34. /// <value>
  35. /// The terminal width in columns.
  36. /// </value>
  37. public uint Columns { get; set; }
  38. /// <summary>
  39. /// Gets or sets the terminal width in rows (e.g., 24).
  40. /// </summary>
  41. /// <value>
  42. /// The terminal width in rows.
  43. /// </value>
  44. public uint Rows { get; set; }
  45. /// <summary>
  46. /// Gets or sets the terminal width in pixels (e.g., 640).
  47. /// </summary>
  48. /// <value>
  49. /// The terminal width in pixels.
  50. /// </value>
  51. public uint PixelWidth { get; set; }
  52. /// <summary>
  53. /// Gets or sets the terminal height in pixels (e.g., 480).
  54. /// </summary>
  55. /// <value>
  56. /// The terminal height in pixels.
  57. /// </value>
  58. public uint PixelHeight { get; set; }
  59. /// <summary>
  60. /// Gets or sets the terminal mode.
  61. /// </summary>
  62. /// <value>
  63. /// The terminal mode.
  64. /// </value>
  65. public IDictionary<TerminalModes, uint> TerminalModeValues { get; set; }
  66. /// <summary>
  67. /// Initializes a new instance of the <see cref="PseudoTerminalRequestInfo"/> class.
  68. /// </summary>
  69. public PseudoTerminalRequestInfo()
  70. {
  71. WantReply = true;
  72. }
  73. /// <summary>
  74. /// Initializes a new instance of the <see cref="PseudoTerminalRequestInfo"/> class.
  75. /// </summary>
  76. /// <param name="environmentVariable">The environment variable.</param>
  77. /// <param name="columns">The columns.</param>
  78. /// <param name="rows">The rows.</param>
  79. /// <param name="width">The width.</param>
  80. /// <param name="height">The height.</param>
  81. /// <param name="terminalModeValues">The terminal mode values.</param>
  82. public PseudoTerminalRequestInfo(string environmentVariable, uint columns, uint rows, uint width, uint height, IDictionary<TerminalModes, uint> terminalModeValues)
  83. : this()
  84. {
  85. EnvironmentVariable = environmentVariable;
  86. Columns = columns;
  87. Rows = rows;
  88. PixelWidth = width;
  89. PixelHeight = height;
  90. TerminalModeValues = terminalModeValues;
  91. }
  92. /// <summary>
  93. /// Called when type specific data need to be saved.
  94. /// </summary>
  95. protected override void SaveData()
  96. {
  97. base.SaveData();
  98. Write(EnvironmentVariable);
  99. Write(Columns);
  100. Write(Rows);
  101. Write(Rows);
  102. Write(PixelHeight);
  103. if (TerminalModeValues != null)
  104. {
  105. Write((uint)TerminalModeValues.Count * (1 + 4) + 1);
  106. foreach (var item in TerminalModeValues)
  107. {
  108. Write((byte)item.Key);
  109. Write(item.Value);
  110. }
  111. Write((byte)0);
  112. }
  113. else
  114. {
  115. Write((uint)0);
  116. }
  117. }
  118. }
  119. }