cursor.go raw

   1  // +build !windows
   2  
   3  package ansi
   4  
   5  import (
   6  	"fmt"
   7  )
   8  
   9  // Move the cursor n cells to up.
  10  func CursorUp(n int) {
  11  	fmt.Printf("\x1b[%dA", n)
  12  }
  13  
  14  // Move the cursor n cells to down.
  15  func CursorDown(n int) {
  16  	fmt.Printf("\x1b[%dB", n)
  17  }
  18  
  19  // Move the cursor n cells to right.
  20  func CursorForward(n int) {
  21  	fmt.Printf("\x1b[%dC", n)
  22  }
  23  
  24  // Move the cursor n cells to left.
  25  func CursorBack(n int) {
  26  	fmt.Printf("\x1b[%dD", n)
  27  }
  28  
  29  // Move cursor to beginning of the line n lines down.
  30  func CursorNextLine(n int) {
  31  	fmt.Printf("\x1b[%dE", n)
  32  }
  33  
  34  // Move cursor to beginning of the line n lines up.
  35  func CursorPreviousLine(n int) {
  36  	fmt.Printf("\x1b[%dF", n)
  37  }
  38  
  39  // Move cursor horizontally to x.
  40  func CursorHorizontalAbsolute(x int) {
  41  	fmt.Printf("\x1b[%dG", x)
  42  }
  43  
  44  // Show the cursor.
  45  func CursorShow() {
  46  	fmt.Print("\x1b[?25h")
  47  }
  48  
  49  // Hide the cursor.
  50  func CursorHide() {
  51  	fmt.Print("\x1b[?25l")
  52  }
  53