ic

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2021 License: MIT Imports: 11 Imported by: 0

README

icecream-go

🍦 Never use fmt.Println() for debugging again! A port of the Python IceCream library


Features
  • Close feature parity to the Python implementation
  • Syntax highlighting
  • Customisable outputs
Inspecting variables
// import "github.com/codemicro/icecream-go/ic"

foo := func (i int) int { return i + 333 }
ic.IC(foo(123)) // -> ic| foo(123): 456

bar := map[string]map[int]string{"key": {1: "one"}}
ic.IC(bar["key"][1]) // -> ic| bar["key"][1]: "one"

baz := struct{ Name string }{Name: "codemicro"}
ic.IC(baz.Name) // -> ic| baz.Name: "codemicro"
Inspecting flows
package main

import "github.com/codemicro/icecream-go/ic"

func foo() {
    ic.IC()
    // do things
    if condition {
        ic.IC() 
        // other thing 
    } else {
        ic.IC()
        // another thing
    }
}

func main() {
    foo()
    // -> ic| main.go:7 in github.com/codemicro/something/main.foo
    //    ic| main.go:9 in github.com/codemicro/something/main.foo
}
ic.Format
theAnswer := 42
x := ic.Format(theAnswer)
fmt.Println(x) // -> ic| theAnswer: 42

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfigureDisableSyntaxHighlighting

func ConfigureDisableSyntaxHighlighting()

ConfigureDisableSyntaxHighlighting disables syntax highlighting on output from IC

func ConfigureEnableSyntaxHighlighting

func ConfigureEnableSyntaxHighlighting()

ConfigureEnableSyntaxHighlighting enables syntax highlighting on output from IC

func ConfigureResetOutput

func ConfigureResetOutput()

ConfigureResetOutput resets the output of IC to os.Stderr. Can be overridden by subsequent calls to ConfigureSetOutput or ConfigureSetOutputFunction

func ConfigureResetPrefix

func ConfigureResetPrefix()

ConfigureResetPrefix resets the prefix for outputs from IC and Format to default ("ic| "). This overrides anything set in ConfigureSetPrefix or ConfigureSetPrefixFunction

func ConfigureSetIncludeContext

func ConfigureSetIncludeContext(x bool)

ConfigureSetIncludeContext takes a boolean to signify if every call of Format or IC should include a context string (which include the source file name, line that contains the IC or Format function call and the package name)

func ConfigureSetOutput

func ConfigureSetOutput(wr io.Writer)

ConfigureSetOutput sets the output of IC to the provided io.Writer. Can be overridden by subsequent calls to ConfigureResetOutput or ConfigureSetOutputFunction. A panic will occur if the supplied writer cannot be written to.

func ConfigureSetOutputFunction

func ConfigureSetOutputFunction(x func(string))

ConfigureSetOutputFunction sets the output of IC to an arbitrary function. Can be overridden by subsequent calls to ConfigureResetOutput or ConfigureSetOutput

func ConfigureSetPrefix

func ConfigureSetPrefix(newPrefix string)

ConfigureSetPrefix sets the prefix for output from IC and Format. Can be overridden by subsequent calls to ConfigureResetPrefix or ConfigureSetPrefixFunction

func ConfigureSetPrefixFunction

func ConfigureSetPrefixFunction(pf func() string)

ConfigureSetPrefixFunction sets the prefix for the output from IC and Format to the result of the supplied function. Can be overridden by subsequent calls to ConfigureResetPrefix or ConfigureSetPrefix

func Disable

func Disable()

Disable disables output from IC

func Enable

func Enable()

Enable enables output from IC

func Format

func Format(o ...interface{}) string

Format is the same as IC, except it returns the generated string without syntax highlighting instead of outputting it

func IC

func IC(o ...interface{})

IC takes an arbitrary number of arbitrary type arguments, formats and optionally syntax highlights them then outputs them, by default, on os.Stderr

Types

This section is empty.

Jump to

Keyboard shortcuts

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