1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-23 15:04:36 +03:00
Commit Graph

48 Commits

Author SHA1 Message Date
Wez Furlong
338174b430
mux: fix pid file locking
This got broken around the time we started to re-exec the mux
server.  Since the fd was CLOEXEC we'd essentially unlock and
ignore the lock at the point we'd re-exec.

This commit allows the fd to remain open and locked across
the exec, and causes the exec'd process to set CLOEXEC by
explicitly telling it about the log fd, so that shells and
things spawned by the mux don't hold the lock.
2023-03-29 06:10:11 -07:00
Wez Furlong
ea92df9486
mux server: propagate config CLI options when daemonizing
refs: #3397
2023-03-29 05:40:15 -07:00
Wez Furlong
9fc762a66b
fix build.rs on windows, take 2
refs: https://github.com/wez/wezterm/issues/3390
2023-03-28 19:45:52 -07:00
Wez Furlong
d5e5bf43d1
fix build.rs on windows
refs: https://github.com/wez/wezterm/issues/3390
2023-03-28 19:32:12 -07:00
Wez Furlong
8092886146
windows: add manifest to config-using console apps, force UTF8 ACP
Lua appears to populate package.path to something based on the
executable path on windows, but since it uses msvcrt in ANSI mode,
that string is encoded in whatever 8-bit MBCS is configured by
the host system ACP setting.

Rust expects that to be UTF-8, but Windows doesn't guarantee it.

This commit updates the manifest for wezterm-gui to tell Windows
that it wants its ACP to be set to UTF-8 prior to launch, which
should resolve this situation for the GUI.

This commit also introduces a more cut-down manifest for the
console-subsystem executables that also use the lua config layer,
which should hopefully resolve this issue for them.

This commit was authored on a mac, so fingers crossed that it
even compiles properly on windows!

refs: https://github.com/wez/wezterm/issues/3390
2023-03-28 19:18:48 -07:00
Wez Furlong
a7fde7935b
raise ulimit nofile and nproc to a reasonable min value on unix systems
It's a tremendous PITA for the user to do this at the system level on a
mac, where it is sorely needed.  This commit allows raising to a desired
minimum level, but won't decrease from an already larger soft limit.

refs: https://github.com/wez/wezterm/discussions/3353
2023-03-28 07:29:47 -07:00
Wez Furlong
bc7acc18e0
fixup images with the multiplexer
* Translate from File to EncodedFile as needed
* Adopt blob leases in the mux server
* Fix an issue where the first image sent by the mux server would
  be replaced on the client by its background image, if configured.
  Removed the ImageData::id field to resolve this: you should use
  the hash field instead to identify and disambiguate images.
  Bumped the termwiz API version because this is conceptually
  a breaking change to the API

refs: https://github.com/wez/wezterm/issues/3343
2023-03-23 21:43:28 -07:00
Jalil David Salamé Messina
d541e2e13d fix(clippy): Remove closures where possible
- Removes closures and function calls for types that implement default:

  ```rust
  // Change
  let _my_str = get_str().unwrap_or(String::new);
  // To
  let _my_str = get_str().unwrap_or_default();
  ```

- Uses the `.cloned()/.copied()` methods where possible
- Use function pointer instead of simple closure

May improve performace, as closures generate more code, and this might
unlock some inlining opportunities.
2023-03-19 08:41:38 -07:00
Wez Furlong
2b298f5f96
mux: pass gui window position through from new mux window
Threads through a GuiPosition from mux window creation to allow it to be
used when the corresponding gui window is created.

SpawnCommand now has an optional position field to use for that purpose.

```lua
wezterm.mux.spawn_window {
  position = {
    x = 10,
    y = 300,
    -- Optional origin to use for x and y.
    -- Possible values:
    -- * "ScreenCoordinateSystem" (this is the default)
    -- * "MainScreen" (the primary or main screen)
    -- * "ActiveScreen" (whichever screen hosts the active/focused window)
    -- * {Named="HDMI-1"} - uses a screen by name. See wezterm.gui.screens()
    -- origin = "ScreenCoordinateSystem"
  },
}
```

refs: https://github.com/wez/wezterm/issues/2976
2023-02-05 21:43:37 -07:00
Wez Furlong
02eb0b4294
mux: rename Mux::get() -> try_get(), add "infallible" Mux::get()
This allows removing a bunch of unwrap/expect calls.

However, my primary motive was to replace the cases where we used
Mux::get() == None to indicate that we were not on the main thread.

