Skip to main content

qemu_command_builder/args/
vga.rs

1use crate::parsers::ARG_VGA;
2use crate::to_command::ToCommand;
3use proptest_derive::Arbitrary;
4use std::fmt::Display;
5use std::str::FromStr;
6
7#[derive(Debug, Clone, Hash, Ord, PartialOrd, Eq, PartialEq, Arbitrary)]
8pub enum VGA {
9    /// Cirrus Logic GD5446 Video card. All Windows versions starting
10    /// from Windows 95 should recognize and use this graphic card. For
11    /// optimal performances, use 16 bit color depth in the guest and
12    /// the host OS. (This card was the default before QEMU 2.2)
13    Cirrus,
14
15    /// Standard VGA card with Bochs VBE extensions. If your guest OS
16    /// supports the VESA 2.0 VBE extensions (e.g. Windows XP) and if
17    /// you want to use high resolution modes (>= 1280x1024x16) then you
18    /// should use this option. (This card is the default since QEMU
19    /// 2.2)
20    Std,
21
22    /// VMWare SVGA-II compatible adapter. Use it if you have
23    /// sufficiently recent XFree86/XOrg server or Windows guest with a
24    /// driver for this card.
25    Vmware,
26
27    /// QXL paravirtual graphic card. It is VGA compatible (including
28    /// VESA 2.0 VBE support). Works best with qxl guest drivers
29    /// installed though. Recommended choice when using the spice
30    /// protocol.
31    Qxl,
32
33    /// (sun4m only) Sun TCX framebuffer. This is the default
34    /// framebuffer for sun4m machines and offers both 8-bit and 24-bit
35    /// colour depths at a fixed resolution of 1024x768.
36    Tcx,
37
38    /// (sun4m only) Sun cgthree framebuffer. This is a simple 8-bit
39    /// framebuffer for sun4m machines available in both 1024x768
40    /// (OpenBIOS) and 1152x900 (OBP) resolutions aimed at people
41    /// wishing to run older Solaris versions.
42    Cg3,
43
44    /// Virtio VGA card.
45    Virtio,
46
47    /// Disable VGA card.
48    None,
49}
50
51impl FromStr for VGA {
52    type Err = String;
53
54    fn from_str(s: &str) -> Result<Self, Self::Err> {
55        match s {
56            "cirrus" => Ok(VGA::Cirrus),
57            "std" => Ok(VGA::Std),
58            "vmware" => Ok(VGA::Vmware),
59            "qxl" => Ok(VGA::Qxl),
60            "tcx" => Ok(VGA::Tcx),
61            "cg3" => Ok(VGA::Cg3),
62            "virtio" => Ok(VGA::Virtio),
63            "none" => Ok(VGA::None),
64            other => Err(format!("Unknown vga type: {}", other)),
65        }
66    }
67}
68
69impl Display for VGA {
70    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
71        match self {
72            VGA::Cirrus => write!(f, "cirrus"),
73            VGA::Std => write!(f, "std"),
74            VGA::Vmware => write!(f, "vmware"),
75            VGA::Qxl => write!(f, "qxl"),
76            VGA::Tcx => write!(f, "tcx"),
77            VGA::Cg3 => write!(f, "cg3"),
78            VGA::Virtio => write!(f, "virtio"),
79            VGA::None => write!(f, "none"),
80        }
81    }
82}
83
84impl ToCommand for VGA {
85    fn command(&self) -> String {
86        ARG_VGA.to_string()
87    }
88    fn to_args(&self) -> Vec<String> {
89        let mut args = vec![];
90
91        match self {
92            VGA::Cirrus => {
93                args.push("cirrus".to_string());
94            }
95            VGA::Std => {
96                args.push("std".to_string());
97            }
98            VGA::Vmware => {
99                args.push("vmware".to_string());
100            }
101            VGA::Qxl => {
102                args.push("qxl".to_string());
103            }
104            VGA::Tcx => {
105                args.push("tcx".to_string());
106            }
107            VGA::Cg3 => {
108                args.push("cg3".to_string());
109            }
110            VGA::Virtio => {
111                args.push("virtio".to_string());
112            }
113            VGA::None => {
114                args.push("none".to_string());
115            }
116        }
117        args
118    }
119}