-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3fcc652
commit 62522fe
Showing
7 changed files
with
158 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package utils | ||
|
||
import ( | ||
"foldest-go/lorca" | ||
"sync" | ||
) | ||
|
||
type Front struct { | ||
sync.Mutex | ||
isStart bool | ||
Ui lorca.UI | ||
} | ||
|
||
func mainThread(pf *Front, exitsignal chan<- bool) { | ||
pf.Ui.Eval(`console.log("Starting...");`) | ||
Plog.Print("Starting...\n") | ||
conf := ReadConf() | ||
|
||
rules := ReadRules() | ||
if rules == nil { | ||
Plog.Print("Skipping classify...\n") | ||
} else { | ||
DoClassify(rules, conf.Targetdir, conf.Verbose) | ||
} | ||
|
||
if conf.Tmpbin.Enable { | ||
Plog.Print("Performing tmpbin...\n") | ||
Manage(conf) | ||
} else { | ||
Plog.Print("tmpbin is disabled, skipping...\n") | ||
} | ||
|
||
Plog.Print("Exiting...\n") | ||
pf.Ui.Eval(`console.log("Exiting...");`) | ||
exitsignal <- true | ||
} | ||
|
||
func (pf *Front) Start() { | ||
pf.Lock() | ||
defer pf.Unlock() | ||
exitsignal := make(chan bool) | ||
pf.isStart = true | ||
go mainThread(pf, exitsignal) | ||
<-exitsignal | ||
pf.isStart = false | ||
} | ||
|
||
func (pf *Front) Stop() { | ||
pf.Lock() | ||
defer pf.Unlock() | ||
pf.isStart = false | ||
} | ||
|
||
func (pf *Front) Status() (status bool) { | ||
// pf.Lock() | ||
// defer pf.Unlock() | ||
return pf.isStart | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package utils | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
"sync" | ||
) | ||
|
||
// Logjs : a log method for js to read | ||
type Logjs struct { | ||
// Buf *bytes.Buffer | ||
buf []byte | ||
stdout *chan string | ||
} | ||
|
||
// Plog : global pointer to Logjs | ||
var Plog *Logjs | ||
|
||
// mu : instance mutex | ||
var mu sync.Mutex | ||
|
||
// Init : Init Logjs | ||
func (pl *Logjs) Init(std *chan string) { | ||
mu.Lock() | ||
defer mu.Unlock() | ||
|
||
if Plog == nil { | ||
Plog = &Logjs{} | ||
} | ||
Plog.stdout = std | ||
// Plog.buf []byte = make([]byte, 4096) | ||
} | ||
|
||
// Print : Print a string to Logjs | ||
func (pl *Logjs) Print(format string, a ...interface{}) { | ||
// mu.Lock() | ||
// defer mu.Unlock() | ||
s := fmt.Sprintf(format, a...) | ||
end := regexp.MustCompile(`.*?%c[0;\dm.*?(%c[0m)`) | ||
s = end.ReplaceAllString(s, "</span>") | ||
red := regexp.MustCompile(`.*?(%c[0;31m).*?%c[0m`) | ||
s = red.ReplaceAllString(s, "<span style=\"color: red;\">") | ||
*Plog.stdout <- s | ||
// Plog.Buf.WriteString(line) | ||
} | ||
|
||
// Getline : Get a string from Logjs | ||
func (pl *Logjs) Getline() (lines string) { | ||
// mu.Lock() | ||
// defer mu.Unlock() | ||
|
||
// lines, _ = Plog.Buf.ReadString('\n') | ||
return <-*Plog.stdout | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters