1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-08-09 09:22:48 +03:00

Add ErrorToast function

This commit is contained in:
Stefan Haller
2023-12-22 17:31:13 +01:00
parent 8ca8a43968
commit 99a3ccde71
6 changed files with 46 additions and 20 deletions

View File

@@ -3,6 +3,8 @@ package status
import (
"time"
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/utils"
"github.com/samber/lo"
"github.com/sasha-s/go-deadlock"
@@ -26,7 +28,7 @@ type WaitingStatusHandle struct {
}
func (self *WaitingStatusHandle) Show() {
self.id = self.statusManager.addStatus(self.message, "waiting")
self.id = self.statusManager.addStatus(self.message, "waiting", types.ToastKindStatus)
self.renderFunc()
}
@@ -37,6 +39,7 @@ func (self *WaitingStatusHandle) Hide() {
type appStatus struct {
message string
statusType string
color gocui.Attribute
id int
}
@@ -53,8 +56,8 @@ func (self *StatusManager) WithWaitingStatus(message string, renderFunc func(),
handle.Hide()
}
func (self *StatusManager) AddToastStatus(message string) int {
id := self.addStatus(message, "toast")
func (self *StatusManager) AddToastStatus(message string, kind types.ToastKind) int {
id := self.addStatus(message, "toast", kind)
go func() {
time.Sleep(time.Second * 2)
@@ -65,31 +68,37 @@ func (self *StatusManager) AddToastStatus(message string) int {
return id
}
func (self *StatusManager) GetStatusString() string {
func (self *StatusManager) GetStatusString() (string, gocui.Attribute) {
if len(self.statuses) == 0 {
return ""
return "", gocui.ColorDefault
}
topStatus := self.statuses[0]
if topStatus.statusType == "waiting" {
return topStatus.message + " " + utils.Loader(time.Now())
return topStatus.message + " " + utils.Loader(time.Now()), topStatus.color
}
return topStatus.message
return topStatus.message, topStatus.color
}
func (self *StatusManager) HasStatus() bool {
return len(self.statuses) > 0
}
func (self *StatusManager) addStatus(message string, statusType string) int {
func (self *StatusManager) addStatus(message string, statusType string, kind types.ToastKind) int {
self.mutex.Lock()
defer self.mutex.Unlock()
self.nextId++
id := self.nextId
color := gocui.ColorCyan
if kind == types.ToastKindError {
color = gocui.ColorRed
}
newStatus := appStatus{
message: message,
statusType: statusType,
color: color,
id: id,
}
self.statuses = append([]appStatus{newStatus}, self.statuses...)