Skip to content

Commit

Permalink
chore: terminal
Browse files Browse the repository at this point in the history
Show cursor after interrupting.
Aggregate fmt.Print in iterate_project.go
Working message in windows, after validation
  • Loading branch information
Marvin9 committed Sep 15, 2020
1 parent 69600fd commit c52b615
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
20 changes: 17 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,24 @@ package main
import (
"fmt"
"os"
"os/signal"
"runtime"
"syscall"

"github.com/Marvin9/licensor/utils"

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

func main() {
closeSignal()
if runtime.GOOS == "windows" {
utils.IsWindows = true
}

if !utils.IsWindows {
fmt.Print("\033[s") // save cursor position
fmt.Print("\033[?25l") // hide cursor
} else {
fmt.Print("Working...")
}

// find . | grep -i "\(\.go\|\.sh\)$" | wc -l
Expand All @@ -34,13 +35,26 @@ func main() {
model.LicenseText = lc
}

if utils.IsWindows {
fmt.Print("Working...")
}
model.Start()

// https://www.lihaoyi.com/post/BuildyourownCommandLinewithANSIescapecodes.html#completeness
if !utils.IsWindows {
fmt.Print("\u001b[2K")
fmt.Print("\u001b[0G")
}
fmt.Println("✔️")
fmt.Println("Done ✔️")
utils.ShowCursor()
}

func closeSignal() {
c := make(chan os.Signal)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
<-c
utils.ShowCursor()
os.Exit(1)
}()
}
11 changes: 5 additions & 6 deletions steps/iterate_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,11 @@ func (m *CommandModel) iterateDirectory(path string) {
}

if !utils.IsWindows {
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")
// \u001b[2K => clear entire line
// \033[u => restore cursor position (position where porgram started)
// \u001b[2K => clear entire line [to eliminate overflow issues]
// \u001b[0G => place cursor to 0th position
fmt.Printf("\u001b[2K\033[u\u001b[2K\u001b[0G%v\u001b[0G", fullpath)
}

fileToInjectLicense := file
Expand Down

0 comments on commit c52b615

Please sign in to comment.