1
1
mirror of https://github.com/wez/wezterm.git synced 2024-09-11 14:25:57 +03:00
Commit Graph

147 Commits

Author SHA1 Message Date
Wez Furlong
84bb2fdc46
deps: dedup some nix versions 2024-05-13 11:53:27 -07:00
Wez Furlong
1ca5e6cc90
deps: upgrade smol to 2.0 2024-05-13 10:26:29 -07:00
Jonathan Cammisuli
9d83458632 add PSUEDOCONSOLE_INHERIT_CURSOR as a flag 2024-05-05 14:17:24 -07:00
Jonathan Cammisuli
454ec0a7df windows: set PSEUDOCONSOLE_INHERIT_CURSOR 2024-05-05 14:17:24 -07:00
Wez Furlong
c4113906f9
pty: improve unix path searching
We were unconditionally checking against the cwd for relative paths,
which isn't conformant to posix's path search logic.

This commit revises the search to only do so if the requested executable
starts with either a `.` or `..` path component.

In addition, we now also allow for path components in $PATH to specify
cwd-relative paths.

refs: #4920
2024-02-02 06:41:53 -07:00
Wez Furlong
17dadbeb1e
pty: don't try to spawn a directory from the cwd
When the cwd was set to a directory that contained
an executable directory whose name matched the argv0
of the command to be spawned, we'd incorrectly consider
that to be a valid candidate.

When later trying to spawn this, we'll fail with an EACCESS,
and in the context of wezterm, rust's internal error handling
machinery for this error would fail to write to a descriptor
because our close_random_fds() function has closed that descriptor
during pre_exec.  That in turn would cause rust to print a panic
message to the output stream of this semi-spawned process,
which would show briefly an error message with no useful context.

This commit resolves this issue by explicitly avoiding executable
directories in this case.

refs: https://github.com/wez/wezterm/issues/4920
2024-02-01 17:18:42 -07:00
Chris Olszewski
1670b648b7 chore: add signal getter on exit status 2024-01-24 12:51:39 -07:00
Wez Furlong
6c7aa8159f
SHELL cleanup
* Allow set_environment_variables to set the SHELL.
  Previously, we'd always set it to the shell from the password
  database.  Now we do that by default, but if set_environment_variables
  has been used, we'll preserve that value for the environment
  of the to-be-spawned process

* Clarify the docs:
  * Remove the confusing version dependent sections that started
    with old behavior and rewrite in terms of the behavior that
    has been true for the past year
  * I've heard from a few people that they tried to change COMSPEC
    on Windows and pain ensued.  Try to nudge them to read the
    next paragraph that tells them what they are actually supposed
    to change.

refs: https://github.com/wez/wezterm/issues/4098
refs: https://github.com/wez/wezterm/issues/4168
closes: https://github.com/wez/wezterm/issues/3816
refs: https://github.com/wez/wezterm/issues/3317
2023-08-20 10:42:38 -07:00
Wez Furlong
c399ee665a
hold pane open when spawn fails
Show the error message in the pane itself when a spawn attempt
fails, regardless of the exit_behavior setting.

refs: #3950
refs: #3928
2023-07-09 13:53:41 -07:00
Wez Furlong
6be3f0e7ca
ssh: rewrite exit_behavior=Close -> CloseOnCleanExit during connection
ssh connection or host authentication errors would not be displayed
when the config was in its default exit_behavior=Close state.

This commit introduces some plumbing to allow a pane to override
the effective exit_behavior value, so that ssh sessions can now
rewrite it to CloseOnCleanExit while they are in the process
of connecting.

refs: #3941
2023-07-06 09:28:43 -07:00
Wez Furlong
5fb6db8774
pty: fix unused import warning on windows 2023-04-08 11:13:12 -07:00
Wez Furlong
0ca050e09d
expose the tty name associated with a pane 2023-04-06 17:13:07 -07:00
Wez Furlong
f2a2d099bb
pty: unix: empty signal mask in the spawned child
A user reported that ctrl-c and ctrl-\ had no effect
for them in bash when spawned in a particular way
on their system.  It turned out that the spawning
environment had blocked SIGINT, SIGHUP and SIGQUIT
and that was propagated all the way down through
the wezterm process to the spawned shell.

Let's ensure that we clear all blocked signals
prior to launching our child process.
2023-03-23 11:55:04 -07:00
Wez Furlong
73a1c3b0d3
docs: add --help output pages to the CLI reference 2023-03-21 18:44:26 -07:00
Waleed Khan
4afedd626d build(pty): don't use std::os::fd::RawFd symbol directly
For whatever reason, `portable-pty` doesn't build until Rust v1.66 due to a failure to import `std::os::fd::RawFd`. According to `cargo-msrv`:

