Fix colors in open-link view
parent
1fd43eb671
commit
0aef7e03a5
2
.gdbinit
2
.gdbinit
|
@ -1,2 +1,4 @@
|
||||||
break rust_panic
|
break rust_panic
|
||||||
break core::option::expect_failed::h4927e1fef06c4878
|
break core::option::expect_failed::h4927e1fef06c4878
|
||||||
|
break core::panicking::panic
|
||||||
|
break libcore/panicking.rs:58
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
*/
|
*/
|
||||||
use std::ops::{Index, IndexMut, Deref, DerefMut};
|
use std::ops::{Index, IndexMut, Deref, DerefMut};
|
||||||
use std::convert::From;
|
use std::convert::From;
|
||||||
|
use std::fmt;
|
||||||
use super::position::*;
|
use super::position::*;
|
||||||
use termion::color::AnsiValue;
|
use termion::color::AnsiValue;
|
||||||
|
|
||||||
|
@ -175,12 +176,28 @@ impl<'a> From<&'a String> for CellBuffer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for CellBuffer {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
'_y: for y in 0..self.rows {
|
||||||
|
'_x: for x in 0..self.cols {
|
||||||
|
let c: &char = &self[(x,y)].ch();
|
||||||
|
write!(f, "{}", *c);
|
||||||
|
if *c == '\n' {
|
||||||
|
continue '_y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A single point on a terminal display.
|
/// A single point on a terminal display.
|
||||||
///
|
///
|
||||||
/// A `Cell` contains a character and style.
|
/// A `Cell` contains a character and style.
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||||
pub struct Cell {
|
pub struct Cell {
|
||||||
ch: char,
|
ch: char,
|
||||||
|
|
||||||
fg: Color,
|
fg: Color,
|
||||||
bg: Color,
|
bg: Color,
|
||||||
attrs: Attr,
|
attrs: Attr,
|
||||||
|
|
|
@ -139,12 +139,18 @@ impl Component for MailView {
|
||||||
let mut buf = CellBuffer::from(&text);
|
let mut buf = CellBuffer::from(&text);
|
||||||
match self.mode {
|
match self.mode {
|
||||||
ViewMode::Url => {
|
ViewMode::Url => {
|
||||||
let c_slice: &mut [Cell] = &mut buf;
|
// URL indexes must be colored (ugh..)
|
||||||
for (lidx, l) in finder.links(&envelope.body().text()).enumerate() {
|
let (cols, _) = buf.size();
|
||||||
let i = l.start()+ (lidx * 3);
|
let lines: Vec<&str> = text.split('\n').collect();
|
||||||
for c in c_slice[i..i+3].iter_mut() {
|
let mut shift = 0;
|
||||||
c.set_fg(Color::Byte(226));
|
for (ridx, r) in lines.iter().enumerate() {
|
||||||
|
for (lidx, l) in finder.links(&r).enumerate() {
|
||||||
|
buf[(l.start() + shift - 1, 0)].set_fg(Color::Byte(226));
|
||||||
|
buf[(l.start() + shift - 2, 0)].set_fg(Color::Byte(226));
|
||||||
|
buf[(l.start() + shift - 3, 0)].set_fg(Color::Byte(226));
|
||||||
}
|
}
|
||||||
|
// Each Cell represents one char so next line will be:
|
||||||
|
shift += r.chars().count()+1;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_ => {},
|
_ => {},
|
||||||
|
@ -153,7 +159,7 @@ impl Component for MailView {
|
||||||
};
|
};
|
||||||
let cursor_pos = self.pager.as_mut().map(|p| p.cursor_pos());
|
let cursor_pos = self.pager.as_mut().map(|p| p.cursor_pos());
|
||||||
// TODO: pass string instead of envelope
|
// TODO: pass string instead of envelope
|
||||||
self.pager = Some(Pager::from_buf(buf));
|
self.pager = Some(Pager::from_buf(buf, cursor_pos));
|
||||||
self.dirty = false;
|
self.dirty = false;
|
||||||
}
|
}
|
||||||
self.pager.as_mut().map(|p| p.draw(grid, (set_y(upper_left, y + 1),bottom_right), context));
|
self.pager.as_mut().map(|p| p.draw(grid, (set_y(upper_left, y + 1),bottom_right), context));
|
||||||
|
@ -163,7 +169,7 @@ impl Component for MailView {
|
||||||
match event.event_type {
|
match event.event_type {
|
||||||
UIEventType::Input(Key::Char(c)) if c >= '0' && c <= '9' => { //TODO:this should be an Action
|
UIEventType::Input(Key::Char(c)) if c >= '0' && c <= '9' => { //TODO:this should be an Action
|
||||||
match self.mode {
|
match self.mode {
|
||||||
ViewMode::Url => { self.cmd_buf.push(c);
|
ViewMode::Url => { self.cmd_buf.push(c);
|
||||||
eprintln!("buf is {}", self.cmd_buf);
|
eprintln!("buf is {}", self.cmd_buf);
|
||||||
return; },
|
return; },
|
||||||
_ => {},
|
_ => {},
|
||||||
|
|
|
@ -99,23 +99,23 @@ pub fn copy_area_with_break(grid_dest: &mut CellBuffer, grid_src: &CellBuffer, d
|
||||||
if grid_src[(src_x, src_y)].ch() == '\n' {
|
if grid_src[(src_x, src_y)].ch() == '\n' {
|
||||||
src_y += 1;
|
src_y += 1;
|
||||||
src_x = 0;
|
src_x = 0;
|
||||||
if src_y == get_y(bottom_right!(src)) {
|
if src_y >= get_y(bottom_right!(src)) {
|
||||||
break 'y_;
|
break 'y_;
|
||||||
}
|
}
|
||||||
continue 'y_;
|
continue 'y_;
|
||||||
}
|
}
|
||||||
|
|
||||||
grid_dest[(x,y)] = grid_src[(src_x, src_y)];
|
grid_dest[(x,y)] = grid_src[(src_x, src_y)];
|
||||||
if src_x == get_x(bottom_right!(src)) {
|
src_x += 1;
|
||||||
|
if src_x >= get_x(bottom_right!(src)) {
|
||||||
src_y += 1;
|
src_y += 1;
|
||||||
src_x = 0;
|
src_x = 0;
|
||||||
if src_y == get_y(bottom_right!(src)) {
|
if src_y >= get_y(bottom_right!(src)) {
|
||||||
//clear_area(grid_dest, ((get_x(upper_left!(dest)), y), bottom_right!(dest)));
|
//clear_area(grid_dest, ((get_x(upper_left!(dest)), y), bottom_right!(dest)));
|
||||||
break 'y_;
|
break 'y_;
|
||||||
}
|
}
|
||||||
break 'x_;
|
break 'x_;
|
||||||
}
|
}
|
||||||
src_x += 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -133,13 +133,13 @@ pub fn copy_area(grid_dest: &mut CellBuffer, grid_src: &CellBuffer, dest: Area,
|
||||||
for y in get_y(upper_left!(dest))..=get_y(bottom_right!(dest)) {
|
for y in get_y(upper_left!(dest))..=get_y(bottom_right!(dest)) {
|
||||||
'for_x: for x in get_x(upper_left!(dest))..=get_x(bottom_right!(dest)) {
|
'for_x: for x in get_x(upper_left!(dest))..=get_x(bottom_right!(dest)) {
|
||||||
grid_dest[(x,y)] = grid_src[(src_x, src_y)];
|
grid_dest[(x,y)] = grid_src[(src_x, src_y)];
|
||||||
if src_x == get_x(bottom_right!(src)) {
|
if src_x >= get_x(bottom_right!(src)) {
|
||||||
break 'for_x;
|
break 'for_x;
|
||||||
}
|
}
|
||||||
src_x += 1;
|
src_x += 1;
|
||||||
}
|
}
|
||||||
src_x = get_x(upper_left!(src));
|
src_x = get_x(upper_left!(src));
|
||||||
if src_y == get_y(bottom_right!(src)) {
|
if src_y >= get_y(bottom_right!(src)) {
|
||||||
clear_area(grid_dest, ((get_x(upper_left!(dest)), y), bottom_right!(dest)));
|
clear_area(grid_dest, ((get_x(upper_left!(dest)), y), bottom_right!(dest)));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -178,21 +178,21 @@ impl Pager {
|
||||||
content: content,
|
content: content,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn from_str(s: &str) -> Self {
|
pub fn from_str(s: &str, cursor_pos: Option<usize>) -> Self {
|
||||||
let lines: Vec<&str> = s.trim().split('\n').collect();
|
let lines: Vec<&str> = s.trim().split('\n').collect();
|
||||||
let height = lines.len();
|
let height = lines.len();
|
||||||
let width = lines.iter().map(|l| l.len()).max().unwrap_or(0);
|
let width = lines.iter().map(|l| l.len()).max().unwrap_or(0);
|
||||||
let mut content = CellBuffer::new(width, height, Cell::with_char(' '));
|
let mut content = CellBuffer::new(width, height, Cell::with_char(' '));
|
||||||
Pager::print_string(&mut content, s);
|
Pager::print_string(&mut content, s);
|
||||||
Pager {
|
Pager {
|
||||||
cursor_pos: 0,
|
cursor_pos: cursor_pos.unwrap_or(0),
|
||||||
height: height,
|
height: height,
|
||||||
width: width,
|
width: width,
|
||||||
dirty: true,
|
dirty: true,
|
||||||
content: content,
|
content: content,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn from_buf(buf: CellBuffer) -> Self {
|
pub fn from_buf(buf: CellBuffer, cursor_pos: Option<usize>) -> Self {
|
||||||
let lines: Vec<&[Cell]> = buf.split(|cell| cell.ch() == '\n').collect();
|
let lines: Vec<&[Cell]> = buf.split(|cell| cell.ch() == '\n').collect();
|
||||||
let height = lines.len();
|
let height = lines.len();
|
||||||
let width = lines.iter().map(|l| l.len()).max().unwrap_or(0) + 1;
|
let width = lines.iter().map(|l| l.len()).max().unwrap_or(0) + 1;
|
||||||
|
@ -210,7 +210,7 @@ impl Pager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Pager {
|
Pager {
|
||||||
cursor_pos: 0,
|
cursor_pos: cursor_pos.unwrap_or(0),
|
||||||
height: height,
|
height: height,
|
||||||
width: width,
|
width: width,
|
||||||
dirty: true,
|
dirty: true,
|
||||||
|
|
Loading…
Reference in New Issue