You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: watch.go
    path of file: ./repos/yao/cmd/sui
    
    the code of the file until where you have to start completion: package sui

import (
	"fmt"
	"io/fs"
	"os"
	"os/signal"
	"path/filepath"
	"strings"
	"sync"
	"syscall"

	"github.com/fatih/color"
	"github.com/fsnotif
    
func watch(root string, handler func(event string, name string), interrupt chan uint8) error {
	watcher, err := fsnotify.NewWatcher()
	if err != nil {
		return err
	}
	defer watcher.Close()
	shutdown := make(chan bool, 1)

	err = filepath.Walk(root, func(path string, info fs.FileInfo, err error) error {
		if info.IsDir() {
			if filepath.Base(path) == ".tmp" {
				return filepath.SkipDir
			}

			err = watcher.Add(path)
			if err != nil {
				return err
			}
			log.Info("[Watch] Watching: %s", strings.TrimPrefix(path, root))
			watched.Store(path, true)
		}
		return nil
	})

	if err != nil {
		return err
	}

	go func() {
		for {
			select {
			case <-shutdown:
				log.Info("[Watch] handler exit")
				return

			case event, ok := <-watcher.Events:
				if !ok {
					interrupt <- 1
					return
				}

				basname := filepath.Base(event.Name)
				isdir := true
				if strings.Contains(basname, ".") {
					isdir = false
				}

				events := strings.Split(event.Op.String(), "|")
				for _, eventType := range events {
					// ADD / REMOVE Watching dir
					if isdir {
						switch eventType {
						case "CREATE":
							log.Info("[Watch] Watching: %s", strings.TrimPrefix(event.Name, root))
							watcher.Add(event.Name)
							watched.Store(event.Name, true)
							break

						case "REMOVE":
							log.Info("[Watch] Unwatching: %s", strings.TrimPrefix(event.Name, root))
							watcher.Remove(event.Name)
							watched.Delete(event.Name)
							break
						}
						continue
					}

					file := strings.TrimLeft(event.Name, root)
					handler(eventType, file)
					log.Info("[Watch] %s %s", eventType, file)
				}

				break

			case err, ok := <-watcher.Errors:
				if !ok {
					interrupt <- 2
					return
				}
				log.Error("[Watch] Error: %s", err.Error())
				break
			}
		}
	}()

	for {
		select {
		case code := <-interrupt:
			shutdown <- true
			log.Info("[Watch] Exit(%d)", code)
			fmt.Println(color.YellowString("[Watch] Exit(%d)", code))
			return nil
		}
	}

}