1
0
mirror of https://github.com/zu1k/nali.git synced 2025-01-23 05:39:03 +08:00

no use syscall

This commit is contained in:
zu1k 2020-08-10 13:29:21 +08:00
parent 4afb25d084
commit a51fbc8442
2 changed files with 6 additions and 47 deletions

View File

@ -1,22 +1,20 @@
// +build windows
package app
import (
"bufio"
"fmt"
"os"
"syscall"
"runtime"
"golang.org/x/text/encoding/simplifiedchinese"
"golang.org/x/text/transform"
)
var pipeline = false
var needTransform = false
func init() {
ftype, _ := syscall.GetFileType(syscall.Handle(os.Stdin.Fd()))
pipeline = ftype == 3
stat, _ := os.Stdin.Stat()
needTransform = ((stat.Mode() & os.ModeNamedPipe) != 0) && runtime.GOOS == "windows"
}
func Root(args []string) {
@ -24,7 +22,7 @@ func Root(args []string) {
stdin := bufio.NewScanner(os.Stdin)
for stdin.Scan() {
line := stdin.Text()
if pipeline {
if needTransform {
line, _, _ = transform.String(simplifiedchinese.GBK.NewDecoder(), line)
}
if line == "quit" || line == "exit" {
@ -42,7 +40,7 @@ func CDN(args []string) {
stdin := bufio.NewScanner(os.Stdin)
for stdin.Scan() {
line := stdin.Text()
if pipeline {
if needTransform {
line, _, _ = transform.String(simplifiedchinese.GBK.NewDecoder(), line)
}
if line == "quit" || line == "exit" {

View File

@ -1,39 +0,0 @@
// +build !windows
package app
import (
"bufio"
"fmt"
"os"
)
func Root(args []string) {
if len(args) == 0 {
stdin := bufio.NewScanner(os.Stdin)
for stdin.Scan() {
line := stdin.Text()
if line == "quit" || line == "exit" {
return
}
fmt.Printf("%s\n", ReplaceIPInString(ReplaceCDNInString(line)))
}
} else {
ParseIPs(args)
}
}
func CDN(args []string) {
if len(args) == 0 {
stdin := bufio.NewScanner(os.Stdin)
for stdin.Scan() {
line := stdin.Text()
if line == "quit" || line == "exit" {
return
}
fmt.Println(ReplaceCDNInString(line))
}
} else {
ParseCDNs(args)
}
}