forked from mars/breed
Merge remote-tracking branch 'upstream/main' into append
This commit is contained in:
commit
045b9eed99
|
@ -16,7 +16,7 @@
|
||||||
* along with this program. If not, see https://www.gnu.org/licenses/.
|
* 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::{
|
use crossterm::{
|
||||||
cursor,
|
cursor,
|
||||||
|
@ -41,16 +41,19 @@ impl Buffer {
|
||||||
pub fn draw(&self, out: &mut (impl ExecutableCommand + Write)) -> Result<u32> {
|
pub fn draw(&self, out: &mut (impl ExecutableCommand + Write)) -> Result<u32> {
|
||||||
let (cols, rows) = terminal::size()?;
|
let (cols, rows) = terminal::size()?;
|
||||||
let lr_width = self.text.len_lines().ilog10() + 1;
|
let lr_width = self.text.len_lines().ilog10() + 1;
|
||||||
|
let gutter_width = lr_width + 1;
|
||||||
|
|
||||||
out.execute(cursor::MoveTo(0, 0))?;
|
out.execute(cursor::MoveTo(0, 0))?;
|
||||||
|
|
||||||
for (row, line) in (0..rows).zip(self.text.lines()) {
|
for (row, line) in (0..rows).zip(self.text.lines()) {
|
||||||
write!(out, "{:width$} ", row, width = lr_width as usize)?;
|
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))?;
|
out.execute(cursor::MoveToNextLine(1))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(lr_width + 1)
|
Ok(gutter_width)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clamped_cursor(&self, cursor: Cursor) -> Cursor {
|
pub fn clamped_cursor(&self, cursor: Cursor) -> Cursor {
|
||||||
|
|
Loading…
Reference in New Issue