A separate API has been added to test for that explicitly rather than
implicitly.
2022-12-19 11:55:35 -07:00
Wez Furlong
478cc59be3
mux: Mux is now Send+Sync 2022-12-19 11:54:02 -07:00
Wez Furlong
a050849695 deps: update to clap 4
Deal with some breaking changes
2022-10-04 08:55:31 -07:00
Wez Furlong
de89d650a3 cargo update 2022-08-21 08:51:16 -07:00
Wez Furlong
347e1fdc46 completions: improve zsh completions for --cwd, --config-file, prog
Make these complete the appropriate type of thing
2022-06-19 16:27:59 -07:00
Wez Furlong
66033e4c6d lua api: improve error handling
Don't prevent wezterm from starting up if the gui-startup event
errors out.

Show a toast notification with the error message.

refs: #674
2022-06-18 07:25:05 -07:00
Wez Furlong
699bbce8e2 add gui-startup and mux-startup events
Using the newly exposed-to-lua mux apis, you may now run some lua code
at GUI startup and/or mux startup, just prior to any default windows
being created.

If you happen to spawn any panes as a result of this, wezterm will
skip creating the default program.

```lua
local wezterm = require 'wezterm'
local mux = wezterm.mux

-- This produces a window split horizontally into three equal parts
wezterm.on("gui-startup", function()
  wezterm.log_info("doing gui startup")
  local tab, pane, window = mux.spawn_window{}
  mux.split_pane(pane, {size=0.3})
  mux.split_pane(pane, {size=0.5})
end)

wezterm.on("mux-startup", function()
  wezterm.log_info("doing mux startup")
  local tab, pane, window = mux.spawn_window{}
  mux.split_pane(pane, {size=0.5, direction="Top"})
end)

return {
  unix_domains = {
    {name="unix"}
  },
}
```

refs: #674
refs: #1949
2022-06-17 12:37:19 -07:00
Wez Furlong
df7c09d760 track dpi in mux and terminal model
refs: https://github.com/wez/wezterm/issues/2085
2022-06-15 18:54:51 -07:00
Wez Furlong
f857ec6a5a deps: structopt -> clap 3 2022-05-28 07:07:52 -07:00
Wez Furlong
da7da888cd config: generate errors for things like --config tarm=foo
Invalid option names, or values that evaluate as nil (such as the `foo`
above: that's treated as a global variable reference, but `foo` isn't a
defined global and evaluates as `nil`) will now cause the program
startup to error out with an actionable error message.

Previously, the invalid config name would generate a warning, and the
invalid value would silently have no effect as it has the same effect as
omitting the named value and leaving it as its default value.

I think these cases should both immediately error out and stop
further processing, so that's what we're doing.

This commit also adds support for adding:

```
   #[dynamic(deprecated = "use newer option instead")]
   pub some_config_value: bool,
```

but not options currently use this.
2022-05-21 13:10:30 -07:00
Wez Furlong
03d8f10d11 mux: pass current window_id to Domain::attach
This commit allows the currently active window to:

* Spawn a new tab in the active window (rather than spawning
  a new window) to host the connection status
* Auto-close that connection UI tab (rather than the whole window)
  when the window is no longer needed
* Pass the current window through to use as the primary window when
  assigning remote window/tabs.

The net effect of this is that there are fewer transient windows,
and that it is easier to connect a set of domains to the active
workspace.

refs: https://github.com/wez/wezterm/issues/1874
2022-04-17 18:07:58 -07:00
Wez Furlong
e7b8374c3f thread original umask through when spawning mux server
refs: #1633
2022-02-11 10:00:09 -07:00
Wez Furlong
cf518c9186 fun with sticky bits and RUNTIME_DIR
This commit does two related things, from opposite ends of the spectrum:

* Sets the sticky bit on pid files and unix sockets to avoid tmpwatch
  deleting them in cleanup scenarios
* Falls back to looking at the changed time if the filesystem doesn't
  support reporting creation time when wezterm does its own liveness
  and cleanup checks for unix domain sockets in the runtime dir
* Allow any wezterm instance to perform that cleanup

refs: #1601
2022-01-31 07:29:15 -07:00
Wez Furlong
6d288696c8 Add SwitchToWorkspace keyassignment action
This action causes the active workspace for the gui to change.

If the name is omitted a random name will be generated.
If the workspace doesn't exist, it will be be created.
The optional spawn parameter can be used to launch a specific
program into the new workspace; if omitted, the default prog
will be used.

The gui only supports a single active workspace. Switching workspaces
will repurpose existing gui windows and re-assign them to windows
in the new workspace, adjusting their size to fit those windows,
spawning new windows or closing unused windows as required.

The gui now exits when there are no panes in the active workspace,
rather than no panes at all.

refs: #1531
2022-01-15 13:53:34 -07:00
Wez Furlong
955b37ff64 mux server: redirect stdout,stderr to log file on Windows
This got lost somewhere along the way.

Importantly, we need to explicitly set the pty to use invalid stdio
handles for the spawned child in order to avoid a weird situation
where eg: cmd or powershell would end up writing to the log file
despite it being spawned into its own PTY.

