Client/main:
- Add flags: -host (default "localhost:9000") and -server (run only server)
- When -server is set, startTCPServer(host) and exit
- Use provided host for client connection
- Center header with width-aware lipgloss styling; adjust padding
Server:
- Introduce broadcast struct {text string, exclude net.Conn}
- Hub.msgCh now chan broadcast; send messages with optional exclusion
- On join: send “[join] …” to others (exclude the joiner)
- Broadcast chat lines without exclusion; newline-delimited as before
- Handle “/quit” by breaking loop (graceful disconnect)
- On leave: broadcast “[leave] …” to all
Refactor notes:
- Remove unconditional embedded server from client startup
- Scanner loop unchanged aside from quit handling and broadcast usage
- Introduce typed msgs: connectedMsg, disconnectedMsg, errorMsg, and netMsg
- connectCmd now returns connectedMsg on success instead of “[connected]”
- Add readLineCmd to read a single line via bufio.Reader and emit netMsg
- Handles io.EOF as disconnectedMsg; reports other errors as “[error] read: …”
- Update loop:
- On connectedMsg: store conn, append “[connected]”, schedule first readLineCmd
- On netMsg: append message, schedule next readLineCmd unless it’s a read error
- On disconnectedMsg: append “[disconnected]”, close and clear conn
- UI tweaks: textarea placeholder uses "..." and height reduced from 3 to 2
- Window sizing: set viewport width; removed old netMsg branch now superseded by typed msgs
This removes the scanner goroutine pattern in favor of Cmd-driven incremental reads.
- Add net/bufio/time imports and model fields (conn, server, err)
- initialModel now accepts server address; display it as header
- Init batches textarea.Blink with connectCmd to dial TCP on startup
- Implement connectCmd with 3s timeout; emit [connected]/[disconnected]/error via netMsg
- Spawn scanner goroutine to read lines from conn and forward as netMsg
- Implement sendCmd to write input lines to the connection
- Update: on Enter, send via sendCmd instead of local echo; handle netMsg to append messages and status
- Close connection on Ctrl+C/Esc
- main: start local TCP server in goroutine; delay 200ms; connect to 127.0.0.1:9000
- Minor: append textarea cmd only if non-nil; render server header above viewport