-
-
Notifications
You must be signed in to change notification settings - Fork 442
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
adding bar_label parameter to htoprc #1546
base: main
Are you sure you want to change the base?
Conversation
i will right away commit all the things that might be necessary |
While the PR itself looks fine from a code PoV adding new settings is always a bit tricky as future backwards compatibility has to be taken into account. In the mentioned issue, where this new feature is somewhat discussed, the aim was more for something extensible, that may be added upon later if necessary. As the PR looks now, this is kinda fixed just on this one usecase of just a single character and somewhat neglects the extensibility for e.g. "sub-pixel" highlighting also discussed in the linked issue. Another aspect is that all settings should be available in the UI. This is currently not the case with this PR. @fasterit @natoscott : Further thoughts? |
Oh thanks for the input, :D maybe an integer called bar_type={1-6} where each number represents the type of bar to use is this fine or do you guys have any other ideas? also you said the settings should be available in UI |
I think for the UI settings it should suffice to have it selectable in the setup screen using F2 similar to how the Possible future extension: If we really wanted to include a custom option (fully hypothetical), that one could add 18 code points (9 for each bar level) after the initial "custom" designator. But please leave this out for now. |
oh will get into that right away |
@rustedusted
|
From a technical PoV the complexity is basically just: Treat the bar meter as having 8 times more space and use the remainder when dividing by 8 as the index into the character table. One reason for #714 not being merged yet is the heap of complexity it introduces despite what it tries to achieve. That's also why I pushed the "per meter" flags for rendering, as this allows different meter renderings to be used where necessary, thus reducing the complexity in the meter rendering (only has to care that its exact rendering works properly for the data provided).
That set of characters is meant for a different feature and should be handled as such. That other feature is not subject of this PR. Please don't mix up different things. |
Hey there sorry for the delay was getting myself acquainted with codebase so i could solve take on more issues added the sub pixel rendering, however as you might see the bars are distancing themselves between two differently colored bars should i add sub pixel only for the last bar and keep other bars non subpixel so that it seems consistent instead of disjoint?? if you have any other idea please let me know i feel like the next commits will be much faster now that i know significantly more about the code ig 😄 |
Meter.c
Outdated
const char* bars[7][8] = { | ||
{"|","|","|","|","|","|","|","|"}, | ||
{"#","#","#","#","#","#","#","#"}, | ||
{"⡀","⡄","⡆","⡇","⣇","⣧","⣷","⣿"}, | ||
{"░","░","▒","▒","▓","▓","█","█"}, | ||
{"▏","▎","▍","▌","▋","▊","▉","█"}, | ||
{"▁","▂","▃","▄","▅","▆","▇","█"}, | ||
{"▌","▌","▌","▌","█","█","█","█"} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Include the whitespace character for the various sets, as for e.g. braile you want to use the "zero dots" codepoint, instead of the normal blank character for consistency.
Also you can use " ||||||||"
, which while using one byte more is more compact to write. Furthermore, your type should be:
const char* bars[7][8] = { | |
{"|","|","|","|","|","|","|","|"}, | |
{"#","#","#","#","#","#","#","#"}, | |
{"⡀","⡄","⡆","⡇","⣇","⣧","⣷","⣿"}, | |
{"░","░","▒","▒","▓","▓","█","█"}, | |
{"▏","▎","▍","▌","▋","▊","▉","█"}, | |
{"▁","▂","▃","▄","▅","▆","▇","█"}, | |
{"▌","▌","▌","▌","█","█","█","█"} | |
}; | |
static const char* bars[7] = { | |
" ||||||||", | |
" ########", | |
" ⡀⡄⡆⡇⣇⣧⣷⣿", | |
" ░░▒▒▓▓██", | |
" ▏▎▍▌▋▊▉█", | |
" ▁▂▃▄▅▆▇█", | |
" ▌▌▌▌████", | |
}; |
(Used blank for all of them for now, please update the blanks for the graphical ones)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will commit everything bundled in one commit
i'll change the data type from instead of char to wchar so that we won't have to worry about converting char to wchar on everytime requested
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the changes i was quite uncertain while writing this :D
also i had to ask why don't we use normal space ?
and which is the utf8 character that you're referring to instead of the space.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For Braille you can use this one:
https://www.compart.com/en/unicode/U+2800
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reason for using other ones is for consistency, because sometimes the spacehas a different width in fonts compared to the default blank …
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@BenBE what do you think about this ??
should i add it ?
if yes,
should i replace it instead of the currently used characters for braille?
or should we add utf16 later ??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw adding utf16 is as easy as just adding new line in the array
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, Unicode 13 (March 2020) is fine. For Unicode 16 (September 2024) we can add this as a commented out inclusion, but should not compile it in by default (people shall edit their code if they wish to use it). Regarding the Unicode 16 variant I also have my doubts, if this set should be abbreviated or if there is a slightly extended version. Also for braille you could even do 0 to 8 dots starting at the bottom and adding the bottom-left most empty dot.
P.S.: There's a tool called charmap
that can be useful to look up these characters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so is this done??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if there is anything yet to add please do let me know
i have added everything in the following commits that was suggested if there is anything more please let me know |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please rebase your PR on top of main instead of merging. Also fixes to existing commits should be squashed into the appropriate commits instead of cluttering the history with trial and error: The commit history of a PR should show, what needs to be done to implement a feature, not every turn you took on the way to get there.
Adding the braces can (and should) stay a separate commit, as it only does code style changes and doesn't touch any functionality.
Meter.c
Outdated
@@ -124,26 +125,50 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) { | |||
|
|||
// First draw in the bar[] buffer... | |||
int offset = 0; | |||
double actualBarWidth=0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should be able to avoid this floating point code by defining int wsub = w * barsLen;
(rearranging code may apply) and using wsub
instead of w
whenever referring to the length of the bar, instead of actual cell position on the screen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hey there does this mean i make int actualBarWidth=0;
and no other change??
or do i change entire code to use wsub instead of w (width)?
Meter.c
Outdated
for (uint8_t i = 0; i < this->curItems; i++) { | ||
double value = this->values[i]; | ||
if (isPositive(value) && this->total > 0.0) { | ||
value = MINIMUM(value, this->total); | ||
blockSizes[i] = ceil((value / this->total) * w); | ||
actualBarWidth = ((value / this->total) * w); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The outer parens aren't necessary and should be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Meter.c
Outdated
|
||
const wchar_t *barChars = &bars[settings->barType][1]; | ||
int barsLen = wcslen(barChars); | ||
int subPixel = floor(actualBarWidth * barsLen); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment above. Will most likely reduce to a no-op in that context because no further scaling is needed.
Oh hey there you're right about squashing I didn't know a lot about git just learned few things will make a new pull request to do this I'm really very sorry for the inconvenience |
@rustedusted What are you doing? Try git rebase with |
@Explorer09 i was trying to merge main i did not create a new branch |
in fact i didn't know i had to create a new branch for that matter is there a way to recover this?! |
@rustedusted I don't recommend breaking existing discussions so I would suggest you to keep this branch You can set up a new branch |
hey there just an update i'm working on this issue couldn't work on this yesterday will definitely try putting a commit tomorrow |
organised commits ig:D |
i've made a branch with appropriate changes named new-stream do i make a new pull request?? |
hey also wanted to try out solving other issues can i take a new issue as i feel like this one is about to be solved ig idk tbh:| |
No, just force-push your updated PR on the branch you used to make this one. No need for a new PR, as this splits the discussion unnecessarily. |
faa6f53
to
791d28e
Compare
oh hey there very sorry i did not notice the warning i thought we were compiling with Werror and Wall flag |
a3d603c
to
546915b
Compare
done i don't think there should be any warnings now also i saw the snippet you sent cc1: all warnings being treated as errors this was a message in the snippet you sent i don't get such messages in fact it just showed warnings and ran without any issue |
See: Lines 17 to 29 in 4102862
Pass |
all suggested changes have been made :D |
And some of the updates I did were dropped … diff --git a/Meter.c b/Meter.c
index 00311a57..21e2afd4 100644
--- a/Meter.c
+++ b/Meter.c
@@ -132,14 +132,15 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
assert(startPos <= w);
assert(startPos + w <= RichString_sizeVal(bar));
- const Settings* settings = this->host->settings;
int blockSizes[10];
// First draw in the bar[] buffer...
int offset = 0;
+
+ const Settings* settings = this->host->settings;
const wchar_t* barChars = &bars[settings->barType][1];
const size_t barLen = wcslen(barChars);
- const uint8_t wsub = w * barLen;
+ const size_t wsub = w * barLen;
for (uint8_t i = 0; i < this->curItems; i++) {
double value = this->values[i];
@@ -150,6 +151,7 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
blockSizes[i] = 0;
continue;
}
+
if (isPositive(value) && this->total > 0.0) {
value = MINIMUM(value, this->total);
actualWidth = ceil((value / this->total) * wsub);
@@ -161,7 +163,7 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
// (Control against invalid values)
nextOffset = CLAMP(nextOffset, 0, w);
- for (int j = offset; j < nextOffset; j++){
+ for (int j = offset; j < nextOffset; j++) {
if (RichString_getCharVal(bar, startPos + j) == ' ') {
if (CRT_colorScheme == COLORSCHEME_MONOCHROME) {
assert(i < strlen(BarMeterMode_characters));
@@ -174,7 +176,7 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
}
}
- RichString_setChar(&bar, startPos + nextOffset-1, barChars[actualWidth % barLen]);
+ RichString_setChar(&bar, startPos + nextOffset - 1, barChars[actualWidth % barLen]);
offset = nextOffset;
} |
is there anything remaining |
it was division with zero solved that issue :D was slightly confused for some time |
solved all the checks |
now i don't know what can go wrong |
if there's anything do let me know :D |
If you reword that comparison you can avoid the division completely … Although I'm not fully sure if that short-hand is needed. |
oh are you referring to line 157 in Meter.c well the thing is that sometimes value is extremely small so just to avoid a single level it felt correct most times the value is extremely small so it just occupies a single character space for a character containing mostly empty space something like ⡀ you can try removing it and if you feel that is correct then we can use it |
Meter.c
Outdated
blockSizes[i] = ceil((value / this->total) * w); | ||
} else { | ||
blockSizes[i] = 0; | ||
} | ||
|
||
if ((value / this->total) * wsub < 0.5) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid division by zero …
if ((value / this->total) * wsub < 0.5) { | |
if (value * wsub < 0.5 * this->total) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh right sorry for that made the same mistake
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh wait i think making just one if condition is possible
see the new changes and see if they seem fine
because we need to continue even when total is zero
utf8 bars can be used by going into setup(F2) These bars enable subpixel rendering
it works as expected in this as well removing if might actually be a good method |
i don't know though i'm a newbie |
hey there any updates to this ?! |
adding bar_label feature to change the pipe in htop to any other ascii character user wants
this is addressing feature request #647
The PR only has support for normal ascii characters
i can extend this feature to add UTF-8 characters but the CONTRIBUTING.md suggested that newer features shouldn't unnecessarily increase the footprint of the program
(this is my first commit btw so i don't know much)
also Please look if the change in the file Settings.c is correct
options[1][0] doesn't seem a good way to get the character on right of = sign