Commit Graph

16 Commits

Author SHA1 Message Date
e998fbd230 feat(server+cli): configurable menu via --menu JSON; UI tweaks to form layout 2025-10-18 01:04:25 +07:00
c93b38e8ec feat(client): coordinated broadcast listening with form/menu flow; improved loading UX 2025-10-16 16:45:12 +07:00
76215f14bd feat(client): filter broadcast lines while awaiting MENU/ORDER responses 2025-10-16 16:44:57 +07:00
5e76ca2514 feat(ui): polish layout with borders; embed form in left pane; customize form keymap
- Add lipgloss.RoundedBorder to left/right columns for visual separation
- Render the huh form within the left column box instead of full-screen takeover
- Keep right column (recent orders) visible while filling the form
- Integrate bubbles/key and set a custom Huh keymap:
  - Quit binding: ctrl+c/esc with help text
- Apply base theme to the form via WithTheme(huh.ThemeBase())
- Minor layout tweaks to ensure consistent sizing and padding
2025-10-16 12:50:48 +07:00
d026a30927 feat(client): show local “[order] …” entry after successful submit; introduce server line msg type; WIP reader state in broken snapshot
- Add serverLineMsg type for future server line handling
- On successful orderSubmittedMsg with total:
  - Derive item name from cached menu and append a formatted “[order] Name ordered N × Item ($Total)” to broadcasts
  - Keep broadcasts capped at 10 entries
- Maintain existing ack handling when no total provided

Also add a WIP snapshot (main.go.broken):
- Replace broadcastListening flag with waitingForMenu and waitingForOrderResp
- On connect, start read loop via readServerLineCmd(reader)
- When submitting an order, set waitingForOrderResp and call submitOrderCmd without passing reader
- After orderSubmittedMsg (success or error), resume listenForBroadcastsCmd if conn/reader present

Note: main.go.broken reflects an in-progress refactor toward a single read loop and explicit waiting states.
2025-10-16 12:49:50 +07:00
e523297d5f feat(client): show local “[order] …” entry after successful submit; introduce server line msg type; WIP reader state in broken snapshot
- Add serverLineMsg type for future server line handling
- On successful orderSubmittedMsg with total:
  - Derive item name from cached menu and append a formatted “[order] Name ordered N × Item ($Total)” to broadcasts
  - Keep broadcasts capped at 10 entries
- Maintain existing ack handling when no total provided

Also add a WIP snapshot (main.go.broken):
- Replace broadcastListening flag with waitingForMenu and waitingForOrderResp
- On connect, start read loop via readServerLineCmd(reader)
- When submitting an order, set waitingForOrderResp and call submitOrderCmd without passing reader
- After orderSubmittedMsg (success or error), resume listenForBroadcastsCmd if conn/reader present

Note: main.go.broken reflects an in-progress refactor toward a single read loop and explicit waiting states.
2025-10-16 12:49:25 +07:00
aee33003bf refactor(net): reuse a single buffered reader; manage broadcast loop lifecycle
Client:
- Keep a persistent bufio.Reader on the connection (model.reader)
- On connect, initialize reader and drain initial greetings with deadlines
- Pass reader into fetchMenuCmd, submitOrderCmd, and listenForBroadcastsCmd
- Avoid starting duplicate broadcast listeners with broadcastListening flag
- Start broadcast listener after menu is loaded and form is initialized
- Update commands to read via shared reader instead of creating new ones
- Remove greeting drain from connectCmd (now handled on connectedMsg)
- Minor: small flow tweaks for opening form and handling reconnection

Benefits:
- Prevents interleaved reads from multiple readers on the same net.Conn
- Reduces race conditions and broken protocol reads
- Ensures a single, continuous read loop for broadcasts and responses
2025-10-16 12:48:42 +07:00
616017267e fix(ui): reopen order form if menu already loaded on 'n' instead of refetching
- If menu is cached, build and init form immediately
- Otherwise, show loading status and fetch menu from server
2025-10-16 12:48:12 +07:00
b94670f138 feat(order-console): add pricing, recent order feed, and responsive layout; extend protocol
Client:
- Add menuItem.Price; show prices in menu and compute totals from server ack
- Track and render recent “[order] …” broadcasts in right column
- Responsive layout with header/body/footer and window size handling
- Listen for server broadcasts after connect; keep last 10 orders
- Parse ORDER ack as “OK|<total>”; display “Total: $<amount>”
- Split view rendering into header/left/right/footer helpers
- Enhance form options to include “Name - $Price”
- Add width/height state; remove fixed 80-col assumption

