| 202 | } |
| 203 | |
| 204 | fn display(file: &File) { |
| 205 | // Assemble bytes into a buffer. |
| 206 | // The buffer is sent to the VGA driver without further copying |
| 207 | let buffer_limit = 8000; // Maximum number of bytes |
| 208 | let (mut mem_handle, _) = syscalls::malloc(buffer_limit as u64, 0).unwrap(); |
| 209 | let mut buffer = Buffer(mem_handle.as_mut_slice(buffer_limit), 0); |
| 210 | |
| 211 | // Move cursor to (0,0) |
| 212 | // Set background to blue (44m); foreground white (37m) |
| 213 | write!(buffer, "\x1b[H\x1b[44m\x1b[37m {}", &file.path); |
| 214 | if file.changed { |
| 215 | // Foreground yellow (33m) |
| 216 | write!(buffer, " \x1b[33mchanged\x1b[37m"); |
| 217 | } else { |
| 218 | write!(buffer, " "); |
| 219 | } |
| 220 | // Clear to the right (K), reset colors |
| 221 | write!(buffer, " \x1b[36m^S Save ^Q Quit\x1b[K\x1b[m\n"); |
| 222 | |
| 223 | // Count lines as they are printed |
| 224 | let mut line_number = file.line_start; |
| 225 | let final_line = file.line_start + 24; |
| 226 | let mut line_start = true; |
| 227 | |
| 228 | // Note: Since we don't erase everything, |
| 229 | // we need to erase the end of each incomplete line |
| 230 | for (piece_index, piece) in file.pieces.iter().enumerate() { |
| 231 | if piece_index < file.display_start.piece { |
| 232 | continue; |
| 233 | } |
| 234 | |
| 235 | let mut cursor_pos = file.cursor.pos; |
| 236 | |
| 237 | let bytes = if piece_index == file.display_start.piece { |
| 238 | if cursor_pos < file.display_start.pos { |
| 239 | cursor_pos = 0; |
| 240 | } else { |
| 241 | cursor_pos -= file.display_start.pos; |
| 242 | } |
| 243 | match piece { |
| 244 | Piece::Original{start: start, |
| 245 | len: len} => { |
| 246 | &file.original[(*start + file.display_start.pos)..(start + len)] |
| 247 | }, |
| 248 | Piece::Add{start: start, |
| 249 | len: len} => { |
| 250 | &file.add[(*start + file.display_start.pos)..(start + len)] |
| 251 | } |
| 252 | } |
| 253 | } else { |
| 254 | match piece { |
| 255 | Piece::Original{start: start, |
| 256 | len: len} => { |
| 257 | &file.original[(*start)..(start + len)] |
| 258 | }, |
| 259 | Piece::Add{start: start, |
| 260 | len: len} => { |
| 261 | &file.add[(*start)..(start + len)] |