print points when document is compiling

This commit is contained in:
lukas 2021-08-26 18:00:10 +02:00
parent 9be91accb3
commit a1be37c771

70
Main.go
View File

@ -3,6 +3,7 @@ package main
import ( import (
"bufio" "bufio"
"fmt" "fmt"
"io"
"log" "log"
"os" "os"
"os/exec" "os/exec"
@ -117,13 +118,51 @@ func compileLatex(filename string) (*string, error) {
"-output-format=pdf", "-output-format=pdf",
filename) filename)
stdout, err := cmd.Output() stdout, _ := cmd.StdoutPipe()
stderr, _ := cmd.StderrPipe()
output := string(stdout) cmd.Start()
output := ""
go func() {
scanner := bufio.NewScanner(stdout)
for scanner.Scan() {
m := scanner.Text()
output += m + "\n"
printPoint()
}
fmt.Println()
}()
go func() {
scanner := bufio.NewScanner(stderr)
for scanner.Scan() {
scanner.Text()
printPoint()
}
}()
err := cmd.Wait()
return &output, err return &output, err
} }
var i = 0
func printPoint() {
if i%10 == 0 {
fmt.Printf(".")
}
i++
if i > 500 {
i = 0
fmt.Println()
}
}
func rootCheck() bool { func rootCheck() bool {
cmd := exec.Command("id", "-u") cmd := exec.Command("id", "-u")
output, err := cmd.Output() output, err := cmd.Output()
@ -163,21 +202,8 @@ func installFile(filename string) bool {
fmt.Println("running dnf install now!") fmt.Println("running dnf install now!")
cmd.Start() cmd.Start()
go func() { printReadCloserToStdout(stdout)
scanner := bufio.NewScanner(stdout) printReadCloserToStdout(stderr)
for scanner.Scan() {
m := scanner.Text()
fmt.Println(m)
}
}()
go func() {
scanner := bufio.NewScanner(stderr)
for scanner.Scan() {
m := scanner.Text()
fmt.Println(m)
}
}()
err := cmd.Wait() err := cmd.Wait()
if err != nil { if err != nil {
@ -186,3 +212,13 @@ func installFile(filename string) bool {
} }
return true return true
} }
func printReadCloserToStdout(reader io.ReadCloser) {
go func() {
scanner := bufio.NewScanner(reader)
for scanner.Scan() {
m := scanner.Text()
fmt.Println(m)
}
}()
}