Skip to content

solidiquis/termscroll

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

termscroll

Example program that leverages termscroll to change wallpapers from the terminal:

Installation & Usage

$ go get github.com/solidiquis/termscroll

package main

import (
	"fmt"
	ts "github.com/solidiquis/termscroll"
)

func main() {
	items := []string{
		"item a",
		"item b",
		"item c",
		"item d",
                // ...
	}

        // Graceful exit necessary to unhide cursor
	done := make(chan bool)
	listenForExitSig, cleanup := ts.InitExitStrat(done)
	go listenForExitSig()

        // up() traverses list up
        // down() traverses list down
        // current() gets current active index
	up, down, current := ts.InitRender(items)

        // Read from stdin without buffering
	stdin := make(chan string, 1)
	go ts.ReadStdin(stdin)

readInput:
	for {
		select {
		case <-done:
			break readInput
		case ch := <-stdin:
			switch ch {
			case "k":
				up()
			case "j":
				down()
			case "\n": // Enter
				fmt.Printf("You've selected %s\n", items[current()])
				break readInput
			}
		}
	}
        // unhide cursor 
	cleanup()
}

About

Simple terminal utility to render, scroll, and select through a list of items 💻 ⌨️

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages