use std::cell::RefCell;
use ncurses::*;
use ui::color::COLOR_DEFAULT;
use ui::rendered_line::MatchedLine;
static WINDOW_HEIGHT: i32 = 2500;
pub struct Content {
pub window: WINDOW,
pub state: RefCell<State>,
}
impl Content {
pub fn new(width: i32) -> Content {
Content {
window: newpad(WINDOW_HEIGHT, width),
state: RefCell::new(State::default()),
}
}
pub fn clear(&self) {
wclear(self.window);
}
pub fn resize(&self, width: i32) {
wresize(self.window, WINDOW_HEIGHT, width);
wrefresh(self.window);
}
pub fn height(&self) -> i32 {
let mut current_x: i32 = 0;
let mut current_y: i32 = 0;
getyx(self.window, &mut current_y, &mut current_x);
current_y
}
pub fn calculate_height_change<F>(&self, callback: F) -> i32
where F: Fn()
{
let initial_height = self.height();
callback();
self.height() - initial_height
}
pub fn highlighted_line(&self) -> MatchedLine {
let state = self.state.borrow();
MatchedLine::new(state.highlighted_line, state.highlighted_match)
}
}
pub struct State {
pub attributes: Vec<(usize, fn() -> attr_t)>,
pub foreground: i16,
pub background: i16,
pub highlighted_line: usize,
pub highlighted_match: usize,
}
impl State {
pub fn default() -> State {
State {
attributes: vec![],
foreground: COLOR_DEFAULT,
background: COLOR_DEFAULT,
highlighted_line: 0,
highlighted_match: 0,
}
}
pub fn remove_attribute(&mut self, attr_id: usize) {
let index_option = self.attributes.iter().position(|cur| cur.0 == attr_id);
if let Some(index) = index_option {
self.attributes.remove(index);
}
}
}