-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial Narrative / Track Explanation support
You can now press 'E' to ask pandora why it selected the currently playing track. Fixes #18
- Loading branch information
Showing
11 changed files
with
306 additions
and
9 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,82 @@ | ||
package ui | ||
|
||
import ( | ||
"github.com/gdamore/tcell" | ||
"github.com/nlowe/mousiki/mousiki" | ||
"github.com/sirupsen/logrus" | ||
"gitlab.com/tslocum/cview" | ||
) | ||
|
||
const narrativePopupPageName = "narrativePopup" | ||
|
||
type narrativePopup struct { | ||
*CenteredModal | ||
root *cview.TextView | ||
|
||
cancelFunc func() | ||
|
||
controller *mousiki.StationController | ||
pager *cview.Pages | ||
|
||
log logrus.FieldLogger | ||
} | ||
|
||
func NewNarrativePopupForPager(cancelFunc func(), pager *cview.Pages, controller *mousiki.StationController) *narrativePopup { | ||
result := &narrativePopup{ | ||
root: cview.NewTextView(), | ||
cancelFunc: cancelFunc, | ||
controller: controller, | ||
pager: pager, | ||
log: logrus.WithField("prefix", narrativePopupPageName), | ||
} | ||
|
||
result.root.SetWrap(true). | ||
SetWordWrap(true). | ||
SetTitle("Explanation"). | ||
SetBorder(true). | ||
SetBorderPadding(1, 1, 1, 1) | ||
|
||
result.CenteredModal = NewCenteredModal(result.root) | ||
|
||
pager.AddPage(narrativePopupPageName, result, true, false) | ||
return result | ||
} | ||
|
||
func (n *narrativePopup) Open() { | ||
if page, _ := n.pager.GetFrontPage(); page == narrativePopupPageName { | ||
return | ||
} | ||
|
||
if n.controller.NowPlaying() == nil { | ||
n.log.Debug("No Track is playing") | ||
return | ||
} | ||
|
||
n.log.Info("Fetching Track Narrative") | ||
narrative, err := n.controller.ExplainCurrentTrack() | ||
if err != nil { | ||
n.log.WithError(err).Errorf("Failed to explain current track") | ||
return | ||
} | ||
|
||
n.root.SetText(narrative.Paragraph) | ||
n.pager.ShowPage(narrativePopupPageName) | ||
} | ||
|
||
func (n *narrativePopup) Close() { | ||
if page, _ := n.pager.GetFrontPage(); page != narrativePopupPageName { | ||
return | ||
} | ||
|
||
n.pager.HidePage(narrativePopupPageName) | ||
} | ||
|
||
func (n *narrativePopup) HandleKey(ev *tcell.EventKey) *tcell.EventKey { | ||
if ev.Key() == tcell.KeyEscape || (ev.Key() == tcell.KeyRune && ev.Rune() == 'e') { | ||
n.Close() | ||
|
||
return nil | ||
} | ||
|
||
return ev | ||
} |
Oops, something went wrong.