Server:
- Extend defaultMenu with prices
- Compute total = qty × price; broadcast “[order] … ($xx.xx)”
- Acknowledge ORDER with “OK|<total>” instead of plain “OK”

Proto/UX:
- MENU returns items with price
- ORDER response now includes total for client display
2025-10-16 12:47:38 +07:00
623bc075eb feat(app): pivot from chat UI to order console with menu/order protocol
Client (main.go):
- Replace chat viewport/textarea with a simple order console UI using Bubble Tea + Huh forms
- Add types and messages for connection, menu loading, order submission, and status
- Implement connectCmd with short greeting drain; status updates on connect
- Implement fetchMenuCmd: send "MENU", parse single-line JSON into []menuItem
- Implement submitOrderCmd: send "ORDER <json>", read single-line ack
- Build interactive form (name, menu select, quantity, confirm) with validation
- Add model state for host, status/loading/error, lastOrder, and form fields
- Keyboard controls: n (new order), r (reconnect), q/esc/ctrl+c (quit)
- Simplify program start (remove pre-connect path); alt-screen only
- Remove chat colorization/regex, viewport, and textarea logic

Server (server.go):
- Define menuItem and order structs; add a defaultMenu
- Extend protocol:
  - "MENU" returns single-line JSON array of menu items
  - "ORDER <json>" validates name/item/quantity (with lenient quantity parsing)
    - Acknowledge with "OK" or send "[error] ..." lines
    - Optionally broadcast "[order] ..." to chat for visibility
- Keep existing chat behavior; integrate new commands alongside it

Notes:
- Server logs ORDER parsing and continues to support chat commands
- Error handling surfaces server-side errors to the client status/messages
2025-10-16 12:46:45 +07:00
4332c2e3a5 feat(chat): polish UI text; pre-connect to show welcome; add server logs
Client/main:
- Colorize display: hide raw IDs in rendered messages
  - Chat lines now “Name: message” (ID omitted)
  - [join]/[leave] now “[join] Name” / “[leave] Name”
  - [rename] now “[rename] OldName -> NewName”
  - Welcome now “Welcome Name”
- Init: if already connected, start reading immediately (textarea.Blink + readLineCmd)
- Pre-connect before TUI starts:
  - Dial with 3s timeout, read up to two initial lines with 1s deadline
  - Seed model with pre-read messages and existing conn

Server:
- IDs now lowercase hex; default username uses ID as-is
- Use strings.CutPrefix for “/name ” parsing
- Add structured logs for join/rename/leave with user, id, and remote addr

UI:
- Simplify chat line format for readability; keep color-coding based on ID-derived color
2025-10-15 11:27:59 +07:00
52d4602e33 feat(chat): colorize usernames by ID; refine IDs/usernames and /name parsing
Server:
- Generate 6-char IDs from lowercase hex alphabet "abcdef0123456789"
- Default username now uses the ID as-is (no extra ToLower)
- Use strings.CutPrefix for robust “/name ” command parsing

Client:
- Add colorizeLine to apply ANSI colors based on 6-hex-digit ID
  - Colorize chat lines: "<name> (<id>): <msg>"
  - Colorize [join]/[leave] notices
  - Colorize [rename] events
  - Colorize Welcome banner
- Apply colorizeLine to incoming netMsg before appending

Notes:
- ID regex patterns accept 6 hex digits (case-insensitive), rendered in lowercase
- Keeps non-matching lines unchanged
2025-10-15 11:27:16 +07:00
b80c5190a3 feat(chat): CLI flags, centered header; improve server with selective broadcast and quit handling
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
2025-10-15 11:25:16 +07:00
676b45cd23 refactor(net): modelled connection lifecycle with typed msgs; switch to line-by-line reader
- 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.
2025-10-15 11:23:47 +07:00
cae82f5d55 feat(tui): add TCP client integration and connection status; send input over network
- 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
2025-10-15 11:22:52 +07:00
2651178a16 initial commit 2025-10-15 00:19:34 +07:00