Rewrites the status line at the bottom of the `console`, using the previously queried `console_size`. It is the responsibility of the caller to move the cursor back to the appropriate location after calling this function, and the caller should also hide the cursor before calling this function.
(&self, console: &mut dyn Console, console_size: CharsXY)
| 145 | /// after calling this function, and the caller should also hide the cursor before calling this |
| 146 | /// function. |
| 147 | fn refresh_status(&self, console: &mut dyn Console, console_size: CharsXY) -> io::Result<()> { |
| 148 | // Even though we track file positions as 0-indexed, display them as 1-indexed for a better |
| 149 | // user experience given that this is what all other editor seem to do. |
| 150 | let dirty_marker = if self.dirty { "*" } else { "" }; |
| 151 | let long_details = format!( |
| 152 | " | {}{} | Ln {}, Col {} ", |
| 153 | self.name.as_deref().unwrap_or("<NO NAME>"), |
| 154 | dirty_marker, |
| 155 | self.file_pos.line + 1, |
| 156 | self.file_pos.col + 1 |
| 157 | ); |
| 158 | |
| 159 | let width = usize::from(console_size.x); |
| 160 | let mut status = String::with_capacity(width); |
| 161 | if KEYS_SUMMARY.len() + long_details.len() >= width { |
| 162 | let short_details = format!(" {}:{} ", self.file_pos.line + 1, self.file_pos.col + 1); |
| 163 | if short_details.len() < width { |
| 164 | while status.len() < width - short_details.len() { |
| 165 | status.push(' '); |
| 166 | } |
| 167 | } |
| 168 | status.push_str(&short_details); |
| 169 | } else { |
| 170 | status.push_str(KEYS_SUMMARY); |
| 171 | while status.len() < width - long_details.len() { |
| 172 | status.push(' '); |
| 173 | } |
| 174 | status.push_str(&long_details); |
| 175 | } |
| 176 | status.truncate(width); |
| 177 | |
| 178 | console.locate(CharsXY::new(0, console_size.y - 1))?; |
| 179 | console.set_color(STATUS_COLOR.0, STATUS_COLOR.1)?; |
| 180 | console.write(&status)?; |
| 181 | Ok(()) |
| 182 | } |
| 183 | |
| 184 | /// Refreshes the contents of the whole `console`, using the previously queried `console_size`. |
| 185 | /// |
no test coverage detected