|
|
|
@ -1,35 +1,5 @@
|
|
|
|
|
use ui::components::*;
|
|
|
|
|
use ui::cells::*;
|
|
|
|
|
///A simple box with borders and no content.
|
|
|
|
|
pub struct BoxPanel {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Component for BoxPanel {
|
|
|
|
|
fn draw(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) {
|
|
|
|
|
let upper_left = upper_left!(area);
|
|
|
|
|
let bottom_right = bottom_right!(area);
|
|
|
|
|
grid[upper_left].set_ch('u');
|
|
|
|
|
grid[bottom_right].set_ch('b');
|
|
|
|
|
let width = get_x(bottom_right) - get_x(upper_left);
|
|
|
|
|
let height = get_y(bottom_right) - get_y(upper_left);
|
|
|
|
|
|
|
|
|
|
grid[upper_left].set_ch('┌');
|
|
|
|
|
grid[(get_x(upper_left), get_y(bottom_right))].set_ch(BOTTOM_LEFT_CORNER);
|
|
|
|
|
grid[(get_x(bottom_right), get_y(upper_left))].set_ch('┐');
|
|
|
|
|
grid[bottom_right].set_ch('┘');
|
|
|
|
|
for i in get_y(upper_left) + 1..get_y(bottom_right) {
|
|
|
|
|
grid[(get_x(upper_left), i)].set_ch('│');
|
|
|
|
|
grid[(get_x(upper_left) + width, i)].set_ch('│');
|
|
|
|
|
}
|
|
|
|
|
for i in get_x(upper_left)+1..get_x(bottom_right) {
|
|
|
|
|
grid[(i, get_y(upper_left))].set_ch('─');
|
|
|
|
|
grid[(i, get_y(upper_left) + height)].set_ch('─');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fn process_event(&mut self, _event: &UIEvent, _context: &mut Context) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// A horizontally split in half container.
|
|
|
|
|
pub struct HSplit {
|
|
|
|
@ -116,6 +86,8 @@ impl Component for VSplit {
|
|
|
|
|
|
|
|
|
|
for i in get_y(upper_left)..=get_y(bottom_right) {
|
|
|
|
|
grid[(mid, i)].set_ch(VERT_BOUNDARY);
|
|
|
|
|
grid[(mid, i)].set_fg(Color::Default);
|
|
|
|
|
grid[(mid, i)].set_bg(Color::Default);
|
|
|
|
|
}
|
|
|
|
|
if get_y(bottom_right)> 1 {
|
|
|
|
|
let c = grid.get(mid, get_y(bottom_right)-1).map(|a| a.ch()).unwrap_or_else(|| ' ');
|
|
|
|
@ -142,42 +114,6 @@ impl Component for VSplit {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// A box with a text content.
|
|
|
|
|
pub struct TextBox {
|
|
|
|
|
content: String,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl TextBox {
|
|
|
|
|
pub fn new(s: String) -> Self {
|
|
|
|
|
TextBox {
|
|
|
|
|
content: s,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Component for TextBox {
|
|
|
|
|
fn draw(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) {
|
|
|
|
|
let upper_left = upper_left!(area);
|
|
|
|
|
let bottom_right = bottom_right!(area);
|
|
|
|
|
let mut x = get_x(upper_left);
|
|
|
|
|
let y = get_y(upper_left);
|
|
|
|
|
for c in self.content.chars() {
|
|
|
|
|
grid[(x,y)].set_ch(c);
|
|
|
|
|
x += 1;
|
|
|
|
|
if x == get_x(bottom_right) + 1 {
|
|
|
|
|
x = get_x(upper_left);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if y == get_y(bottom_right) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fn process_event(&mut self, _event: &UIEvent, _context: &mut Context) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// A pager for text.
|
|
|
|
|
/// `Pager` holds its own content in its own `CellBuffer` and when `draw` is called, it draws the
|
|
|
|
|
/// current view of the text. It is responsible for scrolling etc.
|
|
|
|
@ -196,12 +132,14 @@ impl Pager {
|
|
|
|
|
let height = lines.len();
|
|
|
|
|
let width = lines.iter().map(|l| l.len()).max().unwrap_or(0);
|
|
|
|
|
let mut content = CellBuffer::new(width, height, Cell::with_char(' '));
|
|
|
|
|
for (i, l) in lines.iter().enumerate() {
|
|
|
|
|
write_string_to_grid(l,
|
|
|
|
|
&mut content,
|
|
|
|
|
Color::Default,
|
|
|
|
|
Color::Default,
|
|
|
|
|
((0, i), (width -1, i)));
|
|
|
|
|
if width > 0 {
|
|
|
|
|
for (i, l) in lines.iter().enumerate() {
|
|
|
|
|
write_string_to_grid(l,
|
|
|
|
|
&mut content,
|
|
|
|
|
Color::Default,
|
|
|
|
|
Color::Default,
|
|
|
|
|
((0, i), (width -1, i)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Pager {
|
|
|
|
|
cursor_pos: 0,
|
|
|
|
@ -215,24 +153,24 @@ impl Pager {
|
|
|
|
|
|
|
|
|
|
impl Component for Pager {
|
|
|
|
|
fn draw(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) {
|
|
|
|
|
if !self.dirty {
|
|
|
|
|
if !self.is_dirty() {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
let upper_left = upper_left!(area);
|
|
|
|
|
let bottom_right = bottom_right!(area);
|
|
|
|
|
clear_area(grid,
|
|
|
|
|
(upper_left, bottom_right));
|
|
|
|
|
context.dirty_areas.push_back((upper_left, bottom_right));
|
|
|
|
|
|
|
|
|
|
if self.height == 0 {
|
|
|
|
|
self.dirty = false;
|
|
|
|
|
if self.height == 0 || self.height == self.cursor_pos {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
clear_area(grid,
|
|
|
|
|
(upper_left, bottom_right));
|
|
|
|
|
context.dirty_areas.push_back((upper_left, bottom_right));
|
|
|
|
|
|
|
|
|
|
let pager_context: usize = context.settings.pager.pager_context;
|
|
|
|
|
let pager_stop: bool = context.settings.pager.pager_stop;
|
|
|
|
|
let rows = get_y(bottom_right) - get_y(upper_left);
|
|
|
|
|
let page_length = rows / self.height;
|
|
|
|
|
self.dirty = false;
|
|
|
|
|
//let pager_context: usize = context.settings.pager.pager_context;
|
|
|
|
|
//let pager_stop: bool = context.settings.pager.pager_stop;
|
|
|
|
|
//let rows = get_y(bottom_right) - get_y(upper_left);
|
|
|
|
|
//let page_length = rows / self.height;
|
|
|
|
|
let mut inner_x = 0;
|
|
|
|
|
let mut inner_y = self.cursor_pos;
|
|
|
|
|
|
|
|
|
@ -267,6 +205,9 @@ impl Component for Pager {
|
|
|
|
|
self.dirty = true;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
UIEventType::ChangeMode(UIMode::Normal) => {
|
|
|
|
|
self.dirty = true;
|
|
|
|
|
},
|
|
|
|
|
_ => {
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
@ -279,8 +220,10 @@ impl Component for Pager {
|
|
|
|
|
/// Status bar.
|
|
|
|
|
pub struct StatusBar {
|
|
|
|
|
container: Entity,
|
|
|
|
|
position: usize,
|
|
|
|
|
status: String,
|
|
|
|
|
ex_buffer: String,
|
|
|
|
|
mode: UIMode,
|
|
|
|
|
height: usize,
|
|
|
|
|
dirty: bool,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -288,24 +231,31 @@ impl StatusBar {
|
|
|
|
|
pub fn new(container: Entity) -> Self {
|
|
|
|
|
StatusBar {
|
|
|
|
|
container: container,
|
|
|
|
|
position: 0,
|
|
|
|
|
status: String::with_capacity(250),
|
|
|
|
|
status: String::with_capacity(256),
|
|
|
|
|
ex_buffer: String::with_capacity(256),
|
|
|
|
|
dirty: true,
|
|
|
|
|
mode: UIMode::Normal,
|
|
|
|
|
height: 1,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fn draw_status_bar(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) {
|
|
|
|
|
if !self.dirty {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
self.dirty = false;
|
|
|
|
|
clear_area(grid, area);
|
|
|
|
|
let x = write_string_to_grid(&self.status,
|
|
|
|
|
write_string_to_grid(&self.status,
|
|
|
|
|
grid,
|
|
|
|
|
Color::Byte(36),
|
|
|
|
|
Color::Default,
|
|
|
|
|
area);
|
|
|
|
|
context.dirty_areas.push_back(area);
|
|
|
|
|
}
|
|
|
|
|
fn draw_execute_bar(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) {
|
|
|
|
|
clear_area(grid, area);
|
|
|
|
|
write_string_to_grid(&self.ex_buffer,
|
|
|
|
|
grid,
|
|
|
|
|
Color::Byte(124),
|
|
|
|
|
Color::Default,
|
|
|
|
|
area);
|
|
|
|
|
context.dirty_areas.push_back(area);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -313,24 +263,60 @@ impl Component for StatusBar {
|
|
|
|
|
fn draw(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) {
|
|
|
|
|
let upper_left = upper_left!(area);
|
|
|
|
|
let bottom_right = bottom_right!(area);
|
|
|
|
|
|
|
|
|
|
let total_rows = get_y(bottom_right) - get_y(upper_left);
|
|
|
|
|
if total_rows == 0 {
|
|
|
|
|
if total_rows <= self.height {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
let height = self.height;
|
|
|
|
|
|
|
|
|
|
let _ = self.container.component.draw(grid,
|
|
|
|
|
(upper_left, (get_x(bottom_right), get_y(bottom_right)-1)),
|
|
|
|
|
(upper_left, (get_x(bottom_right), get_y(bottom_right) - height)),
|
|
|
|
|
context);
|
|
|
|
|
|
|
|
|
|
if !self.is_dirty() {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
self.dirty = false;
|
|
|
|
|
self.draw_status_bar(grid, (set_y(upper_left, get_y(bottom_right)), bottom_right), context);
|
|
|
|
|
match self.mode {
|
|
|
|
|
UIMode::Normal => {
|
|
|
|
|
},
|
|
|
|
|
UIMode::Execute => {
|
|
|
|
|
self.draw_execute_bar(grid,
|
|
|
|
|
(set_y(upper_left, get_y(bottom_right) - height + 1), set_y(bottom_right, get_y(bottom_right) - height+1)),
|
|
|
|
|
context);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fn process_event(&mut self, event: &UIEvent, context: &mut Context) {
|
|
|
|
|
self.container.rcv_event(event, context);
|
|
|
|
|
match event.event_type {
|
|
|
|
|
UIEventType::RefreshMailbox(ref m) => {
|
|
|
|
|
self.status = format!("Mailbox: {}, Messages: {}, New: {}", m.folder.get_name(), m.collection.len(), m.collection.iter().filter(|e| !e.is_seen()).count());
|
|
|
|
|
self.status = format!("{} |Mailbox: {}, Messages: {}, New: {}", self.mode, m.folder.get_name(), m.collection.len(), m.collection.iter().filter(|e| !e.is_seen()).count());
|
|
|
|
|
self.dirty = true;
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
UIEventType::ChangeMode(m) => {
|
|
|
|
|
let offset = self.status.find('|').unwrap_or(self.status.len());
|
|
|
|
|
self.status.replace_range(..offset, &format!("{} ", m));
|
|
|
|
|
self.dirty = true;
|
|
|
|
|
self.mode = m;
|
|
|
|
|
match m {
|
|
|
|
|
UIMode::Normal => {
|
|
|
|
|
self.height = 1;
|
|
|
|
|
self.ex_buffer.clear()
|
|
|
|
|
},
|
|
|
|
|
UIMode::Execute => {
|
|
|
|
|
self.height = 2;
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
UIEventType::ExInput(Key::Char(c)) => {
|
|
|
|
|
self.dirty = true;
|
|
|
|
|
self.ex_buffer.push(c);
|
|
|
|
|
},
|
|
|
|
|
_ => {},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|