client/commands: leave space for ellipsis

This commit is contained in:
StalkR 2015-04-14 12:18:11 +02:00
parent e1ddd58df4
commit 30087ae0f3
2 changed files with 10 additions and 10 deletions

View File

@ -64,13 +64,13 @@ func indexFragment(s string) int {
// 3. splitLen itself // 3. splitLen itself
func splitMessage(msg string, splitLen int) (msgs []string) { func splitMessage(msg string, splitLen int) (msgs []string) {
// This is quite short ;-) // This is quite short ;-)
if splitLen < 10 { if splitLen < 13 {
splitLen = 10 splitLen = 13
} }
for len(msg) > splitLen { for len(msg) > splitLen {
idx := indexFragment(msg[:splitLen]) idx := indexFragment(msg[:splitLen-3])
if idx < 0 { if idx < 0 {
idx = splitLen idx = splitLen - 3
} }
msgs = append(msgs, msg[:idx] + "...") msgs = append(msgs, msg[:idx] + "...")
msg = msg[idx:] msg = msg[idx:]

View File

@ -60,12 +60,12 @@ func TestSplitMessage(t *testing.T) {
{"", 0, []string{""}}, {"", 0, []string{""}},
{"foo", 0, []string{"foo"}}, {"foo", 0, []string{"foo"}},
{"foo bar baz beep", 0, []string{"foo bar ...", "baz beep"}}, {"foo bar baz beep", 0, []string{"foo bar ...", "baz beep"}},
{"foo bar baz beep", 13, []string{"foo bar baz ...", "beep"}}, {"foo bar baz beep", 15, []string{"foo bar baz ...", "beep"}},
{"foo. bar baz beep", 0, []string{"foo. ...", "bar baz ...", "beep"}}, {"foo. bar baz, beep.", 0, []string{"foo. ...", "bar baz, ...", "beep."}},
{"foo bar, baz beep", 13, []string{"foo bar, ...", "baz beep"}}, {"foo bar, baz beep", 15, []string{"foo bar, ...", "baz beep"}},
{"0123456789012345", 0, []string{"0123456789...", "012345"}}, {"0123456789012345", 0, []string{"0123456789...", "012345"}},
{"0123456789012345", 13, []string{"0123456789012...", "345"}}, {"0123456789012345", 15, []string{"012345678901...", "2345"}},
{"0123456789012345", 20, []string{"0123456789012345"}}, {"0123456789012345", 16, []string{"0123456789012345"}},
} }
for i, test := range tests { for i, test := range tests {
out := splitMessage(test.in, test.sp) out := splitMessage(test.in, test.sp)
@ -81,7 +81,7 @@ func TestClientCommands(t *testing.T) {
// Avoid having to type ridiculously long lines to test that // Avoid having to type ridiculously long lines to test that
// messages longer than SplitLen are correctly sent to the server. // messages longer than SplitLen are correctly sent to the server.
c.cfg.SplitLen = 20 c.cfg.SplitLen = 23
c.Pass("password") c.Pass("password")
s.nc.Expect("PASS password") s.nc.Expect("PASS password")