Implement String method on some enum types for easier debugging

This commit is contained in:
Christian Rocha 2021-03-01 15:49:47 -05:00
parent 08a8d4b5ed
commit 851d21f6c4

View file

@ -64,6 +64,14 @@ const (
stashStateShowingError
)
func (s stashViewState) String() string {
return map[stashViewState]string{
stashStateReady: "ready",
stashStateLoadingDocument: "loading document",
stashStateShowingError: "showing error",
}[s]
}
// The types of documents we are currently showing to the user.
type sectionKey int
@ -74,6 +82,15 @@ const (
filterSection
)
func (s sectionKey) String() string {
return map[sectionKey]string{
localSection: "local",
stashedSection: "stashed",
newsSection: "news",
filterSection: "filtered",
}[s]
}
// section contains definitions and state information for displaying a tab and
// its contents in the file listing view.
type section struct {
@ -116,6 +133,14 @@ const (
filterApplied // a filter is applied and user is not editing filter
)
func (f filterState) String() string {
return map[filterState]string{
unfiltered: "unfiltered",
filtering: "filtering",
filterApplied: "filter applied",
}[f]
}
// selectionState is the state of the currently selected document.
type selectionState int
@ -125,6 +150,14 @@ const (
selectionPromptingDelete
)
func (s selectionState) String() string {
return map[selectionState]string{
selectionIdle: "idle",
selectionSettingNote: "setting note",
selectionPromptingDelete: "prompting for deletion",
}[s]
}
// statusMessageType adds some context to the status message being sent.
type statusMessageType int
@ -135,6 +168,14 @@ const (
errorStatusMessage
)
func (s statusMessageType) String() string {
return map[statusMessageType]string{
normalStatusMessage: "normal",
subtleStatusMessage: "subtle",
errorStatusMessage: "error",
}[s]
}
// statusMessage is an ephemeral note displayed in the UI.
type statusMessage struct {
status statusMessageType