本文整理汇总了Golang中github.com/rthornton128/goncurses.Echo函数的典型用法代码示例。如果您正苦于以下问题:Golang Echo函数的具体用法?Golang Echo怎么用?Golang Echo使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Echo函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GetSecret
func (ui *NcurseUi) GetSecret(prompt string) (output string) {
goncurses.Echo(false)
output = ui.GetString(prompt)
goncurses.Echo(true)
return
}
示例2: GetCommand
func (ui *NcurseUi) GetCommand() (output int) {
goncurses.Update()
goncurses.Echo(false)
output = int(ui.contents.GetChar())
goncurses.Echo(true)
return
}
示例3: configCurses
//sets up the initial configuration of curses. Keeps code in main cleaner.
func configCurses(stdscr *gc.Window) {
if !gc.HasColors() {
log.Fatal("Example requires a colour capable terminal")
}
if err := gc.StartColor(); err != nil {
log.Fatal("Starting Colors failed:", err)
}
gc.Echo(false)
if err := gc.InitPair(1, gc.C_RED, gc.C_BLACK); err != nil {
log.Fatal("InitPair failed: ", err)
}
gc.InitPair(2, gc.C_BLUE, gc.C_BLACK)
gc.InitPair(3, gc.C_GREEN, gc.C_BLACK)
gc.InitPair(4, gc.C_YELLOW, gc.C_BLACK)
gc.InitPair(5, gc.C_CYAN, gc.C_BLACK)
gc.InitPair(6, gc.C_MAGENTA, gc.C_WHITE)
gc.InitPair(7, gc.C_MAGENTA, gc.C_BLACK)
//set background color to black
stdscr.SetBackground(gc.Char(' ') | gc.ColorPair(0))
stdscr.Keypad(true)
gc.Cursor(1)
gc.CBreak(true)
stdscr.Clear()
}
示例4: getPass
// Gets password from input
func getPass() string {
gc.Echo(false)
stdscr := gc.StdScr()
var returnString []byte
x := 0
var c gc.Char
var rawInput gc.Key
for {
rawInput = stdscr.GetChar()
c = gc.Char(rawInput)
if rawInput == gc.KEY_BACKSPACE || c == gc.Char(127) {
if x != 0 {
returnString = returnString[0 : len(returnString)-1]
x--
} else {
continue
}
} else if rawInput == gc.KEY_RETURN {
if x != 0 {
return string(returnString)
}
} else if c > 31 && c < 127 {
returnString = append(returnString, byte(c))
x++
} else {
continue
}
}
}
示例5: main
func main() {
stdscr, err := goncurses.Init()
if err != nil {
log.Fatal("init", err)
}
defer goncurses.End()
goncurses.Raw(true) // turn on raw "uncooked" input
goncurses.Echo(false) // turn echoing of typed characters off
goncurses.Cursor(0) // hide cursor
stdscr.Keypad(true) // allow keypad input
stdscr.Print("Press a key...")
stdscr.Refresh()
if ch := stdscr.GetChar(); ch == goncurses.KEY_F2 {
stdscr.Print("The F2 key was pressed.")
} else {
stdscr.Print("The key pressed is: ")
stdscr.AttrOn(goncurses.A_BOLD)
stdscr.AddChar(goncurses.Char(ch))
stdscr.AttrOff(goncurses.A_BOLD)
}
stdscr.Refresh()
stdscr.GetChar()
}
示例6: main
func main() {
stdscr, err := gc.Init()
if err != nil {
log.Fatal(err)
}
defer gc.End()
gc.Echo(false)
gc.CBreak(true)
gc.Cursor(0)
var panels [2]fp.FilePanel
rows, cols := stdscr.MaxYX()
height, width := rows, cols/2
y, x := 0, 0
activePanel := 0
panels[0] = fp.FilePanel{Height: height, Width: width, Y: y, X: x, Directory: "./", Selected: 0, IsActive: true}
panels[1] = fp.FilePanel{Height: height, Width: width, Y: y, X: x + width, Directory: "/home/kuzzmi/", Selected: 2, IsActive: false}
panels[0].Draw()
panels[1].Draw()
gc.UpdatePanels()
gc.Update()
stdscr.Keypad(true)
// stdscr.GetChar()
main:
for {
switch panels[activePanel].Panel.Window().GetChar() {
case 'q':
break main
case gc.KEY_RETURN:
panels[activePanel].Execute()
case gc.KEY_TAB:
panels[0].ToggleActivity()
panels[1].ToggleActivity()
gc.UpdatePanels()
gc.Update()
if activePanel == 0 {
activePanel = 1
} else {
activePanel = 0
}
case 'u':
panels[activePanel].GoUp()
case 'k':
panels[activePanel].Select(panels[activePanel].Selected - 1)
case 'j':
panels[activePanel].Select(panels[activePanel].Selected + 1)
case 'i':
panels[activePanel].HideHidden()
}
}
stdscr.Delete()
}
示例7: main
func main() {
stdscr, _ := gc.Init()
defer gc.End()
gc.StartColor()
gc.CBreak(true)
gc.Echo(true)
stdscr.Keypad(true)
stdscr.Print("Hit 'tab' to cycle through windows, 'q' to quit")
gc.InitPair(1, gc.C_RED, gc.C_BLACK)
gc.InitPair(2, gc.C_GREEN, gc.C_BLACK)
gc.InitPair(3, gc.C_BLUE, gc.C_BLACK)
gc.InitPair(4, gc.C_CYAN, gc.C_BLACK)
var panels [3]*gc.Panel
y, x := 4, 10
for i := 0; i < 3; i++ {
h, w := 10, 40
title := "Window Number %d"
window, _ := gc.NewWindow(h, w, y+(i*4), x+(i*10))
window.Box(0, 0)
window.MoveAddChar(2, 0, gc.ACS_LTEE)
window.HLine(2, 1, gc.ACS_HLINE, w-2)
window.MoveAddChar(2, w-1, gc.ACS_RTEE)
window.ColorOn(int16(i + 1))
window.MovePrintf(1, (w/2)-(len(title)/2), title, i+1)
window.ColorOff(int16(i + 1))
panels[i] = gc.NewPanel(window)
}
active := 2
for {
gc.UpdatePanels()
gc.Update()
switch stdscr.GetChar() {
case 'q':
return
case gc.KEY_TAB:
active += 1
if active > 2 {
active = 0
}
panels[active].Top()
}
}
}
示例8: main
func main() {
stdscr, err := gc.Init()
if err != nil {
log.Fatal("init:", err)
}
defer gc.End()
// HasColors can be used to determine whether the current terminal
// has the capability of using colours. You could then chose whether or
// not to use some other mechanism, like using A_REVERSE, instead
if !gc.HasColors() {
log.Fatal("Example requires a colour capable terminal")
}
// Must be called after Init but before using any colour related functions
if err := gc.StartColor(); err != nil {
log.Fatal(err)
}
gc.Echo(false)
// Initialize a colour pair. Should only fail if an improper pair value
// is given
if err := gc.InitPair(1, gc.C_RED, gc.C_WHITE); err != nil {
log.Fatal("InitPair failed: ", err)
}
gc.InitPair(2, gc.C_BLACK, gc.C_CYAN)
stdscr.Println("Type any key to proceed and again to exit")
// An example of trying to set an invalid color pair
err = gc.InitPair(-1, gc.C_BLACK, gc.C_CYAN)
stdscr.Println("An intentional error:", err)
stdscr.Keypad(true)
stdscr.MovePrint(12, 30, "Hello, World!!!")
stdscr.Refresh()
stdscr.GetChar()
// Note that background doesn't just accept colours but will fill
// any blank positions with the supplied character too. Note that newly
// added text with spaces in it will have the blanks converted to the fill
// character, if given
stdscr.SetBackground(gc.Char('*') | gc.ColorPair(2))
// ColorOn/Off is a shortcut to calling AttrOn/Off(gc.ColorPair(pair))
stdscr.ColorOn(1)
stdscr.MovePrint(13, 30, "Hello, World in Color!!!")
stdscr.ColorOff(1)
stdscr.Refresh()
stdscr.GetChar()
}
示例9: main
func main() {
stdscr, err := gc.Init()
if err != nil {
log.Fatal(err)
}
defer gc.End()
gc.Cursor(0)
gc.Echo(false)
stdscr.Print("A reversed plus-minus symbol: ")
stdscr.AddChar(gc.ACS_PLMINUS | gc.A_REVERSE)
stdscr.Refresh()
stdscr.GetChar()
}
示例10: NewCursesView
func NewCursesView() (i view.Interface, err error) {
v := new(CursesView)
if v.win, err = cur.Init(); err != nil {
return
}
cur.Echo(false)
cur.Cursor(0)
if err = v.initCursesColors(); err != nil {
return
}
i = v
return
}
示例11: main
func main() {
stdscr, err := gc.Init()
if err != nil {
log.Fatal(err)
}
defer gc.End()
gc.StartColor()
gc.Echo(false)
gc.Raw(true)
var colours = []int16{gc.C_BLACK, gc.C_BLUE, gc.C_CYAN, gc.C_GREEN,
gc.C_MAGENTA, gc.C_RED, gc.C_WHITE, gc.C_YELLOW}
var attributes = []struct {
attr gc.Char
text string
}{
{gc.A_NORMAL, "normal"},
{gc.A_STANDOUT, "standout"},
{gc.A_UNDERLINE | gc.A_BOLD, "underline"},
{gc.A_REVERSE, "reverse"},
{gc.A_BLINK, "blink"},
{gc.A_DIM, "dim"},
{gc.A_BOLD, "bold"},
}
stdscr.MovePrint(0, 0, "Normal terminal colors: ")
for i, c := range colours {
gc.InitPair(int16(i), c, c)
stdscr.ColorOn(int16(i))
stdscr.AddChar(' ')
stdscr.ColorOff(int16(i))
}
stdscr.MovePrint(1, 0, "Bold terminal colors: ")
stdscr.AttrOn(gc.A_BLINK)
for i, _ := range colours {
stdscr.ColorOn(int16(i))
stdscr.AddChar(' ')
stdscr.ColorOff(int16(i))
}
stdscr.AttrOff(gc.A_BLINK)
stdscr.Move(2, 0)
for _, a := range attributes {
stdscr.AttrOn(a.attr)
stdscr.Println(a.text)
stdscr.AttrOff(a.attr)
}
stdscr.GetChar()
}
示例12: initialize
func initialize() {
// catche SIGINT signals
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
signal.Notify(c, syscall.SIGTERM)
go func() {
<-c
shutdown()
}()
// Listen on key events
if !OUT_BATCH {
goncurses.Echo(false) // turn echoing of typed characters off
goncurses.Cursor(0) // hide cursor
go func() {
for true {
ch := screen.GetChar()
if ch == 'q' {
shutdown()
}
}
}()
}
// Activate devices according to user arguments
if DEV_UUID {
static.Initialize()
}
if DEV_CPU {
cpu.Initialize()
}
if DEV_MEMORY {
memory.Initialize()
}
if DEV_NETWORK {
network.Initialize()
}
if DEV_DISK {
disk.Initialize()
}
// create arrays for storing measurements
virtualmachines = make(map[string]models.VirtualMachine)
ppid2vmname = make(map[string]string)
// first initial querying of measurements
updateVirtualMachineLists()
}
示例13: main
func main() {
stdscr, err := goncurses.Init()
if err != nil {
log.Fatal("init:", err)
}
defer goncurses.End()
goncurses.Raw(true)
goncurses.Echo(false)
goncurses.Cursor(0)
stdscr.Clear()
stdscr.Keypad(true)
menu_items := []string{"Choice 1", "Choice 2", "Choice 3", "Choice 4",
"Exit"}
items := make([]*goncurses.MenuItem, len(menu_items))
for i, val := range menu_items {
items[i], _ = goncurses.NewItem(val, "")
defer items[i].Free()
}
menu, err := goncurses.NewMenu(items)
if err != nil {
stdscr.Print(err)
return
}
defer menu.Free()
menu.Post()
stdscr.MovePrint(20, 0, "'q' to exit")
stdscr.Refresh()
for {
goncurses.Update()
ch := stdscr.GetChar()
switch goncurses.KeyString(ch) {
case "q":
return
case "down":
menu.Driver(goncurses.REQ_DOWN)
case "up":
menu.Driver(goncurses.REQ_UP)
}
}
}
示例14: main
func main() {
scr, err := gc.Init()
if err != nil {
log.Fatal("init:", err)
}
defer gc.End()
gc.Echo(false)
scr.Println("Type characters to have them appear on the screen.")
scr.Println("Press 'q' to exit.")
scr.Println()
// Accept input concurrently via a goroutine and connect a channel
in := make(chan gc.Char)
ready := make(chan bool)
go func(w *gc.Window, ch chan<- gc.Char) {
for {
// Block until all write operations are complete
<-ready
// Send typed character down the channel (which is blocking
// in the main loop)
ch <- gc.Char(w.GetChar())
}
}(scr, in)
// Once a character has been received on the 'in' channel the
// 'ready' channel will block until it recieves another piece of data.
// This happens only once the received character has been written to
// the screen. The 'in' channel then blocks on the next loop until
// another 'true' is sent down the 'ready' channel signalling to the
// input goroutine that it's okay to receive input
for {
var c gc.Char
select {
case c = <-in: // blocks while waiting for input from goroutine
scr.Print(string(c))
scr.Refresh()
case ready <- true: // sends once above block completes
}
// Exit when 'q' is pressed
if c == gc.Char('q') {
break
}
}
}
示例15: main
func main() {
stdscr, err := gc.Init()
if err != nil {
log.Fatal("init", err)
}
defer gc.End()
if err := gc.StartColor(); err != nil {
log.Fatal(err)
}
lines, cols := stdscr.MaxYX()
gc.Raw(true) // turn on raw "uncooked" input
gc.Echo(false) // turn echoing of typed characters off
gc.Cursor(0) // hide cursor
stdscr.Timeout(50)
stdscr.Keypad(true) // allow keypad input
gc.InitPair(1, gc.C_YELLOW, gc.C_BLACK)
gc.InitPair(2, gc.C_RED, gc.C_BLACK)
gc.InitPair(3, gc.C_GREEN, gc.C_BLACK)
gc.InitPair(4, gc.C_BLUE, gc.C_BLACK)
gc.InitPair(5, gc.C_WHITE, gc.C_BLACK)
gc.InitPair(6, gc.C_BLACK, gc.C_BLACK)
gc.InitPair(7, gc.C_MAGENTA, gc.C_BLACK)
stdscr.SetBackground(gc.ColorPair(3))
rand.Seed(time.Now().UTC().UnixNano())
state := State{Money: 150}
var build *Thing
things := make([]Thing, 0, 20)
var toUpdate int64 = 0
lastTimestamp := int64(time.Nanosecond) * time.Now().UTC().UnixNano() / int64(time.Millisecond)
frames := make(map[string][][]string)
count := rand.Intn(15) + 25
for i := 0; i < count; i++ {
for {
var kind Kind
var pop int
r := rand.Intn(2)
switch r {
case 0:
kind = &SmallHouse{Frames: &frames}
pop = 10
case 1:
kind = &House{Frames: &frames}
pop = 40
}
house := &Thing{2 + rand.Intn(cols-8), 2 + rand.Intn(lines-8), kind}
overlap := false
for _, thing := range things {
if house.Overlap(&thing) {
overlap = true
break
}
}
if !overlap {
things = append(things, *house)
state.Population += pop
break
}
}
}
var overlap bool
var price float32
showInfo := true
for {
now := int64(time.Nanosecond) * time.Now().UTC().UnixNano() / int64(time.Millisecond)
delta := now - lastTimestamp
lastTimestamp = now
toUpdate -= delta
c := stdscr.GetChar()
switch c {
case 'q':
break
case 'a':
if build != nil && build.X > 0 {
build.X--
}
case 'd':
if build != nil && build.X+build.GetSize().X < cols {
build.X++
}
case 'w':
//.........这里部分代码省略.........