Skip to content

Commit

Permalink
nitx: use AnsiHighlightVisitor
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>
  • Loading branch information
Morriar committed Dec 8, 2017
1 parent 79f8eeb commit bad441d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/doc/commands/commands_model.nit
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ class CmdCode
# Rendering format
#
# Set the output format for this piece of code.
# Can be "raw" or "html".
# Can be "raw", "html" or "ansi".
# Default is "raw".
#
# This format can be different than the format used in the command response.
Expand Down Expand Up @@ -431,9 +431,14 @@ class CmdCode
var hl = new HtmlightVisitor
hl.highlight_node node
return hl.html
else if format == "ansi" then
var hl = new AnsiHighlightVisitor
hl.highlight_node node
return hl.result
end
# TODO make a raw visitor
return node.to_s
var mentity = self.mentity
if mentity == null then return null
return mentity.location.text
end
end

Expand Down
14 changes: 13 additions & 1 deletion src/doc/term/term.nit
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ redef class CmdFeatures
end

redef class CmdCode

redef var format = "ansi" is optional

redef fun execute(no_color) do
var mentity = self.mentity
if mentity == null then return
Expand All @@ -218,7 +221,16 @@ redef class CmdCode
else
print title
end
printn mentity.cs_source_code
if no_color == null or not no_color then
var ansi = render
if ansi != null then
print "~~~"
print ansi.write_to_string
print "~~~"
end
else
printn mentity.cs_source_code
end
end
end

Expand Down

0 comments on commit bad441d

Please sign in to comment.