Skip to content

Commit

Permalink
Add back key
Browse files Browse the repository at this point in the history
  • Loading branch information
mortum5 committed May 3, 2024
1 parent 6814484 commit 8f0a0ac
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
3 changes: 3 additions & 0 deletions choose/choose.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ func (c choose) Update(msg tea.Msg) (m tea.Model, cmd tea.Cmd) {
challenge.Challenge(c.list.SelectedItem().(item)),
c.list.Width()+listStyle.GetHorizontalFrameSize(),
c.list.Height()+listStyle.GetVerticalFrameSize(),
func(msg tea.WindowSizeMsg) (m tea.Model, cmd tea.Cmd) {
return c.Update(msg)
},
)
}
}
Expand Down
3 changes: 3 additions & 0 deletions play/bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type keyBindings struct {
Right key.Binding
Input key.Binding
Next key.Binding
Back key.Binding
Help key.Binding
Learn key.Binding
CloseLearn key.Binding
Expand All @@ -25,6 +26,7 @@ func (k keyBindings) FullHelp() [][]key.Binding {
return [][]key.Binding{
{k.Left, k.Right, k.Up, k.Down, k.Input, k.Next},
{
k.Back,
copyKey(k.Help, "close bindings help"),
k.Learn,
k.CloseLearn,
Expand All @@ -42,6 +44,7 @@ func newBindings() keyBindings {
Right: key.NewBinding(key.WithKeys("right", "d"), key.WithHelp("→/d", "right answer")),
Input: key.NewBinding(key.WithKeys("enter", " ", "f"), key.WithHelp("⮐ / /f", "select answer/open link")),
Next: key.NewBinding(key.WithKeys("n"), key.WithHelp("N", "next answer")),
Back: key.NewBinding(key.WithKeys("backspace", "b"), key.WithHelp("⌫/b", "return to challenge list")),
Help: key.NewBinding(key.WithKeys("h", "?"), key.WithHelp("h/?", "see key bindings")),
Learn: learnB,
CloseLearn: copyDisabled(learnB, "close learn info"),
Expand Down
10 changes: 8 additions & 2 deletions play/play.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,17 @@ type model struct {
question questionModel
learn learn

backHandler BackHandler

help help.Model
}

const copyStatus = "Code has copied to clipboard"
const copyErrStatus = "Code has not copied. Please install xsel, xclip, wl-clipboard or Termux:API"

func New(c challenge.Challenge, width, height int) (tea.Model, tea.Cmd) {
type BackHandler func(tea.WindowSizeMsg) (tea.Model, tea.Cmd)

func New(c challenge.Challenge, width, height int, backHandler BackHandler) (tea.Model, tea.Cmd) {
// normalize line endings
codeLines := lines(c.DefaultCodeSnippet)

Expand Down Expand Up @@ -71,6 +75,7 @@ func New(c challenge.Challenge, width, height int) (tea.Model, tea.Cmd) {
questions: c.Questions,
question: newQuestionModel(c.Questions[0], len(c.Questions) == 1),
learn: newLearn(c.LearningAdvise, c.LearningLinks),
backHandler: backHandler,
help: helpModel,
}

Expand Down Expand Up @@ -140,7 +145,8 @@ func (m model) Update(msg tea.Msg) (r tea.Model, cmd tea.Cmd) {
m.currentQuestion == len(m.questions)-1,
)
}

case key.Matches(msg, m.b.Back):
return m.backHandler(m.w)
case key.Matches(msg, m.b.Help):
m.help.ShowAll = !m.help.ShowAll
case key.Matches(msg, m.b.Quit):
Expand Down

0 comments on commit 8f0a0ac

Please sign in to comment.