lrstanley / girc

:bomb: girc is a flexible IRC library for Go :ok_hand:
https://pkg.go.dev/github.com/lrstanley/girc
MIT License
137 stars 13 forks source link

Split messages #43

Closed lrstanley closed 1 year ago

lrstanley commented 3 years ago

Followup to #42.

/CC @nmeum @robbyoconnor @jwflory

nmeum commented 3 years ago

Not sure if this just me but the tests seem to fail:

lrstanley/girc$ go test
--- FAIL: TestParseEvent (0.00s)
    event_test.go:120: ParseEvent: got ":nick!user@host TEST :test0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000LONG TEXT TRUNCATED HERE", want ":nick!user@host TEST :test0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
FAIL
exit status 1
FAIL    github.com/lrstanley/girc       0.805s
nmeum commented 3 years ago

Any updates on this? Can I somehow be of assistance to get this finished and merged? :)

lrstanley commented 1 year ago

A few years late, but finally got around to finishing this. 😅

All of the below should apply:

  1. Input limit uses multi-byte check. One thing I'm not sure about is if servers that provide their limits are based off runes, or just based off bytes, but the current implementation uses rune length (to a single multi-byte character counts as single character).
  2. Tries to keep colors/backgrounds/color resets/etc between splits. It's not perfect, but it should work "good enough".
  3. If a very long single word is split, it will prefer to keep it together (but on another line) rather than splitting off small chunks at the end (e.g. URLs).
  4. Default is word spliting, and if a word is above 30 characters, I try to split be special characters (e.g. lalkmadlkmasdlka-adasdasdasdasd would split at -).
  5. Worst case, it splits at the exact point necessary to make it fit, if none of the above apply and the entire word is above the maximum length.

As far as logic changes:

  1. girc sets a default max line length of 510, but some of this is subtracted with prefix padding, user length, host length, etc. Some of the subtractions aren't smart checks, just "assume a host will be this long" rather than keeping track of the actual sizes. There might be room for improvement on this item.
  2. Servers can raise this limit with ISUPPORT or similar -- girc should respect that raised limit.
  3. During the connection Send method, we invoke Event.split -- note that not all events are split (only PRIVMSG and NOTICE for now, JOIN's have always had custom logic to split already). Could apply the logic to all commands, but there are some commands that will not support splitting, so prefer to be conservative for now.

Also merged in changes from branch bugfix/issue-50, which includes the swap to a ctx group for keeping track of the core handlers (ping/read/send/etc).

Feel free to test and let me know. Logic is definitely more complex, but I would rather support the above usecases. The only way to make it more clean would be to support a proper lexer for sequence code handling, buuuut that's a lot of work.

codecov-commenter commented 1 year ago

Codecov Report

Merging #43 (2e3a7f1) into master (7713d84) will increase coverage by 0.54%. The diff coverage is 65.84%.

:mega: This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##           master      #43      +/-   ##
==========================================
+ Coverage   55.45%   55.99%   +0.54%     
==========================================
  Files          13       13              
  Lines        3266     3488     +222     
==========================================
+ Hits         1811     1953     +142     
- Misses       1342     1409      +67     
- Partials      113      126      +13     
Impacted Files Coverage Δ
cap.go 23.97% <0.00%> (ø)
cap_sasl.go 0.00% <0.00%> (ø)
cap_tags.go 66.07% <ø> (ø)
commands.go 0.00% <0.00%> (ø)
modes.go 32.47% <ø> (ø)
event.go 65.31% <18.18%> (-5.93%) :arrow_down:
builtin.go 59.80% <50.00%> (-1.04%) :arrow_down:
client.go 64.07% <70.27%> (+0.89%) :arrow_up:
conn.go 53.48% <72.94%> (-0.32%) :arrow_down:
format.go 94.86% <87.96%> (-5.14%) :arrow_down:
... and 1 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.