Skip to content
/ print Public

Print is a set of pretty print macros, useful for print-debugging.

License

Notifications You must be signed in to change notification settings

treeform/print

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

63 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Print - a better echo.

nimble install print

Github Actions

API reference

This library has no dependencies other than the Nim standard library.

About

Use print the same way you would use echo for print-debugging. It prints objects the "Nim way" with syntax highlighting. Even with refs, pointers, or cycles!

import print

let a = 3
print a
a = 3

The "Nim way"

It prints data structures in the same way you would create them in Nim source code. Ideally you can take what it prints out and just copy paste that into code again and it should compile in many cases.

let
  a = 3
  b = "hi there"
  c = "oh\nthis\0isit!"
  d = @[1, 2, 3]
  d2 = [1, 2, 3]
  f = Foo(a:"hi", b:@["a", "abc"], c:1234)

print a, b, c, d, d2, f
a=3 b="hi there" c="oh\nthis\0isit!" d=@[1, 2, 3] d2=[1, 2, 3] f=Foo(a:"hi", b:@["a", "abc"], c:1234)

Syntax highlighting

Screenshot from VS Code:

Image of Yaktocat

If you are piping to a file it will detect not-a-terminal and give you plain ascii instead.

Smart indention

It will try to print out everything in one line, but it if it does not fit it will create indentation levels. Max width is based on current terminal max width.

g2 = Bar(a: "hi a really really long string", b: @["a", "abc"], c: 1234)
print g2

Stuff echo does not do well

It will also print nils, refs, and pointers.

g2=Bar(
  a: "hi a really really long string",
  b: @["a", "abc"],
  c: 1234
)
let
  p1: ptr int = nil
  p2: ref Foo = nil
print p1, p2
p1=nil p2=nil
var three = 3
var pointerToThree = cast[pointer](addr three)
print pointerToThree
pointerToThree=0x00000000004360A0

And even cycles!

It will also stop recursing repeating structures:

type Node = ref object
  data: string
  next: Node
var n = Node(data:"hi")
n.next = n
print n
n=Node(data: "hi", next: ...)

About

Print is a set of pretty print macros, useful for print-debugging.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages