Re: [fpc-pascal] I'm working on automated Help Output for console apps
On 23/11/2020 1:26 pm, James Richters via fpc-pascal wrote: > Any Ideas on how this, or some of it could be accomplished? Or is it all > completely impossible? If the object that you are trying to output has RTTI enabled, then maybe you could query everything you need via TypeInfo (or the new reflection or New RTTI of FPC and Delhi - can't remember the exact name). Maybe looking at tiOPF's tiLog unit could also give some ideas on how to write those - but the tiLog unit definitely doesn't do exactly what you want. Saying that I very often used tiOPF's tiLog support (threaded output to console, file or external window) even in not tiOPF projecst, simply because it was so convenient. Coming back to the first point, tiOPF's tiRTTI unit might also be of use to you. https://github.com/graemeg/tiopf/blob/tiopf2/Core/tiLog.pas Either way, seem there will be some work required to get what you want. ;-) Regards, Graeme -- fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ My public PGP key: http://tinyurl.com/graeme-pgp ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] I'm working on automated Help Output for console apps
I was working on one of my projects and doing some tedious output to the console and now that I have this idea in my head that this could be more automated, I thought that this task should be automated as well.. not sure if it's something that belongs in Graeme's Help Output package, but it's on a similar idea. It seems that I always want to do a writeln of a variable to see that it's doing what I expect.. So sometimes I just stink in a writeln like this: Writeln(ThingA); If I want more than one thing, I can just do: Writeln(ThingA,ThingB); But of course you can't always tell where ThingA stops and ThingB Starts, so I have to at least put in a space: Writeln(ThingA,' ',ThingB); But then I sometimes have such a long list of these, I need to say what they are: Writeln('ThingA: ',ThingA,' ThingB: ',ThingB); And if the variables are some kind of floating point, I need to do something so I don't have to look at un-readable expanded notation... Which I absolutely ALWAYS forget until I run it once.. so I have to go back and put in my standard floating point formatting: Writeln('ThingA: ',ThingA:0:20,' ThingB: ',ThingB:0:20); And sometimes I want to make it a different color so I can spot it in a huge list of output so I will do something like: Textcolor(14); Write('ThingA: '); Textcolor(10); Write(ThingA:0:20); Textcolor(14); Write('ThingB: '); Textcolor(10); Writeln(ThingB:0:20); Then when I'm doing I comment it all out so if I want it again someday, I don't have to type it all: //Textcolor(14); //Write('ThingA: '); //Textcolor(10); //Write(ThingA:0:20); //Textcolor(14); //Write('ThingB: '); //Textcolor(10); //Writeln(ThingB:0:20); So What I would like is a procedure that simplifies all this... but I don't know how to implement it. There are several things I don't have a clue how to do, or if they are even possible. First of all, can I make a procedure with maybe something like a dynamic array of variables of any random types?? So it works like Writeln... With Writeln I can mix variable types and have as many as I want. Next.. can I have it output the name of the variable and it's contents somehow? I would like to end up with a procedure that does all the formatting, so if I give it: ShowMyVariables(Control,ThingA,ThingB); I get something like If Control Then Begin Textcolor(14); Write('ThingA: '); Textcolor(10); Write(ThingA:0:20); Textcolor(14); Write('ThingB: '); Textcolor(10); Writeln(ThingB:0:20); End; I would need to somehow figure out the variable type to see if it's floating point. Any Ideas on how this, or some of it could be accomplished? Or is it all completely impossible? James ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] I'm working on automated Help Output for console apps
On 20/11/2020 6:51 pm, Bart via fpc-pascal wrote: > I know, and there he can see how this capability is detected, hence my > reference to the compiler. Thanks, that's good to know. I'll definitely give it a try too. Regards, Graeme ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] I'm working on automated Help Output for console apps
On Fri, Nov 20, 2020 at 7:21 PM Sven Barth via fpc-pascal wrote: >> You know that fpc trunk now supports coloured output of the compiler >> (messages)? > > > Only on *nix and those versions of Windows 10 that support VT100 codes. > I know, and there he can see how this capability is detected, hence my reference to the compiler. -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] I'm working on automated Help Output for console apps
Bart via fpc-pascal schrieb am Fr., 20. Nov. 2020, 19:11: > On Fri, Nov 20, 2020 at 4:38 PM Graeme Geldenhuys via fpc-pascal > wrote: > > > We often have color output and > > full Unicode support - so we can output color and emojis to highlight > certain success > > or error states in the output. It would be nice to incorporate that into > command > > line help output too, but I'll have to test how well FPC supports that, > and how > > cross-platform it is. > > You know that fpc trunk now supports coloured output of the compiler > (messages)? > Only on *nix and those versions of Windows 10 that support VT100 codes. Regards, Sven > ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] I'm working on automated Help Output for console apps
Hi, I also have a similar library for that purpose: https://github.com/AmirAavani/my-units/blob/master/General-Purpose-Units/ParameterManagerUnit.pp This library expects "ValidArguments.inc" file whose content is like the following: ValidArgumentsInfo : array of AnsiString = ('--InputFile:AnsiString', '--Debug:Boolean'); ValidArgumentsValues : array of AnsiString = ('', 'True'); The second array, ValidArgumentsValue (which should be renamed to DefaultValues) set the default values, if none provided. Amir On 11/20/20 2:38 AM, Benito van der Zander via fpc-pascal wrote: Hi, I also made such a thing: var optionsreader: TCommandLineReader; begin optionsreader := TCommandLineReader.create; optionsreader.declareFile('file', 'The file to be processed'); optionsreader.addAbbreviation('f'); optionsreader.declareFlag('help', ''); optionsreader.addAbbreviation('h'); optionsreader.declareFlag('version', 'Print the version of the application'); optionsreader.addAbbreviation('v'); if optionsreader.existsProperty('help') then writeln(optionsreader.availableOptions); end. Output: --file= or -f The file to be processed --help or -h --version or -v Print the version of the application You can download it at http://www.benibela.de/sources_en.html#rcmdline Benito On 20.11.20 01:33, Graeme Geldenhuys via fpc-pascal wrote: Hi, I'm working on a automated help output writer(s) for console apps. Thus no more tedious and ugly output when you do: myapp -h My aims: * I write a lot of console apps, so this would be very useful to me. * Ability to swap out the help formatter. It's interface based, so custom implementations can easily be created. * Auto align help options and descriptions - the most annoying thing to do manually. ;-) * Ability to define console width in which to format and wrap the help output, but has a default value. * The idea is loosely base on the Java version found in Apache Commons. When it's done I'll obviously shared it as open source somewhere. With that said, below is how I currently use it. It uses the Builder design pattern so gives it the Chain Invocations syntax. I know it's not something often seen in Pascal programs, but it makes it very easy to read and easy to use/type, especially with code completion editors like Lazarus IDE. For those console programmers out there... Is there anything in console help output that you like or wish you had. That way I could possibly add it and make this even more useful to a wider audience. I'm still working on AppName, Version and Usage output. Example code: == var optionlist: TOptions; helpFormatter: IHelpFormatter; header: string; footer: string; begin optionlist := TOptions.Create; optionlist.add(TOption.Builder .isRequired .withDescription('The file to be processed') .hasArg .withArgName('file') .withLongOpt('file') .build('f'));// build() always takes the mandatory short option. optionlist.add(TOption.Builder .withLongOpt('help') .withArgName('test') // this is ignored because .hasArg was not specified .build('h')); optionlist.add(TOption.Builder .withDescription('Print the version of the application') .withLongOpt('version') .build('v')); header := 'Do something useful with an input file' + LineEnding; footer := LineEnding + 'Please report issues athttp://example.com/issues'; helpFormatter := TBasicHelpFormatter.Create(); // sample outputs with increasing verbosity writeln('=== (1)'); helpFormatter.printHelp(optionlist); writeln('=== (2)'); helpFormatter.printHelp('DocView v1.0', optionlist); writeln('=== (3)'); helpFormatter.printHelp('DocView v1.0', header, optionlist, footer); writeln('== the end ='); optionlist.Free; end; == And here is the example output for the 3 options so far: === (1) * -f,--file The file to be processed -h,--help -v,--versionPrint the version of the application * indicates required parameters === (2) DocView v1.0 * -f,--file The file to be processed -h,--help -v,--versionPrint the version of the application * indicates required parameters === (3) DocView v1.0 Do something useful with an input file * -f,--file The file to be processed -h,--help -v,--versionPrint the version of the application * indicates required parameters Please report issues athttp://example.com/issues == the end = Regards, Graeme ___ fpc-pascal maillist -
Re: [fpc-pascal] I'm working on automated Help Output for console apps
On Fri, Nov 20, 2020 at 4:38 PM Graeme Geldenhuys via fpc-pascal wrote: > We often have color output and > full Unicode support - so we can output color and emojis to highlight certain > success > or error states in the output. It would be nice to incorporate that into > command > line help output too, but I'll have to test how well FPC supports that, and > how > cross-platform it is. You know that fpc trunk now supports coloured output of the compiler (messages)? -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] I'm working on automated Help Output for console apps
On 20/11/2020 1:29 pm, James Richters via fpc-pascal wrote: > so as you can see, my #1 item in my wish list is the ability to assign colors, Some good examples there. :-) I wouldn't want to guess how long it takes to create those boxed versions. Wow! At work, our automated CI pipelines run on Linux. We often have color output and full Unicode support - so we can output color and emojis to highlight certain success or error states in the output. It would be nice to incorporate that into command line help output too, but I'll have to test how well FPC supports that, and how cross-platform it is. Regards, Graeme -- fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ My public PGP key: http://tinyurl.com/graeme-pgp ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] I'm working on automated Help Output for console apps
That sounds like a great idea!! Yes I know how tedious it is.Here are some things I like to do. I always use color on my console app text… Yes it makes it more tedious because I have to have a whole bunch of textcolor() commands, but it makes it more readable and useful. I also like to center justify the list, so there is a clear division of commands on the left of the justification and definitions on the right. Here is an example: https://drive.google.com/file/d/1cyEqPUh-CkGYwP8VHXnKPtYwYpH5_ZRY/view?usp=sharing I also like to use box characters around my help boxes.. and of course in a way that makes the task even more tedious... I am only happy if the box has an exactly one character space between the box and the widest entry... and again using color so the box and the contents of the box are all different colors like this: https://drive.google.com/file/d/1cD5r3tIJWdFCQVwIFpKvtQ5LyD6uEnWL/view?usp=sharing Yes I know my formatting is off… if it wasn’t so tedious I would fix it :) I skip the box characters a lot of times because they are so tedious, but I would prefer them… if only there was some automated way to generate a nice clean help menu with a nice even box around it with exactly one space between the box and the widest entry….. For the title, I rename the window title with SetConsoleTitle() I use colors in the version. Here is an example of both of these: https://drive.google.com/file/d/1c5oHb6S2MO3x-cMNMwd2U9GQJCqGnTYt/view?usp=sharing so as you can see, my #1 item in my wish list is the ability to assign colors, but I don’t know if that’s cross platform.. Can Linux even change colors in the console window? Almost all my programs are on Windows 10. I also don’t know if SetConsoleTitle() can be done cross platform, that might be a windows function as well. James -Original Message- From: fpc-pascal On Behalf Of Graeme Geldenhuys via fpc-pascal Sent: Thursday, November 19, 2020 7:33 PM To: FPC-Pascal users discussions Cc: Graeme Geldenhuys Subject: [fpc-pascal] I'm working on automated Help Output for console apps Hi, I'm working on a automated help output writer(s) for console apps. Thus no more tedious and ugly output when you do: myapp -h My aims: * I write a lot of console apps, so this would be very useful to me. * Ability to swap out the help formatter. It's interface based, so custom implementations can easily be created. * Auto align help options and descriptions - the most annoying thing to do manually. ;-) * Ability to define console width in which to format and wrap the help output, but has a default value. * The idea is loosely base on the Java version found in Apache Commons. When it's done I'll obviously shared it as open source somewhere. With that said, below is how I currently use it. It uses the Builder design pattern so gives it the Chain Invocations syntax. I know it's not something often seen in Pascal programs, but it makes it very easy to read and easy to use/type, especially with code completion editors like Lazarus IDE. For those console programmers out there... Is there anything in console help output that you like or wish you had. That way I could possibly add it and make this even more useful to a wider audience. I'm still working on AppName, Version and Usage output. Example code: == var optionlist: TOptions; helpFormatter: IHelpFormatter; header: string; footer: string; begin optionlist := TOptions.Create; optionlist.add(TOption.Builder .isRequired .withDescription('The file to be processed') .hasArg .withArgName('file') .withLongOpt('file') .build('f'));// build() always takes the mandatory short option. optionlist.add(TOption.Builder .withLongOpt('help') .withArgName('test') // this is ignored because .hasArg was not specified .build('h')); optionlist.add(TOption.Builder .withDescription('Print the version of the application') .withLongOpt('version') .build('v')); header := 'Do something useful with an input file' + LineEnding; footer := LineEnding + 'Please report issues at http://example.com/issues'; helpFormatter := TBasicHelpFormatter.Create(); // sample outputs with increasing verbosity writeln('=== (1)'); helpFormatter.printHelp(optionlist); writeln('=== (2)'); helpFormatter.printHelp('DocView v1.0', optionlist); writeln('=== (3)'); helpFormatter.printHelp('DocView v1.0', header, optionlist, footer); writeln('== the end ='); optionlist.Free; end; == And here is the example output for the 3 options so far: === (1) * -f,--file The file to be processed -h,--help -v,--versionPrint the version of
Re: [fpc-pascal] I'm working on automated Help Output for console apps
Hi, I also made such a thing: var optionsreader: TCommandLineReader; begin optionsreader := TCommandLineReader.create; optionsreader.declareFile('file', 'The file to be processed'); optionsreader.addAbbreviation('f'); optionsreader.declareFlag('help', ''); optionsreader.addAbbreviation('h'); optionsreader.declareFlag('version', 'Print the version of the application'); optionsreader.addAbbreviation('v'); if optionsreader.existsProperty('help') then writeln(optionsreader.availableOptions); end. Output: --file= or -f The file to be processed --help or -h --version or -v Print the version of the application You can download it at http://www.benibela.de/sources_en.html#rcmdline Benito On 20.11.20 01:33, Graeme Geldenhuys via fpc-pascal wrote: Hi, I'm working on a automated help output writer(s) for console apps. Thus no more tedious and ugly output when you do: myapp -h My aims: * I write a lot of console apps, so this would be very useful to me. * Ability to swap out the help formatter. It's interface based, so custom implementations can easily be created. * Auto align help options and descriptions - the most annoying thing to do manually. ;-) * Ability to define console width in which to format and wrap the help output, but has a default value. * The idea is loosely base on the Java version found in Apache Commons. When it's done I'll obviously shared it as open source somewhere. With that said, below is how I currently use it. It uses the Builder design pattern so gives it the Chain Invocations syntax. I know it's not something often seen in Pascal programs, but it makes it very easy to read and easy to use/type, especially with code completion editors like Lazarus IDE. For those console programmers out there... Is there anything in console help output that you like or wish you had. That way I could possibly add it and make this even more useful to a wider audience. I'm still working on AppName, Version and Usage output. Example code: == var optionlist: TOptions; helpFormatter: IHelpFormatter; header: string; footer: string; begin optionlist := TOptions.Create; optionlist.add(TOption.Builder .isRequired .withDescription('The file to be processed') .hasArg .withArgName('file') .withLongOpt('file') .build('f'));// build() always takes the mandatory short option. optionlist.add(TOption.Builder .withLongOpt('help') .withArgName('test') // this is ignored because .hasArg was not specified .build('h')); optionlist.add(TOption.Builder .withDescription('Print the version of the application') .withLongOpt('version') .build('v')); header := 'Do something useful with an input file' + LineEnding; footer := LineEnding + 'Please report issues at http://example.com/issues'; helpFormatter := TBasicHelpFormatter.Create(); // sample outputs with increasing verbosity writeln('=== (1)'); helpFormatter.printHelp(optionlist); writeln('=== (2)'); helpFormatter.printHelp('DocView v1.0', optionlist); writeln('=== (3)'); helpFormatter.printHelp('DocView v1.0', header, optionlist, footer); writeln('== the end ='); optionlist.Free; end; == And here is the example output for the 3 options so far: === (1) * -f,--file The file to be processed -h,--help -v,--versionPrint the version of the application * indicates required parameters === (2) DocView v1.0 * -f,--file The file to be processed -h,--help -v,--versionPrint the version of the application * indicates required parameters === (3) DocView v1.0 Do something useful with an input file * -f,--file The file to be processed -h,--help -v,--versionPrint the version of the application * indicates required parameters Please report issues at http://example.com/issues == the end = Regards, Graeme ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] I'm working on automated Help Output for console apps
On 2020-11-20 09:32, Graeme Geldenhuys via fpc-pascal wrote: On 20/11/2020 7:04 am, Sven Barth via fpc-pascal wrote: a way to convert the option list to TConsoleApplication's argument handling so that one doesn't have to declare that twice. Oh, I really like that idea. I'll make sure to include both of those mentioned. Just a comment - I'm not sure how much general the "mandatory" part is. More complex console programs often have "commands" and those have different requirements for additional options. As an example, remember options for common archivers (rar, arj, ...), command-line version control programs (cvs, svn, ...), etc. Tomas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] I'm working on automated Help Output for console apps
On 20/11/2020 7:04 am, Sven Barth via fpc-pascal wrote: > a way to convert the > option list to TConsoleApplication's argument handling so that one doesn't > have to declare that twice. Oh, I really like that idea. I'll make sure to include both of those mentioned. Regards, Graeme -- fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ My public PGP key: http://tinyurl.com/graeme-pgp ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] I'm working on automated Help Output for console apps
On Fri, 20 Nov 2020, Sven Barth via fpc-pascal wrote: Graeme Geldenhuys via fpc-pascal schrieb am Fr., 20. Nov. 2020, 01:33: For those console programmers out there... Is there anything in console help output that you like or wish you had. That way I could possibly add it and make this even more useful to a wider audience. Two things come to mind. The first I don't know whether you have that on your list already: the ability to change the prefixes ('-', '--') and the long argument separator ('='). Of course not specific to a single argument, but for all. The second part is less output specific, but more DRY: a way to convert the option list to TConsoleApplication's argument handling so that one doesn't have to declare that twice. Basically that should be a string for the short options abc:e:f:g:: and an array of strings ['alert','bonus','config:','export:','file:','generate::'] where : means value required and :: means optional value. Michael. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] I'm working on automated Help Output for console apps
Graeme Geldenhuys via fpc-pascal schrieb am Fr., 20. Nov. 2020, 01:33: > For those console programmers out there... Is there anything in console > help > output that you like or wish you had. That way I could possibly add it and > make this even more useful to a wider audience. > Two things come to mind. The first I don't know whether you have that on your list already: the ability to change the prefixes ('-', '--') and the long argument separator ('='). Of course not specific to a single argument, but for all. The second part is less output specific, but more DRY: a way to convert the option list to TConsoleApplication's argument handling so that one doesn't have to declare that twice. Regards, Sven ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal