0
$\begingroup$

Minimal example code:

cols = ToExpression @ ReadString @ "!tput cols";(*valid for linux && macos*)
badline = StringRepeat["-",cols]; 
goodline = StringRepeat["-",cols-1]; 
redline = StringJoin["\033[31m",goodline,"\033[0m"];
Print @ goodline;
Print @ badline;
Print @ redline;

If you run this code in any other way than in the interactive REPL, all lines print as one line, but within the REPL, the last two lines get split. Not sure why 'badline' gets split. 'redline' gets split because the ANSI codes get counted in the string length, so the interface mistakes it as going over the available columns.

Changing option FormatType of \$Output to any form given by \$OutputForms does not work.

How to prevent the unnecessary line splitting?

$\endgroup$
2
  • $\begingroup$ I do not use the script, but try SetOptions[$Output, PageWidth -> Infinity] and see if it makes any difference. You could also try SetOptions[EvaluationNotebook[], LineBreakWithin -> False] that I saw which might make difference.? $\endgroup$ Commented Oct 31, 2024 at 0:28
  • $\begingroup$ First suggestion did not change anything (both PageWidth and TotalWidth set to Infinity). Second suggestion returns $Failed, because I'm in the interactive REPL without a front end. $\endgroup$ Commented Oct 31, 2024 at 1:02

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.