jquast / blessed

Blessed is an easy, practical library for making python terminal apps
http://pypi.python.org/pypi/blessed
MIT License
1.18k stars 71 forks source link

Add Terminal.get_fgcolor() and Terminal.get_bgcolor() #237

Closed stefanholek closed 1 year ago

avylove commented 2 years ago

Sorry we haven't responded to this sooner.

I think there's too much duplication of code. We should probably pull the try/finally block into its own method, maybe a context manager, since that code is the same in three places except a few variables. Then maybe we can do something like:

with self.query_response(query_str, response_re, timeout) as match:
    if match:
        return tuple(int(val, 16) for val in match.groups())

return -1, -1 , -1
codecov[bot] commented 1 year ago

Codecov Report

Base: 95.15% // Head: 95.18% // Increases project coverage by +0.03% :tada:

Coverage data is based on head (f25692a) compared to base (7a114c3). Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #237 +/- ## ========================================== + Coverage 95.15% 95.18% +0.03% ========================================== Files 9 9 Lines 1011 1018 +7 Branches 215 215 ========================================== + Hits 962 969 +7 Misses 45 45 Partials 4 4 ``` | [Impacted Files](https://codecov.io/gh/jquast/blessed/pull/237?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jeff+Quast) | Coverage Δ | | |---|---|---| | [blessed/terminal.py](https://codecov.io/gh/jquast/blessed/pull/237?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jeff+Quast#diff-Ymxlc3NlZC90ZXJtaW5hbC5weQ==) | `97.84% <100.00%> (+0.03%)` | :arrow_up: | Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jeff+Quast). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jeff+Quast)

:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

avylove commented 1 year ago

I rebased and consolidated the common code. Then I noticed all the test data was ffff/ffff/ffff, so I used somes X11 colors instead to make them in range and different values. Out of range values still work, but I don't think it's our place to police that. If the terminal wants to report the values higher than 255, I don't think we care.

@jquast, I think this looks ok to merge. Can you take a look?