Add glyphon renderer
This commit is contained in:
parent
11384d0c33
commit
65b613e6e4
7 changed files with 1511 additions and 919 deletions
619
src/main.rs
619
src/main.rs
|
|
@ -14,17 +14,21 @@ use alacritty_terminal::{
|
|||
};
|
||||
use cosmic_text::{
|
||||
Attrs, AttrsList, Buffer, BufferLine, Family, FontSystem, Metrics, Shaping, Style, SwashCache,
|
||||
SwashContent, Weight, Wrap,
|
||||
Weight, Wrap,
|
||||
};
|
||||
use std::{mem, num::NonZeroU32, rc::Rc, slice, sync::Arc, time::Instant};
|
||||
use tiny_skia::{ColorU8, Paint, PixmapMut, PixmapPaint, PixmapRef, Rect, Transform};
|
||||
use std::{mem, rc::Rc, sync::Arc, time::Instant};
|
||||
use winit::{
|
||||
event::{ElementState, Event as WinitEvent, KeyEvent, Modifiers, WindowEvent},
|
||||
event::{
|
||||
ElementState, Event as WinitEvent, KeyboardInput, ModifiersState, VirtualKeyCode,
|
||||
WindowEvent,
|
||||
},
|
||||
event_loop::{ControlFlow, EventLoopBuilder, EventLoopProxy},
|
||||
keyboard::{Key, ModifiersState, NamedKey},
|
||||
window::WindowBuilder,
|
||||
};
|
||||
|
||||
use self::renderer::Renderer;
|
||||
mod renderer;
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
struct Size {
|
||||
width: f32,
|
||||
|
|
@ -132,6 +136,8 @@ fn colors() -> Colors {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
env_logger::init();
|
||||
|
||||
let mut font_system = FontSystem::new();
|
||||
let mut swash_cache = SwashCache::new();
|
||||
let metrics = Metrics::new(14.0, 20.0);
|
||||
|
|
@ -147,9 +153,7 @@ fn main() {
|
|||
};
|
||||
println!("{}, {}", cell_width, cell_height);
|
||||
|
||||
let event_loop = EventLoopBuilder::<TermEvent>::with_user_event()
|
||||
.build()
|
||||
.unwrap();
|
||||
let event_loop = EventLoopBuilder::<TermEvent>::with_user_event().build();
|
||||
let event_loop_proxy = event_loop.create_proxy();
|
||||
let window = Rc::new(WindowBuilder::new().build(&event_loop).unwrap());
|
||||
let (width, height) = {
|
||||
|
|
@ -180,380 +184,253 @@ fn main() {
|
|||
let mut notifier = Notifier(pty_event_loop.channel());
|
||||
let pty_join_handle = pty_event_loop.spawn();
|
||||
|
||||
let context = softbuffer::Context::new(window.clone()).unwrap();
|
||||
let mut surface = softbuffer::Surface::new(&context, window.clone()).unwrap();
|
||||
let mut modifiers = Modifiers::default();
|
||||
event_loop
|
||||
.run(move |event, elwt| {
|
||||
elwt.set_control_flow(ControlFlow::Wait);
|
||||
let mut renderer = Renderer::new(window.clone()).unwrap();
|
||||
let mut modifiers = ModifiersState::default();
|
||||
event_loop.run(move |event, _elwt, control_flow| {
|
||||
*control_flow = ControlFlow::Wait;
|
||||
|
||||
match event {
|
||||
WinitEvent::WindowEvent {
|
||||
window_id,
|
||||
event: WindowEvent::RedrawRequested,
|
||||
} if window_id == window.id() => {
|
||||
let instant = Instant::now();
|
||||
match event {
|
||||
WinitEvent::RedrawRequested(window_id) if window_id == window.id() => {
|
||||
let instant = Instant::now();
|
||||
|
||||
let (width, height) = {
|
||||
let size = window.inner_size();
|
||||
(size.width, size.height)
|
||||
};
|
||||
surface
|
||||
.resize(
|
||||
NonZeroU32::new(width).unwrap(),
|
||||
NonZeroU32::new(height).unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
renderer.render(&mut buffer, &mut font_system, &mut swash_cache);
|
||||
|
||||
let mut surface_buffer = surface.buffer_mut().unwrap();
|
||||
let surface_buffer_u8 = unsafe {
|
||||
slice::from_raw_parts_mut(
|
||||
surface_buffer.as_mut_ptr() as *mut u8,
|
||||
surface_buffer.len() * 4,
|
||||
)
|
||||
};
|
||||
let mut pixmap =
|
||||
PixmapMut::from_bytes(surface_buffer_u8, width, height).unwrap();
|
||||
pixmap.fill(tiny_skia::Color::from_rgba8(0, 0, 0, 0xFF));
|
||||
|
||||
// Set scroll to view scroll
|
||||
//TODO buffer.set_scroll(*scroll);
|
||||
// Set size, will relayout and shape until scroll if changed
|
||||
buffer.set_size(&mut font_system, width as f32, height as f32);
|
||||
// Shape until scroll, ensures scroll is clamped
|
||||
buffer.shape_until_scroll(&mut font_system, true);
|
||||
// Update scroll after buffer clamps it
|
||||
//TODO *scroll = buffer.scroll();
|
||||
|
||||
let mut paint = Paint::default();
|
||||
paint.anti_alias = false;
|
||||
let pixmap_paint = PixmapPaint::default();
|
||||
let transform = Transform::identity();
|
||||
for run in buffer.layout_runs() {
|
||||
for glyph in run.glyphs.iter() {
|
||||
let physical_glyph = glyph.physical((0., 0.), 1.0);
|
||||
|
||||
let glyph_color = match glyph.color_opt {
|
||||
Some(some) => some,
|
||||
None => cosmic_text::Color::rgb(0xFF, 0xFF, 0xFF),
|
||||
};
|
||||
|
||||
let background_color = cosmic_text::Color(glyph.metadata as u32);
|
||||
if background_color.0 != 0xFF000000 {
|
||||
//TODO: Have to swap RGB for BGR
|
||||
paint.set_color_rgba8(
|
||||
background_color.b(),
|
||||
background_color.g(),
|
||||
background_color.r(),
|
||||
background_color.a(),
|
||||
);
|
||||
pixmap.fill_rect(
|
||||
Rect::from_xywh(
|
||||
glyph.x,
|
||||
run.line_top,
|
||||
glyph.w,
|
||||
metrics.line_height,
|
||||
)
|
||||
.unwrap(),
|
||||
&paint,
|
||||
transform,
|
||||
None,
|
||||
);
|
||||
}
|
||||
|
||||
match swash_cache.get_image(&mut font_system, physical_glyph.cache_key)
|
||||
{
|
||||
Some(image) if !image.data.is_empty() => {
|
||||
let mut data = Vec::with_capacity(
|
||||
(image.placement.width * image.placement.height) as usize,
|
||||
);
|
||||
match image.content {
|
||||
SwashContent::Mask => {
|
||||
let mut i = 0;
|
||||
while i < image.data.len() {
|
||||
//TODO: Have to swap RGB for BGR
|
||||
data.push(
|
||||
ColorU8::from_rgba(
|
||||
glyph_color.b(),
|
||||
glyph_color.g(),
|
||||
glyph_color.r(),
|
||||
image.data[i],
|
||||
)
|
||||
.premultiply(),
|
||||
);
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
SwashContent::Color => {
|
||||
let mut i = 0;
|
||||
while i < image.data.len() {
|
||||
//TODO: Have to swap RGB for BGR
|
||||
data.push(
|
||||
ColorU8::from_rgba(
|
||||
image.data[i + 2],
|
||||
image.data[i + 1],
|
||||
image.data[i],
|
||||
image.data[i + 3],
|
||||
)
|
||||
.premultiply(),
|
||||
);
|
||||
i += 4;
|
||||
}
|
||||
}
|
||||
SwashContent::SubpixelMask => {
|
||||
todo!("TODO: SubpixelMask");
|
||||
}
|
||||
}
|
||||
|
||||
let glyph_pixmap = PixmapRef::from_bytes(
|
||||
unsafe {
|
||||
slice::from_raw_parts(
|
||||
data.as_ptr() as *const u8,
|
||||
data.len() * 4,
|
||||
)
|
||||
},
|
||||
image.placement.width,
|
||||
image.placement.height,
|
||||
)
|
||||
.unwrap();
|
||||
pixmap.draw_pixmap(
|
||||
physical_glyph.x + image.placement.left,
|
||||
run.line_y as i32 + physical_glyph.y - image.placement.top,
|
||||
glyph_pixmap,
|
||||
&pixmap_paint,
|
||||
transform,
|
||||
None,
|
||||
);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
println!("draw {:?}", instant.elapsed());
|
||||
}
|
||||
WinitEvent::WindowEvent {
|
||||
event: WindowEvent::ReceivedCharacter(c),
|
||||
window_id,
|
||||
} if window_id == window.id() => {
|
||||
match (modifiers.logo(), modifiers.ctrl(), modifiers.alt()) {
|
||||
(true, _, _) => {} // Ignore super
|
||||
(false, true, _) => {
|
||||
// Control keys
|
||||
if c >= 'a' && c <= 'z' {
|
||||
notifier.notify(vec![(c as u8) - b'a' + 1]);
|
||||
}
|
||||
}
|
||||
buffer.set_redraw(false);
|
||||
|
||||
surface_buffer.present().unwrap();
|
||||
|
||||
println!("draw {:?}", instant.elapsed());
|
||||
}
|
||||
WinitEvent::WindowEvent {
|
||||
event:
|
||||
WindowEvent::KeyboardInput {
|
||||
event:
|
||||
KeyEvent {
|
||||
logical_key,
|
||||
text: text_opt,
|
||||
state: ElementState::Pressed,
|
||||
..
|
||||
},
|
||||
..
|
||||
},
|
||||
window_id,
|
||||
} if window_id == window.id() => {
|
||||
println!("{:?} {:?}", modifiers, text_opt);
|
||||
match (
|
||||
modifiers.state().contains(ModifiersState::SUPER),
|
||||
modifiers.state().contains(ModifiersState::CONTROL),
|
||||
modifiers.state().contains(ModifiersState::ALT),
|
||||
) {
|
||||
(true, _, _) => {} // Ignore super
|
||||
(false, true, _) => match text_opt {
|
||||
Some(text) if text.len() == 1 => {
|
||||
// Control keys
|
||||
let c = text.chars().next().unwrap_or_default();
|
||||
if c >= 'a' && c <= 'z' {
|
||||
notifier.notify(vec![(c as u8) - b'a' + 1]);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
(false, false, true) => match text_opt {
|
||||
Some(text) => {
|
||||
// Alt keys
|
||||
//TODO: handle alt keys with no text
|
||||
let mut bytes = text.as_bytes().to_vec();
|
||||
bytes.insert(0, b'\x1B');
|
||||
notifier.notify(bytes);
|
||||
}
|
||||
None => {}
|
||||
},
|
||||
(false, false, false) => match text_opt {
|
||||
Some(text) => {
|
||||
notifier.notify(text.as_bytes().to_vec());
|
||||
}
|
||||
None => match logical_key {
|
||||
Key::Named(NamedKey::ArrowUp) => {
|
||||
notifier.notify(b"\x1B[A".as_slice());
|
||||
}
|
||||
Key::Named(NamedKey::ArrowDown) => {
|
||||
notifier.notify(b"\x1B[B".as_slice());
|
||||
}
|
||||
Key::Named(NamedKey::ArrowRight) => {
|
||||
notifier.notify(b"\x1B[C".as_slice());
|
||||
}
|
||||
Key::Named(NamedKey::ArrowLeft) => {
|
||||
notifier.notify(b"\x1B[D".as_slice());
|
||||
}
|
||||
Key::Named(NamedKey::End) => {
|
||||
notifier.notify(b"\x1B[F".as_slice());
|
||||
}
|
||||
Key::Named(NamedKey::Home) => {
|
||||
notifier.notify(b"\x1B[H".as_slice());
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
},
|
||||
(false, false, true) => {
|
||||
// Alt keys
|
||||
let mut buf = [0x1B, 0, 0, 0, 0];
|
||||
let str = c.encode_utf8(&mut buf[1..]);
|
||||
notifier.notify(str.as_bytes().to_vec());
|
||||
}
|
||||
(false, false, false) => {
|
||||
let mut buf = [0, 0, 0, 0];
|
||||
let str = c.encode_utf8(&mut buf);
|
||||
notifier.notify(str.as_bytes().to_vec());
|
||||
}
|
||||
}
|
||||
WinitEvent::WindowEvent {
|
||||
event: WindowEvent::ModifiersChanged(new_modifiers),
|
||||
window_id,
|
||||
} if window_id == window.id() => {
|
||||
modifiers = new_modifiers;
|
||||
}
|
||||
WinitEvent::WindowEvent {
|
||||
event: WindowEvent::Resized(physical_size),
|
||||
window_id,
|
||||
} if window_id == window.id() => {
|
||||
dimensions.width = physical_size.width as f32;
|
||||
dimensions.height = physical_size.height as f32;
|
||||
notifier.on_resize(dimensions.into());
|
||||
term.lock().resize(dimensions);
|
||||
window.request_redraw();
|
||||
}
|
||||
WinitEvent::WindowEvent {
|
||||
event: WindowEvent::CloseRequested,
|
||||
window_id,
|
||||
} if window_id == window.id() => {
|
||||
term.lock().exit();
|
||||
}
|
||||
WinitEvent::UserEvent(user_event) => {
|
||||
println!("{:?}", user_event);
|
||||
match user_event {
|
||||
TermEvent::Exit => elwt.exit(),
|
||||
TermEvent::PtyWrite(text) => notifier.notify(text.into_bytes()),
|
||||
TermEvent::Title(title) => {
|
||||
window.set_title(&title);
|
||||
}
|
||||
WinitEvent::WindowEvent {
|
||||
event:
|
||||
WindowEvent::KeyboardInput {
|
||||
input:
|
||||
KeyboardInput {
|
||||
state: ElementState::Pressed,
|
||||
virtual_keycode: Some(virtual_keycode),
|
||||
..
|
||||
},
|
||||
..
|
||||
},
|
||||
window_id,
|
||||
} if window_id == window.id() => {
|
||||
match (modifiers.logo(), modifiers.ctrl(), modifiers.alt()) {
|
||||
(true, _, _) => {} // Ignore super
|
||||
(false, true, _) => {
|
||||
// Control keys will use ReceivedCharacter instead
|
||||
}
|
||||
(false, false, true) => {
|
||||
//TODO: support Alt keys without character
|
||||
}
|
||||
(false, false, false) => match virtual_keycode {
|
||||
VirtualKeyCode::Up => {
|
||||
notifier.notify(b"\x1B[A".as_slice());
|
||||
}
|
||||
VirtualKeyCode::Down => {
|
||||
notifier.notify(b"\x1B[B".as_slice());
|
||||
}
|
||||
VirtualKeyCode::Right => {
|
||||
notifier.notify(b"\x1B[C".as_slice());
|
||||
}
|
||||
VirtualKeyCode::Left => {
|
||||
notifier.notify(b"\x1B[D".as_slice());
|
||||
}
|
||||
VirtualKeyCode::End => {
|
||||
notifier.notify(b"\x1B[F".as_slice());
|
||||
}
|
||||
VirtualKeyCode::Home => {
|
||||
notifier.notify(b"\x1B[H".as_slice());
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
let instant = Instant::now();
|
||||
|
||||
//TODO: is redraw needed after all events?
|
||||
//TODO: use LineDamageBounds
|
||||
{
|
||||
let mut last_point = Point::new(Line(0), Column(0));
|
||||
let mut text = String::new();
|
||||
let mut attrs_list = AttrsList::new(default_attrs);
|
||||
let term_guard = term.lock();
|
||||
let grid = term_guard.grid();
|
||||
for indexed in grid.display_iter() {
|
||||
if indexed.point.line != last_point.line {
|
||||
let line_i = last_point.line.0 as usize;
|
||||
while line_i >= buffer.lines.len() {
|
||||
buffer.lines.push(BufferLine::new(
|
||||
"",
|
||||
AttrsList::new(default_attrs),
|
||||
Shaping::Advanced,
|
||||
));
|
||||
buffer.set_redraw(true);
|
||||
}
|
||||
|
||||
if buffer.lines[line_i].set_text(text.clone(), attrs_list.clone()) {
|
||||
buffer.set_redraw(true);
|
||||
}
|
||||
|
||||
text.clear();
|
||||
attrs_list.clear_spans();
|
||||
}
|
||||
//TODO: use indexed.point.column?
|
||||
|
||||
//TODO: skip leading spacer?
|
||||
if indexed.cell.flags.contains(Flags::WIDE_CHAR_SPACER) {
|
||||
// Skip wide spacers (cells after wide characters)
|
||||
continue;
|
||||
}
|
||||
|
||||
let start = text.len();
|
||||
text.push(indexed.cell.c);
|
||||
if let Some(zerowidth) = indexed.cell.zerowidth() {
|
||||
for &c in zerowidth {
|
||||
text.push(c);
|
||||
}
|
||||
}
|
||||
let end = text.len();
|
||||
|
||||
let convert_color = |color| {
|
||||
let rgb = match color {
|
||||
Color::Named(named_color) => match colors[named_color] {
|
||||
Some(rgb) => rgb,
|
||||
None => {
|
||||
eprintln!("missing named color {:?}", named_color);
|
||||
Rgb::default()
|
||||
}
|
||||
},
|
||||
Color::Spec(rgb) => rgb,
|
||||
Color::Indexed(index) => match colors[index as usize] {
|
||||
Some(rgb) => rgb,
|
||||
None => {
|
||||
eprintln!("missing indexed color {}", index);
|
||||
Rgb::default()
|
||||
}
|
||||
},
|
||||
};
|
||||
cosmic_text::Color::rgb(rgb.r, rgb.g, rgb.b)
|
||||
};
|
||||
|
||||
let mut attrs = default_attrs;
|
||||
let mut fg = convert_color(indexed.cell.fg);
|
||||
let mut bg = convert_color(indexed.cell.bg);
|
||||
//TODO: better handling of cursor
|
||||
if indexed.point == grid.cursor.point {
|
||||
mem::swap(&mut fg, &mut bg);
|
||||
}
|
||||
attrs = attrs.color(fg);
|
||||
// Use metadata as background color
|
||||
attrs = attrs.metadata(bg.0 as usize);
|
||||
//TODO: more flags
|
||||
if indexed.cell.flags.contains(Flags::BOLD) {
|
||||
attrs = attrs.weight(Weight::BOLD);
|
||||
}
|
||||
if indexed.cell.flags.contains(Flags::ITALIC) {
|
||||
attrs = attrs.style(Style::Italic);
|
||||
}
|
||||
if attrs != attrs_list.defaults() {
|
||||
attrs_list.add_span(start..end, attrs);
|
||||
}
|
||||
|
||||
last_point = indexed.point;
|
||||
}
|
||||
|
||||
//TODO: do not repeat!
|
||||
let line_i = last_point.line.0 as usize;
|
||||
while line_i >= buffer.lines.len() {
|
||||
buffer.lines.push(BufferLine::new(
|
||||
"",
|
||||
AttrsList::new(default_attrs),
|
||||
Shaping::Advanced,
|
||||
));
|
||||
buffer.set_redraw(true);
|
||||
}
|
||||
|
||||
if buffer.lines[line_i].set_text(text, attrs_list) {
|
||||
buffer.set_redraw(true);
|
||||
}
|
||||
}
|
||||
|
||||
if buffer.redraw() {
|
||||
window.request_redraw();
|
||||
}
|
||||
|
||||
println!("buffer update {:?}", instant.elapsed());
|
||||
},
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
})
|
||||
.unwrap();
|
||||
WinitEvent::WindowEvent {
|
||||
event: WindowEvent::ModifiersChanged(new_modifiers),
|
||||
window_id,
|
||||
} if window_id == window.id() => {
|
||||
modifiers = new_modifiers;
|
||||
}
|
||||
WinitEvent::WindowEvent {
|
||||
event: WindowEvent::Resized(physical_size),
|
||||
window_id,
|
||||
} if window_id == window.id() => {
|
||||
let instant = Instant::now();
|
||||
|
||||
dimensions.width = physical_size.width as f32;
|
||||
dimensions.height = physical_size.height as f32;
|
||||
|
||||
notifier.on_resize(dimensions.into());
|
||||
|
||||
term.lock().resize(dimensions);
|
||||
|
||||
buffer.set_size(
|
||||
&mut font_system,
|
||||
dimensions.width as f32,
|
||||
dimensions.height as f32,
|
||||
);
|
||||
|
||||
renderer.resize(physical_size.width, physical_size.height);
|
||||
|
||||
println!("resize {:?}", instant.elapsed());
|
||||
}
|
||||
WinitEvent::WindowEvent {
|
||||
event: WindowEvent::CloseRequested,
|
||||
window_id,
|
||||
} if window_id == window.id() => {
|
||||
term.lock().exit();
|
||||
}
|
||||
WinitEvent::UserEvent(user_event) => {
|
||||
println!("{:?}", user_event);
|
||||
match user_event {
|
||||
//TODO: other error codes?
|
||||
TermEvent::Exit => *control_flow = ControlFlow::ExitWithCode(0),
|
||||
TermEvent::PtyWrite(text) => notifier.notify(text.into_bytes()),
|
||||
TermEvent::Title(title) => {
|
||||
window.set_title(&title);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
let instant = Instant::now();
|
||||
|
||||
//TODO: is redraw needed after all events?
|
||||
//TODO: use LineDamageBounds
|
||||
{
|
||||
let mut last_point = Point::new(Line(0), Column(0));
|
||||
let mut text = String::new();
|
||||
let mut attrs_list = AttrsList::new(default_attrs);
|
||||
let term_guard = term.lock();
|
||||
let grid = term_guard.grid();
|
||||
for indexed in grid.display_iter() {
|
||||
if indexed.point.line != last_point.line {
|
||||
let line_i = last_point.line.0 as usize;
|
||||
while line_i >= buffer.lines.len() {
|
||||
buffer.lines.push(BufferLine::new(
|
||||
"",
|
||||
AttrsList::new(default_attrs),
|
||||
Shaping::Advanced,
|
||||
));
|
||||
buffer.set_redraw(true);
|
||||
}
|
||||
|
||||
if buffer.lines[line_i].set_text(text.clone(), attrs_list.clone()) {
|
||||
buffer.set_redraw(true);
|
||||
}
|
||||
|
||||
text.clear();
|
||||
attrs_list.clear_spans();
|
||||
}
|
||||
//TODO: use indexed.point.column?
|
||||
|
||||
//TODO: skip leading spacer?
|
||||
if indexed.cell.flags.contains(Flags::WIDE_CHAR_SPACER) {
|
||||
// Skip wide spacers (cells after wide characters)
|
||||
continue;
|
||||
}
|
||||
|
||||
let start = text.len();
|
||||
text.push(indexed.cell.c);
|
||||
if let Some(zerowidth) = indexed.cell.zerowidth() {
|
||||
for &c in zerowidth {
|
||||
text.push(c);
|
||||
}
|
||||
}
|
||||
let end = text.len();
|
||||
|
||||
let convert_color = |color| {
|
||||
let rgb = match color {
|
||||
Color::Named(named_color) => match colors[named_color] {
|
||||
Some(rgb) => rgb,
|
||||
None => {
|
||||
eprintln!("missing named color {:?}", named_color);
|
||||
Rgb::default()
|
||||
}
|
||||
},
|
||||
Color::Spec(rgb) => rgb,
|
||||
Color::Indexed(index) => match colors[index as usize] {
|
||||
Some(rgb) => rgb,
|
||||
None => {
|
||||
eprintln!("missing indexed color {}", index);
|
||||
Rgb::default()
|
||||
}
|
||||
},
|
||||
};
|
||||
cosmic_text::Color::rgb(rgb.r, rgb.g, rgb.b)
|
||||
};
|
||||
|
||||
let mut attrs = default_attrs;
|
||||
let mut fg = convert_color(indexed.cell.fg);
|
||||
let mut bg = convert_color(indexed.cell.bg);
|
||||
//TODO: better handling of cursor
|
||||
if indexed.point == grid.cursor.point {
|
||||
mem::swap(&mut fg, &mut bg);
|
||||
}
|
||||
attrs = attrs.color(fg);
|
||||
// Use metadata as background color
|
||||
attrs = attrs.metadata(bg.0 as usize);
|
||||
//TODO: more flags
|
||||
if indexed.cell.flags.contains(Flags::BOLD) {
|
||||
attrs = attrs.weight(Weight::BOLD);
|
||||
}
|
||||
if indexed.cell.flags.contains(Flags::ITALIC) {
|
||||
attrs = attrs.style(Style::Italic);
|
||||
}
|
||||
if attrs != attrs_list.defaults() {
|
||||
attrs_list.add_span(start..end, attrs);
|
||||
}
|
||||
|
||||
last_point = indexed.point;
|
||||
}
|
||||
|
||||
//TODO: do not repeat!
|
||||
let line_i = last_point.line.0 as usize;
|
||||
while line_i >= buffer.lines.len() {
|
||||
buffer.lines.push(BufferLine::new(
|
||||
"",
|
||||
AttrsList::new(default_attrs),
|
||||
Shaping::Advanced,
|
||||
));
|
||||
buffer.set_redraw(true);
|
||||
}
|
||||
|
||||
if buffer.lines[line_i].set_text(text, attrs_list) {
|
||||
buffer.set_redraw(true);
|
||||
}
|
||||
}
|
||||
|
||||
buffer.shape_until_scroll(&mut font_system, true);
|
||||
|
||||
if buffer.redraw() {
|
||||
window.request_redraw();
|
||||
}
|
||||
|
||||
println!("buffer update {:?}", instant.elapsed());
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
});
|
||||
|
||||
//TODO: hangs after event loop exit pty_join_handle.join().unwrap();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue