blob: 63abc837788ea85c948099197da77e6ee79060f6 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
use crate::types::Dimensions;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct MenuInfo {
pub prompt: String,
pub options: Vec<String>,
}
impl MenuInfo {
pub fn new(prompt: String, options: Vec<String>) -> Self {
MenuInfo { prompt, options }
}
/// Returns the inner dimensions of a box necessary to draw this menu. Will
/// not trim either dimension to the size of the terminal
pub fn dimensions(&self) -> Dimensions {
Dimensions {
w: self
.options
.iter()
.map(|s| s.len())
.max()
.unwrap_or(0)
.max(self.prompt.len()) as u16
+ 4,
h: self.options.len() as u16
+ if self.prompt.is_empty() { 0 } else { 2 }
+ 4,
}
}
}
|