• Welcome to PlanetSquires Forums.
 

Request: hide comments via color

Started by Bruce Huber, March 27, 2020, 08:40:27 PM

Previous topic - Next topic

Bruce Huber

Paul, I comment my code *heavily* so that I can remember what-I-did/why-I-did-it. But those heavy comments get in the way of reading the code quote often.

Any chance you could give me a command that would toggle, both, the comment foreground and background colors, from my chosen colors to the same color as the main background color and back again; thereby "hiding" the comments temporarily?

Does that sound like something that would be useful to anyone other than my greedy little self? [smile]

Thanks!
Bruce

Paul Squires

Hmmmm.... that's an interesting idea. I think that maybe it could be done via a UserTool. Invoke the tool via a hotkey, read the WinFBE ini file, and replace the relevant colors, save the ini. WinFBE will read the new ini. I need to check the source code to see if WinFBE does an ApplyProperties to the open documents when configuration file changes (I don't think that it does but that would be easy to add).

Let me give this a shot to see if I can make such a system work. I'll report back once I have something more definitive.
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Pierre Bellisle

I guess that you want the editor to be RO while in "no comment" mode?


Bruce Huber

Oh no, Pierre... I still want to be able to edit my code at that time. The hot-key would be a toggle, so easy to flip on/off if I need to see where any comments are. Plus, any comments on the current line would still show up because of the different coloring that takes place on the "current line" (in most of users' setups).

Pierre Bellisle

#4
I see, if the current line comment is visible then it make sense.
You could also make it pale so you view it but it doesn't grab attention.

SeaVipe

Perhaps there is a way to "Fold" just the comments of a Func/Sub?
Clive Richey

Bruce Huber

@Pierre... I've tried the "pale" option in the past, but it doesn't really work for me.

@SeaVipe... Folding sucks in Scintilla when attempting to use it on a non-block syntax like BASIC. It defaults to using the indent level - and that doesn't work at all in a lot of real world scenarios.

First, just try folding on any of your standard FreeBASIC code. Scintilla gets lost pretty easily there, even when your code is neat and tidy.

Then, add in some of the different types of comments, (', /'...'/, rem, anything after a _ line continuation), and see what you get.

And, heaven forbid you should use preprocessor #if...#endif, etc.... especially at different indent levels than the surrounded code.

Scintilla folding just sucks... [grin]

Pierre Bellisle

No problem,

Note that my post wasn't clear, I meant a pale comment
for the current line only and transparent for the rest.

This said, it's a matter of choice and the client is king. :-)

SeaVipe

I use a black background in the code editor. Comments are displayed in Light Grey, preprocessor in Signal Red and everything else is some bright, vibrant colour. For me, this combination of colours reduces eye strain as well as keeping the Comments fairly subdued. A small, crisp font like Dina 10 also helps.
Clive Richey

Paul Squires

It was a good exercise for me today to create the User Tool that toggles on/off the comment coloring. It certainly looks weird when you toggle off the comments :-)  I setup the User Tool to invoke via Ctrl+9. Each time it runs it will update the WinFBE config ini. WinFBE detects the new config file, reloads it, and then applies the new settings to all open documents. You just need to remember to re-enable comments prior to closing your main application otherwise when you restart, the comment colors will default to the off colors and you don't want that.

You will need to wait until I upload the next WinFBE version in order to try this out because I had to make a small addition to the main WinFBE message loop in order to re-apply the changed properties.
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

José Roca

Quote from: SeaVipe on March 28, 2020, 08:15:59 PM
I use a black background in the code editor. Comments are displayed in Light Grey, preprocessor in Signal Red and everything else is some bright, vibrant colour. For me, this combination of colours reduces eye strain as well as keeping the Comments fairly subdued. A small, crisp font like Dina 10 also helps.

I always have been unable to work with a black backgroung. Can it be because I live in a very sunny country?

Bruce Huber

Paul, maybe down the road you can throw an [initial comment colors] into the config and have those colors set only when the user sets them through the options dialog. Then, you could pull those values at startup and shove them into the normal [comment colors] as you go. That would bypass the "forgot* and "unscheduled-restart" issues. But many thanks for now!

José, I would get a headache from staring at a bright screen all day... I wear and hat and sunglasses when I go outside... but that would be silly to do when working at my computer! [BIG grin] (Of course, I don't think it's at all silly if you are actually sitting there with a hat and sunglasses on while you stare at your white, bright screen.) [BIG grin again]

And SeaVipe, it sounds like we are related... but my eyes are obviously much worse than yours.... I have my font set to Lucida Console TWELVE for a *MINIMUM*.... later at night, I jump it up to FOURTEEN (or 15 sometimes) so I can keep working. [smile]

Paul Squires

Quote from: José Roca on March 28, 2020, 10:39:10 PM
Quote from: SeaVipe on March 28, 2020, 08:15:59 PM
I use a black background in the code editor. Comments are displayed in Light Grey, preprocessor in Signal Red and everything else is some bright, vibrant colour. For me, this combination of colours reduces eye strain as well as keeping the Comments fairly subdued. A small, crisp font like Dina 10 also helps.

I always have been unable to work with a black backgroung. Can it be because I live in a very sunny country?

You know I am the same way. I have tried several times to switch to black themes in other editors when I had to write web applications. VSCode, Sublime Text and Atom... I always kept coming back to light backgrounds.
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Paul Squires

Quote from: Bruce Huber on March 29, 2020, 01:38:55 AM
Paul, maybe down the road you can throw an [initial comment colors] into the config and have those colors set only when the user sets them through the options dialog. Then, you could pull those values at startup and shove them into the normal [comment colors] as you go. That would bypass the "forgot* and "unscheduled-restart" issues. But many thanks for now!
I've been thinking about this and I think that maybe I'll allow passing parameters to the user tool. So when you set up the tool you can specify a default foreground and background color. That would simplify things greatly.

The "problem" I made for myself is the way that store colors in the WinFBE config file. I pack the colors into repeating groups within the THEME section tag. In addition to the foreground and background color, I also have to store bold, italic, underline. Maybe down the road I will revise how colors are stored.
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Paul Squires

Yes, changing to the command line parameter approach was much better and reliable.

Here is the code as it stands right now. You'll need to wait until the next WinFBE update comes out before it will actually work.


'    HideComments - WinFBE User Tool
'    Copyright (C) 2020 Paul Squires, PlanetSquires Software
'
'    This program is free software: you can redistribute it and/or modify
'    it under the terms of the GNU General Public License as published by
'    the Free Software Foundation, either version 3 of the License, or
'    (at your option) any later version.
'
'    This program is distributed in the hope that it will be useful,
'    but WITHOUT any WARRANTY; without even the implied warranty of
'    MERCHANTABILITY or FITNESS for A PARTICULAR PURPOSE.  See the
'    GNU General Public License for more details.

' Simple WinFBE User Tool that acts as a toggle that changes the internal
' color values for comment colors. By setting the comment foreground color
' to match that of the background color, the comments in the documents
' would essentially render invisible although the text itself does not
' disappear.


' SYNTAX:
'            HideComments <Foreground> <Background>
'
' example:   HideComments 32768 16777215
'


#Define UNICODE

#include once "Afx\AfxWin.inc"
#include once "Afx\AfxStr.inc"
#include once "Afx\CIniFile.inc"

' Colors
enum colors
   ID_THEME  = 1
   CLR_CARET           
   CLR_COMMENTS
   CLR_HIGHLIGHTED     
   CLR_KEYWORD         
   CLR_FOLDMARGIN
   CLR_FOLDSYMBOL     
   CLR_LINENUMBERS     
   CLR_OPERATORS       
   CLR_INDENTGUIDES   
   CLR_PREPROCESSOR   
   CLR_SELECTION       
   CLR_STRINGS         
   CLR_TEXT           
   CLR_WINDOW
end enum

type APPDATA
   wszFilename     as CWSTR
   wszThemeSection as CWSTR
   wszThemeData    as CWSTR
   wszDefaultFG    as CWSTR
   wszDefaultBG    as CWSTR
end type

dim shared g as APPDATA


''
''
function GetParameters() as Long
   ' Get the commandline parameters for the default comment FB and BG colors.
   g.wszDefaultFG = AfxCommand(1)
   g.wszDefaultBG = AfxCommand(2)
   if g.wszDefaultFG = "" then g.wszDefaultFG = "32768"     ' green
   if g.wszDefaultBG = "" then g.wszDefaultBG = "16777215"  ' white
   function = 0
end function


''
''
function LoadThemeData() as long

   ' Retrieve the current Theme from the config file
   dim as CWSTR wszThemeGUID, _      ' {BB8DFE1F-CF2C-4357-BDCE-E1843CDDD608}
                wszThemeSection, _   ' THEME_00, THEME_01, etc
                wszThemeData         ' The actual data of the theme

   dim cIni as CIniFile = g.wszFilename

   wszThemeGUID = cIni.GetString( "Themes", "SelectedTheme" )
   for i as long = 0 to 99
      wszThemeSection = "THEME_" & right( "00" & i, 2 )
      wszThemeData = cIni.GetString( "Themes", wszThemeSection )
      if left(wszThemeData, len(wszThemeGUID)) = wszThemeGUID then
         g.wszThemeSection = wszThemeSection
         g.wszThemeData = wszThemeData
         exit function
      end if   
   next
   function = 0
end function


''
''
function SetThemeColor() as long

   ' The structure of the THEME is:
   ' Theme data is saved in parse blocks separated by a "|" pipe symbol. Within
   ' each of of those parsed pipe blocks the data is further divided and separated
   ' by "," comma blocks. The first pipe block is always the theme id and description.
   ' From pipe block 2 to parsecount, the pipe blocks are the actual colors. Each
   ' color block is comma separated and composed of foreground color, background color,
   ' and 0/1 indicating if to use default background color.

   dim as CWSTR wszComment, wszSavedTheme, wszNewTheme
   dim as CWSTR wszPiece( 1 to 6 )

   ' Get the FG/BG colors from the Theme data currently in the WinFBE config ini.
   wszComment = AfxStrParse( g.wszThemeData, colors.CLR_COMMENTS, "|" )
   
   ' The first comma separated value is the foreground color. The second
   ' value is the background color. The remaining values are not needed.
   for i as long = 1 to 6
      wszPiece(i) = AfxStrParse( wszComment, i, "," )
   next


   ' If the FG and BG colors are the same then the comment color must have
   ' been turned off. If they differ then comments must be turned on.
   if wszPiece(1) = wszPiece(2) then
      ' Reset the colors to the default as specified by the user
      wszPiece(1) = g.wszDefaultFG
      wszPiece(2) = g.wszDefaultBG
      ? "Comments have been turned ON"
   else   
      ' Change the color so that FG matches the BG
      wszPiece(1) = wszPiece(2)
      ? "Comments have been turned OFF"
   end if
   
     
   ' Reassemble the comment data
   wszComment = ""
   for i as long = 1 to 6
      wszComment = wszComment & wszPiece(i) & ","
   next
   wszComment = rtrim(wszComment, ",")
   
   
   ' Reassemble the theme data
   wszNewTheme = ""
   for i as long = 1 to colors.CLR_WINDOW
      if i = colors.CLR_COMMENTS then
         wszNewTheme = wszNewTheme & wszComment & "|"
      else   
         wszNewTheme = wszNewTheme & AfxStrParse( g.wszThemeData, i, "|" ) & "|"
      end if
   next
   g.wszThemeData = rtrim( wszNewTheme, "|" )

   function = 0
end function


''
''
function SaveThemeData() as Long
   ' Save the new theme data to the WinFBE configuration file.
   dim cIni as CIniFile = g.wszFilename
   cIni.WriteValue( "Themes", wstr(g.wszThemeSection), wstr(g.wszThemeData) )
   function = 0
end function



' ========================================================================================
' Main Program entry point
' ========================================================================================

' Set the WinFBE configuration filename
g.wszFilename = "..\Settings\WinFBE.ini"

if AfxFileExists( g.wszFilename ) then
   GetParameters()    ' get commandline comment FG and BG colors
   LoadThemeData()    ' get current WinFBE theme data
   SetThemeColor()    ' this will toggle comments on/off
   SaveThemeData()    ' save theme data back to WinFBE ini
else   
   ? "WinFBE configuration file not found"
end if


Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer