Comments (8)
My bad. It wasn’t my intent to solve the entire issue (hence why I didn’t go any further). I mostly wanted to point out that interface change that I believe should have been among the tasks. Maybe providing a diff was too much. I’ll let @reido2012 do the rest as I was going to all along.
from neomutt.
Hi. I noticed that mutt_str_pretty_size()
doesn’t communicate errors. I think this refactoring is an appropriate time to address this. I propose this change for task 1. It returns the number of characters written, 0 meaning a (non-fatal) error occurred. It also includes updated Doxygen comments, though I haven’t checked whether they compile.
Patch
diff --git a/muttlib.c b/muttlib.c
index fefeb93..db54514 100644
--- a/muttlib.c
+++ b/muttlib.c
@@ -1094,47 +1094,63 @@ void buf_sanitize_filename(struct Buffer *buf, const char *path, short slash)
/**
* mutt_str_pretty_size - Display an abbreviated size, like 3.4K
- * @param buf Buffer for the result
- * @param buflen Length of the buffer
- * @param num Number to abbreviate
+ * @param buf Buffer to write into
+ * @param num Number to abbreviate
+ * @retval num Number of characters written
+ * @retval 0 Error
+ *
+ * Formats a number to abbreviate it with the metric prefixes K and M if
+ * needed. If necessary, the buffer is expanded. The following configuration
+ * flags affect the formatting:
+ *
+ * - `size_show_bytes`: no prefix is used if `num < 1024`.
+ *
+ * - `size_units_on_left`: the prefix precedes the number (e.g. K2 instead of
+ * 2K).
+ *
+ * - `size_show_fractions`: at most one decimal digit is written (e.g. 1.2K).
+ *
+ * - `size_show_mb`: enable the prefix M.
*/
-void mutt_str_pretty_size(char *buf, size_t buflen, size_t num)
+size_t mutt_str_pretty_size(struct Buffer *buf, size_t num)
{
- if (!buf || (buflen == 0))
- return;
+ if (!buf)
+ return 0;
const bool c_size_show_bytes = cs_subset_bool(NeoMutt->sub, "size_show_bytes");
const bool c_size_show_fractions = cs_subset_bool(NeoMutt->sub, "size_show_fractions");
const bool c_size_show_mb = cs_subset_bool(NeoMutt->sub, "size_show_mb");
const bool c_size_units_on_left = cs_subset_bool(NeoMutt->sub, "size_units_on_left");
+ int r;
if (c_size_show_bytes && (num < 1024))
{
- snprintf(buf, buflen, "%d", (int) num);
+ r = buf_add_printf(buf, "%zu", num);
}
else if (num == 0)
{
- mutt_str_copy(buf, c_size_units_on_left ? "K0" : "0K", buflen);
+ return buf_addstr(buf, c_size_units_on_left? "K0" : "0K");
}
else if (c_size_show_fractions && (num < 10189)) /* 0.1K - 9.9K */
{
- snprintf(buf, buflen, c_size_units_on_left ? "K%3.1f" : "%3.1fK",
- (num < 103) ? 0.1 : (num / 1024.0));
+ r = buf_add_printf(buf, c_size_units_on_left ? "K%3.1f" : "%3.1fK",
+ (num < 103) ? 0.1 : (num / 1024.0));
}
else if (!c_size_show_mb || (num < 1023949)) /* 10K - 999K */
{
/* 51 is magic which causes 10189/10240 to be rounded up to 10 */
- snprintf(buf, buflen, c_size_units_on_left ? ("K%zu") : ("%zuK"), (num + 51) / 1024);
+ r = buf_add_printf(buf, c_size_units_on_left ? "K%zu" : "%zuK", (num + 51) / 1024);
}
else if (c_size_show_fractions && (num < 10433332)) /* 1.0M - 9.9M */
{
- snprintf(buf, buflen, c_size_units_on_left ? "M%3.1f" : "%3.1fM", num / 1048576.0);
+ r = buf_add_printf(buf, c_size_units_on_left ? "M%3.1f" : "%3.1fM", num / 1048576.0);
}
else /* 10M+ */
{
/* (10433332 + 52428) / 1048576 = 10 */
- snprintf(buf, buflen, c_size_units_on_left ? ("M%zu") : ("%zuM"), (num + 52428) / 1048576);
+ r = buf_add_printf(buf, units_on_left ? "M%zu" : "%zuM", (num + 52428) / 1048576);
}
+ return r * (r > 0);
}
/**
from neomutt.
General note -- Sorry if this sounds angry; it's not directed at anyone.
Finding "nice easy tasks" for beginners isn't easy for me.
They take time to find and time to document clearly.
In the past, I've tried creating lots of "easy-first-issue" issues, but they've proved a waste of my time.
NeoMutt's code is under constant change/improvement, so the "shelf-life" of an easy task is quite short.
Usually, nobody's interested in tackling them,
so frequently the instructions became out-of-date, because of other refactoring going on,
or the issue would become a bottleneck that I had to resolve myself.
So, I ask everyone I speak to, "Would you like to help?" and I create issues on demand.
/rant
from neomutt.
Hi @flatcap I can't find the branch devel/expando branch.
I do see the devel/new-expando-parser branch though.
Just going to assume you meant that branch but let me know if that's incorrect.
from neomutt.
Ah, I've just merged it, so it's gone.
As a member of NeoMutt, you can create branches on this repo, preferably: devel/SHORT-NAME
If you let me know your email address (I'm, [email protected]) I'll send you my standard Welcome! email.
from neomutt.
Ah got it. Cheers.
I've sent you an email. My email is [email protected]
from neomutt.
mutt_str_pretty_size()
doesn’t communicate errors
true
I think this refactoring is an appropriate time to address this
yep
I propose this change
Right.
Please don't take this the wrong way, but I created the issue for @reido2012 (and assigned it to him) after a discussion on IRC.
I'd love you to help, but I don't want people treading on each others' toes.
If you'd like me to find you a similar task, just ask. Here, on IRC, or drop me an email.
from neomutt.
Thanks for the hints with your diff @Pierre-Colin. I'll take it from here 🙏🏾
@flatcap I appreciate the easy first task documentation and support! Given that the shelf life is short I will try to get the changes done as soon as I can.
from neomutt.
Related Issues (20)
- Do we need to handle <stddef.h> specially? HOT 1
- conditional format strings broken in 2024-04-25 HOT 9
- Duplicate gpg keys in key selection menu for message encryption HOT 18
- segfault while opening a mailbox in from the sidebar HOT 2
- Doubts about paranoic defensive programming style HOT 3
- C dialect HOT 2
- tag-prefix doesn't show-up in attach HOT 5
- Doubts about some `*const` pointers HOT 5
- How to use the notmuch command <modify-labels> to tag emails with tags containing spaces?
- Is it possible to edit the automatic title when forwarding or replying a message? HOT 1
- Progress for postponing a message with remote (IMAP)
- autocrypt breaks command line argument `-e "push foo"` HOT 4
- How to forward an email thread to someone else together with attachments ? HOT 3
- `delete-thread` does not support `tag-prefix` operator
- split outgoing email into batches to work around max number of recipients limit in some SMTP providers (infomaniak) HOT 3
- save-message from GMail over IMAP to local box doesn't delete original HOT 3
- Cannot open an .mbox file with neomutt (although it works with mutt) HOT 4
- neomutt truecolor and kitty
- neomutt does not replace `...` by encrypted subject HOT 6
- Inline-PGP with junk before recognized incorrectly HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from neomutt.