Patchwork crecord: fallback to color = no when curses.use_default_colors() fails

login
register
mail settings
Submitter Elmar Bartel
Date Jan. 4, 2018, 11:47 a.m.
Message ID <528873b321141114df5d.1515066469@nuc15.leo.org>
Download mbox | patch
Permalink /patch/26540/
State Accepted
Headers show

Comments

Elmar Bartel - Jan. 4, 2018, 11:47 a.m.
mercurial/crecord.py |  5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)


# HG changeset patch
# User Elmar Bartel <elb_hg@leo.org>
# Date 1515065680 -3600
#      Thu Jan 04 12:34:40 2018 +0100
# Node ID 528873b321141114df5dcb8327d86ed691e2964b
# Parent  04fe74a8269a68c78a57a9f3698f1c87eff09e74
crecord: fallback to color = no when curses.use_default_colors() fails

Even when python was setup/compiled with curses, curses.use_default_colors()
may raise a curses exception when the TERM environment variable
specifies a value where no propper color configuration is possible.
This patch falls back to non-color mode to let the user continue
instead of failing with an unhandled exception.
Yuya Nishihara - Jan. 6, 2018, 1:57 a.m.
On Thu, 04 Jan 2018 12:47:49 +0100, Elmar Bartel wrote:
>  mercurial/crecord.py |  5 ++++-
>  1 files changed, 4 insertions(+), 1 deletions(-)
> 
> 
> # HG changeset patch
> # User Elmar Bartel <elb_hg@leo.org>
> # Date 1515065680 -3600
> #      Thu Jan 04 12:34:40 2018 +0100
> # Node ID 528873b321141114df5dcb8327d86ed691e2964b
> # Parent  04fe74a8269a68c78a57a9f3698f1c87eff09e74
> crecord: fallback to color = no when curses.use_default_colors() fails

Queued, thanks.

Patch

diff -r 04fe74a8269a -r 528873b32114 mercurial/crecord.py
--- a/mercurial/crecord.py	Thu Jan 04 12:12:07 2018 +0100
+++ b/mercurial/crecord.py	Thu Jan 04 12:34:40 2018 +0100
@@ -1715,7 +1715,10 @@  are you sure you want to review/edit and
         self.yscreensize, self.xscreensize = self.stdscr.getmaxyx()
 
         curses.start_color()
-        curses.use_default_colors()
+        try:
+            curses.use_default_colors()
+        except curses.error:
+            self.usecolor = False
 
         # available colors: black, blue, cyan, green, magenta, white, yellow
         # init_pair(color_id, foreground_color, background_color)