- Messages to a PIN-protected peer now prompt for the PIN and retry, like file sends (was a silent failure). SendMessage takes a pin argument and the TUI tracks whether a pending send is a message or files. - Copy a received message to the clipboard with `y` (in the Messages tab or while reading one). - Send the clipboard as a message with `v` on a device: it opens the compose box pre-filled with the clipboard text to review before sending. - New internal/clipboard package shells out to wl-clipboard / xclip / xsel, and falls back to tmux's paste buffer when running inside tmux on a headless box (tmux load-buffer -w also reaches the outer clipboard via set-clipboard, which omaterm enables by default). No system tool -> "clipboard unavailable". - Route the standard logger to the debug log (or discard) at startup so stray stdlib logging — e.g. net/http's "unsolicited response on idle channel" notice after a peer sends a late response — can't paint over the TUI. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
52 lines
1.2 KiB
Go
52 lines
1.2 KiB
Go
// Package dbg provides opt-in debug logging to the file named by $OMARCHY_SEND_LOG.
|
|
// When the variable is unset, logging is a no-op. It is safe for concurrent use.
|
|
package dbg
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
"sync"
|
|
"time"
|
|
)
|
|
|
|
var (
|
|
once sync.Once
|
|
mu sync.Mutex
|
|
f *os.File
|
|
)
|
|
|
|
func setup() {
|
|
path := os.Getenv("OMARCHY_SEND_LOG")
|
|
if path == "" {
|
|
return
|
|
}
|
|
file, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0o600)
|
|
if err != nil {
|
|
return
|
|
}
|
|
f = file
|
|
}
|
|
|
|
// Writer returns the debug log file if $OMARCHY_SEND_LOG is set, else io.Discard.
|
|
// It's used to redirect the standard logger away from the terminal so stray
|
|
// stdlib logging (e.g. net/http's "unsolicited response" notice) can't corrupt
|
|
// the TUI; the output is still captured in the debug log when enabled.
|
|
func Writer() io.Writer {
|
|
once.Do(setup)
|
|
if f == nil {
|
|
return io.Discard
|
|
}
|
|
return f
|
|
}
|
|
|
|
// Logf appends a timestamped line to the debug log if $OMARCHY_SEND_LOG is set.
|
|
func Logf(format string, args ...any) {
|
|
once.Do(setup)
|
|
if f == nil {
|
|
return
|
|
}
|
|
mu.Lock()
|
|
defer mu.Unlock()
|
|
fmt.Fprintf(f, "%s "+format+"\n", append([]any{time.Now().Format("15:04:05.000")}, args...)...)
|
|
}
|