-
Notifications
You must be signed in to change notification settings - Fork 372
Add color support for input bar #764
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
Conversation
src/fe-text/gui-entry.c
Outdated
term_set_color(root_window, ATTR_RESET); | ||
term_move(root_window, xpos, entry->ypos); | ||
|
||
for (i = entry->scrstart + pos; i < entry->text_len; i++) { | ||
col = entry->scrstart + pos < entry->text_len ? | ||
entry->colors + entry->scrstart + pos : 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.
s/0/NULL/
src/fe-text/gui-entry.c
Outdated
@@ -266,14 +274,19 @@ static void gui_entry_draw_from(GUI_ENTRY_REC *entry, int pos) | |||
if (xpos > end_xpos) | |||
break; | |||
|
|||
if (*col != color) { |
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 col
is set to NULL
above you get a NPE.
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 the intention was that col
is only set to NULL
if the loop won't run.
Perhaps this should instead use entry->colors[i]
, since col
is equal to entry->colors + i
at all points during the loop?
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.
That's much better!
src/fe-text/gui-entry.c
Outdated
@@ -505,6 +522,10 @@ void gui_entry_insert_text(GUI_ENTRY_REC *entry, const char *str) | |||
} | |||
} | |||
|
|||
for(i = 0; i < len; i++) { |
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.
Missing space after for
.
src/fe-text/gui-entry.c
Outdated
@@ -700,6 +726,9 @@ void gui_entry_erase(GUI_ENTRY_REC *entry, int size, CUTBUFFER_UPDATE_OP update_ | |||
g_memmove(entry->text + entry->pos - size, entry->text + entry->pos, | |||
(entry->text_len-entry->pos+1) * sizeof(unichar)); | |||
|
|||
g_memmove(entry->colors + entry->pos - size, entry->colors + entry->pos, |
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 memmove
above has a +1
that's missing here, why is that?
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'm not entirely sure. This is straight from the original patch.
Is entry->text
NULL
-terminated, and entry->colors
implicitly has the same number of elements?
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.
That's it, sorry for the noise.
src/fe-text/gui-entry.c
Outdated
(entry->text_len-entry->pos-size+1) * sizeof(unichar)); | ||
(entry->text_len-entry->pos-size+1) * sizeof(unichar)); | ||
|
||
g_memmove(entry->colors + entry->pos, entry->colors + entry->pos + size, |
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.
Ditto as before.
src/fe-text/gui-entry.c
Outdated
g_free(first_color); | ||
g_free(sep_color); | ||
g_free(second_color); | ||
|
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.
Stray newline.
src/fe-text/gui-entry.c
Outdated
for (i = pos; i < end; i++) { | ||
if (entry->colors[i] != color) { | ||
entry->colors[i] = color; | ||
update = 1; |
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.
s/1/TRUE/
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 assume FALSE
on L1109 too?
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.
Yep.
src/fe-text/gui-entry.c
Outdated
@@ -700,6 +726,9 @@ void gui_entry_erase(GUI_ENTRY_REC *entry, int size, CUTBUFFER_UPDATE_OP update_ | |||
g_memmove(entry->text + entry->pos - size, entry->text + entry->pos, | |||
(entry->text_len-entry->pos+1) * sizeof(unichar)); | |||
|
|||
g_memmove(entry->colors + entry->pos - size, entry->colors + entry->pos, |
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.
That's it, sorry for the noise.
src/fe-text/gui-entry.c
Outdated
for (i = pos; i < end; i++) { | ||
if (entry->colors[i] != color) { | ||
entry->colors[i] = color; | ||
update = 1; |
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.
Yep.
src/fe-text/gui-entry.c
Outdated
@@ -266,14 +274,19 @@ static void gui_entry_draw_from(GUI_ENTRY_REC *entry, int pos) | |||
if (xpos > end_xpos) | |||
break; | |||
|
|||
if (*col != color) { |
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.
That's much better!
src/fe-text/gui-entry.c
Outdated
@@ -1042,3 +1100,31 @@ void gui_entry_redraw(GUI_ENTRY_REC *entry) | |||
gui_entry_fix_cursor(entry); | |||
gui_entry_draw(entry); | |||
} | |||
|
|||
void gui_entry_set_color(GUI_ENTRY_REC *entry, int pos, int len, int color) |
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 we should add a couple of checks to make sure pos
and len
are >= 0
to avoid some potential memory corruption bugs due to careless scripts.
src/fe-text/gui-entry.c
Outdated
@@ -1042,3 +1103,31 @@ void gui_entry_redraw(GUI_ENTRY_REC *entry) | |||
gui_entry_fix_cursor(entry); | |||
gui_entry_draw(entry); | |||
} | |||
|
|||
void gui_entry_set_color(GUI_ENTRY_REC *entry, int pos, int len, int color) |
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 we should add a couple of checks to make sure pos
and len
are >= 0
to avoid some potential memory corruption bugs due to careless scripts.
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 in 8326588
seems mostly ok, but I don't like having to use the internal colour attributes from XS -- maybe we can add in some functions to do colour code conversions between \004, % and this. And another thing: it doesn't do 24bit "true colour" (api is term_set_color2, didn't exist back then) The more general question is if we like this implementation. Alternative would be to have in-line colours like in print text / gui prompt. But this code here is much simpler. In general I think it would be a nice to have feature for your and the other use case |
What if we reuse the same parsing logic that's used for themes formats? It's not that good but at least spares us from writing another parser and having the script writers learn a new set of specifiers.
The principle of separation between data and metadata applies here.
I'm using it to turn the whole prompt red whenever there's a |
if we had something more generic like in line colours then it could offer more flexibility like also in line altering of the actual displayed text. think of a blinking "warning" appended to the prompt or an in line display of spelling suggestions after the unrecognised word |
I'm not entirely sure how inline colors would work here. Using format codes instead of ints sounds good, though. I have no idea how I'd implement that, but I can take a look and poke around IRC and see if I can put something together. |
just conceptually speaking, one way to think about inline colours would be to take the input
then call a function (e.g. XS) which would change it to
and that's what would then be visible. This would demand the callback to transform "input" into "displayed input" to be called at basically every change to the prompt colours would then be realised by "returning"
from the signal handler. There /should/ be some methods in irssi (which may need to be moved to some util/misc function) that turn %codes into the appropriate attributes |
todo: change XS to work on %-codes (maybe exposing some functions for \004 conversion at the same time) |
8326588
to
2ff6a07
Compare
first version, still some errors, feel free to play with it and fix the remaining bugs |
99e2257
to
3e4e52b
Compare
Irssi::gui_input_clear_extents(pos, len) |
5f89de5
to
7ce9de4
Compare
@GinjaNinja32 I changed the api again slightly,extent -> extents. hope you can test this again and discuss any usability issues that we may need to fix before merge |
7ce9de4
to
9072e98
Compare
@irssi/developers I think we should merge this |
This is mostly a rebase of this patch, with a few bugfixes (a segfault in
gui_entry_transpose_words
, and a pointer-to-int assignment).Allows scripts to specify that ranges of characters in the input bar should be rendered in specific colors; the original intent for this was to implement a spellchecker, my use is to colorise nicks in the input bar.
Example script using this, mostly based on my rewritten colorize_nicks.pl: https://thanatos.gn32.uk/f/colorise_input.pl (I'll likely clean up the code a little and submit for scripts.irssi.org, assuming this PR gets merged)