This commit enables the following config to work for local (not mux yet!)
panes:
```lua
local wezterm = require 'wezterm'
wezterm.on("format-tab-title", function(tab, tabs, panes, config, hover, max_width)
if tab.is_active then
return {
{Background={Color="blue"}},
{Text=" " .. tab.active_pane.title .. " "},
}
end
local has_unseen_output = false
for _, pane in ipairs(tab.panes) do
if pane.has_unseen_output then
has_unseen_output = true
break;
end
end
if has_unseen_output then
return {
{Background={Color="Orange"}},
{Text=" " .. tab.active_pane.title .. " "},
}
end
return tab.active_pane.title
end)
return {
}
```
refs: https://github.com/wez/wezterm/discussions/796
160 lines
4.6 KiB
Rust
160 lines
4.6 KiB
Rust
use super::*;
|
|
use crate::terminalstate::performer::Performer;
|
|
use std::sync::Arc;
|
|
use termwiz::escape::parser::Parser;
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
#[cfg_attr(feature = "use_serde", derive(Serialize, Deserialize))]
|
|
pub enum ClipboardSelection {
|
|
Clipboard,
|
|
PrimarySelection,
|
|
}
|
|
|
|
pub trait Clipboard {
|
|
fn set_contents(
|
|
&self,
|
|
selection: ClipboardSelection,
|
|
data: Option<String>,
|
|
) -> anyhow::Result<()>;
|
|
}
|
|
|
|
impl Clipboard for Box<dyn Clipboard> {
|
|
fn set_contents(
|
|
&self,
|
|
selection: ClipboardSelection,
|
|
data: Option<String>,
|
|
) -> anyhow::Result<()> {
|
|
self.as_ref().set_contents(selection, data)
|
|
}
|
|
}
|
|
|
|
pub trait DeviceControlHandler {
|
|
fn handle_device_control(&mut self, _control: termwiz::escape::DeviceControlMode);
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
#[cfg_attr(feature = "use_serde", derive(Serialize, Deserialize))]
|
|
pub enum Alert {
|
|
Bell,
|
|
ToastNotification {
|
|
/// The title text for the notification.
|
|
title: Option<String>,
|
|
/// The message body
|
|
body: String,
|
|
/// Whether clicking on the notification should focus the
|
|
/// window/tab/pane that generated it
|
|
focus: bool,
|
|
},
|
|
/// When the title, or something that likely influences the title,
|
|
/// has been changed
|
|
TitleMaybeChanged,
|
|
/// When the color palette has been updated
|
|
PaletteChanged,
|
|
/// A UserVar has changed value
|
|
SetUserVar {
|
|
name: String,
|
|
value: String,
|
|
},
|
|
/// When something bumps the seqno in the terminal model and
|
|
/// the terminal is not focused
|
|
OutputSinceFocusLost,
|
|
}
|
|
|
|
pub trait AlertHandler {
|
|
fn alert(&mut self, alert: Alert);
|
|
}
|
|
|
|
pub trait DownloadHandler {
|
|
fn save_to_downloads(&self, name: Option<String>, data: Vec<u8>);
|
|
}
|
|
|
|
/// Represents an instance of a terminal emulator.
|
|
pub struct Terminal {
|
|
/// The terminal model/state
|
|
state: TerminalState,
|
|
/// Baseline terminal escape sequence parser
|
|
parser: Parser,
|
|
}
|
|
|
|
impl Deref for Terminal {
|
|
type Target = TerminalState;
|
|
|
|
fn deref(&self) -> &TerminalState {
|
|
&self.state
|
|
}
|
|
}
|
|
|
|
impl DerefMut for Terminal {
|
|
fn deref_mut(&mut self) -> &mut TerminalState {
|
|
&mut self.state
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
|
pub struct TerminalSize {
|
|
pub physical_rows: usize,
|
|
pub physical_cols: usize,
|
|
pub pixel_width: usize,
|
|
pub pixel_height: usize,
|
|
}
|
|
|
|
impl Terminal {
|
|
/// Construct a new Terminal.
|
|
/// `physical_rows` and `physical_cols` describe the dimensions
|
|
/// of the visible portion of the terminal display in terms of
|
|
/// the number of text cells.
|
|
///
|
|
/// `pixel_width` and `pixel_height` describe the dimensions of
|
|
/// that same visible area but in pixels.
|
|
///
|
|
/// `term_program` and `term_version` are required to identify
|
|
/// the host terminal program; they are used to respond to the
|
|
/// terminal identification sequence `\033[>q`.
|
|
///
|
|
/// `writer` is anything that implements `std::io::Write`; it
|
|
/// is used to send input to the connected program; both keyboard
|
|
/// and mouse input is encoded and written to that stream, as
|
|
/// are answerback responses to a number of escape sequences.
|
|
pub fn new(
|
|
size: TerminalSize,
|
|
config: Arc<dyn TerminalConfiguration>,
|
|
term_program: &str,
|
|
term_version: &str,
|
|
// writing to the writer sends data to input of the pty
|
|
writer: Box<dyn std::io::Write + Send>,
|
|
) -> Terminal {
|
|
Terminal {
|
|
state: TerminalState::new(size, config, term_program, term_version, writer),
|
|
parser: Parser::new(),
|
|
}
|
|
}
|
|
|
|
/// Feed the terminal parser a slice of bytes from the output
|
|
/// of the associated program.
|
|
/// The slice is not required to be a complete sequence of escape
|
|
/// characters; it is valid to feed in chunks of data as they arrive.
|
|
/// The output is parsed and applied to the terminal model.
|
|
pub fn advance_bytes<B: AsRef<[u8]>>(&mut self, bytes: B) {
|
|
self.state.increment_seqno();
|
|
{
|
|
let bytes = bytes.as_ref();
|
|
|
|
let mut performer = Performer::new(&mut self.state);
|
|
|
|
self.parser.parse(bytes, |action| performer.perform(action));
|
|
}
|
|
self.trigger_unseen_output_notif();
|
|
}
|
|
|
|
pub fn perform_actions(&mut self, actions: Vec<termwiz::escape::Action>) {
|
|
self.state.increment_seqno();
|
|
{
|
|
let mut performer = Performer::new(&mut self.state);
|
|
for action in actions {
|
|
performer.perform(action);
|
|
}
|
|
}
|
|
self.trigger_unseen_output_notif();
|
|
}
|
|
}
|