diff options
| author | historia <[not public]> | 2026-06-25 04:46:40 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-06-25 04:46:40 -0400 |
| commit | 2725e2927a1595c7b100d942d1f14146252adeb7 (patch) | |
| tree | e8bc2292634a2d686c751981ddb3097517cccc6a /internal/net/server.go | |
| parent | 94a06fbbe682701ca4d4bd2a70cd74d8df29c932 (diff) | |
| download | thehouseoficarus-2725e2927a1595c7b100d942d1f14146252adeb7.tar.gz | |
feat: who, global chat, removed redundant YAML IDs
Diffstat (limited to 'internal/net/server.go')
| -rw-r--r-- | internal/net/server.go | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/internal/net/server.go b/internal/net/server.go index 6626592..5c98b62 100644 --- a/internal/net/server.go +++ b/internal/net/server.go @@ -9,6 +9,7 @@ import ( "sync" "thehouseoficarus/internal/action" + "thehouseoficarus/internal/color" "thehouseoficarus/internal/config" "thehouseoficarus/internal/player" ) @@ -329,6 +330,21 @@ func (s *Server) handleSession(sess *Session, handler func(*Session, string)) { } } +// wrap applies the player's wrap_width option to outgoing text. It is a no-op +// before login (no Player) so the welcome banner is never reflowed. The width +// is clamped to a minimum of 80 columns. +func (sess *Session) wrap(msg string) string { + if sess.Player == nil { + return msg + } + width := sess.Player.OptionInt("wrap_width") + if width < 80 { + width = 80 + } + return color.WrapANSI(msg, width) +} + +// Write sends raw text with no wrapping. Used for prompts and partial lines. func (sess *Session) Write(msg string) { sess.writeMu.Lock() defer sess.writeMu.Unlock() @@ -336,6 +352,7 @@ func (sess *Session) Write(msg string) { } func (sess *Session) WriteLine(msg string) { + msg = sess.wrap(msg) sess.writeMu.Lock() defer sess.writeMu.Unlock() sess.Conn.Write([]byte(msg + "\r\n")) @@ -345,14 +362,15 @@ func (sess *Session) WriteLines(lines ...string) { sess.writeMu.Lock() defer sess.writeMu.Unlock() for _, l := range lines { - sess.Conn.Write([]byte(l + "\r\n")) + sess.Conn.Write([]byte(sess.wrap(l) + "\r\n")) } } func (sess *Session) Writef(format string, args ...interface{}) { + msg := sess.wrap(fmt.Sprintf(format, args...)) sess.writeMu.Lock() defer sess.writeMu.Unlock() - sess.Conn.Write([]byte(fmt.Sprintf(format, args...))) + sess.Conn.Write([]byte(msg)) } func (sess *Session) Close() error { |
