Update variable with tabs count #3181
-
My idea was to change the window_decorations property conditionally, if number of tabs is 1, show the default vlaor "TITLE | RESIZE", but if it's 2 or more change to "RESIZE". I combine this with hide_tab_bar_if_only_one_tab = true which hides the window bar, which is perfect when viewing the tabs (2 tabs or more, but not when I have 1 tab or open terminal) I tried to first get the total number of tabs in the current window but it fails (return nil), this is what I got, -- To show window bar
local current_window_id = nil
wezterm.on('window-focus-changed', function(window, pane)
current_window_id = window:window_id()
end)
local function get_tabs_count()
local current_window = wezterm.mux.get_window(current_window_id)
local tabs = current_window:tabs()
return #tabs
end This other work for me local mux = wezterm.mux
local windows = mux.all_windows()[1]:tabs()
print(#windows) But i don't want to use manual value 1 for the window as it wouldn't work if i open more windows, also i get a warning saying: caused by: cannot get Mux: not running on the mux thread? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Each thread, and different execution contexts, may run with a fresh lua state. You can use https://wezfurlong.org/wezterm/config/lua/wezterm/GLOBAL.html for sharing data in that way. However, because there can be multiple windows, it doesn't make a lot of sense to try to track the window in any kind of global state. wezterm always passes the current window to the various event callbacks; you should always use the window parameter that is passed to them when you want to operate on the current window. |
Beta Was this translation helpful? Give feedback.
-
I am trying to implement something similar, what did you end up going with for getting tab count and and then dynamically setting window decorations? |
Beta Was this translation helpful? Give feedback.
Each thread, and different execution contexts, may run with a fresh lua state.
As such, you cannot share data by storing it directly in global variables.
You can use https://wezfurlong.org/wezterm/config/lua/wezterm/GLOBAL.html for sharing data in that way.
However, because there can be multiple windows, it doesn't make a lot of sense to try to track the window in any kind of global state.
wezterm always passes the current window to the various event callbacks; you should always use the window parameter that is passed to them when you want to operate on the current window.