1use rmpv::Value;
2
3use crate::{Message, Neovim};
4
5pub struct AttachOptions {
6 rgb: Option<bool>,
7 ui_override: Option<bool>,
8 ext_cmdline: Option<bool>,
9 ext_hlstate: Option<bool>,
10 ext_linegrid: Option<bool>,
11 ext_messages: Option<bool>,
12 ext_multigrid: Option<bool>,
13 ext_popupmenu: Option<bool>,
14 ext_tabline: Option<bool>,
15 ext_termcolors: Option<bool>,
16 term_name: Option<String>,
17 term_colors: Option<u16>,
18 term_background: Option<String>,
19}
20
21impl Default for AttachOptions {
22 fn default() -> Self {
23 Self {
24 rgb: Some(true),
25 ui_override: Some(true),
26 ext_cmdline: Some(true),
27 ext_hlstate: Some(true),
28 ext_linegrid: Some(true),
29 ext_messages: Some(true),
30 ext_multigrid: Some(true),
31 ext_popupmenu: Some(true),
32 ext_tabline: Some(true),
33 ext_termcolors: Some(true),
34 term_name: None,
35 term_colors: None,
36 term_background: None,
37 }
38 }
39}
40
41impl AttachOptions {
42 pub fn new() -> Self {
43 Self {
44 rgb: None,
45 ui_override: None,
46 ext_cmdline: None,
47 ext_hlstate: None,
48 ext_linegrid: None,
49 ext_messages: None,
50 ext_multigrid: None,
51 ext_popupmenu: None,
52 ext_tabline: None,
53 ext_termcolors: None,
54 term_name: None,
55 term_colors: None,
56 term_background: None,
57 }
58 }
59
60 #[must_use]
61 pub fn build(self) -> Value {
62 let mut options: Vec<(Value, Value)> = vec![];
63
64 if let Some(value) = self.rgb {
65 options.push((Value::from("rgb"), Value::from(value)));
66 }
67
68 if let Some(value) = self.ui_override {
69 options.push((Value::from("override"), Value::from(value)));
70 }
71
72 if let Some(value) = self.ext_cmdline {
73 options.push((Value::from("ext_cmdline"), Value::from(value)));
74 }
75
76 if let Some(value) = self.ext_hlstate {
77 options.push((Value::from("ext_hlstate"), Value::from(value)));
78 }
79
80 if let Some(value) = self.ext_linegrid {
81 options.push((Value::from("ext_linegrid"), Value::from(value)));
82 }
83
84 if let Some(value) = self.ext_messages {
85 options.push((Value::from("ext_messages"), Value::from(value)));
86 }
87
88 if let Some(value) = self.ext_multigrid {
89 options.push((Value::from("ext_multigrid"), Value::from(value)));
90 }
91
92 if let Some(value) = self.ext_popupmenu {
93 options.push((Value::from("ext_popupmenu"), Value::from(value)));
94 }
95
96 if let Some(value) = self.ext_tabline {
97 options.push((Value::from("ext_tabline"), Value::from(value)));
98 }
99
100 if let Some(value) = self.ext_termcolors {
101 options.push((Value::from("ext_termcolors"), Value::from(value)));
102 }
103
104 if let Some(value) = self.term_name {
105 options.push((Value::from("term_name"), Value::from(value)));
106 }
107
108 if let Some(value) = self.term_colors {
109 options.push((Value::from("term_colors"), Value::from(value)));
110 }
111
112 if let Some(value) = self.term_background {
113 options.push((Value::from("term_background"), Value::from(value)));
114 }
115
116 Value::Map(options)
117 }
118}
119
120impl Neovim {
121 pub async fn attach(
122 &self,
123 width: u16,
124 height: u16,
125 options: Value,
126 ) -> Result<Message, crate::neovim::Error> {
127 self.request(
128 "nvim_ui_attach".to_owned(),
129 vec![Value::from(width), Value::from(height), options],
130 )
131 .await
132 }
133}