using System.Runtime.InteropServices;
namespace DodoSSH.Client.Ssh;
///
/// A pseudo-terminal's dimensions.
///
///
/// Both the character grid and the pixel extent, because the SSH pty-req and
/// window-change requests carry both. Pixel dimensions are what let a remote program draw
/// sixel graphics or size an image correctly; sending zeroes is legal and tells the remote there is
/// no pixel information, which is not the same as telling it the terminal is zero pixels wide.
///
/// Character columns.
/// Character rows.
/// Width in pixels, or 0 when unknown.
/// Height in pixels, or 0 when unknown.
[StructLayout(LayoutKind.Auto)]
public readonly record struct TerminalSize(
ushort Columns,
ushort Rows,
ushort PixelWidth = 0,
ushort PixelHeight = 0)
{
/// The conventional default, for a session opened before the UI has measured itself.
public static TerminalSize Default => new(80, 24);
/// Whether the size is usable as a terminal.
///
/// A zero dimension is worth rejecting rather than forwarding: a resize to 0×0 arrives naturally
/// when a pane is collapsed or a window minimised, and passing it on makes the remote's idea of
/// the terminal nonsensical until the next resize.
///
public bool IsUsable => Columns > 0 && Rows > 0;
}