Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

silvercircle

macrumors member
Original poster
Nov 18, 2010
61
7
What is the best approach to use two sets of colors for syntax highlighting in a text editor?
Dark mode require other colors compared to light mode.

When a user switches between dark and light mode, what is the best way to handle this?
Going over all the attributes seems overkill but I don't see another solution right now.
 
I think it will depend on the text editor.

Since you didn't identify the text editor, my comments will necessarily be generalized.

The primary feature I'd look for is named groups of attributes. Older versions of Xcode's editor had this feature. You could give the current set of font and color settings a name, and then reinstate them at any time by choosing the name from the popup menu. For example, I'd fiddle around with the colors for the attributes, then save them as "Dark Foobar", or "Dark Knigget", or whatever darkling name you wanted. With a named group of attributes, it should be much easier to activate manually, because it's just one choice. You could then also look into scripting that choice, maybe resorting to UI scripting as a last resort.

Another thing I'd look at is the scripting vocabulary of the text editor. If it exposes things like colors to AppleScript, then you can just write an AppleScript (or a bash script that runs the 'osascript' command) that tells the editor to set whatever colors you want.

If the text editor doesn't have named groups of attributes, or lacks scriptable color settings, then you'll probably end up needing to use UI Scripting. That could become quite complex very quickly, so it might not be worth doing.

One other possibility is to use the 'defaults' command in a Terminal window to see what the text editor stores in its defaults parameters. The color settings might be accessible that way, which would make them accessible to shell scripts.
 
I think it will depend on the text editor.

Since you didn't identify the text editor, my comments will necessarily be generalized.

...
Sorry, I missed your reply.
And I should have made it clear that is was for my own text editor, how to handle these things in Objective-C (or Swift).
Problem is that when you use a colored syntax, some colors will be terrible when dark mode is used with a color set that is fine for the standard mode.
But I think the only way to go is to use enumerateAtrtribute or similar and change the color.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.