```
$ cargo msrv --linear
Fetching index
Determining the Minimum Supported Rust Version (MSRV) for toolchain aarch64-apple-darwin
Using check command cargo check
 ⠲ Checking 1.68.0                ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
 ⠴ Checking 1.68.0                ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Check for toolchain '1.68.0-aarch64-apple-darwin' succeeded
Check for toolchain '1.67.1-aarch64-apple-darwin' succeeded
Check for toolchain '1.66.1-aarch64-apple-darwin' succeeded

Check for toolchain '1.65.0-aarch64-apple-darwin' failed with:
┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Compiling libc v0.2.139                                                                                                               │
│    Compiling autocfg v1.1.0                                                                                                           │
│     Checking cfg-if v1.0.0                                                                                                            │
│    Compiling proc-macro2 v1.0.51                                                                                                      │
│    Compiling quote v1.0.23                                                                                                            │
│    Compiling syn v1.0.109                                                                                                             │
│    Compiling unicode-ident v1.0.8                                                                                                     │
│    Compiling version_check v0.9.4                                                                                                     │
│    Compiling pkg-config v0.3.26                                                                                                       │
│    Compiling memchr v2.5.0                                                                                                            │
│     Checking bitflags v1.3.2                                                                                                          │
│     Checking once_cell v1.17.1                                                                                                        │
│    Compiling log v0.4.17                                                                                                              │
│    Compiling num-traits v0.2.15                                                                                                       │
│    Compiling futures-core v0.3.26                                                                                                     │
│    Compiling crossbeam-utils v0.8.15                                                                                                  │
│    Compiling serde_derive v1.0.152                                                                                                    │
│    Compiling thiserror v1.0.39                                                                                                        │
│    Compiling serde v1.0.152                                                                                                           │
│    Compiling jobserver v0.1.26                                                                                                        │
│     Checking pin-project-lite v0.2.9                                                                                                  │
│    Compiling cc v1.0.79                                                                                                               │
│     Checking getrandom v0.2.8                                                                                                         │
│     Checking scopeguard v1.1.0                                                                                                        │
│    Compiling ahash v0.7.6                                                                                                             │
│     Checking futures-sink v0.3.26                                                                                                     │
│     Checking futures-io v0.3.26                                                                                                       │
│    Compiling slab v0.4.8                                                                                                              │
│     Checking lazy_static v1.4.0                                                                                                       │
│    Compiling lock_api v0.4.9                                                                                                          │
│     Checking smallvec v1.10.0                                                                                                         │
│     Checking num_cpus v1.15.0                                                                                                         │
│    Compiling num-integer v0.1.45                                                                                                      │
│    Compiling siphasher v0.3.10                                                                                                        │
│    Compiling rand_core v0.6.4                                                                                                         │
│     Checking fastrand v1.9.0                                                                                                          │
│    Compiling rand v0.8.5                                                                                                              │
│    Compiling phf_shared v0.11.1                                                                                                       │
│    Compiling memoffset v0.8.0                                                                                                         │
│     Checking adler v1.0.2                                                                                                             │
│     Checking pin-utils v0.1.0                                                                                                         │
│    Compiling indexmap v1.9.2                                                                                                          │
│    Compiling futures-channel v0.3.26                                                                                                  │
│    Compiling libz-sys v1.1.8                                                                                                          │
│    Compiling anyhow v1.0.69                                                                                                           │
│     Checking hashbrown v0.12.3                                                                                                        │
│    Compiling phf_generator v0.11.1                                                                                                    │
│    Compiling futures-task v0.3.26                                                                                                     │
│     Checking miniz_oxide v0.6.2                                                                                                       │
│     Checking socket2 v0.4.9                                                                                                           │
│    Compiling crossbeam-epoch v0.9.14                                                                                                  │
│    Compiling futures-util v0.3.26                                                                                                     │
│    Compiling crc32fast v1.3.2                                                                                                         │
│     Checking strsim v0.10.0                                                                                                           │
│     Checking crossbeam-channel v0.5.7                                                                                                 │
│     Checking fnv v1.0.7                                                                                                               │
│    Compiling typenum v1.16.0                                                                                                          │
│    Compiling memoffset v0.6.5                                                                                                         │
│     Checking event-listener v2.5.3                                                                                                    │
│     Checking byteorder v1.4.3                                                                                                         │
│     Checking concurrent-queue v2.1.0                                                                                                  │
│     Checking parking v2.0.0                                                                                                           │
│    Compiling rayon-core v1.11.0                                                                                                       │
│     Checking waker-fn v1.1.0                                                                                                          │
│     Checking async-lock v2.7.0                                                                                                        │
│     Checking futures-lite v1.12.0                                                                                                     │
│     Checking signal-hook-registry v1.4.1                                                                                              │
│     Checking crossbeam-deque v0.8.3                                                                                                   │
│    Compiling generic-array v0.14.6                                                                                                    │
│     Checking flate2 v1.0.25                                                                                                           │
│     Checking spin v0.9.5                                                                                                              │
│     Checking nanorand v0.7.0                                                                                                          │
│     Checking aho-corasick v0.7.20                                                                                                     │
│    Compiling polling v2.5.2                                                                                                           │
│     Checking regex-syntax v0.6.28                                                                                                     │
│    Compiling ucd-trie v0.1.5                                                                                                          │
│     Checking either v1.8.1                                                                                                            │
│    Compiling phf_codegen v0.11.1                                                                                                      │
│    Compiling lua-src v544.0.1                                                                                                         │
│    Compiling luajit-src v210.4.5+resty2cf5186                                                                                         │
│    Compiling nom v5.1.2                                                                                                               │
│    Compiling num-rational v0.4.1                                                                                                      │
│     Checking rayon v1.7.0                                                                                                             │
│    Compiling async-io v1.12.0                                                                                                         │
│     Checking weezl v0.1.7                                                                                                             │
│     Checking regex-automata v0.1.10                                                                                                   │
│     Checking async-task v4.3.0                                                                                                        │
│     Checking simd-adler32 v0.3.4                                                                                                      │
│    Compiling core-foundation-sys v0.8.3                                                                                               │
│     Checking base64 v0.21.0                                                                                                           │
│     Checking tinyvec_macros v0.1.1                                                                                                    │
│     Checking rustc-hash v1.1.0                                                                                                        │
│     Checking lab v0.11.0                                                                                                              │
│    Compiling tinyvec v1.6.0                                                                                                           │
│     Checking zune-inflate v0.2.50                                                                                                     │
│    Compiling mlua v0.8.8                                                                                                              │
│     Checking regex v1.7.1                                                                                                             │
│    Compiling terminfo v0.7.5                                                                                                          │
│     Checking png v0.17.7                                                                                                              │
│     Checking threadpool v1.8.1                                                                                                        │
│     Checking dirs-sys v0.3.7                                                                                                          │
│     Checking percent-encoding v2.2.0                                                                                                  │
│     Checking half v2.2.1                                                                                                              │
│     Checking lebe v0.5.2                                                                                                              │
│     Checking color_quant v1.1.0                                                                                                       │
│     Checking bit_field v0.10.2                                                                                                        │
│     Checking form_urlencoded v1.1.0                                                                                                   │
│     Checking gif v0.11.4                                                                                                              │
│     Checking unicode-normalization v0.1.22                                                                                            │
│     Checking dirs v4.0.0                                                                                                              │
│     Checking jpeg-decoder v0.3.0                                                                                                      │
│     Checking block-buffer v0.9.0                                                                                                      │
│     Checking digest v0.9.0                                                                                                            │
│     Checking async-channel v1.8.0                                                                                                     │
│     Checking phf_shared v0.10.0                                                                                                       │
│    Compiling libgit2-sys v0.14.2+1.5.1                                                                                                │
│     Checking cpufeatures v0.2.5                                                                                                       │
│     Checking unicode-bidi v0.3.10                                                                                                     │
│     Checking utf8parse v0.2.0                                                                                                         │
│     Checking opaque-debug v0.3.0                                                                                                      │
│    Compiling thiserror-impl v1.0.39                                                                                                   │
│    Compiling futures-macro v0.3.26                                                                                                    │
│    Compiling wezterm-dynamic-derive v0.1.0 (/Users/waleed/Workspace/wezterm/wezterm-dynamic/derive)                                   │
│    Compiling bytemuck_derive v1.4.0                                                                                                   │
│    Compiling phf_macros v0.11.1                                                                                                       │
│    Compiling pin-project-internal v1.0.12                                                                                             │
│     Checking tiff v0.8.1                                                                                                              │
│    Compiling signal-hook v0.3.15                                                                                                      │
│     Checking deltae v0.3.0                                                                                                            │
│     Checking scoped_threadpool v0.1.9                                                                                                 │
│     Checking atomic-waker v1.1.0                                                                                                      │
│     Checking blocking v1.3.0                                                                                                          │
│     Checking bytemuck v1.13.1                                                                                                         │
│     Checking phf v0.11.1                                                                                                              │
│    Compiling idna v0.3.0                                                                                                              │
│     Checking csscolorparser v0.6.2                                                                                                    │
│     Checking pin-project v1.0.12                                                                                                      │
│     Checking filedescriptor v0.8.2 (/Users/waleed/Workspace/wezterm/filedescriptor)                                                   │
│    Compiling pest v2.5.6                                                                                                              │
│     Checking flume v0.10.14                                                                                                           │
│     Checking sha2 v0.9.9                                                                                                              │
│     Checking exr v1.5.3                                                                                                               │
│     Checking vtparse v0.6.2 (/Users/waleed/Workspace/wezterm/vtparse)                                                                 │
│    Compiling num-derive v0.3.3                                                                                                        │
│     Checking phf v0.10.1                                                                                                              │
│     Checking nix v0.24.3                                                                                                              │
│     Checking signal-hook v0.1.17                                                                                                      │
│     Checking termios v0.3.3                                                                                                           │
│     Checking serial-core v0.4.0                                                                                                       │
│     Checking ioctl-rs v0.1.6                                                                                                          │
│     Checking termios v0.2.2                                                                                                           │
│    Compiling async-net v1.7.0                                                                                                         │
│     Checking semver-parser v0.10.2                                                                                                    │
│    Compiling async-process v1.6.0                                                                                                     │
│    Compiling pest_meta v2.5.6                                                                                                         │
│    Compiling async-fs v1.6.0                                                                                                          │
│     Checking semver v0.11.0                                                                                                           │
│     Checking memmem v0.1.1                                                                                                            │
│     Checking unicode-segmentation v1.10.1                                                                                             │
│     Checking finl_unicode v1.2.0                                                                                                      │
│     Checking fixedbitset v0.4.2                                                                                                       │
│     Checking hex v0.4.3                                                                                                               │
│     Checking same-file v1.0.6                                                                                                         │
│     Checking walkdir v2.3.2                                                                                                           │
│     Checking serial-unix v0.4.0                                                                                                       │
│    Compiling pest_generator v2.5.6                                                                                                    │
│     Checking url v2.3.1                                                                                                               │
│     Checking image v0.24.5                                                                                                            │
│     Checking async-executor v1.5.0                                                                                                    │
│     Checking bstr v0.2.17                                                                                                             │
│    Compiling miniz_oxide v0.4.4                                                                                                       │
│     Checking serial v0.4.0                                                                                                            │
│     Checking nix v0.25.1                                                                                                              │
│     Checking euclid v0.22.7                                                                                                           │
│     Checking dirs-sys-next v0.1.2                                                                                                     │
│     Checking filetime v0.2.20                                                                                                         │
│     Checking winnow v0.3.4                                                                                                            │
│     Checking downcast-rs v1.2.0                                                                                                       │
│     Checking shell-words v1.1.0                                                                                                       │
│     Checking dirs-next v2.0.0                                                                                                         │
│     Checking smol v1.3.0                                                                                                              │
│     Checking lru v0.7.8                                                                                                               │
│     Checking fsevent-sys v4.1.0                                                                                                       │
│     Checking match_cfg v0.1.0                                                                                                         │
│    Compiling pest_derive v2.5.6                                                                                                       │
│     Checking promise v0.2.0 (/Users/waleed/Workspace/wezterm/promise)                                                                 │
│     Checking hostname v0.3.1                                                                                                          │
│     Checking notify v5.1.0                                                                                                            │
│     Checking colorgrad v0.6.2                                                                                                         │
│    Compiling enum-display-derive v0.1.1                                                                                               │
│    Compiling wezterm-config-derive v0.1.0 (/Users/waleed/Workspace/wezterm/config/derive)                                             │
│     Checking umask v0.1.0 (/Users/waleed/Workspace/wezterm/umask)                                                                     │
│     Checking shlex v1.1.0                                                                                                             │
│    Compiling openssl-src v300.0.12+3.0.8                                                                                              │
│     Checking foreign-types-shared v0.1.1                                                                                              │
│     Checking itoa v1.0.6                                                                                                              │
│     Checking foreign-types v0.3.2                                                                                                     │
│    Compiling io-lifetimes v1.0.5                                                                                                      │
│    Compiling rustix v0.36.9                                                                                                           │
│     Checking errno v0.2.8                                                                                                             │
│    Compiling openssl-sys v0.9.71                                                                                                      │
│     Checking ordered-float v3.4.0                                                                                                     │
│     Checking toml_datetime v0.6.1                                                                                                     │
│     Checking serde_spanned v0.6.1                                                                                                     │
│    Compiling objc_exception v0.1.2                                                                                                    │
│     Checking wezterm-dynamic v0.1.0 (/Users/waleed/Workspace/wezterm/wezterm-dynamic)                                                 │
│     Checking toml_edit v0.19.4                                                                                                        │
│     Checking portable-pty v0.8.0 (/Users/waleed/Workspace/wezterm/pty)                                                                │
│ error[E0412]: cannot find type `RawFd` in `std::os::fd`                                                                               │
│    --> pty/src/unix.rs:326:48                                                                                                         │
│     |                                                                                                                                 │
│ 326 |     fn as_raw_fd(&self) -> Option<std::os::fd::RawFd> {                                                                         │
│     |                                                ^^^^^ not found in `std::os::fd`                                                 │
│     |                                                                                                                                 │
│ help: consider importing this type alias                                                                                              │
│     |                                                                                                                                 │
│ 3   | use std::os::unix::prelude::RawFd;                                                                                              │
│     |                                                                                                                                 │
│ help: if you import `RawFd`, refer to it directly                                                                                     │
│     |                                                                                                                                 │
│ 326 -     fn as_raw_fd(&self) -> Option<std::os::fd::RawFd> {                                                                         │
│ 326 +     fn as_raw_fd(&self) -> Option<RawFd> {                                                                                      │
│     |                                                                                                                                 │
│                                                                                                                                       │
│ error[E0412]: cannot find type `RawFd` in `std::os::fd`                                                                               │
│    --> pty/src/serial.rs:245:48                                                                                                       │
│     |                                                                                                                                 │
│ 245 |     fn as_raw_fd(&self) -> Option<std::os::fd::RawFd> {                                                                         │
│     |                                                ^^^^^ not found in `std::os::fd`                                                 │
│     |                                                                                                                                 │
│ help: consider importing this type alias                                                                                              │
│     |                                                                                                                                 │
│ 8   | use std::os::unix::prelude::RawFd;                                                                                              │
│     |                                                                                                                                 │
│ help: if you import `RawFd`, refer to it directly                                                                                     │
│     |                                                                                                                                 │
│ 245 -     fn as_raw_fd(&self) -> Option<std::os::fd::RawFd> {                                                                         │
│ 245 +     fn as_raw_fd(&self) -> Option<RawFd> {                                                                                      │
│     |                                                                                                                                 │
│                                                                                                                                       │
│ error[E0412]: cannot find type `RawFd` in `std::os::fd`                                                                               │
│    --> pty/src/lib.rs:114:48                                                                                                          │
│     |                                                                                                                                 │
│ 114 |     fn as_raw_fd(&self) -> Option<std::os::fd::RawFd>;                                                                          │
│     |                                                ^^^^^ not found in `std::os::fd`                                                 │
│     |                                                                                                                                 │
│ help: consider importing this type alias                                                                                              │
│     |                                                                                                                                 │
│ 40  | use std::os::unix::prelude::RawFd;                                                                                              │
│     |                                                                                                                                 │
│ help: if you import `RawFd`, refer to it directly                                                                                     │
│     |                                                                                                                                 │
│ 114 -     fn as_raw_fd(&self) -> Option<std::os::fd::RawFd>;                                                                          │
│ 114 +     fn as_raw_fd(&self) -> Option<RawFd>;                                                                                       │
│     |                                                                                                                                 │
│                                                                                                                                       │
│ error[E0603]: module `fd` is private                                                                                                  │
│    --> pty/src/unix.rs:326:44                                                                                                         │
│     |                                                                                                                                 │
│ 326 |     fn as_raw_fd(&self) -> Option<std::os::fd::RawFd> {                                                                         │
│     |                                            ^^ private module                                                                    │
│     |                                                                                                                                 │
│ note: the module `fd` is defined here                                                                                                 │
│                                                                                                                                       │
│ error[E0603]: module `fd` is private                                                                                                  │
│    --> pty/src/serial.rs:245:44                                                                                                       │
│     |                                                                                                                                 │
│ 245 |     fn as_raw_fd(&self) -> Option<std::os::fd::RawFd> {                                                                         │
│     |                                            ^^ private module                                                                    │
│     |                                                                                                                                 │
│ note: the module `fd` is defined here                                                                                                 │
│                                                                                                                                       │
│ error[E0603]: module `fd` is private                                                                                                  │
│    --> pty/src/lib.rs:114:44                                                                                                          │
│     |                                                                                                                                 │
│ 114 |     fn as_raw_fd(&self) -> Option<std::os::fd::RawFd>;                                                                          │
│     |                                            ^^ private module                                                                    │
│     |                                                                                                                                 │
│ note: the module `fd` is defined here                                                                                                 │
│                                                                                                                                       │
│     Checking wezterm-color-types v0.2.0 (/Users/waleed/Workspace/wezterm/color-types)                                                 │
│     Checking wezterm-bidi v0.2.2 (/Users/waleed/Workspace/wezterm/bidi)                                                               │
│ Some errors have detailed explanations: E0412, E0603.                                                                                 │
│ For more information about an error, try `rustc --explain E0412`.                                                                     │
│ error: could not compile `portable-pty` due to 6 previous errors                                                                      │
│ warning: build failed, waiting for other jobs to finish...                                                                            │
└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
   Finished The MSRV is: 1.66.1   ██████████████████████████████████████████████████████████████████████████████████████████████ 00:05:30
```

