Add a minibuffer #131
@ -347,25 +347,41 @@ impl<'a, 'b> TrackState<'a, 'b> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Minibuffer;
|
struct Minibuffer<'a> {
|
||||||
|
paragraphs: Vec<Paragraph<'a>>,
|
||||||
|
columns: u16,
|
||||||
|
}
|
||||||
|
|
||||||
impl Minibuffer {
|
impl Minibuffer<'_> {
|
||||||
fn paragraphs(state: &AppPublicState) -> Vec<Paragraph> {
|
fn paragraphs(state: &AppPublicState) -> Self {
|
||||||
match state {
|
match state {
|
||||||
AppState::Browse(_) => vec![
|
AppState::Browse(_) => Minibuffer {
|
||||||
Paragraph::new("m: show info overlay"),
|
paragraphs: vec![
|
||||||
Paragraph::new("g: show reload menu"),
|
Paragraph::new("m: show info overlay"),
|
||||||
],
|
Paragraph::new("g: show reload menu"),
|
||||||
AppState::Info(_) => vec![Paragraph::new("m: hide info overlay")],
|
],
|
||||||
AppState::Reload(_) => vec![
|
columns: 3,
|
||||||
Paragraph::new("d: reload database"),
|
},
|
||||||
Paragraph::new("l: reload library"),
|
AppState::Info(_) => Minibuffer {
|
||||||
Paragraph::new("g: hide reload menu"),
|
paragraphs: vec![Paragraph::new("m: hide info overlay")],
|
||||||
],
|
columns: 3,
|
||||||
AppState::Error(_) => {
|
},
|
||||||
vec![Paragraph::new("Press any key to dismiss the error message")]
|
AppState::Reload(_) => Minibuffer {
|
||||||
}
|
paragraphs: vec![
|
||||||
AppState::Critical(_) => vec![Paragraph::new("Press ctrl+c to terminate the program")],
|
Paragraph::new("g: hide reload menu"),
|
||||||
|
Paragraph::new("d: reload database"),
|
||||||
|
Paragraph::new("l: reload library"),
|
||||||
|
],
|
||||||
|
columns: 3,
|
||||||
|
},
|
||||||
|
AppState::Error(_) => Minibuffer {
|
||||||
|
paragraphs: vec![Paragraph::new("Press any key to dismiss the error message...")],
|
||||||
|
columns: 1,
|
||||||
|
},
|
||||||
|
AppState::Critical(_) => Minibuffer {
|
||||||
|
paragraphs: vec![Paragraph::new("Press ctrl+c to terminate the program...")],
|
||||||
|
columns: 1,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -472,10 +488,13 @@ impl Ui {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn columns(paragraphs: Vec<Paragraph>, area: Rect) -> Vec<Column> {
|
fn columns(paragraphs: Vec<Paragraph>, min: u16, area: Rect) -> Vec<Column> {
|
||||||
let mut x = area.x;
|
let mut x = area.x;
|
||||||
let mut width = area.width;
|
let mut width = area.width;
|
||||||
let mut remaining = paragraphs.len() as u16;
|
let mut remaining = paragraphs.len() as u16;
|
||||||
|
if remaining < min {
|
||||||
|
remaining = min;
|
||||||
|
}
|
||||||
|
|
||||||
let mut blocks = vec![];
|
let mut blocks = vec![];
|
||||||
for paragraph in paragraphs.into_iter() {
|
for paragraph in paragraphs.into_iter() {
|
||||||
@ -501,11 +520,12 @@ impl Ui {
|
|||||||
|
|
||||||
fn render_columns<B: Backend>(
|
fn render_columns<B: Backend>(
|
||||||
paragraphs: Vec<Paragraph>,
|
paragraphs: Vec<Paragraph>,
|
||||||
|
min: u16,
|
||||||
active: bool,
|
active: bool,
|
||||||
area: Rect,
|
area: Rect,
|
||||||
frame: &mut Frame<'_, B>,
|
frame: &mut Frame<'_, B>,
|
||||||
) {
|
) {
|
||||||
for column in Self::columns(paragraphs, area).into_iter() {
|
for column in Self::columns(paragraphs, min, area).into_iter() {
|
||||||
frame.render_widget(
|
frame.render_widget(
|
||||||
column
|
column
|
||||||
.paragraph
|
.paragraph
|
||||||
@ -531,7 +551,9 @@ impl Ui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn render_minibuffer<B: Backend>(state: &AppPublicState, ar: Rect, fr: &mut Frame<'_, B>) {
|
fn render_minibuffer<B: Backend>(state: &AppPublicState, ar: Rect, fr: &mut Frame<'_, B>) {
|
||||||
let paragraphs = Minibuffer::paragraphs(state)
|
let mut mb = Minibuffer::paragraphs(state);
|
||||||
|
mb.paragraphs = mb
|
||||||
|
.paragraphs
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|p| p.alignment(Alignment::Center))
|
.map(|p| p.alignment(Alignment::Center))
|
||||||
.collect();
|
.collect();
|
||||||
@ -544,7 +566,7 @@ impl Ui {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Self::render_info_widget("Minibuffer", Paragraph::new(""), false, ar, fr);
|
Self::render_info_widget("Minibuffer", Paragraph::new(""), false, ar, fr);
|
||||||
Self::render_columns(paragraphs, false, area, fr);
|
Self::render_columns(mb.paragraphs, mb.columns, false, area, fr);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_main_frame<B: Backend>(
|
fn render_main_frame<B: Backend>(
|
||||||
|
Loading…
Reference in New Issue
Block a user