Skip to content
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

[RFC] Colour quoted text #1441

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open

Conversation

Nelyah
Copy link

@Nelyah Nelyah commented Oct 10, 2019

Context

I feel like being able to render quote text according to the quoted level with colours is important. At least it is for me in terms of readability.

This PR is to answer this particular feature. An issue has been opened #746, but it was answered with #612 and then #1015. These are great features, but don't quite target this specific issue.

Modifications

I modified the file alot/widget/thread.py to call the parse_text_colour function, if we are looking at words linewise. The function parse_text_colour asks the config to check if we want to parse quoted text. If yes, it proceeds and calls the function parse_quotes.

The latter returns the theme value associated with the quote_level in the theme file (if there is one).

Example configuration

This is working well for me and it passes the tests. This is how I set it up in my config file to make either > or four spaces a quote symbol.:

quote_symbol = '( {4}|>)'
parse_quotes = True

I am fairly new to this project, please let me know if there are obvious things I am missing.

@pazz
Copy link
Owner

pazz commented Oct 10, 2019

Welcome to alot @Nelyah, and thanks for starting to contribute right away!
Would you mind sharing a screenshot so that we can better understand what exactly the feature is and which the consequences of the code changes are?

Would this only change the urwid representation or does your code changes the text of follow-up reply emails?

@Nelyah
Copy link
Author

Nelyah commented Oct 10, 2019

Thank you @pazz, this is a wonderful piece of software you got there!

Here is a screenshot of a sample mail. I set up the colours being close from one another, but this can be changed with the options quote_level_i in the configuration file (where i is the quotation level wished for). I declared those only up to i=7. Let me know if you'd wish more colour contrast.

Screenshot from 2019-10-10 18-17-58

Would this only change the urwid representation or does your code changes the text of follow-up reply emails?

No, this should only change the urwid representation. The only real modification to existing code is to change the attr theming value (in alot/widget/thread.py). I am getting the new attr value by parsing the mail body and searching it for quotation markers (which can be defined in the configuration file)

alot/widgets/colour_text.py Outdated Show resolved Hide resolved
alot/widgets/colour_text.py Outdated Show resolved Hide resolved
alot/widgets/colour_text.py Show resolved Hide resolved
@Nelyah
Copy link
Author

Nelyah commented Oct 11, 2019

I just added the tests as well

tests/widgets/test_colour_text.py Outdated Show resolved Hide resolved
tests/widgets/test_colour_text.py Outdated Show resolved Hide resolved
tests/widgets/test_colour_text.py Show resolved Hide resolved
tests/widgets/test_colour_text.py Show resolved Hide resolved
tests/widgets/test_colour_text.py Outdated Show resolved Hide resolved
@Nelyah
Copy link
Author

Nelyah commented Oct 11, 2019

Thank you for the feedback, @lucc! And sorry if this has taken some time and back and forth.

Copy link
Owner

@pazz pazz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please squash down those commits that make trivial changes or revert stuff you introduced yourself earlier? I started to review the commits one by one and realized that some of my (line) comments are already addressed in later commits...

alot/widgets/colour_text.py Show resolved Hide resolved
alot/widgets/colour_text.py Outdated Show resolved Hide resolved
is_quoted = False
quote_colour = None
symbol = settings.get('quote_symbol')
if symbol is None:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the fallback option when getting the config setting? https://github.com/pazz/alot/blob/master/alot/settings/manager.py#L239
(note that the defaul is "> ", with a trailing space)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense here to specify a fallback? If I understand correctly we would still get the default settings value of the variable we're requesting (in this case from quote_symbol : >), even if no fallback is defined.

alot/widgets/colour_text.py Show resolved Hide resolved
@@ -17,6 +17,10 @@ input_timeout = float(default=1.0)
# .. note:: this config setting is equivalent to, but independent of, the 'search.exclude_tags' in the notmuch config.
exclude_tags = force_list(default=list())

# Show quotes be parsed
parse_quotes = boolean(default=True)
quote_symbol = string(default='>')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not use the existing quote_prefix?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't see it before!

