Giter Club home page Giter Club logo

wlog's Introduction

WLogPull Requests

Package wlog creates simple to use UI structure. The UI is used to simply print to the screen. There a wrappers that will wrap each other to create a good looking UI. You can add color and prefixes as well as make it thread safe.

Documentation

https://pkg.go.dev/github.com/dixonwille/wlog/v3

Installation

WLog can be added to your go module file by running:

go get github.com/dixonwille/wlog/v3@latest

You can them import the library using an import statement:

import "github.com/dixonwille/wlog/v3"

Idea Behind WLog

I used Mitchellh's CLI structure and wrapping for the different structures. It was a clean look and feel. Plus it was pretty simple to use. But I didn't want all the other cli stuff that came with the package so I created this.

For color I use DavidDenGCN's Go-ColorText. His color package allows for color that is available cross-platforms. I made a wrapper with all possible color combinations with his package. So you only have to import this package (one less line).

Example Usage

This example creates a new wlog.UI instance, simulates a user providing input and calls UI functions that show output. If you wish to try the example and provide your own user input you can replace the reader variable with a reader such as os.Stdin which will read from a terminal.

var ui wlog.UI
reader := strings.NewReader("User Input\r\n") //Simulate user typing "User Input" then pressing [enter] when reading from os.Stdin
ui = wlog.New(reader, os.Stdout, os.Stdout)
ui = wlog.AddPrefix("?", wlog.Cross, " ", "", "", "~", wlog.Check, "!", ui)
ui = wlog.AddConcurrent(ui)

ui.Ask("Ask question", "")
ui.Error("Error message")
ui.Info("Info message")
ui.Output("Output message")
ui.Running("Running message")
ui.Success("Success message")
ui.Warn("Warning message")

Output:

? Ask question
✗ Error message
 Info message
Output message
~ Running message
✓ Success message
! Warning message

On Windows it outputs to this (this includes color):

winss

On Mac it outputs to this (this includes color):

macss

wlog's People

Contributors

dependabot[bot] avatar dixonwille avatar sonarbeserk avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.