some changes but tui::update() still doesn't work

This commit is contained in:
Steven Hugg 2014-01-16 19:23:22 -05:00
parent cae5e36d74
commit e6eb6f97e7
2 changed files with 28 additions and 19 deletions

View File

@ -21,6 +21,7 @@ pub static BLACK: u8 = 0;
pub static WHITE: u8 = 15; pub static WHITE: u8 = 15;
pub static EMPTY: TermCell = TermCell { fg:WHITE, bg:BLACK, ch:' ' }; pub static EMPTY: TermCell = TermCell { fg:WHITE, bg:BLACK, ch:' ' };
pub static UNKNOWN: TermCell = TermCell { fg:255, bg:255, ch:'\uffff' };
#[deriving(Clone)] #[deriving(Clone)]
pub struct Buffer pub struct Buffer
@ -50,6 +51,8 @@ pub struct Terminal
lastbuf: Buffer, lastbuf: Buffer,
} }
static NEXTLINE: &'static str = "\r\x1b[1B";
impl Terminal impl Terminal
{ {
pub fn new() -> Terminal pub fn new() -> Terminal
@ -65,32 +68,31 @@ impl Terminal
fn update(&mut self, buf: &Buffer) fn update(&mut self, buf: &Buffer)
{ {
let ref mut hout = self.hout; let ref mut hout = self.hout;
let mut prev = EMPTY; let mut prev = UNKNOWN;
for y in range(0,buf.height) for y in range(0,buf.height)
{ {
let mut blanks = 0;
for x in range(0,buf.width) for x in range(0,buf.width)
{ {
let cell = buf.buf[y][x]; let cell = buf.buf[y][x];
let last = self.lastbuf.buf[y][x]; let last = self.lastbuf.buf[y][x];
let mut dirty = false; let dirty = cell.fg != prev.fg || cell.bg != prev.bg || cell.ch != last.ch;
if (cell.fg != prev.fg) if (dirty)
{ {
if blanks > 0
{
hout.write_str(format!("\x1b[{}C", blanks));
blanks = 0;
}
hout.write_str(format!("\x1b[38;5;{}m", cell.fg)); hout.write_str(format!("\x1b[38;5;{}m", cell.fg));
dirty = true;
}
if (cell.bg != prev.bg)
{
hout.write_str(format!("\x1b[48;5;{}m", cell.bg)); hout.write_str(format!("\x1b[48;5;{}m", cell.bg));
dirty = true;
}
// TODO
//if (dirty || cell.ch != last.ch)
{
hout.write_char(cell.ch); hout.write_char(cell.ch);
} else {
blanks += 1;
} }
prev = cell; prev = cell;
} }
hout.write_char('\n'); hout.write_str(NEXTLINE);
} }
} }
@ -106,7 +108,7 @@ impl Terminal
hout.write_str(format!("\x1b[48;5;{}m", cell.bg)); hout.write_str(format!("\x1b[48;5;{}m", cell.bg));
hout.write_char(cell.ch); hout.write_char(cell.ch);
} }
hout.write_char('\n'); hout.write_str(NEXTLINE);
} }
} }
@ -118,9 +120,11 @@ impl Terminal
// scroll up N lines // scroll up N lines
self.hout.write_str(format!("\x1b[{}A", buf.height)); self.hout.write_str(format!("\x1b[{}A", buf.height));
// update dirty cells // update dirty cells
self.update(buf); // TODO: self.update(buf);
self.redraw(buf);
} else { } else {
// redraw entire window // redraw entire window
for i in range(0,buf.height) { self.hout.write_str("\n"); }
// TODO: rescroll window // TODO: rescroll window
self.redraw(buf); self.redraw(buf);
} }

13
tui.rs
View File

@ -53,9 +53,14 @@ fn draw_text_line(a2: &AppleII, buf: &mut Buffer, flash: bool, y: uint)
} }
// if the char. changed, draw it // if the char. changed, draw it
let ch = (b & 0x7f) as char; let ch = (b & 0x7f) as char;
let cell = lazyterm::TermCell { fg:lazyterm::WHITE, bg:lazyterm::BLACK, ch:ch }; let mut cell = if !invert {
buf.set(x, y, cell); lazyterm::TermCell { bg:lazyterm::BLACK, fg:lazyterm::WHITE, ch:ch }
//drawTextChar(x, y, b & 0x7f, invert); } else {
lazyterm::TermCell { bg:lazyterm::WHITE, fg:lazyterm::BLACK, ch:ch }
};
buf.set(x*2, y, cell);
cell.ch = ' ';
buf.set(x*2+1, y, cell);
} }
} }
@ -79,7 +84,7 @@ fn main()
cpu.reset(); cpu.reset();
let mut term = Terminal::new(); let mut term = Terminal::new();
let mut buf = Buffer::new(40,24); let mut buf = Buffer::new(80,24);
// mismatched types: expected `<generic integer #5>` but found `<generic float #0>` // mismatched types: expected `<generic integer #5>` but found `<generic float #0>`
let speedup = 2; let speedup = 2;