termbox_common.go 994 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package termbox
  2. // private API, common OS agnostic part
  3. type cellbuf struct {
  4. width int
  5. height int
  6. cells []Cell
  7. }
  8. func (this *cellbuf) init(width, height int) {
  9. this.width = width
  10. this.height = height
  11. this.cells = make([]Cell, width*height)
  12. }
  13. func (this *cellbuf) resize(width, height int) {
  14. if this.width == width && this.height == height {
  15. return
  16. }
  17. oldw := this.width
  18. oldh := this.height
  19. oldcells := this.cells
  20. this.init(width, height)
  21. this.clear()
  22. minw, minh := oldw, oldh
  23. if width < minw {
  24. minw = width
  25. }
  26. if height < minh {
  27. minh = height
  28. }
  29. for i := 0; i < minh; i++ {
  30. srco, dsto := i*oldw, i*width
  31. src := oldcells[srco : srco+minw]
  32. dst := this.cells[dsto : dsto+minw]
  33. copy(dst, src)
  34. }
  35. }
  36. func (this *cellbuf) clear() {
  37. for i := range this.cells {
  38. c := &this.cells[i]
  39. c.Ch = ' '
  40. c.Fg = foreground
  41. c.Bg = background
  42. }
  43. }
  44. const cursor_hidden = -1
  45. func is_cursor_hidden(x, y int) bool {
  46. return x == cursor_hidden || y == cursor_hidden
  47. }