Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sebi2020/go-ncurses
Golang ncurses wrapper
https://github.com/sebi2020/go-ncurses
go golang ncurses wrapper
Last synced: 2 days ago
JSON representation
Golang ncurses wrapper
- Host: GitHub
- URL: https://github.com/sebi2020/go-ncurses
- Owner: Sebi2020
- License: gpl-3.0
- Created: 2019-08-25T10:23:02.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2019-09-07T18:01:40.000Z (about 5 years ago)
- Last Synced: 2024-06-21T13:54:51.820Z (5 months ago)
- Topics: go, golang, ncurses, wrapper
- Language: Go
- Size: 79.1 KB
- Stars: 3
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# go-ncurses
[![GoDoc](https://godoc.org/github.com/Sebi2020/go-ncurses?status.svg)](https://godoc.org/github.com/Sebi2020/go-ncurses)**go-ncurses** is a wrapper for [go](https://www.golang.org) of the famous ncurses library.
```go
package ncursesimport (
"fmt"
)main() {
w,_ := ncurses.Initscr()
// Ensure, that ncurses will be properly exited
defer ncurses.Endwin()
defer func() {
if r := recover(); r != nil {
ncurses.Endwin()
fmt.Printf("panic:\n%s\n", r)
os.Exit(-1)
}
}()// Enable color mode
ncurses.StartColor()// Define color pairs
ncurses.AddColorPair("bw", ncurses.ColorGreen,ncurses.ColorBlack)
ncurses.AddColorPair("wb",ncurses.ColorWhite, ncurses.ColorBlue)// Set cursor visiblity to hidden
ncurses.SetCursor(ncurses.CURSOR_HIDDEN)// Automatically refresh after each command
w.AutoRefresh = true// Set color for stdscr-window to system defaults.
w.Wbkgd("std")// Draw a border around main window (stdscr)
w.Box()// Create a new window for greeting-text at cell (x=20,y=5) with a size of 25 x 5 cells.
w2,err := ncurses.NewWindow("dialog",ncurses.Position{20,5},ncurses.Size{25,5})// This can fail if the terminal is too small.
if err != nil {
panic(err)
}
w2.AutoRefresh = true// Use color pair wb (2)
w2.Wbkgd("wb")// Draw a border around our "Greeting Window".
w2.Box()// Move cursor relative to the window borders of w2
w2.Move(2,3)// Output our greeting text
fmt.Fprintf(w2, "Hello from Go\u2122-Lang!")// Move cursor relative to the beginning of our main window
w.Move(17,19)// Output exit instruction for the user
fmt.Fprintf(w," => Press a key to exit <=")// Wait for user input (e.g. keypress)
w.Getch()
}
```