Merge remote-tracking branch 'upstream/main' into append

This commit is contained in:
Emma Tebibyte 2023-04-11 16:54:30 -04:00
commit 045b9eed99
1 changed files with 6 additions and 3 deletions

View File

@ -16,7 +16,7 @@
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
use std::io::{ stdin, stdout, Read, Stdout, Write };
use std::io::{stdout, Stdout, Write};
use crossterm::{
cursor,
@ -41,16 +41,19 @@ impl Buffer {
pub fn draw(&self, out: &mut (impl ExecutableCommand + Write)) -> Result<u32> {
let (cols, rows) = terminal::size()?;
let lr_width = self.text.len_lines().ilog10() + 1;
let gutter_width = lr_width + 1;
out.execute(cursor::MoveTo(0, 0))?;
for (row, line) in (0..rows).zip(self.text.lines()) {
write!(out, "{:width$} ", row, width = lr_width as usize)?;
write!(out, "{}", line.as_str().unwrap_or("").trim_end())?;
let width = line.len_chars().saturating_sub(1); // lop off whitespace
let rhs = width.min(cols as usize - gutter_width as usize);
write!(out, "{}", line.slice(0..rhs))?;
out.execute(cursor::MoveToNextLine(1))?;
}
Ok(lr_width + 1)
Ok(gutter_width)
}
pub fn clamped_cursor(&self, cursor: Cursor) -> Cursor {