# client.Client.lock

- **Module:** client.Client
- **Package:** libtmux
- **Language:** Rust
- **Kind:** method
- **Source:** https://github.com/libtmux/libtmux-rs/blob/8a648c0894dfffc9303583f753b6c8ae01f2fe76/crates/libtmux/src/client.rs#L456
- **Page:** https://libtmux.org/reference/rs/client-client-lock/

```
client.Client.lock(self) -> Result<(), Error>
```

Lock this client's terminal.

Runs the `lock-command` option, which is `lock -np` unless the server
was told otherwise. [`crate::Session::lock`] locks every client
attached to one session and [`crate::Server::lock_all`] locks every
client on the server; this locks exactly one.

tmux marks a locked client with the flag it uses for a suspended one,
so a locked client leaves [`crate::Server::clients`] the same way and
comes back when its `lock-command` exits. A server with
`lock-after-time` set reaches that state with nobody asking.

# Errors

Returns an error when tmux refuses the command. Reading through the
handle while the client is locked gives [`Error::ClientSuspended`],
not [`Error::ObjectGone`].
