summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Haller <stefan@haller-berlin.de>2023-12-22 17:31:13 +0100
committerStefan Haller <stefan@haller-berlin.de>2024-01-14 17:45:35 +0100
commit99a3ccde71ceebcbf8045655ef604a1965e64a5a (patch)
treebb66b951db6d0bdfa84c82e94aec4105a234fcc8
parent8ca8a4396859559d818c2b5a51411da7d618ee70 (diff)
Add ErrorToast function
-rw-r--r--pkg/gui/controllers/helpers/app_status_helper.go14
-rw-r--r--pkg/gui/gui.go2
-rw-r--r--pkg/gui/popup/popup_handler.go12
-rw-r--r--pkg/gui/status/status_manager.go25
-rw-r--r--pkg/gui/test_mode.go3
-rw-r--r--pkg/gui/types/common.go10
6 files changed, 46 insertions, 20 deletions
diff --git a/pkg/gui/controllers/helpers/app_status_helper.go b/pkg/gui/controllers/helpers/app_status_helper.go
index 8e4741bd5..fd6bc247f 100644
--- a/pkg/gui/controllers/helpers/app_status_helper.go
+++ b/pkg/gui/controllers/helpers/app_status_helper.go
@@ -5,6 +5,7 @@ import (
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/gui/status"
+ "github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/utils"
)
@@ -23,7 +24,7 @@ func NewAppStatusHelper(c *HelperCommon, statusMgr func() *status.StatusManager,
}
}
-func (self *AppStatusHelper) Toast(message string) {
+func (self *AppStatusHelper) Toast(message string, kind types.ToastKind) {
if self.c.RunningIntegrationTest() {
// Don't bother showing toasts in integration tests. You can't check for
// them anyway, and they would only slow down the test unnecessarily by
@@ -31,7 +32,7 @@ func (self *AppStatusHelper) Toast(message string) {
return
}
- self.statusMgr().AddToastStatus(message)
+ self.statusMgr().AddToastStatus(message, kind)
self.renderAppStatus()
}
@@ -87,7 +88,8 @@ func (self *AppStatusHelper) HasStatus() bool {
}
func (self *AppStatusHelper) GetStatusString() string {
- return self.statusMgr().GetStatusString()
+ appStatus, _ := self.statusMgr().GetStatusString()
+ return appStatus
}
func (self *AppStatusHelper) renderAppStatus() {
@@ -95,7 +97,8 @@ func (self *AppStatusHelper) renderAppStatus() {
ticker := time.NewTicker(time.Millisecond * utils.LoaderAnimationInterval)
defer ticker.Stop()
for range ticker.C {
- appStatus := self.statusMgr().GetStatusString()
+ appStatus, color := self.statusMgr().GetStatusString()
+ self.c.Views().AppStatus.FgColor = color
self.c.OnUIThread(func() error {
self.c.SetViewContent(self.c.Views().AppStatus, appStatus)
return nil
@@ -127,7 +130,8 @@ func (self *AppStatusHelper) renderAppStatusSync(stop chan struct{}) {
for {
select {
case <-ticker.C:
- appStatus := self.statusMgr().GetStatusString()
+ appStatus, color := self.statusMgr().GetStatusString()
+ self.c.Views().AppStatus.FgColor = color
self.c.SetViewContent(self.c.Views().AppStatus, appStatus)
// Redraw all views of the bottom line:
bottomLineViews := []*gocui.View{
diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go
index 6eaa1b8db..6acdc804c 100644
--- a/pkg/gui/gui.go
+++ b/pkg/gui/gui.go
@@ -517,7 +517,7 @@ func NewGui(
func(message string, f func() error) {
gui.helpers.AppStatus.WithWaitingStatusSync(message, f)
},
- func(message string) { gui.helpers.AppStatus.Toast(message) },
+ func(message string, kind types.ToastKind) { gui.helpers.AppStatus.Toast(message, kind) },
func() string { return gui.Views.Confirmation.TextArea.GetContent() },
func() bool { return gui.c.InDemo() },
)
diff --git a/pkg/gui/popup/popup_handler.go b/pkg/gui/popup/popup_handler.go
index 82bf846e0..1eb81e800 100644
--- a/pkg/gui/popup/popup_handler.go
+++ b/pkg/gui/popup/popup_handler.go
@@ -22,7 +22,7 @@ type PopupHandler struct {
createMenuFn func(types.CreateMenuOptions) error
withWaitingStatusFn func(message string, f func(gocui.Task) error)
withWaitingStatusSyncFn func(message string, f func() error)
- toastFn func(message string)
+ toastFn func(message string, kind types.ToastKind)
getPromptInputFn func() string
inDemo func() bool
}
@@ -38,7 +38,7 @@ func NewPopupHandler(
createMenuFn func(types.CreateMenuOptions) error,
withWaitingStatusFn func(message string, f func(gocui.Task) error),
withWaitingStatusSyncFn func(message string, f func() error),
- toastFn func(message string),
+ toastFn func(message string, kind types.ToastKind),
getPromptInputFn func() string,
inDemo func() bool,
) *PopupHandler {
@@ -63,10 +63,14 @@ func (self *PopupHandler) Menu(opts types.CreateMenuOptions) error {
}
func (self *PopupHandler) Toast(message string) {
- self.toastFn(message)
+ self.toastFn(message, types.ToastKindStatus)
}
-func (self *PopupHandler) SetToastFunc(f func(string)) {
+func (self *PopupHandler) ErrorToast(message string) {
+ self.toastFn(message, types.ToastKindError)
+}
+
+func (self *PopupHandler) SetToastFunc(f func(string, types.ToastKind)) {
self.toastFn = f
}
diff --git a/pkg/gui/status/status_manager.go b/pkg/gui/status/status_manager.go
index da4f5f14c..f85036463 100644
--- a/pkg/gui/status/status_manager.go
+++ b/pkg/gui/status/status_manager.go
@@ -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...)
diff --git a/pkg/gui/test_mode.go b/pkg/gui/test_mode.go
index bc4436053..65009fb78 100644
--- a/pkg/gui/test_mode.go
+++ b/pkg/gui/test_mode.go
@@ -7,6 +7,7 @@ import (
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/gui/popup"
+ "github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/integration/components"
"github.com/jesseduffield/lazygit/pkg/utils"
)
@@ -35,7 +36,7 @@ func (gui *Gui) handleTestMode() {
toastChan := make(chan string, 100)
gui.PopupHandler.(*popup.PopupHandler).SetToastFunc(
- func(message string) { toastChan <- message })
+ func(message string, kind types.ToastKind) { toastChan <- message })
test.Run(&GuiDriver{gui: gui, isIdleChan: isIdleChan, toastChan: toastChan})
diff --git a/pkg/gui/types/common.go b/pkg/gui/types/common.go
index 6e16df6b0..afa4156c8 100644
--- a/pkg/gui/types/common.go
+++ b/pkg/gui/types/common.go
@@ -144,10 +144,18 @@ type IPopupHandler interface {
WithWaitingStatusSync(message string, f func() error) error
Menu(opts CreateMenuOptions) error
Toast(message string)
- SetToastFunc(func(string))
+ ErrorToast(message string)
+ SetToastFunc(func(string, ToastKind))
GetPromptInput() string
}
+type ToastKind int
+
+const (
+ ToastKindStatus ToastKind = iota
+ ToastKindError
+)
+
type CreateMenuOptions struct {
Title string
Items []*MenuItem