Skip to content

Commit

Permalink
add keyboard shortcut for copying share string
Browse files Browse the repository at this point in the history
  • Loading branch information
jozsefsallai committed Feb 17, 2022
1 parent 08e203d commit 06cccf8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (ls LetterState) String() string {
case LetterStateContainedMatch:
return "🟨"
case LetterStateNoMatch:
return "⬜"
return "🔳" // fix console display in certain fonts
default:
return ""
}
Expand Down
4 changes: 2 additions & 2 deletions game/blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (m *AppModel) renderStatisticsBlock() string {
output = append(output, m.getDistributionProgressBar(maxDistribution, i))
}

output = append(output, "\n\nPress ← to view game summary.\nPress Ctrl+C to exit.")
output = append(output, "\n\nPress ← to view game summary.\nPress Ctrl+S to copy the share string.\nPress Ctrl+C to exit.")

statistics := lipgloss.JoinVertical(lipgloss.Left, output...)

Expand All @@ -132,7 +132,7 @@ func (m *AppModel) renderFinalMessageBlock() string {
message += "Press Ctrl+N to start a new game.\n"
}

message += "Press Ctrl+C to exit."
message += "Press Ctrl+S to copy the share string.\nPress Ctrl+C to exit."

return lipgloss.NewStyle().
Padding(1, 2).
Expand Down
7 changes: 3 additions & 4 deletions game/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"pkg.nimblebun.works/clipboard"
"pkg.nimblebun.works/wordle-cli/common"
"pkg.nimblebun.works/wordle-cli/common/save"
)
Expand Down Expand Up @@ -84,9 +83,7 @@ func (m *AppModel) View() string {
grid := m.renderGrid()

if m.GameState != common.GameStateRunning {
if m.NewGame {
_ = clipboard.WriteAll(m.getShareString())
}
m.copyShareString(true)

var finalBlock string

Expand Down Expand Up @@ -121,6 +118,8 @@ func (m *AppModel) handleKeyDown(t tea.KeyType, r []rune) (tea.Model, tea.Cmd) {
return m, m.displayGameSummary()
case tea.KeyCtrlN:
return m, m.new()
case tea.KeyCtrlS:
return m, m.copyShareString(false)
case tea.KeyRunes:
if len(r) != 1 {
return m, nil
Expand Down
16 changes: 16 additions & 0 deletions game/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"unicode"

tea "github.com/charmbracelet/bubbletea"
"pkg.nimblebun.works/clipboard"
"pkg.nimblebun.works/wordle-cli/common"
"pkg.nimblebun.works/wordle-cli/common/save"
"pkg.nimblebun.works/wordle-cli/words"
Expand Down Expand Up @@ -224,6 +225,21 @@ func (m *AppModel) getShareString() string {
return strings.Join(rows, "\n")
}

func (m *AppModel) copyShareString(automatic bool) tea.Cmd {
if m.GameState == common.GameStateRunning {
return nil
}

if automatic && !m.NewGame {
return nil
}

str := strings.ReplaceAll(m.getShareString(), "🔳", "⬜")
_ = clipboard.WriteAll(str)

return nil
}

func (m *AppModel) save() {
m.SaveData.LastGameID = m.ID
m.SaveData.LastGameGrid = m.Grid
Expand Down

0 comments on commit 06cccf8

Please sign in to comment.