However, I notice that it has a space added to it. That would mean that a line like:

>> Level 2 quote level

wouldn't get interpreted correctly, because the regex r'^ *({} *){{{}}}'.format(symbol, quote_level) wouldn't match. It would still be possible to change it but the default wouldn't work really well.

I'm not sure in what context quote_prefix is used. A first solution would be to remove the space and accommodate for this wherever it is used. A second could be to rename my quote_symbol to something more explicit, like quotation_regex_detection.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this new option is necessary. The two most commonly used characters for quoting text are > and |, and I've only ever seen the bracket being used (wikipedia reference).

It would make the PR leaner to assume only those two characters highlight quotes in messages, plus it would avoid some weird unit tests verifying that the code behaves as expected when using [Aa] for quote_symbol.

@Nelyah
Copy link
Author

Nelyah commented Nov 3, 2019

I'll do the licence change and add the quote_prefix (didn't see it previously).
However squashing commits (which I have already pushed to origin) through a rebase means I am rewriting all of my commits as my new master diverges from origin/master, isn't it?
I'm not quite a git professional, but let me know if this is what I should do (unless there is a better solution for it)

@lucc
Copy link
Collaborator

lucc commented Nov 4, 2019

You can do an interactive rebase. Like this git rebase --interactive origin/master message-body-colour. Learn more about it from the docs.

@pazz pazz added this to the 0.9 milestone Nov 21, 2019
@pazz
Copy link
Owner

pazz commented May 6, 2020

Where are we on this? It'd be a shame to let this get too old and diverge from master too much to be useful..

@Nelyah
Copy link
Author

Nelyah commented May 6, 2020

Oh, I'm sorry.

I had some things happening at the time and it just slipped out of my mind. I will get back to this in the next few days! Sorry again for the delay...

pazz and others added 7 commits May 8, 2020 19:16
Also generate the docs for those settings
As of now, only the function parse_quotes is implemented, but other ideas could be added.
Add tests for checking that:
- Regex works
- Empty quote means we return None
- Check we're actually getting the expected attribute
@Nelyah
Copy link
Author

Nelyah commented May 8, 2020

I rebased and resolved a few merge conflicts (mainly in thread.py with FocusableText being replaced by ANSIText), but have not yet added anything else.

I added a few [tags] to my commits to help myself (and maybe you as well) since it's been a while I worked on this. I'll remove them before merging this.

Repository owner deleted a comment from Nelyah May 12, 2020
@@ -17,6 +17,10 @@ input_timeout = float(default=1.0)
# .. note:: this config setting is equivalent to, but independent of, the 'search.exclude_tags' in the notmuch config.
exclude_tags = force_list(default=list())

# Show quotes be parsed
parse_quotes = boolean(default=True)
quote_symbol = string(default='>')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this new option is necessary. The two most commonly used characters for quoting text are > and |, and I've only ever seen the bracket being used (wikipedia reference).

It would make the PR leaner to assume only those two characters highlight quotes in messages, plus it would avoid some weird unit tests verifying that the code behaves as expected when using [Aa] for quote_symbol.

symbol = settings.get('quote_symbol')
quote_colour = None

for quote_level in range(1, max_quote_level+1):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think running 7 regex matches on a line that has 7 levels of nested quoting is too much.

I made it work (with a dirty patch) on my local branch with only two calls to re.match(), for any amount of nesting, I think it's the better way to go about it.

Plus if we remove the quote_symbol option (c.f. my other comment), it will be easier to parse spaces properly (RFC reference)

'colourmode': 256
}

SETTINGS_test_symbol_regex = {'quote_symbol': '([Aa]|<>.b|>)',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned in another comment, this is a weird thing to test for. Maybe we don't need the code to be that generic.


else:
# If there is no match at some point,
# we simply use the last level match colour
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think cycling back to the colours for the first level of quoting is a better option:

  • 8 → 1
  • 9 → 2
  • 15 → 1
  • 16 → 2

etc.

Basically a modulo.

@lucc lucc removed this from the 0.9 milestone Jul 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants