/examples/hello/hello.go

https://code.google.com/p/goncurses/ · Go · 38 lines · 16 code · 6 blank · 16 comment · 3 complexity · 38b6f1f764869edb815f61c58af7a9fd MD5 · raw file

  1. // goncurses - ncurses library for Go.
  2. // Copyright 2011 Rob Thornton. All rights reserved.
  3. // Use of this source code is governed by a BSD-style
  4. // license that can be found in the LICENSE file.
  5. /* The classic "Hello, World!" program in Goncurses! */
  6. package main
  7. import (
  8. "code.google.com/p/goncurses"
  9. "log"
  10. )
  11. func main() {
  12. // Initialize goncurses. It's essential End() is called to ensure the
  13. // terminal isn't altered after the program ends
  14. stdscr, err := goncurses.Init()
  15. if err != nil {
  16. log.Fatal("init", err)
  17. }
  18. defer goncurses.End()
  19. // (Go)ncurses draws by cursor position and uses reverse cartisian
  20. // coordinate system (y,x). Initially, the cursor is positioned at the
  21. // coordinates 0,0 so the first call to Print will output the text at the
  22. // top, left position of the screen since stdscr is a window which
  23. // represents the terminal's screen size.
  24. stdscr.Print("Hello, World!")
  25. stdscr.MovePrint(3, 0, "Press any key to continue")
  26. // Refresh() flushes output to the screen. Internally, it is the same as
  27. // calling NoutRefresh() on the window followed by a call to Update()
  28. stdscr.Refresh()
  29. // GetChar will block execution until an input event, like typing a
  30. // character on your keyboard, is received
  31. stdscr.GetChar()
  32. }