XZise has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/210935

Change subject: [IMPROV] More sensible input()
......................................................................

[IMPROV] More sensible input()

Instead of stripping text from both sides it just strips from from the
right (as there a space is actually added). It now also checks whether
there is a color code at the end. In that case it checks the character
before that color code instead of checking the last character to insert
the default value.

Change-Id: I7447bf199a89bfe67702778203511b96ee1df530
---
M pywikibot/userinterfaces/terminal_interface_base.py
1 file changed, 13 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/35/210935/1

diff --git a/pywikibot/userinterfaces/terminal_interface_base.py 
b/pywikibot/userinterfaces/terminal_interface_base.py
index 968a14b..1f10c9a 100755
--- a/pywikibot/userinterfaces/terminal_interface_base.py
+++ b/pywikibot/userinterfaces/terminal_interface_base.py
@@ -221,13 +221,20 @@
         @rtype: unicode
         """
         assert(not password or not default)
-        end_marker = ':'
-        question = question.strip()
-        if question[-1] == ':':
+        end_marker = ''
+        question = question.rstrip()
+        if question[-1] == '}':
+            color_start = question.rfind('\03{')
+            if color_start == question.rfind('{') - 1:
+                end_marker = question[color_start:]
+                question = question[:color_start]
+        if question[-1] == '?':
+            end_marker = '?' + end_marker
             question = question[:-1]
-        elif question[-1] == '?':
-            question = question[:-1]
-            end_marker = '?'
+        else:
+            if question[-1] == ':':
+                question = question[:-1]
+            end_marker = ':' + end_marker
         if default:
             question = question + ' (default: %s)' % default
         question = question + end_marker

-- 
To view, visit https://gerrit.wikimedia.org/r/210935
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7447bf199a89bfe67702778203511b96ee1df530
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: XZise <commodorefabia...@gmx.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to