From eaec27d1df2ff4009c8a0dd81550ae071cd50292 Mon Sep 17 00:00:00 2001
From: Caleb Bassi <calebjbassi@gmail.com>
Date: Thu, 7 Mar 2019 02:00:36 -0800
Subject: [PATCH] Add sync.Locker interface to Drawable interface

Many widget implementations will want to update asynchronously, so now termui performs locks a widget when drawing. Users should call `Lock()` on their widgets when performing an asynchronous update.
---
 CHANGELOG.md | 6 ++++++
 block.go     | 3 +++
 grid.go      | 2 ++
 render.go    | 4 ++++
 4 files changed, 15 insertions(+)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index a3fdc3b..dc0c555 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ## [Unreleased]
 
+## 2019/03/07
+
+### Changed
+
+- Added sync.Locker interface to Drawable interface
+
 ## 2019/03/01
 
 ### Changed
diff --git a/block.go b/block.go
index f030d88..a032326 100644
--- a/block.go
+++ b/block.go
@@ -6,6 +6,7 @@ package termui
 
 import (
 	"image"
+	"sync"
 )
 
 // Block is the base struct inherited by most widgets.
@@ -25,6 +26,8 @@ type Block struct {
 
 	Title      string
 	TitleStyle Style
+
+	sync.Mutex
 }
 
 func NewBlock() *Block {
diff --git a/grid.go b/grid.go
index b3a6af2..02fb8b3 100644
--- a/grid.go
+++ b/grid.go
@@ -153,6 +153,8 @@ func (self *Grid) Draw(buf *Buffer) {
 
 		entry.SetRect(x, y, x+w, y+h)
 
+		entry.Lock()
 		entry.Draw(buf)
+		entry.Unlock()
 	}
 }
diff --git a/render.go b/render.go
index 88fbbdc..74c0ec8 100644
--- a/render.go
+++ b/render.go
@@ -6,6 +6,7 @@ package termui
 
 import (
 	"image"
+	"sync"
 
 	tb "github.com/nsf/termbox-go"
 )
@@ -14,12 +15,15 @@ type Drawable interface {
 	GetRect() image.Rectangle
 	SetRect(int, int, int, int)
 	Draw(*Buffer)
+	sync.Locker
 }
 
 func Render(items ...Drawable) {
 	for _, item := range items {
 		buf := NewBuffer(item.GetRect())
+		item.Lock()
 		item.Draw(buf)
+		item.Unlock()
 		for point, cell := range buf.CellMap {
 			if point.In(buf.Rectangle) {
 				tb.SetCell(