Refreshes only the line under the cursor, using the previously queried `console_size`.
(
&self,
console: &mut dyn Console,
console_size: CharsXY,
)
| 214 | |
| 215 | /// Refreshes only the line under the cursor, using the previously queried `console_size`. |
| 216 | fn refresh_current_line( |
| 217 | &self, |
| 218 | console: &mut dyn Console, |
| 219 | console_size: CharsXY, |
| 220 | ) -> io::Result<()> { |
| 221 | debug_assert!(self.file_pos.line >= self.viewport_pos.line); |
| 222 | debug_assert!( |
| 223 | self.file_pos.line < self.viewport_pos.line + usize::from(console_size.y - 1) |
| 224 | ); |
| 225 | |
| 226 | let row = self.file_pos.line - self.viewport_pos.line; |
| 227 | let row = if cfg!(debug_assertions) { |
| 228 | u16::try_from(row).expect("Computed y must have fit on screen") |
| 229 | } else { |
| 230 | row as u16 |
| 231 | }; |
| 232 | |
| 233 | console.set_color(TEXT_COLOR.0, TEXT_COLOR.1)?; |
| 234 | console.locate(CharsXY::new(0, row))?; |
| 235 | console.clear(ClearType::CurrentLine)?; |
| 236 | |
| 237 | let line = &self.content[self.file_pos.line]; |
| 238 | if line.len() > self.viewport_pos.col { |
| 239 | console.write(&line.range( |
| 240 | self.viewport_pos.col, |
| 241 | self.viewport_pos.col + usize::from(console_size.x), |
| 242 | ))?; |
| 243 | } |
| 244 | Ok(()) |
| 245 | } |
| 246 | |
| 247 | /// Moves the cursor down by the given number of lines in `nlines` or to the last line if there |
| 248 | /// are insufficient lines to perform the move. |