Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
number571 committed Oct 22, 2024
1 parent 49072e6 commit 5a42cf1
Show file tree
Hide file tree
Showing 5 changed files with 1,234 additions and 1,193 deletions.
5 changes: 0 additions & 5 deletions cmd/tools/pmanager/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,3 @@ $ go run . -salt="service-name" -work=24
master-key
J64mESAVm2o-8q6nWaywsoQbQvn8pf7U74O-Vr9HwSDu
```

```bash
$ echo "master-key" | go run . -salt="service-name" -work=24
J64mESAVm2o-8q6nWaywsoQbQvn8pf7U74O-Vr9HwSDu
```
52 changes: 49 additions & 3 deletions cmd/tools/pmanager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"flag"
"fmt"
"os"
"os/exec"
"runtime"

"github.com/number571/go-peer/pkg/crypto/keybuilder"
)
Expand All @@ -26,9 +28,53 @@ func main() {
}

func readUntilEOL() string {
res, _, err := bufio.NewReader(os.Stdin).ReadLine()
if err != nil {
var (
p = make([]byte, 0, 256)
b = make([]byte, 1)
)

if runtime.GOOS == "windows" {
res, _, err := bufio.NewReader(os.Stdin).ReadLine()
if err != nil {
panic(err)
}
return string(res)
}

if err := exec.Command("stty", "-F", "/dev/tty", "cbreak", "min", "1").Run(); err != nil {
panic(err)
}
if err := exec.Command("stty", "-F", "/dev/tty", "-echo").Run(); err != nil {
panic(err)
}
return string(res)
defer func() { _ = exec.Command("stty", "-F", "/dev/tty", "echo").Run() }()

for {
if _, err := os.Stdin.Read(b); err != nil {
panic(err)
}
if b[0] == '\n' { // <enter>
fmt.Println()
break
}
if b[0] == 127 { // <backspace>
if len(p) == 0 {
continue
}
fmt.Print("\r")
for i := 0; i < len(p); i++ {
fmt.Print(" ")
}
fmt.Print("\r")
for i := 0; i < len(p)-1; i++ {
fmt.Print("*")
}
p = p[:len(p)-1]
continue
}
fmt.Print("*")
p = append(p, b[0])
}

return string(p)
}
2 changes: 1 addition & 1 deletion test/result/badge_codelines.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 5a42cf1

Please sign in to comment.