tools: Added color to git_log output.

- Added a simple parser for termcodes to termstr.
- Added missing 'italic' conversion in termstr.
- Simplified termcode for 'normal'.
This commit is contained in:
Andrew Hamilton 2019-07-09 12:00:39 +10:00
parent ee064f00af
commit f6cb615c97
16 changed files with 178 additions and 100 deletions

View file

@ -1,2 +1,2 @@
(Bdef(B (Bhi(B():(B (B
(B (Bprint(B((B"hi"(B)(B
def hi(): 
 print("hi")

View file

@ -1,15 +1,15 @@
(Bsize:(B 12.0 B(B (12 bytes)(B
(Bpermissions:(B ?rwxr-xr-x(B (755)(B
size: 12.0 B (12 bytes)
permissions: ?rwxr-xr-x (755)
(Bmodified time:(B Sun Jan 31 23:14:05 2016(B (1454282045 secs)(B
(Bcreation time:(B Sun Jan 31 23:14:05 2016(B (1454282045 secs)(B
(Baccess time:(B Sun Jan 31 23:14:07 2016(B (1454282047 secs)(B
modified time: Sun Jan 31 23:14:05 2016 (1454282045 secs)
creation time: Sun Jan 31 23:14:05 2016 (1454282045 secs)
access time: Sun Jan 31 23:14:07 2016 (1454282047 secs)
(Bowner:(B foo(B (1111 uid)(B
(Bgroup:(B foo(B (1111 gid)(B
owner: foo (1111 uid)
group: foo (1111 gid)
(Bhardlinks:(B 2
(Bsymlink:(B no
hardlinks: 2
symlink: no
(Bmime type:(B text/x-python; charset=us-ascii
(Bfile type:(B Python script, ASCII text executable (B
mime type: text/x-python; charset=us-ascii
file type: Python script, ASCII text executable 

View file

@ -1,8 +1,8 @@
(B▀▀▀▀▀▀(B▀▀▀▀(B▀▀▀▀▀▀(B
(B▀▀▀(B▀(B▀▀(B▀▀▀▀(B▀▀(B▀(B▀▀▀(B
(B▀▀(B▀(B▀▀▀▀▀▀▀▀▀▀(B▀(B▀(B▀(B
(B▀(B▀▀▀▀▀▀▀▀▀▀▀▀▀▀(B▀(B
(B▀(B▀(B▀▀▀▀▀▀▀▀▀▀▀▀(B▀(B▀(B
(B▀(B▀(B▀(B▀▀▀▀▀▀▀▀▀▀(B▀(B▀(B▀(B
(B▀▀▀(B▀(B▀(B▀▀▀▀▀▀(B▀(B▀(B▀(B▀▀(B
(B▀▀▀▀▀(B▀(B▀(B▀▀▀▀(B▀▀▀▀▀(B
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀

View file

@ -1,8 +1,8 @@
(B▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀(B
(B▀▀▀▀(B▀(B▀▀▀▀▀▀(B▀▀(B▀▀▀(B
(B▀▀(B▀(B▀▀▀▀▀▀▀▀▀▀(B▀(B▀▀(B
(B▀▀(B▀▀▀▀▀▀▀▀▀▀▀▀(B▀(B▀(B
(B▀▀(B▀▀▀▀▀▀▀▀▀▀▀▀(B▀(B▀(B
(B▀▀(B▀(B▀▀▀▀▀▀▀▀▀▀▀(B▀▀(B
(B▀▀▀(B▀(B▀▀▀▀▀▀▀▀(B▀(B▀▀▀(B
(B▀▀▀▀▀▀▀(B▀▀(B▀▀▀▀▀▀▀(B
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀

View file

@ -1,8 +1,8 @@
(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀▀(B▀(B▀(B▀(B▀(B
(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀▀(B
(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B
(B▀(B▀(B▀(B▀▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B
(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B
(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀▀(B▀(B▀(B▀(B
(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B
(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B▀(B
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀

View file

@ -1,8 +1,8 @@
(B▀▀▀▀▀▀(B▀▀▀▀(B▀▀▀▀▀▀(B
(B▀▀▀(B▀(B▀▀(B▀▀▀▀(B▀▀(B▀(B▀▀▀(B
(B▀▀(B▀(B▀▀▀▀▀▀▀▀▀▀(B▀(B▀(B▀(B
(B▀(B▀▀▀▀▀▀▀▀▀▀▀▀▀▀(B▀(B
(B▀(B▀(B▀▀▀▀▀▀▀▀▀▀▀▀(B▀(B▀(B
(B▀(B▀(B▀(B▀▀▀▀▀▀▀▀▀▀(B▀(B▀(B▀(B
(B▀▀▀(B▀(B▀(B▀▀▀▀▀▀(B▀(B▀(B▀(B▀▀(B
(B▀▀▀▀▀(B▀(B▀(B▀▀▀▀(B▀▀▀▀▀(B
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀

View file

@ -1,8 +1,8 @@
(B▀▀▀▀▀▀(B▀▀▀▀(B▀▀▀▀▀▀(B
(B▀▀▀(B▀(B▀▀(B▀▀▀▀(B▀▀(B▀(B▀▀▀(B
(B▀▀(B▀(B▀▀▀▀▀▀▀▀▀▀(B▀(B▀(B▀(B
(B▀(B▀▀▀▀▀▀▀▀▀▀▀▀▀▀(B▀(B
(B▀(B▀(B▀▀▀▀▀▀▀▀▀▀▀▀(B▀(B▀(B
(B▀(B▀(B▀(B▀▀▀▀▀▀▀▀▀▀(B▀(B▀(B▀(B
(B▀▀▀(B▀(B▀(B▀▀▀▀▀▀(B▀(B▀(B▀(B▀▀(B
(B▀▀▀▀▀(B▀(B▀(B▀▀▀▀(B▀▀▀▀▀(B
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀

View file

@ -1,8 +1,8 @@
(B▀▀▀▀▀▀(B▀▀▀▀(B▀▀▀▀▀▀(B
(B▀▀▀(B▀(B▀▀(B▀▀▀▀(B▀▀(B▀(B▀▀▀(B
(B▀▀(B▀(B▀▀▀▀▀▀▀▀▀▀(B▀(B▀(B▀(B
(B▀(B▀▀▀▀▀▀▀▀▀▀▀▀▀▀(B▀(B
(B▀(B▀(B▀▀▀▀▀▀▀▀▀▀▀▀(B▀(B▀(B
(B▀(B▀(B▀(B▀▀▀▀▀▀▀▀▀▀(B▀(B▀(B▀(B
(B▀▀▀(B▀(B▀(B▀▀▀▀▀▀(B▀(B▀(B▀(B▀▀(B
(B▀▀▀▀▀(B▀(B▀(B▀▀▀▀(B▀▀▀▀▀(B
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀

View file

@ -1,8 +1,8 @@
(B▀▀▀▀▀▀(B▀▀▀▀(B▀▀▀▀▀▀(B
(B▀▀▀(B▀(B▀▀(B▀▀▀▀(B▀▀(B▀(B▀▀▀(B
(B▀▀(B▀(B▀▀▀▀▀▀▀▀▀▀(B▀(B▀(B▀(B
(B▀(B▀▀▀▀▀▀▀▀▀▀▀▀▀▀(B▀(B
(B▀(B▀(B▀▀▀▀▀▀▀▀▀▀▀▀(B▀(B▀(B
(B▀(B▀(B▀(B▀▀▀▀▀▀▀▀▀▀(B▀(B▀(B▀(B
(B▀▀▀(B▀(B▀(B▀▀▀▀▀▀(B▀(B▀(B▀(B▀▀(B
(B▀▀▀▀▀(B▀(B▀(B▀▀▀▀(B▀▀▀▀▀(B
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀

View file

@ -1,4 +1,4 @@
(B

(B> def hi():(B
(B> print("hi")(B
> def hi():
> print("hi")

View file

@ -1 +1 @@
(Bdef(B (Bhi(B():(B
def hi():

View file

@ -9,6 +9,7 @@ import unittest
os.environ["TERM"] = "xterm-256color"
import eris.terminal
from eris.termstr import TermStr, CharStyle
import eris.termstr as termstr
@ -55,7 +56,7 @@ class CharStyleTests(unittest.TestCase):
def test_code_for_term(self):
self.assertEqual(self.style.code_for_term(),
"\x1b(B\x1b[m\x1b[38;2;255;255;255m\x1b[48;2;0;0;0m")
"\x1b[m\x1b[38;2;255;255;255m\x1b[48;2;0;0;0m")
class TermStrTests(unittest.TestCase):
@ -122,6 +123,28 @@ class TermStrTests(unittest.TestCase):
self.assertEqual(foo_bold.rjust(0), foo_bold)
self.assertEqual(foo_bold.rjust(5), TermStr(" ") + foo_bold)
def test_from_term(self):
def test_round_trip(term_str):
self.assertEqual(TermStr.from_term(str(term_str)), term_str)
test_round_trip(TermStr("foo"))
test_round_trip(TermStr("foo").bold())
test_round_trip(TermStr("foo").underline())
test_round_trip(TermStr("foo").italic())
test_round_trip(termstr.TermStr("foo").fg_color(termstr.Color.red))
test_round_trip(termstr.TermStr("foo").fg_color(termstr.Color.red).\
bg_color(termstr.Color.green))
test_round_trip(termstr.TermStr("foo").fg_color(1))
test_round_trip(termstr.TermStr("foo").bg_color(10))
self.assertEqual(TermStr.from_term(eris.terminal.ESC + "[33mfoo"),
termstr.TermStr("foo").fg_color(3))
self.assertEqual(TermStr.from_term(eris.terminal.ESC + "[45mfoo"),
termstr.TermStr("foo").bg_color(5))
self.assertEqual(TermStr.from_term(eris.terminal.ESC + "[45mfoo" +
eris.terminal.ESC + "[mbar"),
termstr.TermStr("foo").bg_color(5) +
termstr.TermStr("bar"))
if __name__ == "__main__":
unittest.main()