However, the issue is simple to work around: just don't use the symbol `std::os::fd::RawFd` directly. This commit:

1) changes the interface to use a new exported symbol `RawFd` from the `crate::unix` module;
2) imports `std::os::unix::io::RawFd` instead of `std::os::fd::RawFd` as the symbol exported from `crate::unix`.

Doing so fixes the build in earlier versions of Rust:

```
$ cargo +1.63.0 check -p portable-pty --all-targets
    Checking portable-pty v0.8.0 (/Users/waleed/Workspace/wezterm/pty)
error[E0412]: cannot find type `RawFd` in `std::os::fd`
   --> pty/src/unix.rs:326:48
    |
326 |     fn as_raw_fd(&self) -> Option<std::os::fd::RawFd> {
    |                                                ^^^^^ not found in `std::os::fd`
    |
help: consider importing this type alias
    |
3   | use std::os::unix::prelude::RawFd;
    |
help: if you import `RawFd`, refer to it directly
    |
326 -     fn as_raw_fd(&self) -> Option<std::os::fd::RawFd> {
326 +     fn as_raw_fd(&self) -> Option<RawFd> {
    |

error[E0412]: cannot find type `RawFd` in `std::os::fd`
   --> pty/src/serial.rs:245:48
    |
245 |     fn as_raw_fd(&self) -> Option<std::os::fd::RawFd> {
    |                                                ^^^^^ not found in `std::os::fd`
    |
help: consider importing this type alias
    |
8   | use std::os::unix::prelude::RawFd;
    |
help: if you import `RawFd`, refer to it directly
    |
245 -     fn as_raw_fd(&self) -> Option<std::os::fd::RawFd> {
245 +     fn as_raw_fd(&self) -> Option<RawFd> {
    |

error[E0412]: cannot find type `RawFd` in `std::os::fd`
   --> pty/src/lib.rs:114:48
    |
114 |     fn as_raw_fd(&self) -> Option<std::os::fd::RawFd>;
    |                                                ^^^^^ not found in `std::os::fd`
    |
help: consider importing this type alias
    |
40  | use std::os::unix::prelude::RawFd;
    |
help: if you import `RawFd`, refer to it directly
    |
114 -     fn as_raw_fd(&self) -> Option<std::os::fd::RawFd>;
114 +     fn as_raw_fd(&self) -> Option<RawFd>;
    |

error[E0603]: module `fd` is private
   --> pty/src/unix.rs:326:44
    |
326 |     fn as_raw_fd(&self) -> Option<std::os::fd::RawFd> {
    |                                            ^^ private module
    |
note: the module `fd` is defined here

error[E0603]: module `fd` is private
   --> pty/src/serial.rs:245:44
    |
245 |     fn as_raw_fd(&self) -> Option<std::os::fd::RawFd> {
    |                                            ^^ private module
    |
note: the module `fd` is defined here

error[E0603]: module `fd` is private
   --> pty/src/lib.rs:114:44
    |
114 |     fn as_raw_fd(&self) -> Option<std::os::fd::RawFd>;
    |                                            ^^ private module
    |
note: the module `fd` is defined here

Some errors have detailed explanations: E0412, E0603.
For more information about an error, try `rustc --explain E0412`.
error: could not compile `portable-pty` due to 6 previous errors
warning: build failed, waiting for other jobs to finish...
error: could not compile `portable-pty` due to 6 previous errors

$ cargo +1.63.0 check -p portable-pty --all-targets
    Finished dev [unoptimized + debuginfo] target(s) in 0.17s
```
2023-03-12 20:48:01 -07:00
Wez Furlong
33f25e9ce6
reduce latency when heavily using foreground process info
The tcgetpgrp call appears to have high variance in latency, ranging
from 200-700us on my system.

If you have 10 tabs and mouse over the tab bar, that's around 7ms
spent per frame just figuring out the foreground process; that doesn't
include actually extracting the process executable or current working
directory paths.

This was exacerbated by the mouse move events triggering a tab bar
recompute on every pixel of mouse movement.

This commit takes the following steps to resolve this:

* We now only re-compute the tab bar when the UI item is changed by
  a mouse movement
* A simple single-item cache is now used on unix that allows the caller
  to proceed quickly with stale-but-probably-still-mostly-accurate data
  while queuing up an update to a background thread which can absorb
  the latency.

The result of this is that hovering over several tabs in quick
succession no longer takes a noticeable length of time to render the
hover, but the consequence is that the contents of a given tab may be
stale by 300-400ms.

I think that trade-off is worth while.

We already have a similar trade-off on Windows, although we don't
yet do the updates in a different thread on Windows. Perhaps in
a follow up commit?

refs: https://github.com/wez/wezterm/issues/2991
2023-01-21 15:25:57 -07:00
Wez Furlong
ee2aac0902
mux: require that Domain be Send + Sync 2022-12-19 11:52:38 -07:00
Wez Furlong
7158c435d5 lua: patch os.getenv with our own function
ad9490ee8f unset SHELL from the
environment on startup which had the consequence of causing
`os.getenv("SHELL")` to return `nil` when used in the config file.

Rather than simply restoring SHELL env var, recognize that reading
the environment from a long lived process is prone to seeing
stable environment forever.

We already compensate for this in the pty crate's understanding
of the base environment, so this commit patches `os.getenv`
and replaces it with our own imlementation that uses that same
logic.

The base environment logic has been extended to set SHELL from
the passwd database to round things out.

refs: https://github.com/wez/wezterm/discussions/2481
2022-09-04 15:39:28 -07:00
Wez Furlong
1b9ea2de3f change text cursor to fa_lock when entering passwords
There are caveats to determining this, but when we think
password entry is enabled, switch the cursor to the font-awesome
lock glyph instead of the normal cursor sprite.

fa_lock is used because it is monochrome and can thus be tinted
to the configured cursor color, and it respects blinking/easing.

refs: https://github.com/wez/wezterm/issues/2460
2022-09-02 09:00:28 -07:00
Wez Furlong
a599567423 cargo fmt 2022-09-01 06:54:27 -07:00
Wez Furlong
44ae864709 pty: fix build on windows 2022-09-01 06:02:16 -07:00
Wez Furlong
c0a841eecb pty: set SHELL to the shell we selected
refs: #2469
2022-09-01 05:37:51 -07:00
Wez Furlong
9082c79b34 pty: actually return the shell we found
this was masked for me because my dotfiles have a special case
to run zsh when launching sh as a login shell. doh!

refs: https://github.com/wez/wezterm/issues/2469
2022-09-01 05:24:05 -07:00
Wez Furlong
0d85d05442 update conpty to v1.14.2281.0 release 2022-08-29 08:32:08 -07:00
Davide Cavalca
0048209bcf Add missing license files 2022-08-17 07:19:12 -07:00
Wez Furlong
c8ca80f67e pty: fix doc example 2022-08-12 09:44:49 -07:00
Wez Furlong
53febb14ff pty: fixup for macos
e6421d1b72 removed this bit from the
example:

```
-
-    // Note that we're waiting until after we've read the output
-    // to call `wait` on the process.
-    // On macOS Catalina, waiting on the process seems to prevent
-    // its output from making it into the pty.
-    println!("child status: {:?}", child.wait().unwrap());
```

This commit revisits that and puts in place a differently horrible
solution for macos.

The issue is that if we don't put in a short sleep on macos, then
for a short lived process like `whoami` in this example, we end up
reading output like this:

```
; cargo run --example whoami
   Compiling portable-pty v0.8.0 (/Users/wez/wez-personal/wezterm/pty)
    Finished dev [unoptimized + debuginfo] target(s) in 0.60s
     Running `/Users/wez/wez-personal/wezterm/target/debug/examples/whoami`
child status: ExitStatus { code: 0, signal: None }
output: \r\n^D\u{8}\u{8}wez\r\n%
```

