Opened 3 years ago
Closed 3 years ago
#29204 closed enhancement (fixed)
character art: avoid line breaks in elements of lists
Reported by:  Markus Wageringel  Owned by:  

Priority:  major  Milestone:  sage9.1 
Component:  misc  Keywords:  ascii_art, unicode_art 
Cc:  Merged in:  
Authors:  Markus Wageringel  Reviewers:  Vincent Delecroix 
Report Upstream:  N/A  Work issues:  
Branch:  7255829 (Commits, GitHub, GitLab)  Commit:  725582982f126b850c8beb041aa6ba29f41a4379 
Dependencies:  #29202  Stopgaps: 
Description
Motivated by #29203, this ticket changes the ASCII and unicode representation of containers such as lists, tuples, sets and dictionaries, so that line breaks inside the container elements are avoided, but line breaks between elements are preferred. For example, a list of lists:
Before:
sage: %display ascii_art 80 sage: [[1..5], [1..5], [1..25], [1..5], [1..15]] [ [ 1, 2, 3, 4, 5 ], [ 1, 2, 3, 4, 5 ], [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 ], [ 1, 2, 3, 4, 5 ], [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ] ]
After:
[ [ 1, 2, 3, 4, 5 ], [ 1, 2, 3, 4, 5 ], [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 ], [ 1, 2, 3, 4, 5 ], [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ] ]
This is implemented by changing the internal representation of the breakpoints of character art elements to keep track of the nesting of elements.
This ticket also deprecates get_breakpoints
as its output is now less useful due to the change of the internal representation of _breakpoints
, so it should only be used internally.
Change History (8)
comment:1 Changed 3 years ago by
Authors:  → Markus Wageringel 

Branch:  → u/ghmwageringel/29204 
Commit:  → b1f18b5177af0a9b34e17da3ccf98241e440e9ae 
Dependencies:  → #29202 
Keywords:  ascii_art unicode_art added 
Status:  new → needs_review 
comment:2 Changed 3 years ago by
Reviewers:  → Vincent Delecroix 

comment:3 Changed 3 years ago by
Status:  needs_review → positive_review 

comment:4 Changed 3 years ago by
Status:  positive_review → needs_work 

On python 2:
********************************************************************** File "src/sage/typeset/character_art_factory.py", line 376, in sage.typeset.character_art_factory.CharacterArtFactory.build_list Failed example: str(ascii_art([[1..5], [1..5], [1..25], [1..5], [1..15]])) Exception raised: Traceback (most recent call last): File "/var/lib/buildbot/slave/sage2_git/build/local/lib/python2.7/sitepackages/sage/doctest/forker.py", line 681, in _run self.compile_and_execute(example, compiler, test.globs) File "/var/lib/buildbot/slave/sage2_git/build/local/lib/python2.7/sitepackages/sage/doctest/forker.py", line 1123, in compile_and_execute exec(compiled, globs) File "<doctest sage.typeset.character_art_factory.CharacterArtFactory.build_list[6]>", line 1, in <module> str(ascii_art([(ellipsis_range(Integer(1),Ellipsis,Integer(5))), (ellipsis_range(Integer(1),Ellipsis,Integer(5))), (ellipsis_range(Integer(1),Ellipsis,Integer(25))), (ellipsis_range(Integer(1),Ellipsis,Integer(5))), (ellipsis_range(Integer(1),Ellipsis,Integer(15)))])) File "sage/structure/sage_object.pyx", line 194, in sage.structure.sage_object.SageObject.__repr__ (build/cythonized/sage/structure/sage_object.c:2436) result = reprfunc() File "/var/lib/buildbot/slave/sage2_git/build/local/lib/python2.7/sitepackages/sage/typeset/character_art.py", line 159, in _repr_ return self._split_repr_(hsize) File "/var/lib/buildbot/slave/sage2_git/build/local/lib/python2.7/sitepackages/sage/typeset/character_art.py", line 397, in _split_repr_ for bp in self._splitting_points(size): File "/var/lib/buildbot/slave/sage2_git/build/local/lib/python2.7/sitepackages/sage/typeset/character_art.py", line 334, in _splitting_points for bp_next in breakpoints: TypeError: instance has no next() method ********************************************************************** 1 item had failures: 1 of 8 in sage.typeset.character_art_factory.CharacterArtFactory.build_list [56 tests, 1 failure, 14.16 s]  sage t long src/sage/combinat/shuffle.py # 1 doctest failed sage t long src/sage/dynamics/cellular_automata/solitons.py # 1 doctest failed sage t long src/sage/groups/fqf_orthogonal.py # 92 doctests failed sage t long src/sage/groups/matrix_gps/isometries.py # 4 doctests failed sage t long src/sage/matrix/matrix0.pyx # 2 doctests failed sage t long src/sage/modules/fg_pid/fgp_module.py # 17 doctests failed sage t long src/sage/modules/free_quadratic_module_integer_symmetric.py # 75 doctests failed sage t long src/sage/modules/torsion_quadratic_module.py # 117 doctests failed sage t long src/sage/quadratic_forms/genera/genus.py # 7 doctests failed sage t long src/sage/repl/display/formatter.py # 1 doctest failed sage t long src/sage/repl/rich_output/backend_base.py # 8 doctests failed sage t long src/sage/repl/ipython_extension.py # 2 doctests failed sage t long src/sage/typeset/ascii_art.py # 1 doctest failed sage t long src/sage/typeset/character_art.py # 5 doctests failed sage t long src/sage/typeset/character_art_factory.py # 1 doctest failed 
comment:5 Changed 3 years ago by
Commit:  b1f18b5177af0a9b34e17da3ccf98241e440e9ae → 725582982f126b850c8beb041aa6ba29f41a4379 

Branch pushed to git repo; I updated commit sha1. New commits:
7255829  29204: fix iterator for python 2

comment:6 Changed 3 years ago by
Status:  needs_work → needs_review 

Sorry about that. This passes all tests with Python 2 now.
comment:7 Changed 3 years ago by
Status:  needs_review → positive_review 

comment:8 Changed 3 years ago by
Branch:  u/ghmwageringel/29204 → 725582982f126b850c8beb041aa6ba29f41a4379 

Resolution:  → fixed 
Status:  positive_review → closed 
New commits:
29204: avoid breaking character art of nested elements