Add support for setting window title
This commit is contained in:
parent
77b4f825c9
commit
2714deeafb
3 changed files with 18 additions and 1 deletions
|
|
@ -13,6 +13,9 @@ Procedure when bumping the version number:
|
||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- `Frame::set_title`
|
||||||
|
|
||||||
## v0.2.0 - 2023-08-31
|
## v0.2.0 - 2023-08-31
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ use crate::{Pos, Size, Styled, WidthDb};
|
||||||
pub struct Frame {
|
pub struct Frame {
|
||||||
pub(crate) widthdb: WidthDb,
|
pub(crate) widthdb: WidthDb,
|
||||||
pub(crate) buffer: Buffer,
|
pub(crate) buffer: Buffer,
|
||||||
|
pub(crate) title: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Frame {
|
impl Frame {
|
||||||
|
|
@ -24,6 +25,7 @@ impl Frame {
|
||||||
|
|
||||||
pub fn reset(&mut self) {
|
pub fn reset(&mut self) {
|
||||||
self.buffer.reset();
|
self.buffer.reset();
|
||||||
|
self.title = None;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cursor(&self) -> Option<Pos> {
|
pub fn cursor(&self) -> Option<Pos> {
|
||||||
|
|
@ -42,6 +44,10 @@ impl Frame {
|
||||||
self.set_cursor(None);
|
self.set_cursor(None);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_title(&mut self, title: Option<String>) {
|
||||||
|
self.title = title;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn widthdb(&mut self) -> &mut WidthDb {
|
pub fn widthdb(&mut self) -> &mut WidthDb {
|
||||||
&mut self.widthdb
|
&mut self.widthdb
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ use crossterm::event::{
|
||||||
use crossterm::style::{PrintStyledContent, StyledContent};
|
use crossterm::style::{PrintStyledContent, StyledContent};
|
||||||
use crossterm::terminal::{
|
use crossterm::terminal::{
|
||||||
BeginSynchronizedUpdate, Clear, ClearType, EndSynchronizedUpdate, EnterAlternateScreen,
|
BeginSynchronizedUpdate, Clear, ClearType, EndSynchronizedUpdate, EnterAlternateScreen,
|
||||||
LeaveAlternateScreen,
|
LeaveAlternateScreen, SetTitle,
|
||||||
};
|
};
|
||||||
use crossterm::{ExecutableCommand, QueueableCommand};
|
use crossterm::{ExecutableCommand, QueueableCommand};
|
||||||
|
|
||||||
|
|
@ -253,6 +253,7 @@ impl Terminal {
|
||||||
|
|
||||||
self.draw_differences()?;
|
self.draw_differences()?;
|
||||||
self.update_cursor()?;
|
self.update_cursor()?;
|
||||||
|
self.update_title()?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
@ -287,4 +288,11 @@ impl Terminal {
|
||||||
self.out.queue(Hide)?;
|
self.out.queue(Hide)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn update_title(&mut self) -> io::Result<()> {
|
||||||
|
if let Some(title) = &self.frame.title {
|
||||||
|
self.out.queue(SetTitle(title.clone()))?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue