# client.Client.lock

- **Module:** client.Client
- **Package:** libtmux
- **Language:** Rust
- **Kind:** method
- **Source:** https://github.com/libtmux/libtmux-rs/blob/f0e37052c232636b61d095817046e6bfc8f2ca40/crates/libtmux/src/client.rs#L430
- **Page:** https://libtmux.org/en/rs/latest/reference/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`].
