mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-29 23:17:32 +02:00
Extract WaitingStatusHandle
This commit is contained in:
parent
05c32e292e
commit
c222a618a8
@ -36,9 +36,7 @@ func (self *AppStatusHelper) Toast(message string) {
|
||||
// withWaitingStatus wraps a function and shows a waiting status while the function is still executing
|
||||
func (self *AppStatusHelper) WithWaitingStatus(message string, f func(gocui.Task) error) {
|
||||
self.c.OnWorker(func(task gocui.Task) {
|
||||
self.statusMgr().WithWaitingStatus(message, func() {
|
||||
self.renderAppStatus()
|
||||
|
||||
self.statusMgr().WithWaitingStatus(message, self.renderAppStatus, func() {
|
||||
if err := f(task); err != nil {
|
||||
self.c.OnUIThread(func() error {
|
||||
return self.c.Error(err)
|
||||
|
@ -16,6 +16,24 @@ type StatusManager struct {
|
||||
mutex deadlock.Mutex
|
||||
}
|
||||
|
||||
// Can be used to manipulate a waiting status while it is running (e.g. pause
|
||||
// and resume it)
|
||||
type WaitingStatusHandle struct {
|
||||
statusManager *StatusManager
|
||||
message string
|
||||
renderFunc func()
|
||||
id int
|
||||
}
|
||||
|
||||
func (self *WaitingStatusHandle) Show() {
|
||||
self.id = self.statusManager.addStatus(self.message, "waiting")
|
||||
self.renderFunc()
|
||||
}
|
||||
|
||||
func (self *WaitingStatusHandle) Hide() {
|
||||
self.statusManager.removeStatus(self.id)
|
||||
}
|
||||
|
||||
type appStatus struct {
|
||||
message string
|
||||
statusType string
|
||||
@ -26,12 +44,13 @@ func NewStatusManager() *StatusManager {
|
||||
return &StatusManager{}
|
||||
}
|
||||
|
||||
func (self *StatusManager) WithWaitingStatus(message string, f func()) {
|
||||
id := self.addStatus(message, "waiting")
|
||||
func (self *StatusManager) WithWaitingStatus(message string, renderFunc func(), f func()) {
|
||||
handle := &WaitingStatusHandle{statusManager: self, message: message, renderFunc: renderFunc, id: -1}
|
||||
handle.Show()
|
||||
|
||||
f()
|
||||
|
||||
self.removeStatus(id)
|
||||
handle.Hide()
|
||||
}
|
||||
|
||||
func (self *StatusManager) AddToastStatus(message string) int {
|
||||
|
Loading…
x
Reference in New Issue
Block a user