func loadDraw(w *draw.Window, statusCh chan string) { var buffer bytes.Buffer buffer.WriteString("~/.pwm/database") statusCh <- fmt.Sprintf("Choose a Filename: %s", buffer.String()) cb := make(chan string) go func() { for { buf, ok := <-cb if !ok { break } statusCh <- fmt.Sprintf("Choose a Filename: %s", buf) } }() draw.GetString(&buffer, cb) defer func() { if r := recover(); r != nil { switch r.(type) { case *os.PathError: statusCh <- fmt.Sprintf("No such file: %s", buffer.String()) default: statusCh <- fmt.Sprintf("Could not load database: %s", buffer.String()) } } }() root := LoadFile(buffer.String()) ScreenList["Database"] = Database(w, root, statusCh) }
func defDraw(w *draw.Window, statusCh chan string) { var buffer bytes.Buffer dir, err := filepath.Abs(filepath.Dir(os.Args[0])) if err != nil { panic(err) } buffer.WriteString(dir) statusCh <- fmt.Sprintf("Choose a Filename: %s", buffer.String()) cb := make(chan string) go func() { for { buf, ok := <-cb if !ok { break } statusCh <- fmt.Sprintf("Choose a Filename: %s", buf) } }() draw.GetString(&buffer, cb) statusCh <- fmt.Sprintf("Final String: %s", buffer.String()) }