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

github.com/sethgrid/curse

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/sethgrid/curse

  • v0.0.0-20181231162520-d4ee583ebf0f
  • Source
  • Go
  • Socket score

Version published
Created
Source

Curse

A utility for manipulating the terminal cursor. Current feature set:

  • Get terminal cursor position
  • Move cursor
  • Move up, down n-lines
  • Clear line
  • Clear Screen (up, down, all)
  • Set Color

Basic Example usage (see below for an inline-progress bar):

    package main

    import (
        "fmt"
        "log"

        "github.com/sethgrid/curse"
    )

    func main() {

        c, err := curse.New()
        if err != nil {
            log.Fatal(err)
        }

        c.SetColorBold(curse.RED).SetBackgroundColor(curse.BLACK)
        fmt.Println("Position: ", c.Position)
        c.SetDefaultStyle()
        fmt.Println("something to be erased")
        c.MoveUp(1).EraseCurrentLine().MoveDown(1)
    }

Progress Bar Example:

    package main

    import (
        "fmt"
        "strings"
        "time"

        "github.com/sethgrid/curse"
    )

    func main() {
        fmt.Println("Progress Bar")
        total := 150
        progressBarWidth := 80
        c, _ := curse.New()

        // give some buffer space on the terminal
        fmt.Println()

        // display a progress bar
        for i := 0; i <= total; i++ {
            c.MoveUp(1)
            c.EraseCurrentLine()
            fmt.Printf("%d/%d ", i, total)

            c.MoveDown(1)
            c.EraseCurrentLine()
            fmt.Printf("%s", progressBar(i, total, progressBarWidth))

            time.Sleep(time.Millisecond * 25)
        }
        // end the previous last line of output
        fmt.Println()
        fmt.Println("Complete")
    }

    func progressBar(progress, total, width int) string {
        bar := make([]string, width)
        for i, _ := range bar {
            if float32(progress)/float32(total) > float32(i)/float32(width) {
                bar[i] = "*"
            } else {
                bar[i] = " "
            }
        }
        return "[" + strings.Join(bar, "") + "]"
    }

FAQs

Package last updated on 31 Dec 2018

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