-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: clean up global task config handling
- Loading branch information
Showing
5 changed files
with
76 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package task | ||
|
||
import ( | ||
"github.com/charmbracelet/bubbles/key" | ||
tea "github.com/charmbracelet/bubbletea" | ||
"github.com/leg100/pug/internal/tui" | ||
"github.com/leg100/pug/internal/tui/keys" | ||
) | ||
|
||
// Config is global task configuration | ||
type Config struct { | ||
// disableAutoscroll disables auto-scrolling of task output. | ||
disableAutoscroll bool | ||
// showInfo shows further info about the task. | ||
showInfo bool | ||
} | ||
|
||
type ( | ||
// toggleAutoscrollMsg toggles whether task output is auto-scrolled. | ||
toggleAutoscrollMsg struct{} | ||
|
||
// toggleShowInfo toggles whether task info is shown. | ||
toggleShowInfo struct{} | ||
) | ||
|
||
// Update updates global configuration of tasks. | ||
func (c *Config) Update(msg tea.Msg) tea.Cmd { | ||
switch msg := msg.(type) { | ||
case tea.KeyMsg: | ||
switch { | ||
case key.Matches(msg, keys.Global.Autoscroll): | ||
c.disableAutoscroll = !c.disableAutoscroll | ||
|
||
// Inform user, and send out message to all cached task models to | ||
// toggle autoscroll. | ||
return tea.Batch( | ||
tui.CmdHandler(toggleAutoscrollMsg{}), | ||
tui.ReportInfo("Toggled autoscroll %s", boolToOnOff(!c.disableAutoscroll)), | ||
) | ||
case key.Matches(msg, localKeys.ToggleInfo): | ||
c.showInfo = !c.showInfo | ||
|
||
// Send out message to all cached task models to toggle task info | ||
return tui.CmdHandler(toggleShowInfo{}) | ||
} | ||
} | ||
return nil | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters