From 0f2f3734d96ec13293848b0625068acff7e5cdec Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Mon, 26 Apr 2021 19:55:23 -0700 Subject: [PATCH] add wezterm.column_width refs: https://github.com/wez/wezterm/issues/647 --- config/src/lua.rs | 7 ++++++- docs/changelog.md | 1 + docs/config/lua/wezterm/column_width.md | 13 +++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 docs/config/lua/wezterm/column_width.md diff --git a/config/src/lua.rs b/config/src/lua.rs index 615b5109c..9e55a6374 100644 --- a/config/src/lua.rs +++ b/config/src/lua.rs @@ -7,7 +7,7 @@ use mlua::{Lua, Table, Value}; use serde::*; use smol::prelude::*; use std::path::Path; -use termwiz::cell::{AttributeChange, CellAttributes}; +use termwiz::cell::{unicode_column_width, AttributeChange, CellAttributes}; use termwiz::color::{AnsiColor, ColorAttribute, ColorSpec, RgbColor}; use termwiz::input::Modifiers; use termwiz::surface::change::Change; @@ -115,6 +115,11 @@ pub fn make_lua_context(config_file: &Path) -> anyhow::Result { })?, )?; + wezterm_mod.set( + "column_width", + lua.create_function(|_, s: String| Ok(unicode_column_width(&s)))?, + )?; + wezterm_mod.set("font", lua.create_function(font)?)?; wezterm_mod.set( "font_with_fallback", diff --git a/docs/changelog.md b/docs/changelog.md index de0c342a1..2a002601d 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -44,6 +44,7 @@ As features stabilize some brief notes about them will accumulate here. * New: [Quick Select Mode](quickselect.md) for a tmux-fingers/tmux-thumbs style mouse-less select and copy flow [#732](https://github.com/wez/wezterm/issues/732) * 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 ### 20210405-110924-a5bb5be8 diff --git a/docs/config/lua/wezterm/column_width.md b/docs/config/lua/wezterm/column_width.md new file mode 100644 index 000000000..4b75189a8 --- /dev/null +++ b/docs/config/lua/wezterm/column_width.md @@ -0,0 +1,13 @@ +# wezterm.column_width(string) + +*Since: nightly builds only* + +Given a string parameter, returns the number of columns that that text occupies +in the terminal, which is useful together with +[format-tab-title](../window-events/format-tab-title.md) and +[update-right-status](../window-events/update-right-status.md) to +compute/layout tabs and status information. + +This is different from [string.len](https://www.lua.org/manual/5.3/manual.html#pdf-string.len) +which returns the number of bytes that comprise the string. +