Sublime Forum

Word wrap in console

#1

In ST 4107, word wrap is enabled by default in the console.
Is there a way to disable it by default, avoiding to disable it each time?

0 Likes

#2

I assume by console you mean the build output? In that case you can use "word_wrap": false in the build system to turn it off.

0 Likes

#3

Unfortunately not: I mean the console (View > Show Console).

0 Likes

#4

If you want to do it for the console input, the you need to create a file by the name of Console Input Widget.sublime-settings and set word_wrap to false there (It’s anyways by default not enabled there).

As far as I know, console output cannot be configured to use word_wrap or to do anything much really (It looks like word wrapped by default)

0 Likes

#5

It’s possible to turn word wrap off in the console output, but as far as I’m aware that is purely a manual action because there’s no way to safely and programmatically determine what the view is that underlies the output. Thus it’s only possible with manual intervention.

0 Likes

#6

Good point. Never knew I could focus the console output and turn word wrap off. But yes, console output cant be determined from even view.element(). But I’d imagine if one manually focuses the console output, a key binding could turn word wrap off. So, not so much painful if one really wants it.

0 Likes

#7

It appears that it is no longer possible to toggle word wrap off in the console output; that option is greyed out in the “View” menu. Likewise, trying to alter the view settings programmatically has no effect:
sublime.active_window().get_output_panel(‘console’).settings().get(‘word_wrap’)

This returns “False” for me, even though it is clearly enabled. Trying set the setting does nothing.

Word wrap makes it very hard for me to read the console output while debugging a plugin which uses the standard Python logger, since about half of the line is taken by the logger’s header (date, log level, logger name), so lines are almost always wrapped, making it impossible to understand things at a glance.

The workaround I currently use is to manually copy the console content (Ctrl-C) and paste it into a blank view (Ctrl-V) with word wrap off. This is obviously a bit tedious… I haven’t found a way to do this programmatically, since there doesn’t seem to be any API to access the console content. All of the plugins that claim to redirect the console output to a file (SublimeLog and Logging Control) haven’t been updated in 8 years, and are not working (at least not in Sublime Text 4).

How do people manage this?

(edit: I have found a better workaround, which is to manually set up a file handler for my plugin’s loggers; then the log statements are sent to a file and I don’t have to deal with the limitations of Sublime’s console. The console was more convenient though, so I’m still interested in solving the original problem)

0 Likes

#8

That setting doesn’t work because get_output_panel('console') doesn’t actually get you the view that relates to the Console; it’s just a normal ouput panel named console. After you do that, you’ll notice that the panel chooser now has an entry named Output: Console that you can pick.

This is also visible by asking the API what kind of view you’ve got; for example:

>>> window.get_output_panel("console").element()
'output:output'

view.element() gives you a representation of what the view represents; output:output is “A general output panel.”. The docs also mention (emphasis mine):

The console output, indexer status output and license input controls are not accessible via the API.

While the menu entry for altering the setting in the console used to work, it no longer does. I suspect that this was done on purpose to stop all programattic access to the console so there may not be a direct way to pull that off.

To answer your other question about how people manage this, personally I don’t use the Python logger to sent plugin output anywhere because it seems too heavyweight (the info in the header does not seem useful to me for spontaneous plugin output).

In most cases I use my own log function similar to the one linked below, which prepends the package name to the output it generates and also allows me to send messages to the status bar or invoke dialogs (in all cases the log gets sent to the console for historical purposes).

The version linked below also shows a secondary way to pull this off; by creating your own log output panel and sending data out to it yourself. In the case of this example, it requires you to specify panel=True in the log call, but you could also just always send output there.

As seen in the code snippet, you’re in full control of the settings when you do that, and you can even use your own custom syntax (so for example you could color highlight your logs).

0 Likes