Class: Muxr::Client
- Inherits:
-
Object
- Object
- Muxr::Client
- Defined in:
- lib/muxr/client.rb
Overview
The muxr client. It is a small front-end whose only jobs are:
1. Connect to the server's Unix socket and send HELLO with the
terminal's current size.
2. Put the controlling TTY into the alt screen + raw mode.
3. Forward every STDIN read as an INPUT frame.
4. Write every OUTPUT frame payload straight to STDOUT.
5. Send RESIZE on SIGWINCH; exit cleanly on BYE / server EOF.
The client owns no Session, no PTYs, and no Renderer — that all lives in the server process. This is the piece that comes and goes during detach / reattach.
Constant Summary collapse
- SELECT_TIMEOUT =
0.1
Instance Method Summary collapse
-
#connect ⇒ Object
Opens the socket.
-
#initialize(session_name) ⇒ Client
constructor
A new instance of Client.
- #run ⇒ Object
Constructor Details
#initialize(session_name) ⇒ Client
Returns a new instance of Client.
19 20 21 22 23 24 25 26 27 |
# File 'lib/muxr/client.rb', line 19 def initialize(session_name) @session_name = session_name @socket_path = Application.socket_path_for(session_name) @sock = nil @running = false @resize_pending = false @exit_code = 0 @bye_reason = nil end |
Instance Method Details
#connect ⇒ Object
Opens the socket. Returns true on success. Raises Errno::ENOENT / Errno::ECONNREFUSED to the caller, which is bin/muxr’s job to handle by spawning a server.
32 33 34 35 36 37 |
# File 'lib/muxr/client.rb', line 32 def connect @sock = UNIXSocket.new(@socket_path) rows, cols = terminal_size Protocol.write(@sock, Protocol::HELLO, Protocol.encode_size(rows, cols)) true end |
#run ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/muxr/client.rb', line 39 def run raise "must call #connect first" unless @sock enter_terminal_mode install_winch_trap @running = true begin loop_forever ensure leave_terminal_mode @sock.close rescue nil end @exit_code end |