Code Monkey home page Code Monkey logo

ansi-escapes's Introduction

ansi-scapes GoDoc

ansi-scapes is a minimal Go library for ANSI escape sequences. It handles the small differences in the Apple's Terminal app, as well as enable and disable escape sequences on Windows 10 v1511 and later.

๐Ÿšง ansi-escapes is still under development, and is subject to change ๐Ÿšง

Features

  • Constants for simple escape sequences
  • Functions for sequences with parameters
  • Correct functionality across terminal emulators
  • Ability to enable/disable escape sequence processing on Windows v1511 and later

Installation

With the Go Programming Language,

$ go get -u github.com/snugfox/ansi-escapes

Usage

Go's import mechanism does not allow package names to contain hyphens, so import the package as escapes.

import escapes "github.com/snugfox/ansi-escapes"

Example

package main

import (
  "bytes"
  "fmt"
  "os"

  escapes "github.com/snugfox/ansi-escapes"
)

func main() {
  // Enable support on Windows for this application. It is safe to include on
  // OSes other than Windows, as the functions will only return nil; thus
  // compiled out.
  escapes.EnableVirtualTerminal(escapes.Stdout)
  defer escapes.DisableVirtualTerminal(escapes.Stdout)

  // Erase the screen. Remember that fmt.Println would print the newline *after*
  // the escape sequence.
  fmt.Print(escapes.EraseScreen)

  // Move the cursor one column to the right
  fmt.Print(escapes.CursorForward)

  // Move the cursor to (1, 1)
  fmt.Print(escapes.CursorPos(1, 1))

  // Display a super secret image
  var buf bytes.Buffer
  file, _ := os.Open("meow.jpg")
  buf.ReadFrom(file)
  fmt.Print(escapes.Image(buf.Bytes()))
}

License

MIT (c) Snug_Fox

ansi-escapes's People

Contributors

firlus avatar snugfox avatar

Watchers

 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.