Wrap text in a unicode-aware way

This commit is contained in:
Joscha 2022-05-28 20:55:22 +02:00
parent 8fae7d2bf1
commit 37634139b0
5 changed files with 164 additions and 0 deletions

View file

@ -5,6 +5,7 @@ use crossterm::style::ContentStyle;
use crate::buffer::Buffer;
pub use crate::buffer::{Pos, Size};
use crate::widthdb::WidthDB;
use crate::wrap;
#[derive(Debug, Default)]
pub struct Frame {
@ -55,6 +56,10 @@ impl Frame {
self.widthdb.width(s)
}
pub fn wrap(&mut self, text: &str, width: usize) -> Vec<usize> {
wrap::wrap(text, width, &mut self.widthdb)
}
pub fn write(&mut self, pos: Pos, content: &str, style: ContentStyle) {
self.buffer.write(&mut self.widthdb, pos, content, style);
}