Skip to content

Commit

Permalink
Merge pull request #4 from ondrovic/dev
Browse files Browse the repository at this point in the history
Updates
  • Loading branch information
ondrovic authored Oct 5, 2024
2 parents e345733 + 0a6c183 commit 7fba984
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 19 deletions.
2 changes: 1 addition & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ internal:
utils.go:
✔ Adjust funcs based on FileSize option change @done(24-08-18 11:39)
✔ Adjust funcs to search by FileNameFilter option @done(24-08-18 11:39)
Fix table alignment issues
Fix table alignment issues @done(24-10-05 17:44)
☐ For detailed view add filesize total
☐ Create logic to find duplicate files
☐ hash comparison
Expand Down
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ go 1.22.6
toolchain go1.23.0

require (
github.com/jedib0t/go-pretty/v6 v6.6.0
github.com/jedib0t/go-pretty/v6 v6.6.1-0.20241005144220-9949e904f6d4
github.com/ondrovic/common v0.1.24
github.com/pterm/pterm v0.12.79
github.com/spf13/cobra v1.8.1
github.com/spf13/viper v1.19.0
golang.org/x/sys v0.26.0
golang.org/x/term v0.25.0
)

require (
Expand All @@ -36,10 +38,8 @@ require (
github.com/subosito/gotenv v1.6.0 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/term v0.24.0 // indirect
golang.org/x/text v0.18.0 // indirect
golang.org/x/exp v0.0.0-20241004190924-225e2abe05e6 // indirect
golang.org/x/text v0.19.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
20 changes: 10 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/jedib0t/go-pretty/v6 v6.6.0 h1:wmZVuAcEkZRT+Aq1xXpE8IGat4vE5WXOMmBpbQqERXw=
github.com/jedib0t/go-pretty/v6 v6.6.0/go.mod h1:zbn98qrYlh95FIhwwsbIip0LYpwSG8SUOScs+v9/t0E=
github.com/jedib0t/go-pretty/v6 v6.6.1-0.20241005144220-9949e904f6d4 h1:pYahwH3eOZVslRGRinj9v8Ek7XLoeAjGd+buVi0uHjw=
github.com/jedib0t/go-pretty/v6 v6.6.1-0.20241005144220-9949e904f6d4/go.mod h1:zbn98qrYlh95FIhwwsbIip0LYpwSG8SUOScs+v9/t0E=
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/klauspost/cpuid/v2 v2.0.10/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c=
github.com/klauspost/cpuid/v2 v2.0.12/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c=
Expand Down Expand Up @@ -117,8 +117,8 @@ go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 h1:e66Fs6Z+fZTbFBAxKfP3PALWBtpfqks2bwGcexMxgtk=
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0/go.mod h1:2TbTHSBQa924w8M6Xs1QcRcFwyucIwBGpK1p2f1YFFY=
golang.org/x/exp v0.0.0-20241004190924-225e2abe05e6 h1:1wqE9dj9NpSm04INVsJhhEUzhuDVjbcyKH91sVyPATw=
golang.org/x/exp v0.0.0-20241004190924-225e2abe05e6/go.mod h1:NQtJDoLvd6faHhE7m4T/1IY708gDefGGjR/iUW8yQQ8=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
Expand All @@ -139,22 +139,22 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.24.0 h1:Mh5cbb+Zk2hqqXNO7S1iTjEphVL+jb8ZWaqh/g+JWkM=
golang.org/x/term v0.24.0/go.mod h1:lOBK/LVxemqiMij05LGJ0tzNr8xlmwBRJ81PX6wVLH8=
golang.org/x/term v0.25.0 h1:WtHI/ltw4NvSUig5KARz9h521QvRC8RmF/cuYqifU24=
golang.org/x/term v0.25.0/go.mod h1:RPyXicDX+6vLxogjjRxjgD2TKtmAO6NZBsBRfrOLu7M=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
Expand Down
17 changes: 17 additions & 0 deletions internal/utils/terminal_size_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//go:build !windows
// +build !windows

package utils

import (
"fmt"
"golang.org/x/term"
"os"
)

func getTerminalSize() (int, int, error) {
if !term.IsTerminal(int(os.Stdout.Fd())) {
return 0, 0, fmt.Errorf("not a terminal")
}
return term.GetSize(int(os.Stdin.Fd()))
}
25 changes: 25 additions & 0 deletions internal/utils/terminal_size_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//go:build windows
// +build windows

package utils

import (
"golang.org/x/sys/windows"
"os"
)

func getTerminalSize() (int, int, error) {
return getTerminalSizeWindows()
}

func getTerminalSizeWindows() (int, int, error) {
handle := windows.Handle(os.Stdout.Fd())
var info windows.ConsoleScreenBufferInfo
err := windows.GetConsoleScreenBufferInfo(handle, &info)
if err != nil {
return 0, 0, err
}
width := int(info.Window.Right - info.Window.Left + 1)
height := int(info.Window.Bottom - info.Window.Top + 1)
return width, height, nil
}
36 changes: 33 additions & 3 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func getFiles(ff types.FileFinder) (interface{}, int, int64, error) {
defer wg.Done()
path := filepath.Join(ff.RootDirectory, entry.Name())
if entry.IsDir() {
processDirectory(path, ff, &detailedResults, &results, &totalCount, &totalFileSize, &mu, &wg, semaphore)
processDirectory(path, ff, &detailedResults, &results, &totalCount, &totalFileSize, &mu, semaphore)
} else {
processFile(entry, path, ff, fileSize, &detailedResults, &results, &totalCount, &totalFileSize, &mu)
}
Expand All @@ -119,7 +119,7 @@ func convertFileSizeFilter(fileSizeFilter string) (int64, error) {
return commonUtils.ConvertStringSizeToBytes(fileSizeFilter)
}

func processDirectory(path string, ff types.FileFinder, detailedResults *[]types.EntryResult, results *map[string][]string, totalCount *int, totalFileSize *int64, mu *sync.Mutex, wg *sync.WaitGroup, semaphore chan struct{}) {
func processDirectory(path string, ff types.FileFinder, detailedResults *[]types.EntryResult, results *map[string][]string, totalCount *int, totalFileSize *int64, mu *sync.Mutex, semaphore chan struct{}) {
semaphore <- struct{}{} // Acquire semaphore
defer func() { <-semaphore }() // Release semaphore

Expand Down Expand Up @@ -401,9 +401,36 @@ func formatResultHyperLink(link, txt string) string {
return text.Hyperlink(link, txt)
}

// func getTerminalSize() (int, int, error) {
// if !isatty.IsTerminal(os.Stdout.Fd()) {
// return 0, 0, fmt.Errorf("not a terminal")
// }

// if runtime.GOOS == "windows" {
// return getTerminalSizeWindows()
// }
// return term.GetSize(int(os.Stdin.Fd()))
// }

// func getTerminalSizeWindows() (int, int, error) {
// handle := windows.Handle(os.Stdout.Fd())
// var info windows.ConsoleScreenBufferInfo
// err := windows.GetConsoleScreenBufferInfo(handle, &info)
// if err != nil {
// return 0, 0, err
// }
// width := int(info.Window.Right - info.Window.Left + 1)
// height := int(info.Window.Bottom - info.Window.Top + 1)
// return width, height, nil
// }

func renderResultsToTable(results interface{}, totalCount int, totalFileSize int64, ff types.FileFinder) {
t := table.Table{}

w, _, err := getTerminalSize()
if err != nil {
fmt.Printf("error getting terminal size %v\n", err)
}
// fmt.Printf("Terminal size: Width = %d, Height = %d\n", w, h)
// Determine header and footer based on the type of results
var header table.Row
var footer table.Row
Expand Down Expand Up @@ -445,6 +472,9 @@ func renderResultsToTable(results interface{}, totalCount int, totalFileSize int
t.AppendFooter(footer)

t.SetStyle(table.StyleColoredDark)
t.Style().Size = table.SizeOptions{
WidthMin: w,
}
t.SetOutputMirror(os.Stdout)
t.Render()
}

0 comments on commit 7fba984

Please sign in to comment.