where the EOT that we send on Drop somehow gets *prepended* to the output
that we read from the pty with a couple of BELs thrown in.

I'm not sure WTF is happening on macOS for that to occur; feels like
some kind of race wrt. process startup and initializing the pty in the
system.

The reader has to be started before we close it as well, otherwise
the same issue can occur.
2022-08-12 08:37:20 -07:00
Wez Furlong
e6421d1b72 pty: try_clone_writer -> take_writer
This breaking API change allows us to explicitly generate EOF when the
taken writer is dropped.

The examples have been updated to show how to manage read, write
and waiting without deadlock for both linux and windows.
Need to confirm that this is still good on macOS, but my
confidence is high.

I've also removed ssh2 support from this crate as part of this
change. We haven't used it directly in wezterm in a long while
and removing it from here means that there is slightly less code
to keep compiling over and over.

refs: https://github.com/wez/wezterm/discussions/2392
refs: https://github.com/wez/wezterm/issues/1396
2022-08-12 07:56:46 -07:00
Wez Furlong
6542566e8f apply executable checks to $SHELL and /etc/passwd lookup
refs: https://github.com/wez/wezterm/issues/2378
2022-08-09 20:12:28 -07:00
Wez Furlong
9cd72fefe2 pty: cmdbuilder: check for executable access when resolving program
`wezterm start -- /etc/profile` would crash on macOS because
`/etc/profile` isn't executable.

This commit checks for executable access as a prereq for both the
path search and the absolute path cases and generates a non-crashing
error:

```
$ wezterm start -- /etc/profile
17:24:03.574  ERROR  wezterm_gui > Unable to spawn /etc/profile because it doesn't exist on the filesystem or is not executable (EACCES: Permission denied); terminating
```
2022-08-09 17:29:22 -07:00
Wez Furlong
404d742c14 Teach wezterm how to spawn programs when running in flatpak
This commit allows wezterm to spawn programs into the host rather
than in the container environment.

It feels weird that it is so trivial to "break out" of the container
sandbox, but I'm not complaining.

There are some unfortunate consequences:

* there is no `wezterm` installed on the host, so no ability to `wezterm
  cli` to control it from other apps
* The unix domain socket is scoped inside the sandbox, so there's "no
  way" for `wezterm cli` to reach inside anyway.

But: with this, it is at least usable to start a flatpak and open a
shell.

refs: https://github.com/wez/wezterm/issues/2229
2022-08-03 07:04:31 -07:00
Wez Furlong
d78cc6edb8 new: exec_domains
An ExecDomain is a variation on WslDomain with the key difference
being that you can control how to map the command that would be
executed.

The idea is that the user can define eg: a domain for a docker
container, or a domain that chooses to run every command in its
own cgroup.

The example below shows a really crappy implementation as a
demonstration:

```
local wezterm = require 'wezterm'

return {
  exec_domains = {
    -- Commands executed in the woot domain have "WOOT" echoed
    -- first and are then run via bash.
    -- `cmd` is a SpawnCommand
    wezterm.exec_domain("woot", function(cmd)
      if cmd.args then
        cmd.args = {
          "bash",
          "-c",
          "echo WOOT && " .. wezterm.shell_join_args(cmd.args)
        }
      end
      -- you must return the SpawnCommand that will be run
      return cmd
    end),
  },
  default_domain = "woot",
}
```

This commit unfortunately does more than should go into a single
commit, but I'm a bit too lazy to wrangle splitting it up.

* Reverts the nil/null stuff from #2177 and makes the
  `ExtendSelectionToMouseCursor` parameter mandatory to dodge
  a whole load of urgh around nil in table values. That is
  necessary because SpawnCommand uses optional fields and the
  userdata proxy was making that a PITA.
* Adds some shell quoting helper functions
* Adds ExecDomain itself, which is really just a way to
  to run a callback to fixup the command that will be run.
  That command is converted to a SpawnCommand for the callback
  to process in lua and return an adjusted version of it,
  then converted back to a command builder for execution.

refs: https://github.com/wez/wezterm/issues/1776
2022-07-07 16:38:14 -07:00
Wez Furlong
abfd2c2dc7 pty: fix compilation warning on !windows 2022-04-19 13:58:27 -07:00
Wez Furlong
d64bc7248e pty: pre-fill base env from registry env settings on Windows
I think I'd like to make a config option for this, but for the moment,
this first pass unconditionally updates the base environment with
data from the registry.

refs: https://github.com/wez/wezterm/issues/1848
2022-04-19 09:56:23 -07:00
Wez Furlong
f7b34438ed add clean_exit_codes config
refs: https://github.com/wez/wezterm/issues/1889
2022-04-19 07:48:49 -07:00
Wez Furlong
0f6ee20b28 pty: ExitStatus now understands signals and impl Display
Improves the fidelity of the information in ExitStatus and shows it
in the wezterm exit_behavior output to clarify the status.
2022-04-09 06:15:54 -07:00
Wez Furlong
255e059dab and this time with feeling!
I think this really will sort out the win32 build.
If not, I'll have to walk over to my windows machine and turn it on. :-p
2022-04-06 19:58:45 -07:00
Wez Furlong
9e1a6c5a75 maybe fix win32 build for real
nth time's the charm!
2022-04-06 19:44:38 -07:00
Wez Furlong
5eb3b122a6 really fix win32 build :-p
I'm not actually on win32 so this is speculative!
2022-04-06 18:49:48 -07:00
Wez Furlong
6e07fc5b9a fix win32 build
6cad4c35e9 calls get_shell, but
that isn't available on windows... it is now.
2022-04-06 18:42:56 -07:00
Wez Furlong
6cad4c35e9 Improve exit_behavior messaging some more 2022-04-06 17:53:46 -07:00
Wez Furlong
37d2b04af6 fix some warnings on windows 2022-03-18 10:29:01 -07:00
Wez Furlong
0a7e30e9bc serial: fix busy waiting on unix systems.
The serial port is always in non-blocking mode so we need to use our
own timeout and `poll(2)`.

While we're in here, the `wait` method could cause the gui to exit
immediately on startup because we'd interpret its immediate error
return result as child process completion.

This commit makes the wait method look at the carrier detect signal
and propagates IO errors back as completion events.

refs: https://github.com/wez/wezterm/issues/1594
2022-02-12 11:38:45 -07:00
Wez Furlong
c4009d8e1d deps: shell-words -> 1.1.0 2022-02-06 18:32:10 -07:00
Wez Furlong
e4ed2c93e2 encoding my preferred import grouping in the rustfmt config
This uses an unstable option in rustfmt, you `cargo +nightly fmt`
needs to be used to format the code correctly.
2022-01-17 13:50:51 -07:00
Wez Furlong
0e9924e585 new: WslDomain, a variant on the local domain
The idea is that we want to be able to spawn into wsl with the
convenience of a local domain, but without the awkwardness of
it having a different filesystem namespace.

It would also be great to be able to spawn a new tab or pane
in the same domain and pick up the cwd of the existing one.

The WslDomain allows the user to explicitly list WslDomains
and control eg: default shell, username and so on, but wezterm
will pre-fill a default list of domains based on the `wsl -l`
output that we were already using in the launcher menu.

The existing LocalDomain has been augmented to understand that
it may need to fixup a command invocation and that gives it
the opportunity to rewrite the command so that we can launch
it via `wsl.exe` and pass down the cwd and so on.

This same technique might be extensible to eg: docker instances
in the future.

This commit:

* Introduces `wsl_domains` config and its default list of wsl
  distributions
* Creates LocalDomain instances from that list
* The launcher menu allows spawning a new tab via one of those domains
2022-01-08 15:05:05 -07:00
Wez Furlong
a0cbea2703 term: ignore first OSC title change sequence on Windows
ConPTY emits a sequence that sets the title to the name of the
program that is initially launched into it.

This commit tries to ignore that sequence in that circumstance,
so that the logic in b5d156c282
can more dynamically set the tab title.
2021-12-25 01:10:37 -07:00
Wez Furlong
019de77fcf pty: fix weird cross-compile issue
For some reason, winapi's HANDLE type isn't compatible with the core
rust ffi HANDLE type when cross compiling.

This commit adds some casts.

```
cd pty
cargo build --release --target x86_64-pc-windows-msvc
```

refs: #1389
2021-12-12 09:46:17 -07:00
Wez Furlong
7250237b9a pty: actually fix win32 build 2021-12-11 10:03:43 -07:00
Wez Furlong
a65a4af9a7 pty: speculative fixup of win32 build 2021-12-11 09:30:51 -07:00