diff options
author | rabite <rabite@posteo.de> | 2019-02-01 00:21:16 +0100 |
---|---|---|
committer | rabite <rabite@posteo.de> | 2019-02-01 00:21:16 +0100 |
commit | b7bbcff2840f5b0b0b46f9188ae45be0075f9864 (patch) | |
tree | bc7dc7322403b4cd7c48e26bf8f77dc2a02f8171 /src/textview.rs | |
parent | 305d26d7b6ca2f4b3b289365d3f4d56bb2930d95 (diff) |
lots of stuff.
Diffstat (limited to 'src/textview.rs')
-rw-r--r-- | src/textview.rs | 56 |
1 files changed, 26 insertions, 30 deletions
diff --git a/src/textview.rs b/src/textview.rs index dbb2770..5cb5b47 100644 --- a/src/textview.rs +++ b/src/textview.rs @@ -1,15 +1,15 @@ -use termion::event::{Key}; +use ::rayon::prelude::*; use std::io::BufRead; -use crate::widget::Widget; +use crate::coordinates::{Coordinates, Position, Size}; use crate::files::File; -use crate::coordinates::{Coordinates,Size,Position}; use crate::term::sized_string; +use crate::widget::Widget; pub struct TextView { pub lines: Vec<String>, - pub buffer: Vec<String>, + pub buffer: String, pub coordinates: Coordinates, } @@ -17,11 +17,11 @@ impl TextView { pub fn new_from_file(file: &File) -> TextView { let file = std::fs::File::open(&file.path).unwrap(); let file = std::io::BufReader::new(file); - let lines = file.lines().take(100).map(|line| line.unwrap() ).collect(); + let lines = file.lines().take(100).map(|line| line.unwrap()).collect(); TextView { lines: lines, - buffer: vec![], + buffer: String::new(), coordinates: Coordinates::new(), } } @@ -49,34 +49,30 @@ impl Widget for TextView { fn set_coordinates(&mut self, coordinates: &Coordinates) { self.coordinates = coordinates.clone(); } - fn render_header(&self) -> String { "".to_string() } - fn refresh(&mut self) { - let (xsize,ysize) = self.get_size().size(); - let (xpos, ypos) = self.get_position().position(); - - let lines = self.lines - .iter() - .take(ysize as usize) - .map(|line| sized_string(&line, xsize)).collect(); - - - self.buffer = lines; + fn render_header(&self) -> String { + "".to_string() } - fn get_drawlist(&self) -> String { - let (xsize,ysize) = self.get_size().size(); - let (xpos, ypos) = self.get_position().position(); + fn refresh(&mut self) { + let (xsize, ysize) = self.get_size().size(); + let (xpos, _) = self.get_position().position(); - self.buffer - .iter() + self.buffer = self + .lines + .par_iter() .take(ysize as usize) .enumerate() - .map(|(i, line)|{ - format!("{}{:xsize$}", - crate::term::goto_xy(xpos,i as u16), - line, - xsize = xsize as usize) - - }).collect() + .map(|(i, line)| { + format!( + "{}{:xsize$}", + crate::term::goto_xy(xpos, i as u16), + sized_string(&line, xsize), + xsize = xsize as usize + ) + }) + .collect(); + } + fn get_drawlist(&self) -> String { + self.buffer.clone() } } |