Skip to content

Add --watch mode, Unix socket live-push, and stdin support#3

Open
Halicea wants to merge 5 commits intorabfulton:masterfrom
42dotmk:master
Open

Add --watch mode, Unix socket live-push, and stdin support#3
Halicea wants to merge 5 commits intorabfulton:masterfrom
42dotmk:master

Conversation

@Halicea
Copy link
Copy Markdown

@Halicea Halicea commented Apr 28, 2026

Summary

  • Watch mode (--watch / -w): Monitors the open file with GFileMonitor and
    Switching files via the toolbar transparently moves the monitor to the new file.
  • Unix socket live-push (--socket): When launched with --socket, ViewMD
    creates /tmp/viewmd-<pid>.sock and prints VIEWMD_SOCKET=<path> to stdout. Editor
    plugins can connect, push raw Markdown, and optionally prefix the payload with
    CURSOR:<line>\n to scroll the preview to the current edit position — no disk write
    required.
  • Stdin support (-): Passing - as the filename reads content from stdin
    (cat file.md | viewmd -).

Test plan

  • viewmd --watch file.md — edit and save, confirm auto-reload
  • Same file via toolbar Reload while --watch is active — monitor must not
    restart
  • Open a different file via toolbar while --watch is active — monitor follows
  • viewmd --socket file.md, then echo "# Hello" | nc -U $VIEWMD_SOCKET
    content updates live
  • Socket with cursor: { printf 'CURSOR:5\n'; cat file.md; } | nc -U $VIEWMD_SOCKET — scrolls to line 5
  • cat file.md | viewmd - — renders correctly
  • viewmd - from a terminal (no pipe) — prints error, does not hang
  • Normal viewmd file.md launch — no socket file created, no extra stdout
    output
  • Quit while --watch or --socket is active — no crash, socket file cleaned
    up

🤖 Generated with Claude Code

@rabfulton
Copy link
Copy Markdown
Owner

Some good ideas here, I like the watch option! Two minor issure for your consideration:

  1. Your line scrolling does anot account for line wrapping so will not always scroll to the correct place in a document. There is already some scrolling functions in the codebase that tackle this issue when handling internal links gtk_text_view_scroll_to_mark().

  2. It would be preferrable if you can make the socket input feature make nonblocking so that it can never hang the UI thread.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants