diff --git a/README.md b/README.md index 3ffe7b6..ba03951 100644 --- a/README.md +++ b/README.md @@ -152,6 +152,8 @@ Pane commands take argument arrays. [`send_text`][pane-send_text] types literal text, [`send_keys`][pane-send_keys] sends key names such as `Enter`, and [`capture`][pane-capture] reads the screen. +Omit `name:` to let tmux name a session or window. Omit `command:` to run +its configured `default-command` or, when empty, `default-shell`. [`Pane#resize`][pane-resize] and [`Window#resize`][window-resize] set sizes in cells: @@ -160,11 +162,9 @@ cells: require "libtmux" LibTmux::Server.start do |server| - created = server.new_session( - name: "work", command: ["/bin/sh"], receipt: true - ) + created = server.new_session(command: ["/bin/sh"], receipt: true) pane = created.pane - side = pane.split(direction: :horizontal, size: "40%", command: ["/bin/cat"]) + side = pane.split(direction: :horizontal, size: "40%") pane.send_text("echo café") pane.send_keys("Enter") @@ -176,6 +176,7 @@ LibTmux::Server.start do |server| break if line sleep 0.1 end + raise "shell did not print café" unless line puts "captured: #{line}" created.window.resize(width: 100, height: 30) diff --git a/docs/reference/api.md b/docs/reference/api.md index 5559100..1107f91 100644 --- a/docs/reference/api.md +++ b/docs/reference/api.md @@ -68,41 +68,41 @@ type checking. See [signature proof](behavior.md#signature-proof). | Method | Declared return | Contract | | --- | --- | --- | | [#attach](../../gems/libtmux-async/lib/libtmux/async/server.rb#L53) | `bot` | [Async unsupported operations](behavior.md#async-unsupported-operations) | -| [#capabilities](../../gems/libtmux/lib/libtmux/server.rb#L239) | `::LibTmux::Capabilities` | [Daemon capabilities](behavior.md#daemon-capabilities) | +| [#capabilities](../../gems/libtmux/lib/libtmux/server.rb#L240) | `::LibTmux::Capabilities` | [Daemon capabilities](behavior.md#daemon-capabilities) | | [#close](../../gems/libtmux-async/lib/libtmux/async/server.rb#L19) | `nil` | [Async scope](behavior.md#async-scope) | | [#delete_buffer](../../gems/libtmux/lib/libtmux/operations.rb#L69) | `::LibTmux::CommandResult` | [Buffers](behavior.md#buffers) | | [#diagnostics](../../gems/libtmux-async/lib/libtmux/async/server.rb#L24) | `::LibTmux::Async::scope_diagnostics` | [Diagnostics](behavior.md#diagnostics) | | [#display](../../gems/libtmux/lib/libtmux/operations.rb#L18) | `::LibTmux::CommandResult` | [Formats](behavior.md#formats) | -| [#endpoint](../../gems/libtmux/lib/libtmux/server.rb#L148) | `::LibTmux::Endpoint` | [Borrowed bindings](behavior.md#borrowed-bindings) | +| [#endpoint](../../gems/libtmux/lib/libtmux/server.rb#L149) | `::LibTmux::Endpoint` | [Borrowed bindings](behavior.md#borrowed-bindings) | | [#environment](../../gems/libtmux/lib/libtmux/operations.rb#L92) | `::String?` | [Environment](behavior.md#environment) | -| [#explain_panes](../../gems/libtmux/lib/libtmux/server.rb#L405) | `::Hash[::Symbol, untyped]` | [Source query plans](behavior.md#source-query-plans) | +| [#explain_panes](../../gems/libtmux/lib/libtmux/server.rb#L407) | `::Hash[::Symbol, untyped]` | [Source query plans](behavior.md#source-query-plans) | | [#hooks](../../gems/libtmux/lib/libtmux/operations.rb#L11) | `::LibTmux::Hooks` | [Options and hooks](behavior.md#options-and-hooks) | -| [#kill](../../gems/libtmux/lib/libtmux/server.rb#L299) | `::LibTmux::CommandResult` | [Killing daemons](behavior.md#killing-daemons) | +| [#kill](../../gems/libtmux/lib/libtmux/server.rb#L300) | `::LibTmux::CommandResult` | [Killing daemons](behavior.md#killing-daemons) | | [#list_buffers](../../gems/libtmux/lib/libtmux/operations.rb#L73) | `::Array[{ name: ::String, size: ::Integer }]` | [Buffers](behavior.md#buffers) | | [#list_clients](../../gems/libtmux/lib/libtmux/operations.rb#L100) | `::Array[{ name: ::String, pid: ::Integer, created: ::Integer, tty: ::String?, session_id: ::String?, control: bool }]` | [Live acquisition](behavior.md#live-acquisition) | -| [#list_panes](../../gems/libtmux/lib/libtmux/server.rb#L332) | `::Array[::LibTmux::Pane]` | [Live acquisition](behavior.md#live-acquisition) | -| [#list_sessions](../../gems/libtmux/lib/libtmux/server.rb#L324) | `::Array[::LibTmux::Session]` | [Live acquisition](behavior.md#live-acquisition) | +| [#list_panes](../../gems/libtmux/lib/libtmux/server.rb#L334) | `::Array[::LibTmux::Pane]` | [Live acquisition](behavior.md#live-acquisition) | +| [#list_sessions](../../gems/libtmux/lib/libtmux/server.rb#L326) | `::Array[::LibTmux::Session]` | [Live acquisition](behavior.md#live-acquisition) | | [#list_window_links](../../gems/libtmux/lib/libtmux/operations.rb#L80) | `::Array[::LibTmux::WindowLink]` | [Live acquisition](behavior.md#live-acquisition) | -| [#list_windows](../../gems/libtmux/lib/libtmux/server.rb#L328) | `::Array[::LibTmux::Window]` | [Live acquisition](behavior.md#live-acquisition) | -| [#new_session](../../gems/libtmux/lib/libtmux/server.rb#L310) | `::LibTmux::CreationReceipt` / `::LibTmux::Session` | [Creation](behavior.md#creation) | +| [#list_windows](../../gems/libtmux/lib/libtmux/server.rb#L330) | `::Array[::LibTmux::Window]` | [Live acquisition](behavior.md#live-acquisition) | +| [#new_session](../../gems/libtmux/lib/libtmux/server.rb#L311) | `::LibTmux::CreationReceipt` / `::LibTmux::Session` | [Creation](behavior.md#creation) | | [#open_control](../../gems/libtmux-async/lib/libtmux/async/server.rb#L28) | `T` / `::LibTmux::Async::ControlConnection` | [Control connections](behavior.md#control-connections) | | [#options](../../gems/libtmux/lib/libtmux/operations.rb#L7) | `::LibTmux::Options` | [Options and hooks](behavior.md#options-and-hooks) | | [#owned?](../../gems/libtmux/lib/libtmux/owned.rb#L16) | `bool` | [Borrowed bindings](behavior.md#borrowed-bindings) | -| [#pane](../../gems/libtmux/lib/libtmux/server.rb#L344) | `::LibTmux::Pane` | [Live handles](behavior.md#live-handles) | +| [#pane](../../gems/libtmux/lib/libtmux/server.rb#L346) | `::LibTmux::Pane` | [Live handles](behavior.md#live-handles) | | [#read_buffer](../../gems/libtmux/lib/libtmux/operations.rb#L65) | `::LibTmux::CommandResult` | [Buffers](behavior.md#buffers) | | [#run](../../gems/libtmux-async/lib/libtmux/async/server.rb#L15) | `::LibTmux::CommandResult` | [Raw commands](behavior.md#raw-commands) | | [#run_group](../../gems/libtmux/lib/libtmux/group.rb#L32) | `::LibTmux::GroupResult` | [Command groups](behavior.md#command-groups) | -| [#search_panes](../../gems/libtmux/lib/libtmux/server.rb#L401) | `::LibTmux::Selection[::LibTmux::PaneSnapshot]` | [Source query execution](behavior.md#source-query-execution) | -| [#session](../../gems/libtmux/lib/libtmux/server.rb#L336) | `::LibTmux::Session` | [Live handles](behavior.md#live-handles) | +| [#search_panes](../../gems/libtmux/lib/libtmux/server.rb#L403) | `::LibTmux::Selection[::LibTmux::PaneSnapshot]` | [Source query execution](behavior.md#source-query-execution) | +| [#session](../../gems/libtmux/lib/libtmux/server.rb#L338) | `::LibTmux::Session` | [Live handles](behavior.md#live-handles) | | [#set_environment](../../gems/libtmux/lib/libtmux/operations.rb#L88) | `::LibTmux::CommandResult` | [Environment](behavior.md#environment) | -| [#snapshot](../../gems/libtmux/lib/libtmux/server.rb#L395) | `::LibTmux::Snapshot` | [Snapshot acquisition](behavior.md#snapshot-acquisition) | +| [#snapshot](../../gems/libtmux/lib/libtmux/server.rb#L397) | `::LibTmux::Snapshot` | [Snapshot acquisition](behavior.md#snapshot-acquisition) | | [#source_file](../../gems/libtmux/lib/libtmux/operations.rb#L42) | `::LibTmux::CommandResult` | [Source files](behavior.md#source-files) | -| [#supports_control?](../../gems/libtmux/lib/libtmux/server.rb#L231) | `bool` | [Borrowed bindings](behavior.md#borrowed-bindings) | +| [#supports_control?](../../gems/libtmux/lib/libtmux/server.rb#L232) | `bool` | [Borrowed bindings](behavior.md#borrowed-bindings) | | [#switch_client](../../gems/libtmux/lib/libtmux/terminal.rb#L39) | `::LibTmux::CommandResult` | [Client switching](behavior.md#client-switching) | -| [#tmux_version](../../gems/libtmux/lib/libtmux/server.rb#L226) | `::String` | [Borrowed bindings](behavior.md#borrowed-bindings) | +| [#tmux_version](../../gems/libtmux/lib/libtmux/server.rb#L227) | `::String` | [Borrowed bindings](behavior.md#borrowed-bindings) | | [#unset_environment](../../gems/libtmux/lib/libtmux/operations.rb#L96) | `::LibTmux::CommandResult` | [Environment](behavior.md#environment) | | [#wait_for](../../gems/libtmux/lib/libtmux/operations.rb#L47) | `::LibTmux::CommandResult` | [Wait channels](behavior.md#wait-channels) | -| [#window](../../gems/libtmux/lib/libtmux/server.rb#L340) | `::LibTmux::Window` | [Live handles](behavior.md#live-handles) | +| [#window](../../gems/libtmux/lib/libtmux/server.rb#L342) | `::LibTmux::Window` | [Live handles](behavior.md#live-handles) | | [#window_link](../../gems/libtmux/lib/libtmux/operations.rb#L84) | `::LibTmux::WindowLink` | [Live handles](behavior.md#live-handles) | | [#write_buffer](../../gems/libtmux/lib/libtmux/operations.rb#L57) | `::LibTmux::CommandResult` | [Buffers](behavior.md#buffers) | | [.open](../../gems/libtmux-async/lib/libtmux/async/server.rb#L61) | `bot` | [Async unsupported operations](behavior.md#async-unsupported-operations) | @@ -648,7 +648,7 @@ type checking. See [signature proof](behavior.md#signature-proof). | --- | --- | --- | | [#==](../../gems/libtmux/lib/libtmux/entity.rb#L78) | `bool` | [Live handles](behavior.md#live-handles) | | [#break_out](../../gems/libtmux/lib/libtmux/operations.rb#L358) | `::LibTmux::Window` | [Entity mutation](behavior.md#entity-mutation) | -| [#capture](../../gems/libtmux/lib/libtmux/entity.rb#L350) | `::LibTmux::CommandResult` | [Pane input and capture](behavior.md#pane-input-and-capture) | +| [#capture](../../gems/libtmux/lib/libtmux/entity.rb#L351) | `::LibTmux::CommandResult` | [Pane input and capture](behavior.md#pane-input-and-capture) | | [#copy_command](../../gems/libtmux/lib/libtmux/operations.rb#L426) | `::LibTmux::CommandResult` | [Copy mode](behavior.md#copy-mode) | | [#copy_mode](../../gems/libtmux/lib/libtmux/operations.rb#L410) | `::LibTmux::CommandResult` | [Copy mode](behavior.md#copy-mode) | | [#display](../../gems/libtmux/lib/libtmux/operations.rb#L254) | `::LibTmux::CommandResult` | [Formats](behavior.md#formats) | @@ -667,11 +667,11 @@ type checking. See [signature proof](behavior.md#signature-proof). | [#resize](../../gems/libtmux/lib/libtmux/operations.rb#L325) | `::LibTmux::CommandResult` | [Entity mutation](behavior.md#entity-mutation) | | [#respawn](../../gems/libtmux/lib/libtmux/operations.rb#L381) | `::LibTmux::CommandResult` | [Entity mutation](behavior.md#entity-mutation) | | [#select](../../gems/libtmux/lib/libtmux/operations.rb#L321) | `::LibTmux::CommandResult` | [Entity mutation](behavior.md#entity-mutation) | -| [#send_keys](../../gems/libtmux/lib/libtmux/entity.rb#L380) | `::LibTmux::CommandResult` | [Pane input and capture](behavior.md#pane-input-and-capture) | -| [#send_text](../../gems/libtmux/lib/libtmux/entity.rb#L374) | `::LibTmux::CommandResult` | [Pane input and capture](behavior.md#pane-input-and-capture) | +| [#send_keys](../../gems/libtmux/lib/libtmux/entity.rb#L381) | `::LibTmux::CommandResult` | [Pane input and capture](behavior.md#pane-input-and-capture) | +| [#send_text](../../gems/libtmux/lib/libtmux/entity.rb#L375) | `::LibTmux::CommandResult` | [Pane input and capture](behavior.md#pane-input-and-capture) | | [#server](../../gems/libtmux/lib/libtmux/entity.rb#L61) | `::LibTmux::Server` | [Live handles](behavior.md#live-handles) | | [#snapshot](../../gems/libtmux/lib/libtmux/entity.rb#L74) | `::LibTmux::PaneSnapshot` | [Snapshot acquisition](behavior.md#snapshot-acquisition) | -| [#split](../../gems/libtmux/lib/libtmux/entity.rb#L345) | `::LibTmux::Pane` | [Creation](behavior.md#creation) | +| [#split](../../gems/libtmux/lib/libtmux/entity.rb#L346) | `::LibTmux::Pane` | [Creation](behavior.md#creation) | | [#swap](../../gems/libtmux/lib/libtmux/operations.rb#L343) | `::LibTmux::CommandResult` | [Entity mutation](behavior.md#entity-mutation) | | [#wait_for_text](../../gems/libtmux/lib/libtmux/text_wait.rb#L22) | `::LibTmux::TextWait::Result` | [Pane text waits](behavior.md#pane-text-waits) | @@ -760,45 +760,45 @@ type checking. See [signature proof](behavior.md#signature-proof). | Method | Declared return | Contract | | --- | --- | --- | | [#attach](../../gems/libtmux/lib/libtmux/terminal.rb#L52) | `::LibTmux::TerminalResult` | [Terminal attachment](behavior.md#terminal-attachment) | -| [#capabilities](../../gems/libtmux/lib/libtmux/server.rb#L239) | `::LibTmux::Capabilities` | [Daemon capabilities](behavior.md#daemon-capabilities) | -| [#close](../../gems/libtmux/lib/libtmux/server.rb#L250) | `nil` | [Closing bindings](behavior.md#closing-bindings) | +| [#capabilities](../../gems/libtmux/lib/libtmux/server.rb#L240) | `::LibTmux::Capabilities` | [Daemon capabilities](behavior.md#daemon-capabilities) | +| [#close](../../gems/libtmux/lib/libtmux/server.rb#L251) | `nil` | [Closing bindings](behavior.md#closing-bindings) | | [#delete_buffer](../../gems/libtmux/lib/libtmux/operations.rb#L69) | `::LibTmux::CommandResult` | [Buffers](behavior.md#buffers) | -| [#diagnostics](../../gems/libtmux/lib/libtmux/server.rb#L289) | `{ admitted_requests: ::Integer, reserved_process_slots: ::Integer, control_connections: ::Integer, closed: bool, limits: { max_requests: ::Integer, max_controls: ::Integer, close_timeout: ::Numeric } }` | [Diagnostics](behavior.md#diagnostics) | +| [#diagnostics](../../gems/libtmux/lib/libtmux/server.rb#L290) | `{ admitted_requests: ::Integer, reserved_process_slots: ::Integer, control_connections: ::Integer, closed: bool, limits: { max_requests: ::Integer, max_controls: ::Integer, close_timeout: ::Numeric } }` | [Diagnostics](behavior.md#diagnostics) | | [#display](../../gems/libtmux/lib/libtmux/operations.rb#L18) | `::LibTmux::CommandResult` | [Formats](behavior.md#formats) | -| [#endpoint](../../gems/libtmux/lib/libtmux/server.rb#L148) | `::LibTmux::Endpoint` | [Borrowed bindings](behavior.md#borrowed-bindings) | +| [#endpoint](../../gems/libtmux/lib/libtmux/server.rb#L149) | `::LibTmux::Endpoint` | [Borrowed bindings](behavior.md#borrowed-bindings) | | [#environment](../../gems/libtmux/lib/libtmux/operations.rb#L92) | `::String?` | [Environment](behavior.md#environment) | -| [#explain_panes](../../gems/libtmux/lib/libtmux/server.rb#L405) | `::Hash[::Symbol, untyped]` | [Source query plans](behavior.md#source-query-plans) | +| [#explain_panes](../../gems/libtmux/lib/libtmux/server.rb#L407) | `::Hash[::Symbol, untyped]` | [Source query plans](behavior.md#source-query-plans) | | [#hooks](../../gems/libtmux/lib/libtmux/operations.rb#L11) | `::LibTmux::Hooks` | [Options and hooks](behavior.md#options-and-hooks) | -| [#kill](../../gems/libtmux/lib/libtmux/server.rb#L299) | `::LibTmux::CommandResult` | [Killing daemons](behavior.md#killing-daemons) | +| [#kill](../../gems/libtmux/lib/libtmux/server.rb#L300) | `::LibTmux::CommandResult` | [Killing daemons](behavior.md#killing-daemons) | | [#list_buffers](../../gems/libtmux/lib/libtmux/operations.rb#L73) | `::Array[{ name: ::String, size: ::Integer }]` | [Buffers](behavior.md#buffers) | | [#list_clients](../../gems/libtmux/lib/libtmux/operations.rb#L100) | `::Array[{ name: ::String, pid: ::Integer, created: ::Integer, tty: ::String?, session_id: ::String?, control: bool }]` | [Live acquisition](behavior.md#live-acquisition) | -| [#list_panes](../../gems/libtmux/lib/libtmux/server.rb#L332) | `::Array[::LibTmux::Pane]` | [Live acquisition](behavior.md#live-acquisition) | -| [#list_sessions](../../gems/libtmux/lib/libtmux/server.rb#L324) | `::Array[::LibTmux::Session]` | [Live acquisition](behavior.md#live-acquisition) | +| [#list_panes](../../gems/libtmux/lib/libtmux/server.rb#L334) | `::Array[::LibTmux::Pane]` | [Live acquisition](behavior.md#live-acquisition) | +| [#list_sessions](../../gems/libtmux/lib/libtmux/server.rb#L326) | `::Array[::LibTmux::Session]` | [Live acquisition](behavior.md#live-acquisition) | | [#list_window_links](../../gems/libtmux/lib/libtmux/operations.rb#L80) | `::Array[::LibTmux::WindowLink]` | [Live acquisition](behavior.md#live-acquisition) | -| [#list_windows](../../gems/libtmux/lib/libtmux/server.rb#L328) | `::Array[::LibTmux::Window]` | [Live acquisition](behavior.md#live-acquisition) | -| [#new_session](../../gems/libtmux/lib/libtmux/server.rb#L310) | `::LibTmux::CreationReceipt` / `::LibTmux::Session` | [Creation](behavior.md#creation) | -| [#open_control](../../gems/libtmux/lib/libtmux/server.rb#L348) | `T` / `::LibTmux::ControlConnection` | [Control connections](behavior.md#control-connections) | +| [#list_windows](../../gems/libtmux/lib/libtmux/server.rb#L330) | `::Array[::LibTmux::Window]` | [Live acquisition](behavior.md#live-acquisition) | +| [#new_session](../../gems/libtmux/lib/libtmux/server.rb#L311) | `::LibTmux::CreationReceipt` / `::LibTmux::Session` | [Creation](behavior.md#creation) | +| [#open_control](../../gems/libtmux/lib/libtmux/server.rb#L350) | `T` / `::LibTmux::ControlConnection` | [Control connections](behavior.md#control-connections) | | [#options](../../gems/libtmux/lib/libtmux/operations.rb#L7) | `::LibTmux::Options` | [Options and hooks](behavior.md#options-and-hooks) | | [#owned?](../../gems/libtmux/lib/libtmux/owned.rb#L16) | `bool` | [Borrowed bindings](behavior.md#borrowed-bindings) | -| [#pane](../../gems/libtmux/lib/libtmux/server.rb#L344) | `::LibTmux::Pane` | [Live handles](behavior.md#live-handles) | +| [#pane](../../gems/libtmux/lib/libtmux/server.rb#L346) | `::LibTmux::Pane` | [Live handles](behavior.md#live-handles) | | [#read_buffer](../../gems/libtmux/lib/libtmux/operations.rb#L65) | `::LibTmux::CommandResult` | [Buffers](behavior.md#buffers) | -| [#run](../../gems/libtmux/lib/libtmux/server.rb#L246) | `::LibTmux::CommandResult` | [Raw commands](behavior.md#raw-commands) | +| [#run](../../gems/libtmux/lib/libtmux/server.rb#L247) | `::LibTmux::CommandResult` | [Raw commands](behavior.md#raw-commands) | | [#run_group](../../gems/libtmux/lib/libtmux/group.rb#L32) | `::LibTmux::GroupResult` | [Command groups](behavior.md#command-groups) | -| [#search_panes](../../gems/libtmux/lib/libtmux/server.rb#L401) | `::LibTmux::Selection[::LibTmux::PaneSnapshot]` | [Source query execution](behavior.md#source-query-execution) | -| [#session](../../gems/libtmux/lib/libtmux/server.rb#L336) | `::LibTmux::Session` | [Live handles](behavior.md#live-handles) | +| [#search_panes](../../gems/libtmux/lib/libtmux/server.rb#L403) | `::LibTmux::Selection[::LibTmux::PaneSnapshot]` | [Source query execution](behavior.md#source-query-execution) | +| [#session](../../gems/libtmux/lib/libtmux/server.rb#L338) | `::LibTmux::Session` | [Live handles](behavior.md#live-handles) | | [#set_environment](../../gems/libtmux/lib/libtmux/operations.rb#L88) | `::LibTmux::CommandResult` | [Environment](behavior.md#environment) | -| [#snapshot](../../gems/libtmux/lib/libtmux/server.rb#L395) | `::LibTmux::Snapshot` | [Snapshot acquisition](behavior.md#snapshot-acquisition) | +| [#snapshot](../../gems/libtmux/lib/libtmux/server.rb#L397) | `::LibTmux::Snapshot` | [Snapshot acquisition](behavior.md#snapshot-acquisition) | | [#source_file](../../gems/libtmux/lib/libtmux/operations.rb#L42) | `::LibTmux::CommandResult` | [Source files](behavior.md#source-files) | -| [#supports_control?](../../gems/libtmux/lib/libtmux/server.rb#L231) | `bool` | [Borrowed bindings](behavior.md#borrowed-bindings) | +| [#supports_control?](../../gems/libtmux/lib/libtmux/server.rb#L232) | `bool` | [Borrowed bindings](behavior.md#borrowed-bindings) | | [#switch_client](../../gems/libtmux/lib/libtmux/terminal.rb#L39) | `::LibTmux::CommandResult` | [Client switching](behavior.md#client-switching) | -| [#tmux_version](../../gems/libtmux/lib/libtmux/server.rb#L226) | `::String` | [Borrowed bindings](behavior.md#borrowed-bindings) | +| [#tmux_version](../../gems/libtmux/lib/libtmux/server.rb#L227) | `::String` | [Borrowed bindings](behavior.md#borrowed-bindings) | | [#unset_environment](../../gems/libtmux/lib/libtmux/operations.rb#L96) | `::LibTmux::CommandResult` | [Environment](behavior.md#environment) | | [#wait_for](../../gems/libtmux/lib/libtmux/operations.rb#L47) | `::LibTmux::CommandResult` | [Wait channels](behavior.md#wait-channels) | -| [#window](../../gems/libtmux/lib/libtmux/server.rb#L340) | `::LibTmux::Window` | [Live handles](behavior.md#live-handles) | +| [#window](../../gems/libtmux/lib/libtmux/server.rb#L342) | `::LibTmux::Window` | [Live handles](behavior.md#live-handles) | | [#window_link](../../gems/libtmux/lib/libtmux/operations.rb#L84) | `::LibTmux::WindowLink` | [Live handles](behavior.md#live-handles) | | [#write_buffer](../../gems/libtmux/lib/libtmux/operations.rb#L57) | `::LibTmux::CommandResult` | [Buffers](behavior.md#buffers) | -| [.new](../../gems/libtmux/lib/libtmux/server.rb#L182) | `::LibTmux::Server` | [Borrowed bindings](behavior.md#borrowed-bindings) | -| [.open](../../gems/libtmux/lib/libtmux/server.rb#L150) | `T` / `::LibTmux::Server` | [Borrowed bindings](behavior.md#borrowed-bindings) | +| [.new](../../gems/libtmux/lib/libtmux/server.rb#L183) | `::LibTmux::Server` | [Borrowed bindings](behavior.md#borrowed-bindings) | +| [.open](../../gems/libtmux/lib/libtmux/server.rb#L151) | `T` / `::LibTmux::Server` | [Borrowed bindings](behavior.md#borrowed-bindings) | | [.start](../../gems/libtmux/lib/libtmux/owned.rb#L12) | `::LibTmux::Server` / `T` | [Owned daemons](behavior.md#owned-daemons) | | [.valid_terminal_type?](../../gems/libtmux/lib/libtmux/terminal.rb#L34) | `bool` | [Terminal attachment](behavior.md#terminal-attachment) | @@ -816,10 +816,10 @@ type checking. See [signature proof](behavior.md#signature-proof). | [#inspect](../../gems/libtmux/lib/libtmux/entity.rb#L91) | `::String` | [Live handles](behavior.md#live-handles) | | [#kill](../../gems/libtmux/lib/libtmux/operations.rb#L261) | `::LibTmux::CommandResult` | [Entity removal](behavior.md#entity-removal) | | [#link_window](../../gems/libtmux/lib/libtmux/operations.rb#L275) | `::LibTmux::CommandResult` | [Window links](behavior.md#window-links) | -| [#list_panes](../../gems/libtmux/lib/libtmux/entity.rb#L168) | `::Array[::LibTmux::Pane]` | [Live acquisition](behavior.md#live-acquisition) | +| [#list_panes](../../gems/libtmux/lib/libtmux/entity.rb#L169) | `::Array[::LibTmux::Pane]` | [Live acquisition](behavior.md#live-acquisition) | | [#list_window_links](../../gems/libtmux/lib/libtmux/operations.rb#L271) | `::Array[::LibTmux::WindowLink]` | [Live acquisition](behavior.md#live-acquisition) | -| [#list_windows](../../gems/libtmux/lib/libtmux/entity.rb#L164) | `::Array[::LibTmux::Window]` | [Live acquisition](behavior.md#live-acquisition) | -| [#new_window](../../gems/libtmux/lib/libtmux/entity.rb#L159) | `::LibTmux::CreationReceipt` / `::LibTmux::Window` | [Creation](behavior.md#creation) | +| [#list_windows](../../gems/libtmux/lib/libtmux/entity.rb#L165) | `::Array[::LibTmux::Window]` | [Live acquisition](behavior.md#live-acquisition) | +| [#new_window](../../gems/libtmux/lib/libtmux/entity.rb#L160) | `::LibTmux::CreationReceipt` / `::LibTmux::Window` | [Creation](behavior.md#creation) | | [#options](../../gems/libtmux/lib/libtmux/operations.rb#L246) | `::LibTmux::Options` | [Options and hooks](behavior.md#options-and-hooks) | | [#ref](../../gems/libtmux/lib/libtmux/entity.rb#L61) | `::LibTmux::EntityRef` | [Live handles](behavior.md#live-handles) | | [#rename](../../gems/libtmux/lib/libtmux/operations.rb#L267) | `::LibTmux::CommandResult` | [Entity mutation](behavior.md#entity-mutation) | @@ -977,40 +977,40 @@ type checking. See [signature proof](behavior.md#signature-proof). | [#id](../../gems/libtmux/lib/libtmux/entity.rb#L70) | `::String` | [Live handles](behavior.md#live-handles) | | [#inspect](../../gems/libtmux/lib/libtmux/entity.rb#L91) | `::String` | [Live handles](behavior.md#live-handles) | | [#kill](../../gems/libtmux/lib/libtmux/entity.rb#L87) | `::LibTmux::CommandResult` | [Entity removal](behavior.md#entity-removal) | -| [#list_panes](../../gems/libtmux/lib/libtmux/entity.rb#L229) | `::Array[::LibTmux::Pane]` | [Live acquisition](behavior.md#live-acquisition) | +| [#list_panes](../../gems/libtmux/lib/libtmux/entity.rb#L230) | `::Array[::LibTmux::Pane]` | [Live acquisition](behavior.md#live-acquisition) | | [#options](../../gems/libtmux/lib/libtmux/operations.rb#L246) | `::LibTmux::Options` | [Options and hooks](behavior.md#options-and-hooks) | | [#ref](../../gems/libtmux/lib/libtmux/entity.rb#L61) | `::LibTmux::EntityRef` | [Live handles](behavior.md#live-handles) | | [#rename](../../gems/libtmux/lib/libtmux/operations.rb#L296) | `::LibTmux::CommandResult` | [Entity mutation](behavior.md#entity-mutation) | | [#resize](../../gems/libtmux/lib/libtmux/operations.rb#L307) | `::LibTmux::CommandResult` | [Entity mutation](behavior.md#entity-mutation) | | [#respawn](../../gems/libtmux/lib/libtmux/operations.rb#L300) | `::LibTmux::CommandResult` | [Entity mutation](behavior.md#entity-mutation) | -| [#select_layout](../../gems/libtmux/lib/libtmux/entity.rb#L238) | `::LibTmux::CommandResult` | [Entity mutation](behavior.md#entity-mutation) | +| [#select_layout](../../gems/libtmux/lib/libtmux/entity.rb#L239) | `::LibTmux::CommandResult` | [Entity mutation](behavior.md#entity-mutation) | | [#server](../../gems/libtmux/lib/libtmux/entity.rb#L61) | `::LibTmux::Server` | [Live handles](behavior.md#live-handles) | | [#snapshot](../../gems/libtmux/lib/libtmux/entity.rb#L74) | `::LibTmux::WindowSnapshot` | [Snapshot acquisition](behavior.md#snapshot-acquisition) | -| [#split](../../gems/libtmux/lib/libtmux/entity.rb#L233) | `::LibTmux::Pane` | [Creation](behavior.md#creation) | +| [#split](../../gems/libtmux/lib/libtmux/entity.rb#L234) | `::LibTmux::Pane` | [Creation](behavior.md#creation) | ## LibTmux::WindowLink | Method | Declared return | Contract | | --- | --- | --- | | [#==](../../gems/libtmux/lib/libtmux/entity.rb#L78) | `bool` | [Live handles](behavior.md#live-handles) | -| [#display](../../gems/libtmux/lib/libtmux/entity.rb#L425) | `::LibTmux::CommandResult` | [Formats](behavior.md#formats) | +| [#display](../../gems/libtmux/lib/libtmux/entity.rb#L426) | `::LibTmux::CommandResult` | [Formats](behavior.md#formats) | | [#eql?](../../gems/libtmux/lib/libtmux/entity.rb#L78) | `bool` | [Live handles](behavior.md#live-handles) | | [#hash](../../gems/libtmux/lib/libtmux/entity.rb#L83) | `::Integer` | [Live handles](behavior.md#live-handles) | -| [#hooks](../../gems/libtmux/lib/libtmux/entity.rb#L433) | `::LibTmux::Hooks` | [Options and hooks](behavior.md#options-and-hooks) | +| [#hooks](../../gems/libtmux/lib/libtmux/entity.rb#L434) | `::LibTmux::Hooks` | [Options and hooks](behavior.md#options-and-hooks) | | [#id](../../gems/libtmux/lib/libtmux/entity.rb#L70) | `::String` | [Live handles](behavior.md#live-handles) | -| [#index](../../gems/libtmux/lib/libtmux/entity.rb#L388) | `::Integer` | [Live handles](behavior.md#live-handles) | +| [#index](../../gems/libtmux/lib/libtmux/entity.rb#L389) | `::Integer` | [Live handles](behavior.md#live-handles) | | [#inspect](../../gems/libtmux/lib/libtmux/entity.rb#L91) | `::String` | [Live handles](behavior.md#live-handles) | -| [#kill](../../gems/libtmux/lib/libtmux/entity.rb#L408) | `::LibTmux::CommandResult` | [Window links](behavior.md#window-links) | -| [#move](../../gems/libtmux/lib/libtmux/entity.rb#L412) | `::LibTmux::CommandResult` | [Window links](behavior.md#window-links) | -| [#options](../../gems/libtmux/lib/libtmux/entity.rb#L429) | `::LibTmux::Options` | [Options and hooks](behavior.md#options-and-hooks) | +| [#kill](../../gems/libtmux/lib/libtmux/entity.rb#L409) | `::LibTmux::CommandResult` | [Window links](behavior.md#window-links) | +| [#move](../../gems/libtmux/lib/libtmux/entity.rb#L413) | `::LibTmux::CommandResult` | [Window links](behavior.md#window-links) | +| [#options](../../gems/libtmux/lib/libtmux/entity.rb#L430) | `::LibTmux::Options` | [Options and hooks](behavior.md#options-and-hooks) | | [#ref](../../gems/libtmux/lib/libtmux/entity.rb#L61) | `::LibTmux::EntityRef` | [Live handles](behavior.md#live-handles) | -| [#select](../../gems/libtmux/lib/libtmux/entity.rb#L400) | `::LibTmux::CommandResult` | [Window links](behavior.md#window-links) | +| [#select](../../gems/libtmux/lib/libtmux/entity.rb#L401) | `::LibTmux::CommandResult` | [Window links](behavior.md#window-links) | | [#server](../../gems/libtmux/lib/libtmux/entity.rb#L61) | `::LibTmux::Server` | [Live handles](behavior.md#live-handles) | -| [#session](../../gems/libtmux/lib/libtmux/entity.rb#L396) | `::LibTmux::Session` | [Live handles](behavior.md#live-handles) | +| [#session](../../gems/libtmux/lib/libtmux/entity.rb#L397) | `::LibTmux::Session` | [Live handles](behavior.md#live-handles) | | [#snapshot](../../gems/libtmux/lib/libtmux/entity.rb#L74) | `::LibTmux::WindowLinkSnapshot` | [Snapshot acquisition](behavior.md#snapshot-acquisition) | -| [#swap](../../gems/libtmux/lib/libtmux/entity.rb#L419) | `::LibTmux::CommandResult` | [Window links](behavior.md#window-links) | -| [#unlink](../../gems/libtmux/lib/libtmux/entity.rb#L404) | `::LibTmux::CommandResult` | [Window links](behavior.md#window-links) | -| [#window](../../gems/libtmux/lib/libtmux/entity.rb#L392) | `::LibTmux::Window` | [Live handles](behavior.md#live-handles) | +| [#swap](../../gems/libtmux/lib/libtmux/entity.rb#L420) | `::LibTmux::CommandResult` | [Window links](behavior.md#window-links) | +| [#unlink](../../gems/libtmux/lib/libtmux/entity.rb#L405) | `::LibTmux::CommandResult` | [Window links](behavior.md#window-links) | +| [#window](../../gems/libtmux/lib/libtmux/entity.rb#L393) | `::LibTmux::Window` | [Live handles](behavior.md#live-handles) | ## LibTmux::WindowLinkSnapshot diff --git a/docs/reference/behavior.md b/docs/reference/behavior.md index 4a074fb..d5626c5 100644 --- a/docs/reference/behavior.md +++ b/docs/reference/behavior.md @@ -356,11 +356,14 @@ aggregate client success only. ## Creation `new_session`, `new_window` and `split` return exact tmux-assigned handles. -`command` requires a nonempty argv array. A single executable is protected -from tmux's single-string shell interpretation; shell execution requires an -explicit shell argv. Names and cwd are escaped against tmux format expansion; -environment values are literal strings. Environment defaults to empty, cwd -to unspecified, and new windows/splits use `focus: false`. +Omit `command:` to use tmux's `default-command`. When that option is empty, +tmux starts `default-shell`. To run a specific program, supply a nonempty +argv array. A single executable runs literally. To interpret shell syntax, +pass an explicit shell argv. Omit `name:` to let tmux name a session or window. + +Names and cwd are escaped against tmux format expansion. Environment values +are literal strings. Environment defaults to empty, cwd to unspecified, and +new windows and splits use `focus: false`. A supplied cwd is checked as a local directory before dispatch; concurrent filesystem changes can still trigger tmux's native fallback. Window indexes diff --git a/examples/api/split_resize.rb b/examples/api/split_resize.rb index a7b8e22..93df034 100644 --- a/examples/api/split_resize.rb +++ b/examples/api/split_resize.rb @@ -5,11 +5,9 @@ require "libtmux" LibTmux::Server.start do |server| - created = server.new_session( - name: "work", command: ["/bin/sh"], receipt: true - ) + created = server.new_session(command: ["/bin/sh"], receipt: true) pane = created.pane - side = pane.split(direction: :horizontal, size: "40%", command: ["/bin/cat"]) + side = pane.split(direction: :horizontal, size: "40%") pane.send_text("echo café") pane.send_keys("Enter") @@ -21,6 +19,7 @@ break if line sleep 0.1 end + raise "shell did not print café" unless line puts "captured: #{line}" created.window.resize(width: 100, height: 30) diff --git a/examples/manifest.json b/examples/manifest.json index e66dee2..8a13462 100644 --- a/examples/manifest.json +++ b/examples/manifest.json @@ -202,7 +202,7 @@ "LibTmux::Pane#resize", "LibTmux::Window#resize" ], - "description": "Split a pane, type into the first pane and poll until its output line appears, then resize the window and the second pane. The shell echoes the typed command, so the poll matches a whole line.", + "description": "Start an automatically named session running /bin/sh. Read a whole output line from the shell and resize a second pane running the default command.", "output": "captured: café\nside pane: 20 columns\n" } }, diff --git a/gems/libtmux/CHANGELOG.md b/gems/libtmux/CHANGELOG.md index 68bc8ef..65c680c 100644 --- a/gems/libtmux/CHANGELOG.md +++ b/gems/libtmux/CHANGELOG.md @@ -21,6 +21,8 @@ in the [main changelog](../../CHANGELOG.md). - `Server#write_buffer` raises `UnsupportedFeatureError` for an empty payload before sending it to tmux. Nonempty writes keep their existing behavior. (#172) +- Session, window and pane creation can run the daemon's configured command or + shell. Omit the session or window name to let tmux choose it. (#186) - `Server#list_windows` and `Server#list_panes` return empty collections when their bound daemon is running without sessions. (#174) diff --git a/gems/libtmux/README.md b/gems/libtmux/README.md index 92fb593..022d220 100644 --- a/gems/libtmux/README.md +++ b/gems/libtmux/README.md @@ -250,9 +250,11 @@ matching panes: 1 ### [`Server#new_session`][server-new_session]: a session and its first window -`new_session` starts a detached session that runs `command:`, an argv array. -Keep the session reference to target it by ID. Read the name tmux stored -from a snapshot. +Omit `name:` to let tmux name the detached session. Omit `command:` to +use tmux's `default-command` or, when empty, `default-shell`. Pass an argv +array to run a specific program. The receipt includes the session, window +and pane IDs. Keep the session reference to target it by ID and read the +effective name from a snapshot. ```ruby @@ -288,7 +290,8 @@ More: [Session name behavior by tmux release][behavior-creation]. ### [`Session#new_window`][session-new_window]: add a window [`Pane#split`][pane-split] and [`Window#split`][window-split] add panes the -same way. A new window takes a `name:` and the same `command:` as a session: +same way. A new window accepts the same optional `name:` and `command:` +as a session. Splits also accept `command:`. ```ruby diff --git a/gems/libtmux/lib/libtmux/entity.rb b/gems/libtmux/lib/libtmux/entity.rb index 7065269..f7c7caf 100644 --- a/gems/libtmux/lib/libtmux/entity.rb +++ b/gems/libtmux/lib/libtmux/entity.rb @@ -126,7 +126,8 @@ def target # - Window links: {#list_window_links} # # **Creating a window.** A new window starts detached unless `focus: true`, and - # runs `command:`, an argv array rather than a shell string. It answers the + # uses tmux’s name and default command or shell unless you supply `name:` + # and `command:` (an argv array). It answers the # {Window}, or with `receipt: true` a {CreationReceipt}. `index:` places it at # that index. # @@ -156,7 +157,7 @@ def target # # - Expand a format: {Entity#display} class Session < Entity - def new_window(name:, command:, index: nil, cwd: nil, environment: {}, focus: false, receipt: false, timeout: 5.0, cancel: nil) + def new_window(name: nil, command: nil, index: nil, cwd: nil, environment: {}, focus: false, receipt: false, timeout: 5.0, cancel: nil) server.__send__(:create_window, ref, name: name, command: command, index: index, cwd: cwd, environment: environment, focus: focus, receipt: receipt, timeout: timeout, cancel: cancel) end @@ -194,7 +195,7 @@ def list_panes(timeout: 5.0, cancel: nil) # - Panes: {#list_panes} # # **Splitting and arranging.** Splitting needs `direction:`, `:horizontal` or - # `:vertical`, and `command:`, an argv array. `size:` is a count of cells or a + # `:vertical`, with optional `command:` to run an argv array. `size:` is a count of cells or a # percentage string such as `"30%"`, and the new pane is detached unless # `focus: true`. It answers the new {Pane}. A layout is a native name, an # unambiguous prefix of one, or a saved layout. JSON layouts raise @@ -230,7 +231,7 @@ def list_panes(timeout: 5.0, cancel: nil) server.__send__(:list_entities, :pane, ["-t", target], timeout: timeout, cancel: cancel) end - def split(direction:, command:, size: nil, cwd: nil, environment: {}, focus: false, timeout: 5.0, cancel: nil) + def split(direction:, command: nil, size: nil, cwd: nil, environment: {}, focus: false, timeout: 5.0, cancel: nil) server.__send__(:split_window, ref, direction: direction, command: command, size: size, cwd: cwd, environment: environment, focus: focus, timeout: timeout, cancel: cancel) end @@ -309,7 +310,7 @@ def select_layout(layout, timeout: 5.0, cancel: nil) # - Capture: {#capture} # # **Splitting and arranging.** Splitting needs `direction:`, `:horizontal` or - # `:vertical`, and `command:`, an argv array. It answers the new {Pane}, which + # `:vertical`, with optional `command:` to run an argv array. It answers the new {Pane}, which # stays detached unless `focus: true`. Breaking out moves the pane into a new # window in the session you name and answers that {Window}. # @@ -342,7 +343,7 @@ def select_layout(layout, timeout: 5.0, cancel: nil) # - Hooks: {Entity#hooks} # - Expand a format: {Entity#display} class Pane < Entity - def split(direction:, command:, size: nil, cwd: nil, environment: {}, focus: false, timeout: 5.0, cancel: nil) + def split(direction:, command: nil, size: nil, cwd: nil, environment: {}, focus: false, timeout: 5.0, cancel: nil) server.__send__(:split_window, ref, direction: direction, command: command, size: size, cwd: cwd, environment: environment, focus: focus, timeout: timeout, cancel: cancel) end diff --git a/gems/libtmux/lib/libtmux/server.rb b/gems/libtmux/lib/libtmux/server.rb index e0af760..cacd5f0 100644 --- a/gems/libtmux/lib/libtmux/server.rb +++ b/gems/libtmux/lib/libtmux/server.rb @@ -99,8 +99,9 @@ module LibTmux # - Down: {Session#list_windows}, {Session#list_panes}, {Window#list_panes} # - Up: {Entity#server} # - # **Changing things.** Creating a session starts it detached, running - # `command:`, an argv array rather than a shell string, and answers the + # **Changing things.** A new session starts detached. Omit `name:` for a tmux + # name and `command:` for its default command or shell. Supply an argv + # array to run a particular program. The call returns the # {Session} or, with `receipt: true`, a {CreationReceipt}. Kill stops the tmux # server, which closing does only for an owned server. Switching a client # points the client named by `client:` at a session. @@ -307,9 +308,10 @@ def kill(timeout: 5.0, cancel: nil) # Read `session.snapshot.name` for the effective name and retain # `session.ref` for subsequent targeting by ID. # @raise [UnsupportedFeatureError] if exact tmux 3.7 refuses punctuation - def new_session(name:, command:, width: nil, height: nil, window_name: nil, cwd: nil, environment: {}, receipt: false, timeout: 5.0, cancel: nil) + def new_session(name: nil, command: nil, width: nil, height: nil, window_name: nil, cwd: nil, environment: {}, receipt: false, timeout: 5.0, cancel: nil) budget = operation_budget(timeout, cancel) - arguments = ["new-session", "-d", "-P", "-F", creation_format(:session, receipt), "-s", literal_name(name)] + arguments = ["new-session", "-d", "-P", "-F", creation_format(:session, receipt)] + arguments.concat(["-s", literal_name(name)]) unless name.nil? arguments.concat(["-n", literal_name(window_name)]) if window_name {"-x" => width, "-y" => height}.each do |flag, value| next if value.nil? @@ -318,7 +320,7 @@ def new_session(name:, command:, width: nil, height: nil, window_name: nil, cwd: arguments.concat([flag, value.to_s]) end arguments.concat(creation_options(cwd: cwd, environment: environment)) - create_entity(:session, arguments + ["--"] + pane_command(command), receipt: receipt, **budget.options) + create_entity(:session, arguments + creation_command(command), receipt: receipt, **budget.options) end def list_sessions(timeout: 5.0, cancel: nil) @@ -624,6 +626,10 @@ def literal_name(name) name.gsub("#", "##") end + def creation_command(command) + command.nil? ? [] : ["--", *pane_command(command)] + end + def pane_command(command) validate_argv(command) raise ArgumentError, "command executable must not be empty" if command.first.empty? @@ -727,9 +733,10 @@ def create_window(ref, name:, command:, index: nil, cwd: nil, environment: {}, f destination = target(ref, :session) destination += ":#{index}" unless index.nil? - arguments = ["new-window", *(focus ? [] : ["-d"]), "-P", "-F", creation_format(:window, receipt), "-t", destination, "-n", literal_name(name)] + arguments = ["new-window", *(focus ? [] : ["-d"]), "-P", "-F", creation_format(:window, receipt), "-t", destination] + arguments.concat(["-n", literal_name(name)]) unless name.nil? arguments.concat(creation_options(cwd: cwd, environment: environment)) - create_entity(:window, arguments + ["--"] + pane_command(command), receipt: receipt, **budget.options) + create_entity(:window, arguments + creation_command(command), receipt: receipt, **budget.options) end def split_window(ref, direction:, command:, size: nil, cwd: nil, environment: {}, focus: false, timeout: 5.0, cancel: nil) @@ -749,7 +756,7 @@ def split_window(ref, direction:, command:, size: nil, cwd: nil, environment: {} arguments = ["split-window", *(focus ? [] : ["-d"]), flag, "-P", "-F", id_format(:pane), "-t", target(ref, ref.kind)] arguments.concat(["-l", size.to_s]) if size arguments.concat(creation_options(cwd: cwd, environment: environment)) - create_entity(:pane, arguments + ["--"] + pane_command(command), **budget.options) + create_entity(:pane, arguments + creation_command(command), **budget.options) end end end diff --git a/gems/libtmux/sig/libtmux.rbs b/gems/libtmux/sig/libtmux.rbs index 8fe2c8e..6325867 100644 --- a/gems/libtmux/sig/libtmux.rbs +++ b/gems/libtmux/sig/libtmux.rbs @@ -124,8 +124,8 @@ module LibTmux class Session < Entity def snapshot: (**untyped) -> SessionSnapshot def kill: (?expected_windows: Array[EntityRef]?, ?expected_panes: Array[EntityRef]?, ?timeout: Numeric, ?cancel: untyped) -> CommandResult - def new_window: (name: String, command: Array[String], receipt: true, ?index: Integer?, ?cwd: String?, ?environment: Hash[String, String], ?focus: bool, ?timeout: Numeric, ?cancel: untyped) -> CreationReceipt - | (name: String, command: Array[String], ?receipt: false, ?index: Integer?, ?cwd: String?, ?environment: Hash[String, String], ?focus: bool, ?timeout: Numeric, ?cancel: untyped) -> Window + def new_window: (?name: String?, ?command: Array[String]?, receipt: true, ?index: Integer?, ?cwd: String?, ?environment: Hash[String, String], ?focus: bool, ?timeout: Numeric, ?cancel: untyped) -> CreationReceipt + | (?name: String?, ?command: Array[String]?, ?receipt: false, ?index: Integer?, ?cwd: String?, ?environment: Hash[String, String], ?focus: bool, ?timeout: Numeric, ?cancel: untyped) -> Window def list_windows: (?timeout: Numeric, ?cancel: untyped) -> Array[Window] def list_panes: (?timeout: Numeric, ?cancel: untyped) -> Array[Pane] end @@ -133,13 +133,13 @@ module LibTmux class Window < Entity def snapshot: (**untyped) -> WindowSnapshot def list_panes: (?timeout: Numeric, ?cancel: untyped) -> Array[Pane] - def split: (direction: :horizontal | :vertical, command: Array[String], ?size: Integer | String | nil, ?cwd: String?, ?environment: Hash[String, String], ?focus: bool, ?timeout: Numeric, ?cancel: untyped) -> Pane + def split: (direction: :horizontal | :vertical, ?command: Array[String]?, ?size: Integer | String | nil, ?cwd: String?, ?environment: Hash[String, String], ?focus: bool, ?timeout: Numeric, ?cancel: untyped) -> Pane def select_layout: (String | Symbol, ?timeout: Numeric, ?cancel: untyped) -> CommandResult end class Pane < Entity def snapshot: (**untyped) -> PaneSnapshot - def split: (direction: :horizontal | :vertical, command: Array[String], ?size: Integer | String | nil, ?cwd: String?, ?environment: Hash[String, String], ?focus: bool, ?timeout: Numeric, ?cancel: untyped) -> Pane + def split: (direction: :horizontal | :vertical, ?command: Array[String]?, ?size: Integer | String | nil, ?cwd: String?, ?environment: Hash[String, String], ?focus: bool, ?timeout: Numeric, ?cancel: untyped) -> Pane def capture: (?start: Integer | String | nil, ?finish: Integer | String | nil, ?join: bool, ?escapes: bool, ?escape_bytes: bool, ?preserve_trailing: bool, ?trim_trailing: bool, ?alternate: bool, ?mode_screen: bool, ?pending: bool, ?timeout: Numeric, ?cancel: untyped) -> CommandResult def send_text: (String, ?timeout: Numeric, ?cancel: untyped) -> CommandResult def send_keys: (*String, ?timeout: Numeric, ?cancel: untyped) -> CommandResult @@ -237,8 +237,8 @@ module LibTmux def close: () -> nil def diagnostics: () -> {admitted_requests: Integer, reserved_process_slots: Integer, control_connections: Integer, closed: bool, limits: {max_requests: Integer, max_controls: Integer, close_timeout: Numeric}} def kill: (?timeout: Numeric, ?cancel: untyped) -> CommandResult - def new_session: (name: String, command: Array[String], receipt: true, ?width: Integer?, ?height: Integer?, ?window_name: String?, ?cwd: String?, ?environment: Hash[String, String], ?timeout: Numeric, ?cancel: untyped) -> CreationReceipt - | (name: String, command: Array[String], ?receipt: false, ?width: Integer?, ?height: Integer?, ?window_name: String?, ?cwd: String?, ?environment: Hash[String, String], ?timeout: Numeric, ?cancel: untyped) -> Session + def new_session: (?name: String?, ?command: Array[String]?, receipt: true, ?width: Integer?, ?height: Integer?, ?window_name: String?, ?cwd: String?, ?environment: Hash[String, String], ?timeout: Numeric, ?cancel: untyped) -> CreationReceipt + | (?name: String?, ?command: Array[String]?, ?receipt: false, ?width: Integer?, ?height: Integer?, ?window_name: String?, ?cwd: String?, ?environment: Hash[String, String], ?timeout: Numeric, ?cancel: untyped) -> Session def list_sessions: (?timeout: Numeric, ?cancel: untyped) -> Array[Session] def list_windows: (?timeout: Numeric, ?cancel: untyped) -> Array[Window] def list_panes: (?timeout: Numeric, ?cancel: untyped) -> Array[Pane] diff --git a/test/integration/readme_commands_test.rb b/test/integration/readme_commands_test.rb index 18bba06..ab849cb 100644 --- a/test/integration/readme_commands_test.rb +++ b/test/integration/readme_commands_test.rb @@ -251,6 +251,16 @@ def test_the_runner_rejects_what_the_readmes_must_not_do assert_match(/does not show a command/, refusal("Prose only.\n")) end + def test_split_recipe_does_not_require_a_posix_login_shell + sandbox = Sandbox.new + recipe = File.join(Blocks::ROOT, "examples/api/split_resize.rb") + result = sandbox.run("env", "SHELL=/bin/cat", "LC_ALL=C", Gem.ruby, recipe) + assert result.status.success?, result.stderr + assert_equal "captured: café\nside pane: 20 columns\n".b, result.stdout.b + ensure + sandbox&.close + end + def test_each_workspace_load_runs_against_a_server_of_its_own workspace = "```yaml\nsession_name: a\nwindows:\n - window_name: a\n panes: [{}]\n```\n" load = "```console\n$ libtmux-workspace load \\\n --socket \"$TMUX_SOCKET\" \\\n workspace.yaml\n```\n" diff --git a/test/integration/server_test.rb b/test/integration/server_test.rb index 6a7c5ad..9b61d2c 100644 --- a/test/integration/server_test.rb +++ b/test/integration/server_test.rb @@ -7,6 +7,28 @@ require "socket" class ServerTest < Minitest::Test + def test_omitted_creation_names_and_commands_use_tmux_defaults + LibTmuxTest::TmuxFixture.open do |fixture| + open_server(fixture) do |server| + server.options(scope: :session).set("default-command", "exec /bin/cat") + native, _, status = fixture.tmux("new-window", "-d", "-P", "-F", '#{pane_start_command}', "-t", "fixture") + assert status.success? + assert_includes native, "/bin/cat" + created = server.new_session(receipt: true) + added = created.entity.new_window(name: nil, command: nil, receipt: true) + panes = [created.pane, added.pane, added.window.split(direction: :horizontal), + added.pane.split(direction: :vertical)] + panes.each do |pane| + assert_equal native, pane.display('#{pane_start_command}').text + end + refute_empty created.entity.snapshot.name + refute_empty added.window.snapshot.name + assert_raises(ArgumentError) { created.entity.new_window(command: []) } + assert_raises(ArgumentError) { server.new_session(name: "") } + end + end + end + def test_literal_creation_topology_and_terminal_input LibTmuxTest::TmuxFixture.open do |fixture| executable = File.join(File.dirname(fixture.socket_path), "literal ; executable")