mirror of
https://github.com/wez/wezterm.git
synced 2024-12-23 21:32:13 +03:00
parent
7e996950f6
commit
c4dc358282
@ -151,6 +151,37 @@ pub fn make_lua_context(config_file: &Path) -> anyhow::Result<Lua> {
|
||||
)?,
|
||||
)?;
|
||||
|
||||
wezterm_mod.set(
|
||||
"truncate_left_to_width",
|
||||
lua.create_function(
|
||||
|_, (s, max_width, min_width): (String, usize, Option<usize>)| {
|
||||
let mut result = vec![];
|
||||
let mut len = 0;
|
||||
for g in s.graphemes(true).rev() {
|
||||
let g_len = grapheme_column_width(g);
|
||||
if g_len + len > max_width {
|
||||
break;
|
||||
}
|
||||
result.push(g);
|
||||
len += g_len;
|
||||
}
|
||||
|
||||
if let Some(min_width) = min_width {
|
||||
while len < min_width {
|
||||
if len >= max_width {
|
||||
break;
|
||||
}
|
||||
result.push(" ");
|
||||
len += 1;
|
||||
}
|
||||
}
|
||||
|
||||
result.reverse();
|
||||
Ok(result.join(""))
|
||||
},
|
||||
)?,
|
||||
)?;
|
||||
|
||||
wezterm_mod.set("font", lua.create_function(font)?)?;
|
||||
wezterm_mod.set(
|
||||
"font_with_fallback",
|
||||
|
@ -46,7 +46,7 @@ As features stabilize some brief notes about them will accumulate here.
|
||||
* Fixed: tabs would remain hovered after moving the mouse down into the main terminal area [#591](https://github.com/wez/wezterm/issues/591)
|
||||
* New: [tab_bar_at_bottom](config/lua/config/tab_bar_at_bottom.md) setting to put the tab bar at the bottom of the window [#278](https://github.com/wez/wezterm/issues/278)
|
||||
* New: [wezterm.column_width](config/lua/wezterm/column_width.md) function for measuring the displayed width of a string
|
||||
* New: [wezterm.truncate_to_width](config/lua/wezterm/truncate_to_width.md) function for truncating/padding a string based on its displayed width
|
||||
* New: [wezterm.truncate_to_width](config/lua/wezterm/truncate_to_width.md) and [wezterm.truncate_left_to_width](config/lua/wezterm/truncate_left_to_width.md) function for truncating/padding a string based on its displayed width
|
||||
|
||||
### 20210405-110924-a5bb5be8
|
||||
|
||||
|
15
docs/config/lua/wezterm/truncate_left_to_width.md
Normal file
15
docs/config/lua/wezterm/truncate_left_to_width.md
Normal file
@ -0,0 +1,15 @@
|
||||
# wezterm.truncate_left_to_width(string, max_width, min_width)
|
||||
|
||||
*Since: nightly builds only*
|
||||
|
||||
Returns a copy of `string` that is no longer than `max_width` columns
|
||||
(as measured by [wezterm.column_width](column_width.md)), and, optionally,
|
||||
no shorter than `min_width` columns, padding out with spaces.
|
||||
|
||||
Truncation and padding occur on the left hand side of the string.
|
||||
|
||||
For example, `wezterm.truncate_to_width("hello", 3)` returns `"llo"`,
|
||||
and `wezterm.truncate_to_width("a", 10, 5)` returns " a"`.
|
||||
|
||||
See also: [wezterm.truncate_to_width](truncate_to_width.md)
|
||||
|
@ -6,6 +6,9 @@ Returns a copy of `string` that is no longer than `max_width` columns
|
||||
(as measured by [wezterm.column_width](column_width.md)), and, optionally,
|
||||
no shorter than `min_width` columns, padding out with spaces.
|
||||
|
||||
Truncation and padding occur on the right hand side of the string.
|
||||
|
||||
For example, `wezterm.truncate_to_width("hello", 3)` returns `"hel"`,
|
||||
and `wezterm.truncate_to_width("a", 10, 5)` returns "a "`.
|
||||
|
||||
See also: [wezterm.truncate_left_to_width](truncate_left_to_width.md)
|
||||
|
Loading…
Reference in New Issue
Block a user