func NewStatusbarWidget(x, y, w int, hideGuids bool, g *gocui.Gui) *StatusbarWidget {
	widget := &StatusbarWidget{
		name:      "statusBarWidget",
		x:         x,
		y:         y,
		w:         w,
		hideGuids: hideGuids,
		messages:  map[string]eventing.StatusEvent{},
	}

	widget.currentMessage = &eventing.StatusEvent{}

	newEvents := eventing.SubscribeToStatusEvents()
	// Start loop for showing loading in statusbar
	go func() {
		for {
			// Wait for a second to see if we have any new messages
			timeout := time.After(time.Second)
			select {
			case eventObj := <-newEvents:
				// See if we have any new events
				event := eventObj.(eventing.StatusEvent)
				widget.messages[event.ID()] = event
				// Favor the most recent message
				widget.currentMessage = &event
			case <-timeout:
				// Update the UI
				continue
			}

			for _, message := range widget.messages {
				// Remove any that have now expired
				if message.HasExpired() {
					delete(widget.messages, message.ID())
					continue
				}
			}

			// Set the current message to a non-expired message favor in-progress messages
			if !widget.currentMessage.HasExpired() || !widget.currentMessage.InProgress {
				foundInProgress := false
				for _, message := range widget.messages {
					if message.InProgress {
						foundInProgress = true
						widget.currentMessage = &message
						break
					}
				}

				if !foundInProgress {
					for _, message := range widget.messages {
						widget.currentMessage = &message
						break
					}
				}
			}

			g.Update(func(gui *gocui.Gui) error {
				if widget.currentMessage.InProgress {
					widget.messageAddition = widget.messageAddition + "."
				} else {
					widget.messageAddition = ""
				}
				return nil
			})

			time.Sleep(time.Second)

		}
	}()
	return widget
}
// NewStatusbarWidget create new instance and start go routine for spinner
NewStatusbarWidget create new instance and start go routine for spinner
// NewStatusbarWidget create new instance and start go routine for spinner
func NewStatusbarWidget(x, y, w int, hideGuids bool, g *gocui.Gui) *StatusbarWidget {
	widget := &StatusbarWidget{
		name:      "statusBarWidget",
		x:         x,
		y:         y,
		w:         w,
		hideGuids: hideGuids,
		messages:  map[string]eventing.StatusEvent{},
	}
	widget.currentMessage = &eventing.StatusEvent{}
	newEvents := eventing.SubscribeToStatusEvents()
	go func() {
		for {
			timeout := time.After(time.Second)
			select {
			case eventObj := <-newEvents:
				event := eventObj.(eventing.StatusEvent)
				widget.messages[event.ID()] = event
				widget.currentMessage = &event
			case <-timeout:
				continue
			}
			for _, message := range widget.messages {
				if message.HasExpired() {
					delete(widget.messages, message.ID())
					continue
				}
			}
			if !widget.currentMessage.HasExpired() || !widget.currentMessage.InProgress {
				foundInProgress := false
				for _, message := range widget.messages {
					if message.InProgress {
						foundInProgress = true
						widget.currentMessage = &message
						break
					}
				}
				if !foundInProgress {
					for _, message := range widget.messages {
						widget.currentMessage = &message
						break
					}
				}
			}
			g.Update(func(gui *gocui.Gui) error {
				if widget.currentMessage.InProgress {
					widget.messageAddition = widget.messageAddition + "."
				} else {
					widget.messageAddition = ""
				}
				return nil
			})
			time.Sleep(time.Second)
		}
	}()
	return widget
}
func NewStatusbarWidget ( x , y , w int , hideGuids bool , g * gocui . Gui ) * StatusbarWidget { widget := & StatusbarWidget { name : " " , x : x , y : y , w : w , hideGuids : hideGuids , messages : map [ string ] eventing . StatusEvent { } , } widget . currentMessage = & eventing . StatusEvent { } newEvents := eventing . SubscribeToStatusEvents ( ) go func ( ) { for { timeout := time . After ( time . Second ) select { case eventObj := <- newEvents : event := eventObj . ( eventing . StatusEvent ) widget . messages [ event . ID ( ) ] = event widget . currentMessage = & event case <- timeout : continue } for _ , message := range widget . messages { if message . HasExpired ( ) { delete ( widget . messages , message . ID ( ) ) continue } } if ! widget . currentMessage . HasExpired ( ) || ! widget . currentMessage . InProgress { foundInProgress := false for _ , message := range widget . messages { if message . InProgress { foundInProgress = true widget . currentMessage = & message break } } if ! foundInProgress { for _ , message := range widget . messages { widget . currentMessage = & message break } } } g . Update ( func ( gui * gocui . Gui ) error { if widget . currentMessage . InProgress { widget . messageAddition = widget . messageAddition + " " } else { widget . messageAddition = " " } return nil } ) time . Sleep ( time . Second ) } } ( ) return widget }
NewStatusbarWidget create new instance and start go routine for spinner
NewStatusbarWidget create new instance and start go routine for spinner
// Start loop for showing loading in statusbar // Wait for a second to see if we have any new messages // See if we have any new events // Favor the most recent message // Update the UI // Remove any that have now expired // Set the current message to a non-expired message favor in-progress messages