Skip to content

Commit

Permalink
Merge pull request #6 from mattn/windows
Browse files Browse the repository at this point in the history
Support Windows
  • Loading branch information
Yash-Handa committed Nov 1, 2020
2 parents 9542954 + bd00002 commit 483c3a3
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 54 deletions.
4 changes: 2 additions & 2 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ builds:
# supported OS
goos:
- linux
# - windows
- windows
- darwin
# supported ARCH
goarch:
Expand Down Expand Up @@ -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 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
8 changes: 4 additions & 4 deletions internal/dir/dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
63 changes: 63 additions & 0 deletions internal/dir/dir_unix.go
Original file line number Diff line number Diff line change
@@ -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 changes: 16 additions & 0 deletions internal/dir/dir_windows.go
Original file line number Diff line number Diff line change
@@ -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 changes: 0 additions & 46 deletions internal/dir/formatterStuff.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
11 changes: 9 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import (
"io"
"log"
"os"
"runtime"
"sort"

"github.com/Yash-Handa/logo-ls/assets"
"github.com/Yash-Handa/logo-ls/internal/api"
"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() {
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -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()
}
Expand Down

0 comments on commit 483c3a3

Please sign in to comment.