Skip to content

Commit

Permalink
chore: Better terminal output
Browse files Browse the repository at this point in the history
  • Loading branch information
Marvin9 committed Sep 13, 2020
1 parent 6494f34 commit 486dd10
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
23 changes: 9 additions & 14 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,16 @@ package main
import (
"fmt"
"os"
"time"

"github.com/Marvin9/licensor/steps"
)

func main() {
fmt.Print("\033[s") // save cursor position
fmt.Print("\033[?25l") // hide cursor

// find . | grep -i "\(\.go\|\.sh\)$" | wc -l
fmt.Print("Working")
go (func() {
for {
for i := 0; i < 3; i++ {
fmt.Print(".")
time.Sleep(time.Millisecond * 500)
}
for i := 0; i < 3; i++ {
fmt.Print("\b \b")
}
}
})()

var model steps.CommandModel
model.MakeModel(os.Args)
model.Validate()
Expand All @@ -33,6 +24,10 @@ func main() {
}

model.Start()
fmt.Print("\r \r")

// https://www.lihaoyi.com/post/BuildyourownCommandLinewithANSIescapecodes.html#completeness
fmt.Print("\u001b[2K")
fmt.Print("\u001b[0G")
fmt.Println("✔️")
fmt.Print("\033[?25h")
}
7 changes: 7 additions & 0 deletions steps/iterate_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ func (m *CommandModel) iterateDirectory(path string) {
continue
}

fmt.Print("\u001b[2K") // clear entire line
fmt.Print("\033[u") // restore cursor position (position where porgram started)
fmt.Print("\u001b[2K") // clear entire line [to eliminate overflow issues]
fmt.Print("\u001b[0G") // place cursor to 0th position
fmt.Print(fullpath)
fmt.Print("\u001b[0G")

fileToInjectLicense, err := os.OpenFile(fullpath, os.O_WRONLY, os.ModePerm)
if err != nil {
utils.LogError(err)
Expand Down

0 comments on commit 486dd10

Please sign in to comment.