Skip to content

Commit

Permalink
feat: comparator batcat ui
Browse files Browse the repository at this point in the history
  • Loading branch information
Gornak40 committed Jul 31, 2024
1 parent 345155e commit 7a3144d
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ for i in $(gibon -i 42619 -m contest); do gibon -i $i -m commit && gibon -i $i -
![gibon logo](https://algolymp.ru/static/img/gibon.png)

## kultq
*Anti plagiarism checker with web UI and interactive shell.*
*Anti plagiarism checker with interactive shell.*

## pepel
*Generate hasher solution based on a/ans/out files.*
Expand Down
2 changes: 1 addition & 1 deletion cmd/kultq/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func main() {
parser := argparse.NewParser("kultq", "Anti plagiarism checker with web UI and interactive shell.")
parser := argparse.NewParser("kultq", "Anti plagiarism checker with interactive shell.")
contestDir := parser.String("c", "contest", &argparse.Options{
Required: true,
Help: "Contest directory with <problem>/<user-login>/<run>.[py|cpp]",
Expand Down
22 changes: 22 additions & 0 deletions ejudge/kultq/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
type Config struct {
DreamPath string `json:"dreamPath"`
StatBounds []float64 `json:"statBounds"`
Batcat string `json:"batcat"`
}

type Engine struct {
Expand Down Expand Up @@ -43,6 +44,7 @@ func (e *Engine) Run() error {
}
e.probMapa[f.Name()] = p
}

e.runShell()

return nil
Expand All @@ -64,6 +66,16 @@ func (e *Engine) comRunFunc(c *ishell.Context) {
e.runProbs(c, sprobs)
}

func confirm(c *ishell.Context, message string) (bool, error) {
c.Print(message, " [y/N]? ")
yn, err := c.ReadLineErr()
if err != nil {
return false, err
}

return yn == "y" || yn == "Y", nil
}

func (e *Engine) comSliceFunc(c *ishell.Context) {
choice := c.MultiChoice(e.probNames, "Which problem you want to slice?")
if choice == -1 {
Expand Down Expand Up @@ -105,6 +117,16 @@ func (e *Engine) comSliceFunc(c *ishell.Context) {
}

c.Printf("Slice size: %d pairs\n", len(slip))
if len(slip) == 0 {
return
}
if yn, _ := confirm(c, "Start comparator"); yn {
if err := e.startUI(c, slip); err != nil {
c.Err(err)

return
}
}
}

func (e *Engine) comStatsFunc(c *ishell.Context) {
Expand Down
41 changes: 41 additions & 0 deletions ejudge/kultq/ui.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package kultq

import (
"errors"
"io"
"os"
"os/exec"

"github.com/abiosoft/ishell/v2"
)

func (e *Engine) startUI(c *ishell.Context, slip []statPair) error {
printCode := func(path string) error {
bat := exec.Command(e.cfg.Batcat, "--pager", "cat", path) //nolint:gosec // this is the way
bat.Stdout = os.Stdout

return bat.Run()
}

for _, s := range slip {
if err := printCode(s.path1); err != nil {
return err
}
if err := printCode(s.path2); err != nil {
return err
}
c.Println("Score (%):", s.score*100) //nolint:mnd //percents
yn, err := confirm(c, "Kill this guys (Ctrl+D to stop)?")
if errors.Is(err, io.EOF) {
return nil
}
if err != nil {
return err
}
if yn {
c.Println("KILLED") // TODO: implement
}
}

return nil
}
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fatih/color v1.17.0 // indirect
github.com/flynn-archive/go-shlex v0.0.0-20150515145356-3f9db97f8568 // indirect
github.com/kr/pretty v0.1.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/sys v0.22.0 // indirect
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
12 changes: 9 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4=
github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI=
github.com/flynn-archive/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BMXYYRWTLOJKlh+lOBt6nUQgXAfB7oVIQt5cNreqSLI=
github.com/flynn-archive/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:rZfgFAXFS/z/lEd6LJmf9HVZ1LkgYiHx5pHhV5DR16M=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
Expand All @@ -48,8 +53,8 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v
golang.org/x/net v0.0.0-20210916014120-12bc252f5db8/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys=
golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down Expand Up @@ -78,8 +83,9 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 comments on commit 7a3144d

Please sign in to comment.