Initial commit
This commit is contained in:
commit
0b0cce5a74
9 changed files with 269 additions and 0 deletions
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
.idea/
|
||||
*.sh
|
||||
crib
|
20
.gitlab-ci.yml
Normal file
20
.gitlab-ci.yml
Normal file
|
@ -0,0 +1,20 @@
|
|||
image: golang:latest
|
||||
|
||||
stages:
|
||||
- validate
|
||||
|
||||
fmt:
|
||||
stage: validate
|
||||
script:
|
||||
- gofmt -l -s -e .
|
||||
- exit $(gofmt -l -s -e . | wc -l)
|
||||
|
||||
vet:
|
||||
stage: validate
|
||||
script:
|
||||
- go vet -composites=false ./...
|
||||
|
||||
test:
|
||||
stage: validate
|
||||
script:
|
||||
- go test -race -v ./...
|
2
CHANGELOG
Normal file
2
CHANGELOG
Normal file
|
@ -0,0 +1,2 @@
|
|||
0.1.0:
|
||||
- Initial release
|
21
LICENSE
Normal file
21
LICENSE
Normal file
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2020 Trevor Slocum <trevor@rocketnine.space>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
9
README.md
Normal file
9
README.md
Normal file
|
@ -0,0 +1,9 @@
|
|||
# crib
|
||||
[![CI status](https://gitlab.com/tslocum/crib/badges/master/pipeline.svg)](https://gitlab.com/tslocum/crib/commits/master)
|
||||
[![Donate](https://img.shields.io/liberapay/receives/rocketnine.space.svg?logo=liberapay)](https://liberapay.com/rocketnine.space)
|
||||
|
||||
[Cribbage.World](https://cribbage.world) terminal client
|
||||
|
||||
## Support
|
||||
|
||||
Please share issues and suggestions [here](https://gitlab.com/tslocum/crib/issues).
|
9
go.mod
Normal file
9
go.mod
Normal file
|
@ -0,0 +1,9 @@
|
|||
module gitlab.com/tslocum/crib
|
||||
|
||||
go 1.14
|
||||
|
||||
require (
|
||||
github.com/gdamore/tcell v1.3.0
|
||||
gitlab.com/tslocum/cview v1.4.6
|
||||
gitlab.com/tslocum/joker v0.1.3
|
||||
)
|
28
go.sum
Normal file
28
go.sum
Normal file
|
@ -0,0 +1,28 @@
|
|||
github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
|
||||
github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko=
|
||||
github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg=
|
||||
github.com/gdamore/tcell v1.3.0 h1:r35w0JBADPZCVQijYebl6YMWWtHRqVEGt7kL2eBADRM=
|
||||
github.com/gdamore/tcell v1.3.0/go.mod h1:Hjvr+Ofd+gLglo7RYKxxnzCBmev3BzsS67MebKS4zMM=
|
||||
github.com/lucasb-eyer/go-colorful v1.0.2/go.mod h1:0MS4r+7BZKSJ5mw4/S5MPN+qHFF1fYclkSPilDOKW0s=
|
||||
github.com/lucasb-eyer/go-colorful v1.0.3 h1:QIbQXiugsb+q10B+MI+7DI1oQLdmnep86tWFlaaUAac=
|
||||
github.com/lucasb-eyer/go-colorful v1.0.3/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
||||
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
|
||||
github.com/mattn/go-runewidth v0.0.8/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
|
||||
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||
github.com/rivo/uniseg v0.1.0 h1:+2KBaVoUmb9XzDsrx/Ct0W/EYOSFf/nWTauy++DprtY=
|
||||
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
gitlab.com/tslocum/cbind v0.1.1 h1:JXXtxMWHgWLvoF+QkrvcNvOQ59juy7OE1RhT7hZfdt0=
|
||||
gitlab.com/tslocum/cbind v0.1.1/go.mod h1:rX7vkl0pUSg/yy427MmD1FZAf99S7WwpUlxF/qTpPqk=
|
||||
gitlab.com/tslocum/cview v1.4.6 h1:dEM/aOsatoaNZOZ511n8hhZABPzTunUdi0RpUw9uXjM=
|
||||
gitlab.com/tslocum/cview v1.4.6/go.mod h1:PW2Ucec7oTYOfK4N+hqm/CKEN9B1PBidq5YJ3ZaeknU=
|
||||
gitlab.com/tslocum/joker v0.1.3 h1:6AVQuc0Rt7LczppZKaAXfr5B5Yg/4sQky2SFaWaF9E4=
|
||||
gitlab.com/tslocum/joker v0.1.3/go.mod h1:bxTQ0FFmBP465r9z76zcm97S4Ld9eCLa3q20TyVM82A=
|
||||
golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9 h1:YTzHMGlqJu67/uEo1lBv0n3wBXhXNeUbB1XfN2vmTm0=
|
||||
golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
58
main.go
Normal file
58
main.go
Normal file
|
@ -0,0 +1,58 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"gitlab.com/tslocum/crib/pkg/render"
|
||||
"gitlab.com/tslocum/cview"
|
||||
"gitlab.com/tslocum/joker"
|
||||
)
|
||||
|
||||
var (
|
||||
app *cview.Application
|
||||
exit = make(chan bool)
|
||||
)
|
||||
|
||||
func main() {
|
||||
app = cview.NewApplication().EnableMouse(true)
|
||||
|
||||
g := cview.NewGrid()
|
||||
|
||||
mainBuf := cview.NewTextView()
|
||||
mainBuf.SetDynamicColors(true)
|
||||
|
||||
cards := joker.Cards{{joker.FaceAce, joker.SuitSpades}, {joker.Face2, joker.SuitSpades}, {joker.Face3, joker.SuitSpades}, {joker.Face10, joker.SuitHearts}}
|
||||
mainBuf.Write(render.Cards(cards, 13, 11, 6))
|
||||
|
||||
b := cview.NewButton("test")
|
||||
|
||||
b.SetSelectedFunc(func() {
|
||||
panic("clicked")
|
||||
})
|
||||
|
||||
g2 := cview.NewGrid()
|
||||
|
||||
b2 := cview.NewButton("test2")
|
||||
|
||||
b2.SetSelectedFunc(func() {
|
||||
panic("clicked")
|
||||
})
|
||||
|
||||
g2.AddItem(b2, 0, 0, 1, 1, 0, 0, false)
|
||||
|
||||
g.AddItem(mainBuf, 0, 0, 1, 1, 0, 0, false)
|
||||
g.AddItem(b, 1, 0, 1, 1, 0, 0, false)
|
||||
g.AddItem(g2, 2, 0, 1, 1, 0, 0, false)
|
||||
|
||||
app.SetRoot(g, true)
|
||||
|
||||
go func() {
|
||||
if err := app.Run(); err != nil {
|
||||
log.Fatalf("failed to run application: %s", err)
|
||||
}
|
||||
|
||||
exit <- true
|
||||
}()
|
||||
|
||||
<-exit
|
||||
}
|
119
pkg/render/card.go
Normal file
119
pkg/render/card.go
Normal file
|
@ -0,0 +1,119 @@
|
|||
package render
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"strconv"
|
||||
|
||||
"gitlab.com/tslocum/joker"
|
||||
"github.com/gdamore/tcell"
|
||||
)
|
||||
|
||||
// TODO Draw large symbol in center
|
||||
func Cards(cards joker.Cards, w int, h int, f int) []byte {
|
||||
if len(cards) == 0 {
|
||||
return []byte{}
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
var n int
|
||||
|
||||
for i := range cards {
|
||||
if i == 0 {
|
||||
buf.WriteRune(tcell.RuneULCorner)
|
||||
} else {
|
||||
buf.WriteRune(tcell.RuneTTee)
|
||||
}
|
||||
cw := f
|
||||
if i == len(cards)-1 {
|
||||
cw = w - 2
|
||||
}
|
||||
for i := 0; i < cw; i++ {
|
||||
buf.WriteRune(tcell.RuneHLine)
|
||||
}
|
||||
}
|
||||
buf.WriteRune(tcell.RuneURCorner)
|
||||
buf.WriteRune('\n')
|
||||
|
||||
for i := 0; i < h-2; i++ {
|
||||
for j, card := range cards {
|
||||
cw := f
|
||||
if j == len(cards)-1 {
|
||||
cw = w - 2
|
||||
}
|
||||
|
||||
buf.WriteRune(tcell.RuneVLine)
|
||||
|
||||
if i == 0 {
|
||||
n, _ = buf.WriteString(cardFace(card))
|
||||
for j := 0; j < cw-n; j++ {
|
||||
buf.WriteRune(' ')
|
||||
}
|
||||
} else if i == 1 {
|
||||
buf.WriteString(card.Suit.Symbol())
|
||||
for j := 0; j < cw-1; j++ {
|
||||
buf.WriteRune(' ')
|
||||
}
|
||||
} else if i == (h-2)/2 {
|
||||
if j == len(cards)-1 {
|
||||
for j := 0; j < (cw / 2); j++ {
|
||||
buf.WriteRune(' ')
|
||||
}
|
||||
buf.WriteString(card.Suit.Symbol())
|
||||
for j := 0; j < cw-(cw/2)-1; j++ {
|
||||
buf.WriteRune(' ')
|
||||
}
|
||||
} else {
|
||||
for j := 0; j < cw-1; j++ {
|
||||
buf.WriteRune(' ')
|
||||
}
|
||||
buf.WriteString(card.Suit.Symbol())
|
||||
}
|
||||
} else if i == h-4 && j == len(cards)-1 {
|
||||
for j := 0; j < cw-1; j++ {
|
||||
buf.WriteRune(' ')
|
||||
}
|
||||
buf.WriteString(card.Suit.Symbol())
|
||||
} else if i == h-3 && j == len(cards)-1 {
|
||||
n = len(cardFace(card))
|
||||
for j := 0; j < cw-n; j++ {
|
||||
buf.WriteRune(' ')
|
||||
}
|
||||
buf.WriteString(cardFace(card))
|
||||
} else {
|
||||
for j := 0; j < cw; j++ {
|
||||
buf.WriteRune(' ')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
buf.WriteRune(tcell.RuneVLine)
|
||||
buf.WriteRune('\n')
|
||||
}
|
||||
|
||||
for i := range cards {
|
||||
if i == 0 {
|
||||
buf.WriteRune(tcell.RuneLLCorner)
|
||||
} else {
|
||||
buf.WriteRune(tcell.RuneBTee)
|
||||
}
|
||||
cw := f
|
||||
if i == len(cards)-1 {
|
||||
cw = w - 2
|
||||
}
|
||||
for i := 0; i < cw; i++ {
|
||||
buf.WriteRune(tcell.RuneHLine)
|
||||
}
|
||||
}
|
||||
buf.WriteRune(tcell.RuneLRCorner)
|
||||
|
||||
return buf.Bytes()
|
||||
}
|
||||
|
||||
func cardFace(card joker.Card) string {
|
||||
switch card.Face {
|
||||
case joker.FaceAce, joker.FaceJack, joker.FaceQueen, joker.FaceKing:
|
||||
return card.Face.Name()[0:1]
|
||||
default:
|
||||
return strconv.Itoa(int(card.Face))
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue