diff options
author | Griffin Smith <root@gws.fyi> | 2019-08-04T00·26-0400 |
---|---|---|
committer | Griffin Smith <root@gws.fyi> | 2019-08-04T00·31-0400 |
commit | e2d2f011c6373894b3cdcfbdb98fbc783504561a (patch) | |
tree | a10ab475547d5496484c1ca89a079b32ca90706f /src/types/menu.rs | |
parent | 48fb3f6624b95e9b18a5ff0a814573445c6bc2ab (diff) |
Add method for writing option menus to viewport
Add a method for writing single-choice menus to the viewport, within a box. Unused for now.
Diffstat (limited to 'src/types/menu.rs')
-rw-r--r-- | src/types/menu.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/types/menu.rs b/src/types/menu.rs new file mode 100644 index 000000000000..63abc837788e --- /dev/null +++ b/src/types/menu.rs @@ -0,0 +1,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, + } + } +} |