q

package module
v0.0.0-...-790b74a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2018 License: MIT Imports: 16 Imported by: 0

README

Background: This is a fork of the excellent q library, which is declared to be feature complete. I have some ideas for improving q and this is where they'll happen.


q

Build Status GoDoc Go Report Card

q is a better way to do print statement debugging.

Type q.Q instead of fmt.Printf and your variables will be printed like this:

q output examples

Why is this better than fmt.Printf?

  • Faster to type
  • Pretty-printed vars and expressions
  • Easier to see inside structs
  • Doesn't go to noisy-ass stdout. It goes to $TMPDIR/q.
  • Pretty colors!

Basic Usage

import "github.com/kalafut/q"
...
q.Q(a, b, c)

// q output can be turned off and on.
q.Off()
q.On()
// Alternatively, use the . import and you can omit the package name.
import . "github.com/kalafut/q"
...
Q(a, b, c)

For best results, dedicate a terminal to tailing $TMPDIR/q while you work.

Install

go get -u github.com/y0ssar1an/q

Put these functions in your shell config. Typing qq or rmqq will then start tailing $TMPDIR/q.

qq() {
    clear
    local gpath="${GOPATH:-$HOME/go}"
    "${gpath%%:*}/src/github.com/y0ssar1an/q/q.sh" "$@"
}
rmqq() {
    if [[ -f "$TMPDIR/q" ]]; then
        rm "$TMPDIR/q"
    fi
    qq
}

Editor Integration

VS Code

Preferences > User Snippets > Go

"qq": {
    "prefix": "qq",
    "body": "q.Q($1) // DEBUG",
    "description": "Pretty-print to $TMPDIR/q"
}
Sublime Text

Tools > Developer > New Snippet

<snippet>
    <content><![CDATA[
q.Q($1) // DEBUG
]]></content>
    <tabTrigger>qq</tabTrigger>
    <scope>source.go</scope>
</snippet>
Atom

Atom > Open Your Snippets

'.source.go':
    'qq':
        'prefix': 'qq'
        'body': 'q.Q($1) // DEBUG'
vim/Emacs

TBD Send me a PR, please :)

Haven't I seen this somewhere before?

Python programmers will recognize this as a Golang port of the q module by zestyping.

Ping does a great job of explaining q in his awesome lightning talk from PyCon 2013. Watch it! It's funny :)

ping's PyCon 2013 lightning talk

FAQ

Why q.Q?

It's quick to type and unlikely to cause naming collisions.

Is q.Q() safe for concurrent use?

Yes.

Documentation

Overview

Package q provides quick and dirty debugging output for tired programmers.

q.Q() is a fast way to pretty-print variables. It's easier than typing fmt.Printf("%#v", whatever). The output will be colorized and nicely formatted. The output goes to $TMPDIR/q, away from the noise of stdout.

q exports a single Q() function. This is how you use it:

import "github.com/y0ssar1an/q"
...
q.Q(a, b, c)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Off

func Off()

Off disables any output until a subsequent call to On.

func On

func On()

On re-enables output that was turned Off.

func Q

func Q(v ...interface{})

Q pretty-prints the given arguments to the $TMPDIR/q log file.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL