Closed octobanana closed 6 years ago
Hello. I really like what you did here, I would like to merge it. Could you squash those commits into one? And if you are at it it would be great if more example phrases were to be added, so multi-select hints could be showcased in more contexts.
I thought about showcasing hints and highlighting at the same time, i.e.: adding phrases: "color_red", "color_green", "color_blue", ... and so on, and coloring those phrases in highlighting callback accordingly, what do you think?
Thanks! I squashed the changes into a single commit.
I think that's a great idea for the color phrases, so I added it in. Each color phrase, such as 'color_magenta' gets displayed as that color, along with its hint. Multiple color phrases on a single line will each be highlighted in their respective color. Let me know what you think, and if that was what you had in mind.
Is it possible to complete more then one phrase per line? So say the line contains color_magenta color_r
, could it autocomplete and show the hint for color_red?
I also ran into an issue where if the completion phrase has a -
or a /
in it, the entire completion value gets added onto the end of the prefix. So if the completion phrase was color-red
, and the line contained color-r
, the hint shows up alright, but after hitting tab the line will then contain color-color-red
.
Hello. New pull request is great stuff.
Completion of more than one phrase just works, but the completer interface seems to be a bit confusing.
Replxx::completions_t hook_completion(std::string const& context, int prefix, void* ud)
context
here is always full input line
prefix
is offset in the input where last word break before cursor occur
so, for:
color_red color_
input, if <TAB>
is pressed at the end of the input line then,
context == "color_red color_"
prefix == 10
With -
character the problem is that -
is a word breaking character so for input:
color-red color-
and <TAB>
pressed at end of line
context == "color-red color-"
prefix == 16
To fix that one can either change set of word breaking characters with set_word_break_characters()
method, or use full context
to infer proper prefix
position.
The same logic applies for hinter hook. One has to take into account this specific semantics while implementing hooks.
So, after small fixes in completer and hinter code, it displays proper hints and perform proper completions.
One thing though, I would prefer to keep coding style consistent and current code base used 1TBS through and through.
Another issue that I found is that only first occurrence of highlighted phrase
get highlighted, e.g.: color_red color_red
only first color_red
gets highlighted.
If you want I can fix all those issues or you can fix them yourself and maybe with fresh understanding of the interface and semantics a better documentation could be proposed?
Thank you for a great contribution, cannot wait to merge it!
I had misunderstood the interface, thanks for the explanation! It makes sense now. It should now display the proper hints and completions. I also changed the style to use 1TBS and tabs. Let me know if I missed any styling, or if you'd like something changed.
You're right, the loop in the color hook was only looking for the first match, good catch! It now loops through the line and finds all matches to be highlighted. I changed the phrase/color data structure to a vector of pairs, where the pair consists of a regex string and a highlighting color. By using a regex search in the color hook, it can now highlight phrases such as integers, decimals, scientific notation, and quoted string values. What do you think of the use of regexes for this purpose?
I'll make this an additional commit, so the changes are more easily seen, and squash it into a single commit once all is good.
Thank you for the great feedback!
Yes! It looks great. The example now shows full capability of the library. You also found a bug :), clear_screen() method while a part of the interface was not really implemented. I fixed that and pushed that small fix so you could use official screen clearing method for ".clear".
I after you rebase and squash I am going to merge it.
Thank you!
Awesome :) the '.clear' command now uses the official method!
It's squashed and ready to go! Let me know if there is anything else that should be changed.
Hey, great work with the library!
I was playing around with the c++ api example, and adapted most of the c lang specific features to use modern c++11 features.
The main changes are the following:
const char*
tostd::string
const char* []
tostd::vector<std::string>
std::vector<std::string>
example word listhelp
clear
andquit
like thehistory
keywordI'm not sure if these changes are of interest to you, but I thought I would share it.