ui: add reflow property to Pager

For displaying format=flowed formatted text/plain attachments properly.
jmap
Manos Pitsidianakis 2019-11-16 20:23:07 +02:00
parent dfa83e486c
commit 1168804cf8
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
2 changed files with 16 additions and 8 deletions

View File

@ -84,13 +84,15 @@ pub struct Composer {
impl Default for Composer {
fn default() -> Self {
let mut pager = Pager::default();
pager.set_reflow(text_processing::Reflow::FormatFlowed);
Composer {
reply_context: None,
account_cursor: 0,
cursor: Cursor::Headers,
pager: Pager::default(),
pager,
draft: Draft::default(),
form: FormWidget::default(),

View File

@ -22,6 +22,7 @@
/*! Various useful components that can be used in a generic fashion.
*/
use super::*;
use text_processing::Reflow;
mod widgets;
@ -282,6 +283,7 @@ pub enum PageMovement {
pub struct Pager {
text: String,
cursor: (usize, usize),
reflow: Reflow,
height: usize,
width: usize,
dirty: bool,
@ -299,14 +301,18 @@ impl fmt::Display for Pager {
impl Pager {
const DESCRIPTION: &'static str = "pager";
pub fn update_from_str(&mut self, text: &str, width: Option<usize>) {
let lines: Vec<String> = if let Some(width) = width {
text.split_lines(width)
} else {
text.trim().split('\n').map(str::to_string).collect()
};
pub fn set_reflow(&mut self, new_val: Reflow) {
self.reflow = new_val;
}
let height = lines.len() + 1;
pub fn reflow(&self) -> Reflow {
self.reflow
}
pub fn update_from_str(&mut self, text: &str, width: Option<usize>) {
let lines: Vec<String> = text.split_lines_reflow(self.reflow, width);
debug!(&lines);
let height = lines.len() + 2;
let width = width.unwrap_or_else(|| lines.iter().map(|l| l.len()).max().unwrap_or(0));
let ascii_drawing = self.content.ascii_drawing;
let mut content = CellBuffer::new(width, height, Cell::with_char(' '));