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

Add support for UNDERLINED, BLINK, REVERSED (with patch!) #38

Open
tartley opened this issue Feb 16, 2015 · 11 comments
Open

Add support for UNDERLINED, BLINK, REVERSED (with patch!) #38

tartley opened this issue Feb 16, 2015 · 11 comments

Comments

@tartley
Copy link
Owner

tartley commented Feb 16, 2015

Migrated from https://code.google.com/p/colorama/issues/detail?id=39
Reported by irmendejong, Dec 7, 2012

I wrote some code to add a few more ansi-styles to colorama.
Unfortunately the win32 style for underlined and reversevideo don't seem to work at all (even though there's constants defined for them). I am simulating the reversevideo one but the underlined one is just not working.

@tartley
Copy link
Owner Author

tartley commented Feb 16, 2015

diff -r 4ccdb5498413 colorama/ansi.py
--- a/colorama/ansi.py  Sun May 27 10:09:37 2012 +0100
+++ b/colorama/ansi.py  Tue Dec 11 01:23:44 2012 +0100
@@ -38,10 +38,13 @@
     RESET   = 49

 class AnsiStyle:
-    BRIGHT    = 1
-    DIM       = 2
-    NORMAL    = 22
-    RESET_ALL = 0
+    BRIGHT     = 1
+    DIM        = 2
+    UNDERLINED = 4
+    BLINK      = 5
+    REVERSEVID = 7
+    NORMAL     = 22
+    RESET_ALL  = 0

 Fore = AnsiCodes( AnsiFore )
 Back = AnsiCodes( AnsiBack )
diff -r 4ccdb5498413 colorama/ansitowin32.py
--- a/colorama/ansitowin32.py   Sun May 27 10:09:37 2012 +0100
+++ b/colorama/ansitowin32.py   Tue Dec 11 01:23:44 2012 +0100
@@ -89,6 +89,7 @@
                 AnsiStyle.BRIGHT: (winterm.style, WinStyle.BRIGHT),
                 AnsiStyle.DIM: (winterm.style, WinStyle.NORMAL),
                 AnsiStyle.NORMAL: (winterm.style, WinStyle.NORMAL),
+                AnsiStyle.REVERSEVID: (winterm.style_reverse_vid, ),
                 AnsiFore.BLACK: (winterm.fore, WinColor.BLACK),
                 AnsiFore.RED: (winterm.fore, WinColor.RED),
                 AnsiFore.GREEN: (winterm.fore, WinColor.GREEN),
diff -r 4ccdb5498413 colorama/tests/ansi_test.py
--- a/colorama/tests/ansi_test.py   Sun May 27 10:09:37 2012 +0100
+++ b/colorama/tests/ansi_test.py   Tue Dec 11 01:23:44 2012 +0100
@@ -54,6 +54,10 @@
         self.assertEquals(Style.DIM, '\033[2m')
         self.assertEquals(Style.NORMAL, '\033[22m')
         self.assertEquals(Style.BRIGHT, '\033[1m')
+        self.assertEquals(Style.RESET_ALL, '\033[0m')
+        self.assertEquals(Style.UNDERLINED, '\033[4m')
+        self.assertEquals(Style.BLINK, '\033[5m')
+        self.assertEquals(Style.REVERSEVID, '\033[7m')


 if __name__ == '__main__':
diff -r 4ccdb5498413 colorama/tests/winterm_test.py
--- a/colorama/tests/winterm_test.py    Sun May 27 10:09:37 2012 +0100
+++ b/colorama/tests/winterm_test.py    Tue Dec 11 01:23:44 2012 +0100
@@ -91,6 +91,23 @@
         self.assertEquals(term._style, 22)
         self.assertEquals(term.set_console.called, True)

+    def testReverseVideo(self):
+        term = WinTerm()
+        term.set_console = Mock()
+        term._style = 0
+        term.fore(4)
+        term.back(5)
+        self.assertEquals(term._fore, 4)
+        self.assertEquals(term._back, 5)
+        term.style_reverse_vid()
+        self.assertEquals(term._fore, 5)
+        self.assertEquals(term._back, 4)
+        self.assertEquals(term._style, 0)
+        term.style_reverse_vid()
+        self.assertEquals(term._fore, 4)
+        self.assertEquals(term._back, 5)
+
+
     @patch('colorama.winterm.win32')
     def testSetConsole(self, mockWin32):
         mockAttr = Mock()
diff -r 4ccdb5498413 colorama/winterm.py
--- a/colorama/winterm.py   Sun May 27 10:09:37 2012 +0100
+++ b/colorama/winterm.py   Tue Dec 11 01:23:44 2012 +0100
@@ -58,6 +58,12 @@
         self._style = style
         self.set_console(on_stderr=on_stderr)

+    def style_reverse_vid(self, style=None, on_stderr=False):
+        # Reverse-video doesn't seem to work on windows, but we can simulate it:
+        # simply flip the current foreground and background colors.
+        self._fore, self._back = self._back, self._fore
+        self.set_console(on_stderr=on_stderr)
+
     def set_console(self, attrs=None, on_stderr=False):
         if attrs is None:
             attrs = self.get_attrs()

@urosjarc
Copy link

urosjarc commented Aug 6, 2015

I really want to ask why UNDERLINE is not implemented yet?

@wiggin15
Copy link
Collaborator

wiggin15 commented Aug 7, 2015

This patch isn't merged because Windows doesn't support these modes.

  • The console attribute COMMON_LVB_UNDERSCORE has no effect on Windows, and it doesn't look like there is a workaround for that.
  • The console attribute COMMON_LVB_REVERSE_VIDEO has no effect on Windows (although this patch implements a workaround for that)
  • There is no console attribute for BLINK on Windows, and the style BLINK doesn't have any effect on standard Unix terminals either.

@urosjarc
Copy link

urosjarc commented Aug 7, 2015

Hm... I suggest to add something like Fore.linux.UNDERLINE and Fore.win.BLINK, if there is something that is not supported on WIN, this doesn't mean that doesn't exist on UNIX. Wouldn't you agree?

@tartley
Copy link
Owner Author

tartley commented Aug 7, 2015

Colorama's purpose is to make Windows terminals behave like a UNIXy one. If you just want to emit ANSI codes to control your UNIXy terminal, I'd recommend using something like termcolor instead of Colorama.

@mxmerz
Copy link

mxmerz commented Nov 2, 2015

I would like to see support for ANSI style 7 (REVERSEVID in diff above) as well.

@luzpaz
Copy link

luzpaz commented Mar 11, 2016

+1 to please make exceptions for platforms that support underline

@MinchinWeb
Copy link

The 1511 update to Windows 10 now supports underline and reverse text.

reverse-text

@kapsh
Copy link

kapsh commented Aug 19, 2017

Hello,
I would like to use underlined style too.

@LitoMore
Copy link

Different results will be obtained in different terminal emulators.

FYI below,

  • italic (Not widely supported)
  • strikethrough (Not widely supported)
  • blue (On Windows the bright version is used since normal blue is illegible)

@angelof-exe
Copy link

In the end, these styles didn't come?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants