-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for markdown output in help messages #29
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
with CLIC.TTY; | ||
with CLIC.Markdown; | ||
|
||
package body CLIC.Formatter is | ||
|
||
Markdown_Enabled : Boolean := False; | ||
|
||
procedure Enable_Markdown is | ||
begin | ||
Markdown_Enabled := True; | ||
end Enable_Markdown; | ||
|
||
procedure Force_Disable_TTY renames TTY.Force_Disable_TTY; | ||
procedure Enable_Color (Force : Boolean := False) | ||
renames TTY.Enable_Color; | ||
|
||
function Chapter (Str : String) return String is | ||
(if Markdown_Enabled | ||
then Markdown.Chapter (Str) | ||
else TTY.Bold (Str)); | ||
|
||
|
||
function Description (Str : String) return String is | ||
(if Markdown_Enabled | ||
then Markdown.Code (Str) | ||
else TTY.Description (Str)); | ||
|
||
function Version (Str : String) return String is | ||
(if Markdown_Enabled | ||
then Markdown.Italic (Str) | ||
else TTY.Version (Str)); | ||
|
||
function Underline (Str : String) return String is | ||
(if Markdown_Enabled | ||
then Markdown.Bold (Str) | ||
else TTY.Underline (Str)); | ||
|
||
function Emph (Str : String) return String is | ||
(if Markdown_Enabled | ||
then Markdown.Code (Str) | ||
else TTY.Emph (Str)); | ||
|
||
|
||
end CLIC.Formatter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package CLIC.Formatter | ||
with Preelaborate | ||
is | ||
|
||
-- Provides markdown or TTY formatting for displaying help pages. | ||
|
||
procedure Force_Disable_TTY; | ||
|
||
procedure Enable_Markdown; | ||
-- Enables markdown output of formatting functions. | ||
|
||
procedure Enable_Color (Force : Boolean := False); | ||
-- Prepares colors for the terminal output. Unless Force, will do nothing | ||
-- if a console redirection is detected. | ||
|
||
function Chapter (Str : String) return String; | ||
function Description (Str : String) return String; | ||
function Version (Str : String) return String; | ||
function Underline (Str : String) return String; | ||
function Emph (Str : String) return String; | ||
|
||
end CLIC.Formatter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
package body CLIC.Markdown is | ||
|
||
function Chapter (Str : String) return String is | ||
("## " & Str); | ||
|
||
function Plain_Text (Str : String) return String is | ||
(Str); | ||
|
||
function Code (Str : String) return String is | ||
('`' & Str & '`'); | ||
|
||
function Bold (Str : String) return String is | ||
('*' & Str & '*'); | ||
|
||
function Italic (Str : String) return String is | ||
('_' & Str & '_'); | ||
|
||
end CLIC.Markdown; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
package CLIC.Markdown | ||
with Preelaborate | ||
is | ||
|
||
function Chapter (Str : String) return String; | ||
function Plain_Text (Str : String) return String; | ||
function Code (Str : String) return String; | ||
function Bold (Str : String) return String; | ||
function Italic (Str : String) return String; | ||
|
||
end CLIC.Markdown; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For me this is not the right way to add a Markdown output for the help pages. You may want to print the help in markdown without changing the formatting of the other outputs of your program.
Also it doesn't make much sens to outputting markdown for other parts of a command line program.
What I did for my [Man page POChttps://github.com//pull/12/files)) is to add a special
Print_Man_Page
to theCLIC.Subcommand.Instance
package.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I like the idea of a Markdown output for the help :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My rationale for doing it through the formatting parameters of
CLIC.Subcommand.Instance
is that all the logic already present inDisplay_Help
can be reused. In fact, when looking at that generic parameters, I figured out that something like I'm doing was envisioned.For example, the recent change about the global switches (a6bea52) would have to be applied in two places if there is a different help page generation for both formats like in #12. Isn't it better if there is a single place where the page is composed and the format can be parameterized?
But the help printing is a single purpose command. When you print the help page, either for generating a markdown format or for directly reading, this will be the single action performed by the application, it doesn't make sense to generate any other output.
Where I agree undoubtedly is that, instead of a global switch (
--markdown
) to be combined with--help
as I thought it, it should be a single switch for a specific subcommand. I was influence by how--no-tty
and similar switches worked and implemented it similarly, but always thinking in this--markdown
switch to be used along with--help
or thehelp
subcommand, not for any other program output.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This solution does work with TTY and Markdown, but it's not going to work for Man or HTML because of more complex output structures (lists in HTML for instance). So we will need another ad-hoc way to have those formats.
@mosteo up to you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If Markdown works well, HTML is indeed the final output of the former.
But, in any case, if @mosteo thinks the same, I don't have any problem in changing it to the other approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should emit a single format that is suitable for conversion with e.g.
pandoc
rather than having multiple generators. If the logic can be reused for the single chosen format, I'd prefer that, but if as @Fabien-Chouteau says, there are structures that won't work, then that forces our hand to have a separate generator.The way I'd go about it would be to use a sample complex page to check both issues: that it can be converted properly and whether the existent logic can be reused.