Skip to content

Commit

Permalink
add back hotkey
Browse files Browse the repository at this point in the history
  • Loading branch information
mortum5 committed May 3, 2024
1 parent 6814484 commit 2916359
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 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.Msg) (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
22 changes: 14 additions & 8 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

parentCallback Callback

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 Callback func(tea.Msg) (tea.Model, tea.Cmd)

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

Expand Down Expand Up @@ -66,12 +70,13 @@ func New(c challenge.Challenge, width, height int) (tea.Model, tea.Cmd) {
Width: width,
Height: height,
},
l: l,
challengeName: c.Name,
questions: c.Questions,
question: newQuestionModel(c.Questions[0], len(c.Questions) == 1),
learn: newLearn(c.LearningAdvise, c.LearningLinks),
help: helpModel,
l: l,
challengeName: c.Name,
questions: c.Questions,
question: newQuestionModel(c.Questions[0], len(c.Questions) == 1),
learn: newLearn(c.LearningAdvise, c.LearningLinks),
parentCallback: callback,
help: helpModel,
}

return m.updateListSize(), cmd
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.parentCallback(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 2916359

Please sign in to comment.