nitx: use AnsiHighlightVisitor
authorAlexandre Terrasa <alexandre@moz-code.org>
Fri, 8 Dec 2017 20:30:43 +0000 (15:30 -0500)
committerAlexandre Terrasa <alexandre@moz-code.org>
Mon, 18 Dec 2017 18:44:43 +0000 (13:44 -0500)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

src/doc/commands/commands_model.nit
src/doc/term/term.nit

index 230bf81..1e88381 100644 (file)
@@ -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.
@@ -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
 
index 33b5221..61d5206 100644 (file)
@@ -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
@@ -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