Re: [fpc-pascal] I'm working on automated Help Output for console apps

2020-11-20 Thread Graeme Geldenhuys via fpc-pascal
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

2020-11-20 Thread Tomas Hajny via fpc-pascal

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

2020-11-20 Thread Benito van der Zander via fpc-pascal

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

2020-11-20 Thread James Richters via fpc-pascal
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 t

Re: [fpc-pascal] I'm working on automated Help Output for console apps

2020-11-20 Thread Graeme Geldenhuys via fpc-pascal
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

2020-11-20 Thread Bart via fpc-pascal
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

2020-11-20 Thread Amir via fpc-pascal

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  -  fpc-pascal@lists.freepascal.

Re: [fpc-pascal] I'm working on automated Help Output for console apps

2020-11-20 Thread Sven Barth via fpc-pascal
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

2020-11-20 Thread Bart via fpc-pascal
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

2020-11-20 Thread Graeme Geldenhuys via fpc-pascal
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


[fpc-pascal] fpmmap problem 64 bit linux

2020-11-20 Thread Rainer Stratmann via fpc-pascal
A 32 bit freepascal program on a 32 bit Linux Debian system is working 
properly. It uses fpmmap for getting the adress of a kms framebuffer.

The same 32 bit program on a 64 bit Linux Debian system *** is not working.
When it comes to the fpmmap it gives an error:

Sys_EINVAL
One of the record fields Start, length or offset is invalid.

https://www.freepascal.org/docs-html/rtl/baseunix/fpmmap.html

I figured out that it likely can only be the offset value since start and 
length 
are always the same.

The offset value I got from a previous DRM function.

On the 32 bit System this offset value is $1000 (fits in 32 bit)
And on the 64 bit System this offset value is $1 (does not fit in 32 
bit).

Can it be possible that the fpmmap function strips the offset value to 32 bit?
Is there another way to call fpmmap more directly?
What does fpmmap exactly?
Where can I research?


***
dpkg --add-architecture i386
apt-get update
apt-get install libc6-i386


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] fpmmap problem 64 bit linux

2020-11-20 Thread Alexander Grotewohl via fpc-pascal
It would seem C handles this at compile time with a define.. mapping mmap to 
mmap64. Which would almost seem to imply you'd end up with a 32 bit binary that 
would only work on 64 bit systems. I'm not really sure how this would work for 
Pascal. You could start by looking in the file listed in the fpmmap docs you 
posted. My guess is the easiest answer is "distribute both 32 and 64 bit 
versions," but that doesn't help when you need to test the 32 bit one..

--
Alexander Grotewohl
https://dcclost.com

--
Alexander Grotewohl
https://dcclost.com

From: fpc-pascal  on behalf of Rainer 
Stratmann via fpc-pascal 
Sent: Friday, November 20, 2020 6:33:51 PM
To: fpc-pascal@lists.freepascal.org 
Cc: Rainer Stratmann 
Subject: [fpc-pascal] fpmmap problem 64 bit linux

A 32 bit freepascal program on a 32 bit Linux Debian system is working
properly. It uses fpmmap for getting the adress of a kms framebuffer.

The same 32 bit program on a 64 bit Linux Debian system *** is not working.
When it comes to the fpmmap it gives an error:

Sys_EINVAL
One of the record fields Start, length or offset is invalid.

https://www.freepascal.org/docs-html/rtl/baseunix/fpmmap.html

I figured out that it likely can only be the offset value since start and length
are always the same.

The offset value I got from a previous DRM function.

On the 32 bit System this offset value is $1000 (fits in 32 bit)
And on the 64 bit System this offset value is $1 (does not fit in 32
bit).

Can it be possible that the fpmmap function strips the offset value to 32 bit?
Is there another way to call fpmmap more directly?
What does fpmmap exactly?
Where can I research?


***
dpkg --add-architecture i386
apt-get update
apt-get install libc6-i386


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal