Patchwork [1,of,4] color: call curses.setupterm() earlier

login
register
mail settings
Submitter Gregory Szorc
Date July 9, 2017, 11:46 p.m.
Message ID <129c9709980108beecfa.1499643974@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/22193/
State Accepted
Headers show

Comments

Gregory Szorc - July 9, 2017, 11:46 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1499628062 25200
#      Sun Jul 09 12:21:02 2017 -0700
# Node ID 129c9709980108beecfa1c02a52c679654de8b21
# Parent  4672db164c986da4442bd864cd044512d975c3f2
color: call curses.setupterm() earlier

It doesn't make sense to iterate over config options and set
ui._terminfoparams if curses.setupterm() will fail and we'll
just clear ui._terminfoparams. So move curses.setupterm()
before any ui._terminfoparams manipulation.

Patch

diff --git a/mercurial/color.py b/mercurial/color.py
--- a/mercurial/color.py
+++ b/mercurial/color.py
@@ -141,6 +141,13 @@  def _terminfosetup(ui, mode):
     # Otherwise, see what the config file says.
     if mode not in ('auto', 'terminfo'):
         return
+
+    try:
+        curses.setupterm()
+    except curses.error:
+        ui._terminfoparams.clear()
+        return
+
     ui._terminfoparams.update(_baseterminfoparams)
 
     for key, val in ui.configitems('color'):
@@ -150,11 +157,6 @@  def _terminfosetup(ui, mode):
         elif key.startswith('terminfo.'):
             newval = (True, '', val.replace('\\E', '\x1b'))
             ui._terminfoparams[key[9:]] = newval
-    try:
-        curses.setupterm()
-    except curses.error as e:
-        ui._terminfoparams.clear()
-        return
 
     for key, (b, e, c) in ui._terminfoparams.items():
         if not b: