Skip to content

Commit

Permalink
lua: add MuxPane:send_text MuxPane:send_paste
Browse files Browse the repository at this point in the history
  • Loading branch information
wez committed Jun 18, 2022
1 parent 1485cf3 commit 5fb60de
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
12 changes: 11 additions & 1 deletion docs/config/lua/MuxPane.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ It has the following methods:

Returns the pane id

## `pane::split{}`
## `pane:split{}`

Splits `pane` and spawns a program into the split, returning the
`MuxPane` object associated with it:
Expand Down Expand Up @@ -114,3 +114,13 @@ pane:split{direction="Top", size=0.333})
pane:split{direction="Top", size=0.5})
```

## `pane:send_paste(text)`

Sends text to the pane as though it was pasted. If bracketed paste mode is
enabled then the text will be sent as a bracketed paste. Otherwise, it will
be sent as-is.

## `pane:send_text(text)`

Sends text to the pane as-is.

15 changes: 15 additions & 0 deletions lua-api-crates/mux/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,21 @@ impl UserData for MuxPane {
let args = args.unwrap_or_default();
args.run(this).await
});
methods.add_method("send_paste", |_, this, text: String| {
let mux = get_mux()?;
let pane = this.resolve(&mux)?;
pane.send_paste(&text)
.map_err(|e| mlua::Error::external(format!("{:#}", e)))?;
Ok(())
});
methods.add_method("send_text", |_, this, text: String| {
let mux = get_mux()?;
let pane = this.resolve(&mux)?;
pane.writer()
.write_all(text.as_bytes())
.map_err(|e| mlua::Error::external(format!("{:#}", e)))?;
Ok(())
});
}
}

Expand Down

0 comments on commit 5fb60de

Please sign in to comment.