Skip to content

Commit

Permalink
Refactor uibuf sizing
Browse files Browse the repository at this point in the history
  • Loading branch information
gchp committed Dec 3, 2014
1 parent 294564a commit c9ee454
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ before_script:
- cargo -V
script:
- cargo build -v
- cargo test view -v
- cargo test -v
20 changes: 10 additions & 10 deletions src/iota/uibuf.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
extern crate rustbox;

use utils;

pub struct UIBuffer {
width: uint,
height: uint,
cells: Vec<Vec<Cell>>
}

impl UIBuffer {
pub fn new() -> UIBuffer {
let cells = Cell::create_grid(' ');
pub fn new(width: uint, height: uint) -> UIBuffer {
let cells = Cell::create_grid(width, height, ' ');

UIBuffer {
width: width,
height: height,
cells: cells,
}
}
Expand All @@ -26,7 +29,7 @@ impl UIBuffer {

/// Recreated the entire grid, will cells containing `ch`.
pub fn fill(&mut self, ch: char) {
self.cells = Cell::create_grid(ch);
self.cells = Cell::create_grid(self.width, self.height, ch);
}

/// Update the `ch` attribute of an individual cell
Expand Down Expand Up @@ -64,14 +67,11 @@ impl Cell {
}
}

pub fn create_grid(ch: char) -> Vec<Vec<Cell>> {
let term_height = utils::get_term_height();
let term_width = utils::get_term_width();

pub fn create_grid(width: uint, height: uint, ch: char) -> Vec<Vec<Cell>> {
let mut rows = Vec::new();
for voffset in range(0, term_height) {
for voffset in range(0, height) {
let mut cells = Vec::new();
for boffset in range(0, term_width) {
for boffset in range(0, width) {
let mut cell = Cell::new();
cell.x = boffset;
cell.y = voffset;
Expand Down
14 changes: 4 additions & 10 deletions src/iota/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ impl<'v> View<'v> {
None => Buffer::new_empty(),
};

let uibuf = UIBuffer::new();
let term_width = utils::get_term_width();
let term_height = utils::get_term_height();
let uibuf = UIBuffer::new(term_width, term_height);
let mut cursor = Cursor::new();
cursor.set_line(Some(&buffer.lines[0]));

Expand Down Expand Up @@ -232,14 +234,13 @@ mod tests {
use cursor::{Cursor, Direction};
use view::View;
use uibuf::UIBuffer;
use utils;

fn setup_view<'v>() -> View<'v> {
let mut view = View {
buffer: Buffer::new(),
top_line_num: 0,
cursor: Cursor::new(),
uibuf: UIBuffer::new(),
uibuf: UIBuffer::new(50, 50),
threshold: 5,
};

Expand Down Expand Up @@ -323,11 +324,4 @@ mod tests {

assert_eq!(view.cursor.get_line().borrow().data, "testsecond".to_string());
}

#[test]
fn test_get_internal_height() {
let view = setup_view();
let term_height = utils::get_term_height();
assert_eq!(view.get_internal_height(), term_height - 2);
}
}

0 comments on commit c9ee454

Please sign in to comment.