From d4c40ab5c1c1fe2df49f54d61632c1c979e63514 Mon Sep 17 00:00:00 2001 From: bptato Date: Wed, 11 Dec 2024 18:37:26 +0100 Subject: pager, mailcap: misc fixes, add prompt for global mailcap In the past, Chawan would read global mailcap (/etc/mailcap, ...) too, but every now and then that would run entries that I didn't even know existed and definitely didn't intend to run. So I changed it to only use ~/.mailcap, but this meant users now had to add mailcap entries for every single mime type. At some point I also changed application/octet-stream to always save to disk, which is usually nice except when a text file is misrecognized as binary. Often times I just want to decide myself what to do. So now there are two layers. First, the global mailcap files (path as per RFC) prompt before executing. Then there is ~/.chawan/auto.mailcap (or ~/.config/chawan/auto.mailcap) which runs entries automatically. If you press shift before selecting an option in the prompt, the corresponding entry gets copied to auto.mailcap. It's also possible to type a new entry on the fly. Overall I think it's quite convenient. One unfortunate side effect is that existing users will have to migrate their entries to auto.mailcap, or redefine external.auto-mailcap to e.g. ~/.mailcap, but this seems acceptable. --- src/utils/twtstr.nim | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/utils') diff --git a/src/utils/twtstr.nim b/src/utils/twtstr.nim index 2734e5ce..5fe93507 100644 --- a/src/utils/twtstr.nim +++ b/src/utils/twtstr.nim @@ -217,16 +217,20 @@ func equalsIgnoreCase*(s1, s2: string): bool {.inline.} = return s1.cmpIgnoreCase(s2) == 0 func startsWithIgnoreCase*(s1, s2: openArray[char]): bool = - if s1.len < s2.len: return false + if s1.len < s2.len: + return false for i in 0 ..< s2.len: if s1[i].toLowerAscii() != s2[i].toLowerAscii(): return false return true func endsWithIgnoreCase*(s1, s2: openArray[char]): bool = - if s1.len < s2.len: return false - for i in countdown(s2.high, 0): - if s1[i].toLowerAscii() != s2[i].toLowerAscii(): + if s1.len < s2.len: + return false + let h1 = s1.high + let h2 = s2.high + for i in 0 ..< s2.len: + if s1[h1 - i].toLowerAscii() != s2[h2 - i].toLowerAscii(): return false return true -- cgit