refs: #1358
2021-12-05 10:11:43 -08:00
Wez Furlong
3b12aa1038 mux: mux_env_remove config to control which env var are removed
closes: #1225
2021-10-17 12:46:16 -07:00
Wez Furlong
fb50014ed5 mux: avoid inheriting wrong pane/socket env
The first problem in #1222 is that the environment in the spawned
mux server has inherited the unix socket path from the GUI that
is the client, rather than the mux server.

That means that `wezterm cli` is operating on the mux namespace
of the client (which is a layered/wrapped view of the mux server),
rather than the mux server.

This fixes `wezterm cli split-pane` in the case where unix domains
are in use together with `connect_automatically = true`, although
there is still a really weird issue with tabs that needs to be
run down.

refs: https://github.com/wez/wezterm/issues/1225 (sort of)
refs: https://github.com/wez/wezterm/issues/1222
2021-10-17 09:44:23 -07:00
Wez Furlong
5cc29d1d8c wezterm-mux-server: keep running after all panes are gone
This has been a commonly requested feature in the past week,
and it's a reasonable one.  The mux server inherited the
close-when-done behavior from when it used to be an alternate
front-end in the same executable as the gui, but it doesn't
need to be that way any more.

We also need to accomodate that case in the client: if the
newly attached domain doesn't result in any panes being imported,
we need to spawn a new command there in order to keep the client
alive.  The pre-existing check for whether the mux was empty had
false positives because the local mux may still reference the
pane from the connection UI, which would finish closing out shortly
after we had decided not to spawn anything, and then the client
would close.

refs: https://github.com/wez/wezterm/issues/631
refs: https://github.com/wez/wezterm/issues/507
2021-04-03 15:00:08 -07:00
Wez Furlong
dbd7fc28a5 Raise minimum Rust version to 1.51, de-vendor openssl on unix
Rust 1.51 allows addressesing a long-standing TODO which was that we
shouldn't need to build a vendored copy of openssl on most sensible unix
systems.

We do require a vendored copy on macOS and Windows, but due to the way
that Cargo's feature resolver worked, it wasn't possible for this
requirement to be respected.

Rust 1.51 introduces `resolver="2"` which can deal with this feature
resolution!

https://doc.rust-lang.org/nightly/cargo/reference/features.html#feature-resolver-version-2

The upshot of this is that building wezterm on real unix systems that
are not macos will now link against the system libssl, resulting in both
a shorter compile time and less headaches arising from having a slightly
different openssl used by wezterm than the rest of the system.

cc: @jsgf
2021-03-25 09:43:50 -07:00
Wez Furlong
2d02df5f38 add --config name=value CLI options
`wezterm`, `wezterm-gui` and `wezterm-mux-server` now all support
a new `--config name=value` CLI option that can be specified
multiple times to supply config overrides.

