counter

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Counter

type Counter struct {
	// contains filtered or unexported fields
}

Counter is a simple counter that can be incremented, decremented, or set to a specific value.

Example
package main

import (
	"time"

	"676f.dev/trout/counter"
	"github.com/fatih/color"
)

func main() {
	c := counter.NewCounter(color.HiCyanString("Hello")+"(", "x)")
	time.Sleep(1 * time.Second)
	c.Inc()
	time.Sleep(1 * time.Second)
	c.Inc()
	time.Sleep(1 * time.Second)
	c.Inc()
	time.Sleep(1 * time.Second)

	c.End()
}
Output:

func NewCounter

func NewCounter(prefix string, suffix string) *Counter

NewCounter creates a counter with the given prefix and suffix.

func NewDefaultCounter added in v1.0.1

func NewDefaultCounter(task string) *Counter

NewDefaultCounter creates a counter with the default (and colored) prefix and suffix.

Example
package main

import (
	"time"

	"676f.dev/trout/counter"
)

func main() {
	c := counter.NewDefaultCounter("test")
	time.Sleep(1 * time.Second)
	c.Inc()
	time.Sleep(1 * time.Second)
	c.Inc()
	time.Sleep(1 * time.Second)
	c.Inc()
	time.Sleep(1 * time.Second)

	c.End()
}
Output:

func (*Counter) Dec added in v1.0.1

func (c *Counter) Dec()

Dec decrements the counter by 1.

func (*Counter) End

func (c *Counter) End()

End prints a newline to the console. This should be called after the counter is no longer needed.

func (*Counter) Inc

func (c *Counter) Inc()

Inc increments the counter by 1.

func (*Counter) To added in v1.0.1

func (c *Counter) To(n int)

To sets the counter to the given value.

Jump to

Keyboard shortcuts

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