lua: add window::effective_config() method
Expose the current window configuration to lua scripts. refs: https://github.com/wez/wezterm/issues/469
This commit is contained in:
1 parent
4389e6dd13
commit
60be1a98a0
6 files changed
+57
-10
No files matched your search
+4
-4
@@ -344,7 +344,7 @@ pub struct StyleRule {
|
||||
}
|
||||
impl_lua_conversion!(StyleRule);
|
||||
|
||||
#[derive(Debug, Deserialize, Clone, Copy, PartialEq, Eq)]
|
||||
#[derive(Debug, Deserialize, Serialize, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum AllowSquareGlyphOverflow {
|
||||
Never,
|
||||
Always,
|
||||
@@ -357,7 +357,7 @@ impl Default for AllowSquareGlyphOverflow {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Clone, Copy, PartialEq, Eq)]
|
||||
#[derive(Debug, Deserialize, Serialize, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum FontLocatorSelection {
|
||||
/// Use fontconfig APIs to resolve fonts (!macos, posix systems)
|
||||
FontConfig,
|
||||
@@ -418,7 +418,7 @@ impl std::str::FromStr for FontLocatorSelection {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Clone, Copy)]
|
||||
#[derive(Debug, Deserialize, Serialize, Clone, Copy)]
|
||||
pub enum FontRasterizerSelection {
|
||||
FreeType,
|
||||
}
|
||||
@@ -463,7 +463,7 @@ impl std::str::FromStr for FontRasterizerSelection {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Clone, Copy)]
|
||||
#[derive(Debug, Deserialize, Serialize, Clone, Copy)]
|
||||
pub enum FontShaperSelection {
|
||||
Allsorts,
|
||||
Harfbuzz,
|
||||
|
||||
+3
-2
@@ -576,7 +576,7 @@ where
|
||||
}
|
||||
|
||||
/// Behavior when the program spawned by wezterm terminates
|
||||
#[derive(Debug, Deserialize, Clone, Copy, PartialEq, Eq)]
|
||||
#[derive(Debug, Deserialize, Serialize, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum ExitBehavior {
|
||||
/// Close the associated pane
|
||||
Close,
|
||||
@@ -592,7 +592,7 @@ impl Default for ExitBehavior {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Clone)]
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct Config {
|
||||
/// The font size, measured in points
|
||||
#[serde(default = "default_font_size", deserialize_with = "de_number")]
|
||||
@@ -1005,6 +1005,7 @@ pub struct Config {
|
||||
#[serde(default = "default_alternate_buffer_wheel_scroll_speed")]
|
||||
pub alternate_buffer_wheel_scroll_speed: u8,
|
||||
}
|
||||
impl_lua_conversion!(Config);
|
||||
|
||||
fn default_alternate_buffer_wheel_scroll_speed() -> u8 {
|
||||
3
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
# `window:effective_config()`
|
||||
|
||||
*Since: nightly*
|
||||
|
||||
Returns a lua table representing the effective configuration for the Window.
|
||||
The table is in the same format as that used to specify the config in
|
||||
the `wezterm.lua` file, but represents the fully-populated state of the
|
||||
configuration, including any CLI or per-window configuration overrides.
|
||||
|
||||
Note: changing the config table will NOT change the effective window config;
|
||||
it is just a copy of that information.
|
||||
|
||||
This example will log the configured font size when `CTRL-SHIFT-E` is pressed:
|
||||
|
||||
```lua
|
||||
local wezterm = require'wezterm'
|
||||
|
||||
wezterm.on("show-font-size", function(window, pane)
|
||||
wezterm.log_error(window:effective_config().font_size);
|
||||
end)
|
||||
|
||||
return {
|
||||
keys = {
|
||||
{key="E", mods="CTRL", action=wezterm.action{EmitEvent="show-font-size"}},
|
||||
},
|
||||
}
|
||||
```
|
||||
@@ -7,7 +7,7 @@
|
||||
use crate::{ensure, format_err, Result};
|
||||
use regex::{Captures, Regex};
|
||||
#[cfg(feature = "use_serde")]
|
||||
use serde::{Deserialize, Deserializer, Serialize};
|
||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
use std::collections::HashMap;
|
||||
use std::fmt::{Display, Error as FmtError, Formatter};
|
||||
use std::ops::Range;
|
||||
@@ -123,13 +123,19 @@ impl Display for Hyperlink {
|
||||
/// URL to view the details for that issue.
|
||||
/// The Rule struct is configuration that is passed to the terminal
|
||||
/// and is evaluated when processing mouse hover events.
|
||||
#[cfg_attr(feature = "use_serde", derive(Deserialize))]
|
||||
#[cfg_attr(feature = "use_serde", derive(Deserialize, Serialize))]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Rule {
|
||||
/// The compiled regex for the rule. This is used to match
|
||||
/// against a line of text from the screen (typically the line
|
||||
/// over which the mouse is hovering).
|
||||
#[cfg_attr(feature = "use_serde", serde(deserialize_with = "deserialize_regex"))]
|
||||
#[cfg_attr(
|
||||
feature = "use_serde",
|
||||
serde(
|
||||
deserialize_with = "deserialize_regex",
|
||||
serialize_with = "serialize_regex"
|
||||
)
|
||||
)]
|
||||
regex: Regex,
|
||||
/// The format string that defines how to transform the matched
|
||||
/// text into a URL. For example, a format string of `$0` expands
|
||||
@@ -153,6 +159,15 @@ where
|
||||
Regex::new(&s).map_err(|e| serde::de::Error::custom(format!("{:?}", e)))
|
||||
}
|
||||
|
||||
#[cfg(feature = "use_serde")]
|
||||
fn serialize_regex<S>(regex: &Regex, serializer: S) -> std::result::Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
let s = regex.to_string();
|
||||
s.serialize(serializer)
|
||||
}
|
||||
|
||||
/// Holds a resolved rule match.
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct RuleMatch {
|
||||
|
||||
@@ -221,7 +221,7 @@ pub struct TabState {
|
||||
|
||||
pub struct TermWindow {
|
||||
pub window: Option<Window>,
|
||||
config: ConfigHandle,
|
||||
pub config: ConfigHandle,
|
||||
/// When we most recently received keyboard focus
|
||||
focused: Option<Instant>,
|
||||
fonts: Rc<FontConfiguration>,
|
||||
|
||||
@@ -55,5 +55,9 @@ impl UserData for GuiWin {
|
||||
.await
|
||||
},
|
||||
);
|
||||
methods.add_async_method("effective_config", |_, this, _: ()| async move {
|
||||
this.with_term_window(move |term_window, _ops| Ok((*term_window.config).clone()))
|
||||
.await
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user