Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/louislef299/scroll

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/louislef299/scroll

  • v1.1.0
  • Source
  • Go
  • Socket score

Version published
Created
Source

Go Scroll Buffer

ANSI Scroll Buffer Stages is a simple package meant to emulate the stages in a cli tool where overall output isn't important unless there is a failure. It consists of a simple buffer abstraction that utilizes ANSI escape codes in the background. This can help when there is a large amount of output to the terminal in stages, but the overall result may be important to communicate to the user.

Demo

Install

go get github.com/louislef299/scroll

Examples

Simple write to the Buffer:

scroll.Printf("hello world")

Erase the existing Buffer:

// Prints hello world 5x
for i := 0; i < 5; i++ {
    scroll.Printf("hello world")
}
scroll.EraseBuffer()

Run print statements in stages:

// Stage 1
for i := 0; i < 5; i++ {
    scroll.Printf("%d: hello from stage 1", i + 1)
}
// end stage
scroll.NewStage("stage 1 complete!")

// Stage 2
for i := 0; i < 5; i++ {
    scroll.Printf("%d: hello from stage 2", i + 1)
}
// end stage
scroll.NewStage("stage 2 complete!")

Create a custom Buffer:

// Creates a new buffer with a size of 5
buff := scroll.New(context.TODO(), os.Stdout, 5)

// Prints hello world 5x
for i := 0; i < 5; i++ {
    buff.Printf("hello world")
}
time.Sleep(time.Second)
buff.NewStage("finish buffer example!")

The ANSI Buffer also implements io.Writer:

log.SetOutput(scroll.New(context.TODO(), 5))
log.Println("written from test")

The writer is unreliable under stress however, as the channels that are created for synchronization are not reliably transferred to packages like log and fmt.

Contributing

The tests are currently visual tests and require a human to watch the output and verify functionality. Not ideal, but that's how it is for now. Feel free to fix it!

References

The scroll package takes some inspiration for the log standard package and Fatih Arslan's color package.

FAQs

Package last updated on 26 Oct 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc