Add support for setting window title

This commit is contained in:
Joscha 2024-01-05 13:33:08 +01:00
parent 77b4f825c9
commit 2714deeafb
3 changed files with 18 additions and 1 deletions

View file

@ -7,6 +7,7 @@ use crate::{Pos, Size, Styled, WidthDb};
pub struct Frame {
pub(crate) widthdb: WidthDb,
pub(crate) buffer: Buffer,
pub(crate) title: Option<String>,
}
impl Frame {
@ -24,6 +25,7 @@ impl Frame {
pub fn reset(&mut self) {
self.buffer.reset();
self.title = None;
}
pub fn cursor(&self) -> Option<Pos> {
@ -42,6 +44,10 @@ impl Frame {
self.set_cursor(None);
}
pub fn set_title(&mut self, title: Option<String>) {
self.title = title;
}
pub fn widthdb(&mut self) -> &mut WidthDb {
&mut self.widthdb
}

View file

@ -11,7 +11,7 @@ use crossterm::event::{
use crossterm::style::{PrintStyledContent, StyledContent};
use crossterm::terminal::{
BeginSynchronizedUpdate, Clear, ClearType, EndSynchronizedUpdate, EnterAlternateScreen,
LeaveAlternateScreen,
LeaveAlternateScreen, SetTitle,
};
use crossterm::{ExecutableCommand, QueueableCommand};
@ -253,6 +253,7 @@ impl Terminal {
self.draw_differences()?;
self.update_cursor()?;
self.update_title()?;
Ok(())
}
@ -287,4 +288,11 @@ impl Terminal {
self.out.queue(Hide)?;
Ok(())
}
fn update_title(&mut self) -> io::Result<()> {
if let Some(title) = &self.frame.title {
self.out.queue(SetTitle(title.clone()))?;
}
Ok(())
}
}