Since there isn't a simple, direct way to update arbitrary fields
of a struct in Rust (there's no runtime reflection), we do this
work in lua.

The config file returns a config table. Before that is mapped
to the Rust Config type, we have a new phase that takes each
of the `--config` values and applies it to the config table.

For example, you can think of configuration as working like this
if wezterm is started as `wezterm --config foo="bar"`:

```lua
config = load_config_file();
config.foo = "bar";
return config;
```

The `--config name=value` option is split into `name` and `value`
parts.  The name part is literally concatenated with `config` in
the generated lua code, so the name MUST be valid in that context.
The `value` portion is literally inserted verbatim as the rvalue in the
assignment.  Not quoting or other processing is done, which means
that you can (and must!) use the same form that you would use in
the config file for the RHS.  Strings must be quoted.  This allows
you to use more complicated expressions on the right hand side,
such as:

```
wezterm --config 'font=wezterm.font("Fira Code")'
```

The overrides stick for the lifetime of the process; even if
you change the config file and reload, then the value specified
by the override will take precedence.

refs: https://github.com/wez/wezterm/issues/469
refs: https://github.com/wez/wezterm/issues/499
2021-02-27 10:53:45 -08:00
Benoit de Chezelles
c576b9d534
Add cli option --config-file (#459)
* Add cli option --config-file
* Update cli arg doc & make it conflict with skipping config
* When the config is given explicitly (either using --config-file or via WEZTERM_CONFIG_FILE), failing to load this file will use the default config.
* Otherwise the config file is searched one by one in a few directories.
2021-02-07 08:47:33 -08:00
Wez Furlong
a9eaf55747 fixup windows build 2020-12-29 16:59:59 -08:00
Wez Furlong
1c0817b2b2 mux: factor out server bits to helper crate 2020-12-29 15:25:15 -08:00
Wez Furlong
c66e8f5c5e use $WEZTERM_LOG to configure log levels ad-hoc
80214319ae broke the use of RUST_LOG to
turn up trace logging.

This commit refactors logger initialization into the env-bootstrap crate
so that it is centralized, and adopts the use of `WEZTERM_LOG` to
override the default logging filters, rather than `RUST_LOG`.
2020-12-23 12:19:19 -08:00
Wez Furlong
80214319ae adjust log levels
Revise logging so that we use info level for things that we want
to always log, and adjust the logger config to always log info
level messages.

That means shifting some warning level logs down lower to debug level so
that they aren't noisy.

closes: https://github.com/wez/wezterm/issues/388
2020-12-20 22:01:06 -08:00
Wez Furlong
91f1cc21fc mux/wezterm: move Renderable into Pane
This makes it easier to overrride/overlay inside the mux when
indicating that we are in tmux mode.

refs: https://github.com/wez/wezterm/issues/336
2020-11-20 09:24:56 -08:00
Wez Furlong
ab0a4fc2d2 mux: fix initial creation of pid file in mux server
We need to create the directory structure that we want to place
the pid file into.
2020-10-29 21:07:49 -07:00
Wez Furlong
f8c35f191b wezterm: add env bootstrap to mux server, too 2020-10-24 23:33:31 -07:00
Wez Furlong
0cd17b0407 fix a post-fork issue that broke the mux server
One of the updates in the past week made the reactor/async-io
stuff sensitive to the fork performed by daemonizing.

We can "simply" re-exec ourselves post-fork to resolve this.
2020-10-09 18:53:54 -07:00
Wez Furlong
9397f2a2db wezterm: allow overriding the default open-uri event
This builds on the new lua event handler plumbing added
in ccea650a93 to co-opt
the default URI opening action:

```lua
wezterm.on("open-uri", function(uri)
  if uri:find("jira") then
    wezterm.log_error("do something with jira")
    wezterm.run_child_process({
      "wezterm",
      "start",
      "--",
      "jira",
      "view",
      extract_task_from_uri(uri)
    })
    -- prevent the default action from opening in a browser
    return false
  else
    -- log but allow the uri to be opened in the browser
    wezterm.log_error("clicken " .. uri)
  end
end)
```

This doesn't allow exactly the sketched out option from
issue #223 to be implemented, but may be close enough
to be useful.

refs: #223
refs: #225
2020-10-07 18:26:16 -07:00
Wez Furlong
8d1af908bf fixup starting mux on windows
* Taught wezterm-mux-server how to `--daemonize` on windows
* Removed pty based command spawn used to spawn unix domain servers.
  This was present because it was the only way to successfully spawn
  wsl in the past.  What I'm finding today is that it doesn't work
  at all for me, generating an `0xc0000142` Application failed to
  initialize error.  A plain command builder spawn seems to work,
  so that's what we're going with.
* Ensure that we put `.exe` on executable name on windows, otherwise
  the spawn may fail.
* `Path::exists()` always returns false for unix domain sockets on
  Windows, so unconditionally try to remove the socket before binding,
  otherwise the bind will falsely fail, claiming that another process
  is already bound.

The docs for mux will need to be updated to show how to revise them
for the new mux server invocation:

```lua
  unix_domains = {
    {
      name = "wsl",
      serve_command = {"wsl", "wezterm-mux-server", "--daemonize"}
    },
  }
```
2020-10-05 20:29:47 -07:00
Wez Furlong
1045652c67 really fix the windows build 2020-10-05 17:13:50 -07:00
Wez Furlong
5eb4d32004 upgrade misc deps, notably, async-task 2020-10-05 00:06:01 -07:00
Wez Furlong
3de4851aed fixup tls mux sessions
This adopts smol more broadly, but not yet completely.
2020-10-04 21:47:12 -07:00
Wez Furlong
19cea53e35 mux: upgrade rcgen
This version no longer generates invalid CA certificates and
allows TLS connections using the internal PKI to advance
further.  Still need to debug an early disconnect.
2020-10-04 10:05:31 -07:00
Wez Furlong
3dc5994fa8 mux: avoid ffi tricks when cloning ssl stream
This was causing a double free
2020-10-04 10:04:58 -07:00
Wez Furlong
e8be716cb3 clean up mux server startup
kindof a lot going on in this commit, unintentionally:

* Need the lua context set to be moved into the config crate
  otherwise configs cannot be parsed by the server and we end
  up with the default configs
* Make the server use smol for async io
* Drop the use of the daemonize crate, which I had forked anyway.
  Just inline our own tighter daemonize module
* Improve daemon spawning synchronization, however, it still needs
  work for windows to avoid blocking forever where we don't do
  daemonizing.
2020-10-04 09:39:28 -07:00
Wez Furlong
a4731fd5ab Use smol/async for the mux server unix sockets 2020-10-03 11:15:57 -07:00
Wez Furlong
0c32963f1c Move server to its own wezterm-mux-server binary 2020-10-03 11:15:57 -07:00