Skip to content

UI - Exit Popup

ユーザーがすでに入力されているキー価値のペアを表示する方法があり、ユーザーが新しいペアを入力する方法があります。作成する必要がある最後の画面は、終了/確認画面です。

この画面では、 stdout パイプに入力したキー価値ペアを出力するか、何も出力せずに閉じるかどうかをユーザーに尋ねています。

if let CurrentScreen::Exiting = app.current_screen {
frame.render_widget(Clear, frame.area()); //this clears the entire screen and anything already drawn
let popup_block = Block::default()
.title("Y/N")
.borders(Borders::NONE)
.style(Style::default().bg(Color::DarkGray));
let exit_text = Text::styled(
"Would you like to output the buffer as json? (y/n)",
Style::default().fg(Color::Red),
);
// the `trim: false` will stop the text from being cut off when over the edge of the block
let exit_paragraph = Paragraph::new(exit_text)
.block(popup_block)
.wrap(Wrap { trim: false });
let area = centered_rect(60, 25, frame.area());
frame.render_widget(exit_paragraph, area);
}

これまでに行ったことのないこの部分の唯一のことは、Clear ウィジェットを使用することです。これは、名前が提案することを行う特別なウィジェットです---レンダリングされたスペース内のすべてをクリアします。