Enable to change the background color of dialogs.#413
Conversation
|
Readline complains about new unknown keywords in inputrc. |
|
@elfham If Reline is mandatory to be compatible with readline, my implementation this time may not be good. |
|
Since inputrc is a common configuration file for Readline and Reline, I'm afraid that apps that use Readline will suffer the side effects of adding this keyword. I'm not an expert on Reline, so I don't know if this is the right way to do it, but how about setting it up in irbrc? |
|
@elfham I did not know that irbrc existed. I'll try to see if I can use it. Thank you. |
|
@elfham I modified irbrc so that it can pass configuration items. (ruby/irb#337) You can try this fix with a Gemfile like the one below. |
|
I have tried this fix and it seems to be working well. |
|
@pocari also confirmed working with no problems |
|
I have also made the foreground color changeable. |
|
Would love to see this feature! Is there any reason it hasn't been approved and merged yet? |
lib/reline/line_editor.rb
Outdated
| fg_color = 37 | ||
| if i == pointer | ||
| bg_color = '45' | ||
| if dialog_render_info.pointer_fg_color |
There was a problem hiding this comment.
How about setting the default values when initializing the reline like other configs?
Lines 546 to 551 in 5b3fc02
Then we don't need these if statements because the dialog_render_info should always have values from the config default. It will also help users getting the default by just calling Reline.dialog_default_fg_color.
If we really worry about the values being nil by accident, we should validate them at the setter.
|
Since we want them to be exposed externally, I think it doesn't matter where they'll be used. The point is to make the values more easily accessible. |
lib/reline.rb
Outdated
| core.add_dialog_proc(:autocomplete, Reline::DEFAULT_DIALOG_PROC_AUTOCOMPLETE, Reline::DEFAULT_DIALOG_CONTEXT) | ||
| core.dialog_default_bg_color = 46 # Cyan | ||
| core.dialog_default_fg_color = 37 # White | ||
| core.dialog_pointer_bg_color = 45 # Maggenta |
There was a problem hiding this comment.
Maggenta => Magenta
There was a problem hiding this comment.
@Maumagnaguagno Thanks. I have fixed it.
|
@pocari Thanks for the update. It looks good to me 👍 # .irbrc
Reline.dialog_default_bg_color = 40
Reline.dialog_pointer_bg_color = 47@hsbt Would you mind giving this a look? I know @aycabta is the maintainer but he seems to have been away for a while. I think being able to change the background color of the dialog is essential for good user-experience. And as shown in ruby/irb#328, the default color doesn't look good with some themes (for example, mine). And many users decided to turn off the autocomplete feature altogether because of the color. Of course, to completely fix the |
|
@st0012
That may be possible. |
|
@st0012 As you said it was possible. Thanks! You can try it with the following I have added a condition because there must be some environments where Reline is not installed. |
|
@pocari To be clear, I know the |
|
@pocari Can you rebase your branch to see if the CI passes? |
…ckground color of the selected item in inputrc.
Co-authored-by: Peter Zhu <peter@peterzhu.ca>
…f github.com:pocari/reline into support-for-changing-the-background-color-of-dialogs
d0559f8 to
2302293
Compare
peterzhu2118
left a comment
There was a problem hiding this comment.
Thank you for your contribution!
|
@hsbt @peterzhu2118 Do you think we can cut a There are a few reasons:
Or do you have any concerns/thoughts? |
|
46, 37 and so on are not “colors”, but attributes including where they are applied to, foreground or background. |
|
@nobu |
|
I feel "color" is still a better name because that's what we want them to be used for. How about this Reline.dialog_default_bg_color = :black
Reline.dialog_pointer_bg_color = :white
Reline.dialog_pointer_fg_color = :black
Reline.dialog_pointer_bg_color = :whiteAnd the color assignment logic can do: # lib/reline/config.rb
def dialog_default_bg_color=(color)
@dialog_default_bg_color = select_color_code(:bg, color)
end
def select_color_code(type, color)
if :bg
case color
when :black
40
when :white
47
# ...... the rest
else
raise ColorNotFound
end
else
case color
when :black
30
when :white
37
# ...... the rest
else
raise ColorNotFound
end
end
end |
|
To set colors only, Another concern is BTW, your def select_color_code(type, color)
case type
when :bg; 40
when :fg; 30
else raise ColorNotFound
end +
case color
when :black; 30
when :white; 37
# ...... the rest
else raise ColorNotFound
endor even |
That's true. But from what I've seen so far, the only request is on color and not other text effects. I'm sure some users would want that but perhaps we can design better APIs for those cases when we get more feedback?
The reason I want to pass color symbol instead of integer is to prevent cases like this, as we won't have 0 available in the case statement.
That's a great suggestion 👍 I'll open a PR shortly. |
The linux man page calls them "color sequences". However, the ANSI escape code standard calls them "control sequences". |
As pointed out in the [comment](ruby#413 (comment)), the code is actually a control sequence and not only for colors. To make the dialog color APIs safer to use, we should restrict its usages and extract away the bg/fg concept from the input. So in this commit, I made these changes: 1. The dialog_*_bg/fg_color APIs only takes and returns color names (symbol): - :black - :red - :green - :yellow - :blue - :magenta - :cyan - :white 2. Add additional dialog_*_bg/fg_color_code APIs to access the raw code.
As pointed out in the [comment](ruby#413 (comment)), the code is actually a control sequence and not only for colors. To make the dialog color APIs safer to use, we should restrict its usages and extract away the bg/fg concept from the input. So in this commit, I made these changes: 1. The dialog_*_bg/fg_color APIs only takes and returns color names (symbol): - :black - :red - :green - :yellow - :blue - :magenta - :cyan - :white 2. Add additional dialog_*_bg/fg_color_sequence APIs to access the raw code.
As pointed out in the [comment](ruby#413 (comment)), the code is actually a control sequence and not only for colors. To make the dialog color APIs safer to use, we should restrict its usages and extract away the bg/fg concept from the input. So in this commit, I made these changes: 1. The dialog_*_bg/fg_color APIs only takes and returns color names (symbol): - :black - :red - :green - :yellow - :blue - :magenta - :cyan - :white 2. Add additional dialog_*_bg/fg_color_sequence APIs to access the raw code.
| str_width = dialog.width - (dialog.scrollbar_pos.nil? ? 0 : @block_elem_width) | ||
| str = padding_space_with_escape_sequences(Reline::Unicode.take_range(item, 0, str_width), str_width) | ||
| @output.write "\e[#{bg_color}m#{str}" | ||
| @output.write "\e[#{bg_color}m\e[#{fg_color}m#{str}" |
There was a problem hiding this comment.
This can be "\e[#{bg_color};#{fg_color}m#{str}".
| @output.write "\e[#{bg_color}m#{str}" | ||
| @output.write "\e[#{bg_color}m\e[#{fg_color}m#{str}" | ||
| if dialog.scrollbar_pos and (dialog.scrollbar_pos != old_dialog.scrollbar_pos or dialog.column != old_dialog.column) | ||
| @output.write "\e[37m" |
As pointed out in the [comment](ruby#413 (comment)), the code is actually a control sequence and not only for colors. To make the dialog color APIs safer to use, we should restrict its usages and extract away the bg/fg concept from the input. So in this commit, I made these changes: 1. The dialog_*_bg/fg_color APIs only takes and returns color names (symbol): - :black - :red - :green - :yellow - :blue - :magenta - :cyan - :white 2. Add additional dialog_*_bg/fg_color_sequence APIs to access the raw code.
As pointed out in the [comment](ruby#413 (comment)), the code is actually a control sequence and not only for colors. To make the dialog color APIs safer to use, we should restrict its usages and extract away the bg/fg concept from the input. So in this commit, I made these changes: 1. The dialog_*_bg/fg_color APIs only takes and returns color names (symbol): - :black - :red - :green - :yellow - :blue - :magenta - :cyan - :white 2. Add additional dialog_*_bg/fg_color_sequence APIs to access the raw code.
As pointed out in the [comment](ruby#413 (comment)), the code is actually a control sequence and not only for colors. To make the dialog color APIs safer to use, we should restrict its usages and extract away the bg/fg concept from the input. So in this commit, I made these changes: 1. The dialog_*_bg/fg_color APIs only takes and returns color names (symbol): - :black - :red - :green - :yellow - :blue - :magenta - :cyan - :white 2. Add additional dialog_*_bg/fg_color_sequence APIs to access the raw code.
…r APIs As pointed out in the [comment](ruby/reline#413 (comment)), the code is actually a control sequence and not only for colors. To make the dialog color APIs safer to use, we should restrict its usages and extract away the bg/fg concept from the input. So in this commit, I made these changes: 1. The dialog_*_bg/fg_color APIs only takes and returns color names (symbol): - :black - :red - :green - :yellow - :blue - :magenta - :cyan - :white 2. Add additional dialog_*_bg/fg_color_sequence APIs to access the raw code. ruby/reline@b32a977766

Reline in its current state also has the ability to change the background color using the bg_color attribute of DialogRenderInfo, but I couldn't seem to use that feature right now.
I changed it so that in addition to the bg_color, the background color of the item being selected for completion can also be set, and then it can be defined in "inputrc" so that the user can choose the color.
default color:

customize sample:

You can try with the following settings