ui: add reflow property to Pager
For displaying format=flowed formatted text/plain attachments properly.jmap
parent
dfa83e486c
commit
1168804cf8
|
@ -84,13 +84,15 @@ pub struct Composer {
|
||||||
|
|
||||||
impl Default for Composer {
|
impl Default for Composer {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
|
let mut pager = Pager::default();
|
||||||
|
pager.set_reflow(text_processing::Reflow::FormatFlowed);
|
||||||
Composer {
|
Composer {
|
||||||
reply_context: None,
|
reply_context: None,
|
||||||
account_cursor: 0,
|
account_cursor: 0,
|
||||||
|
|
||||||
cursor: Cursor::Headers,
|
cursor: Cursor::Headers,
|
||||||
|
|
||||||
pager: Pager::default(),
|
pager,
|
||||||
draft: Draft::default(),
|
draft: Draft::default(),
|
||||||
form: FormWidget::default(),
|
form: FormWidget::default(),
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
/*! Various useful components that can be used in a generic fashion.
|
/*! Various useful components that can be used in a generic fashion.
|
||||||
*/
|
*/
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use text_processing::Reflow;
|
||||||
|
|
||||||
mod widgets;
|
mod widgets;
|
||||||
|
|
||||||
|
@ -282,6 +283,7 @@ pub enum PageMovement {
|
||||||
pub struct Pager {
|
pub struct Pager {
|
||||||
text: String,
|
text: String,
|
||||||
cursor: (usize, usize),
|
cursor: (usize, usize),
|
||||||
|
reflow: Reflow,
|
||||||
height: usize,
|
height: usize,
|
||||||
width: usize,
|
width: usize,
|
||||||
dirty: bool,
|
dirty: bool,
|
||||||
|
@ -299,14 +301,18 @@ impl fmt::Display for Pager {
|
||||||
|
|
||||||
impl Pager {
|
impl Pager {
|
||||||
const DESCRIPTION: &'static str = "pager";
|
const DESCRIPTION: &'static str = "pager";
|
||||||
pub fn update_from_str(&mut self, text: &str, width: Option<usize>) {
|
pub fn set_reflow(&mut self, new_val: Reflow) {
|
||||||
let lines: Vec<String> = if let Some(width) = width {
|
self.reflow = new_val;
|
||||||
text.split_lines(width)
|
}
|
||||||
} else {
|
|
||||||
text.trim().split('\n').map(str::to_string).collect()
|
|
||||||
};
|
|
||||||
|
|
||||||
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 width = width.unwrap_or_else(|| lines.iter().map(|l| l.len()).max().unwrap_or(0));
|
||||||
let ascii_drawing = self.content.ascii_drawing;
|
let ascii_drawing = self.content.ascii_drawing;
|
||||||
let mut content = CellBuffer::new(width, height, Cell::with_char(' '));
|
let mut content = CellBuffer::new(width, height, Cell::with_char(' '));
|
||||||
|
|
Loading…
Reference in New Issue