Merge pull request #6 from mattn/windows

Support Windows
This commit is contained in:
Yash Handa
2020-11-01 06:34:29 +05:30
committed by GitHub
8 changed files with 101 additions and 54 deletions
+2 -2
View File
@@ -17,7 +17,7 @@ builds:
# supported OS
goos:
- linux
# - windows
- windows
- darwin
# supported ARCH
goarch:
@@ -98,4 +98,4 @@ nfpms:
recommends:
- golang
files:
"logo-ls.1.gz": "/usr/share/man/man1/logo-ls.1.gz"
"logo-ls.1.gz": "/usr/share/man/man1/logo-ls.1.gz"
+1
View File
@@ -4,6 +4,7 @@ go 1.15
require (
github.com/go-git/go-git/v5 v5.1.0
github.com/mattn/go-colorable v0.1.7 // indirect
github.com/pborman/getopt/v2 v2.0.0
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a
)
+6
View File
@@ -36,6 +36,10 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mattn/go-colorable v0.1.7 h1:bQGKb3vps/j0E9GfJQ03JyhRuxsvdAanXlT9BTw3mdw=
github.com/mattn/go-colorable v0.1.7/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
@@ -65,6 +69,8 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20190221075227-b4e8571b14e0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 h1:uYVVQ9WP/Ds2ROhcaGPeIdVq0RIXVLwsHlnvJ+cT1So=
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
+4 -4
View File
@@ -77,7 +77,7 @@ func New(d *os.File) (*dir, error) {
t.info.owner, t.info.group = getOwnerGroupInfo(ds)
}
if api.FlagVector&api.Flag_s > 0 {
t.info.blocks = getFileBlocks(ds)
dirBlocks(t.info, ds)
}
if api.FlagVector&api.Flag_i == 0 {
t.info.icon = assets.Icon_Def["diropen"].GetGlyph()
@@ -112,7 +112,7 @@ func New(d *os.File) (*dir, error) {
f.owner, f.group = getOwnerGroupInfo(v)
}
if api.FlagVector&api.Flag_s > 0 {
f.blocks = getFileBlocks(v)
dirBlocks(f, v)
}
if api.FlagVector&api.Flag_i == 0 {
@@ -160,7 +160,7 @@ func New(d *os.File) (*dir, error) {
t.parent.owner, t.parent.group = getOwnerGroupInfo(pds)
}
if api.FlagVector&api.Flag_s > 0 {
t.parent.blocks = getFileBlocks(pds)
dirBlocks(t.parent, pds)
}
if api.FlagVector&api.Flag_i == 0 {
t.parent.icon = assets.Icon_Def["diropen"].GetGlyph()
@@ -195,7 +195,7 @@ func New_ArgFiles(files []os.FileInfo) *dir {
f.owner, f.group = getOwnerGroupInfo(v)
}
if api.FlagVector&api.Flag_s > 0 {
f.blocks = getFileBlocks(v)
dirBlocks(f, v)
}
if api.FlagVector&api.Flag_i == 0 {
f.icon, f.iconColor = getIcon(f.name, f.ext, f.indicator)
+63
View File
@@ -0,0 +1,63 @@
// this file contain dir type definition
// +build !windows
package dir
import (
"os"
"os/user"
"strconv"
"syscall"
"github.com/Yash-Handa/logo-ls/internal/api"
)
func dirBlocks(info *file, fi os.FileInfo) {
if s, ok := fi.Sys().(*syscall.Stat_t); ok {
info.blocks = s.Blocks
}
}
func getOwnerGroupInfo(fi os.FileInfo) (o string, g string) {
if stat, ok := fi.Sys().(*syscall.Stat_t); ok {
if api.FlagVector&(api.Flag_l|api.Flag_o) > 0 {
UID := strconv.Itoa(int(stat.Uid))
if n, ok := userMap[UID]; ok {
o = n
} else {
u, err := user.LookupId(UID)
if err != nil {
o = ""
} else {
o = u.Name
userMap[UID] = u.Name
}
}
}
if api.FlagVector&api.Flag_G == 0 && api.FlagVector&(api.Flag_l|api.Flag_g) > 0 {
GID := strconv.Itoa(int(stat.Gid))
if n, ok := grpMap[GID]; ok {
g = n
} else {
grp, err := user.LookupGroupId(GID)
if err != nil {
g = ""
} else {
g = grp.Name
grpMap[GID] = grp.Name
}
}
}
}
return
}
func getFileBlocks(fi os.FileInfo) int64 {
if s, ok := fi.Sys().(*syscall.Stat_t); ok {
return s.Blocks
}
return 0
}
+16
View File
@@ -0,0 +1,16 @@
// this file contain dir type definition
// +build windows
package dir
import (
"os"
)
func dirBlocks(info *file, fi os.FileInfo) {
}
func getOwnerGroupInfo(fi os.FileInfo) (o string, g string) {
return
}
-46
View File
@@ -3,10 +3,7 @@ package dir
import (
"fmt"
"os"
"os/user"
"strconv"
"strings"
"syscall"
"github.com/Yash-Handa/logo-ls/assets"
"github.com/Yash-Handa/logo-ls/internal/api"
@@ -79,49 +76,6 @@ func lessFuncGenerator(d *dir) {
var grpMap = make(map[string]string)
var userMap = make(map[string]string)
func getOwnerGroupInfo(fi os.FileInfo) (o string, g string) {
if stat, ok := fi.Sys().(*syscall.Stat_t); ok {
if api.FlagVector&(api.Flag_l|api.Flag_o) > 0 {
UID := strconv.Itoa(int(stat.Uid))
if n, ok := userMap[UID]; ok {
o = n
} else {
u, err := user.LookupId(UID)
if err != nil {
o = ""
} else {
o = u.Name
userMap[UID] = u.Name
}
}
}
if api.FlagVector&api.Flag_G == 0 && api.FlagVector&(api.Flag_l|api.Flag_g) > 0 {
GID := strconv.Itoa(int(stat.Gid))
if n, ok := grpMap[GID]; ok {
g = n
} else {
grp, err := user.LookupGroupId(GID)
if err != nil {
g = ""
} else {
g = grp.Name
grpMap[GID] = grp.Name
}
}
}
}
return
}
func getFileBlocks(fi os.FileInfo) int64 {
if s, ok := fi.Sys().(*syscall.Stat_t); ok {
return s.Blocks
}
return 0
}
// get indicator of the file
func getIndicator(modebit os.FileMode) (i string) {
switch {
+9 -2
View File
@@ -5,6 +5,7 @@ import (
"io"
"log"
"os"
"runtime"
"sort"
"github.com/Yash-Handa/logo-ls/assets"
@@ -12,6 +13,7 @@ import (
"github.com/Yash-Handa/logo-ls/internal/ctw"
"github.com/Yash-Handa/logo-ls/internal/dir"
"github.com/Yash-Handa/logo-ls/internal/sysState"
"github.com/mattn/go-colorable"
)
func main() {
@@ -65,9 +67,14 @@ func main() {
}
}
var out io.Writer = os.Stdout
if runtime.GOOS == "windows" {
out = colorable.NewColorableStdout()
}
// process and display all files
if len(args.files) > 0 {
io.Copy(os.Stdout, dir.New_ArgFiles(args.files).Print())
io.Copy(out, dir.New_ArgFiles(args.files).Print())
if len(args.dirs) > 0 {
fmt.Println()
}
@@ -96,7 +103,7 @@ func main() {
sysState.ExitCode(sysState.Code_Serious)
}
// print the info of the files of the directory
io.Copy(os.Stdout, d.Print())
io.Copy(out, d.Print())
if i < len(args.dirs)-1 {
fmt.Println()
}