Skip to content

Commit

Permalink
update function
Browse files Browse the repository at this point in the history
  • Loading branch information
yorukot committed Apr 28, 2024
1 parent 51fb4bf commit 2bdef60
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
14 changes: 0 additions & 14 deletions src/internal/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"fmt"
"io"
"log"
"math"
"os"
"path/filepath"
"regexp"
Expand Down Expand Up @@ -485,19 +484,6 @@ func returnMetaData(m model) model {
return m
}

func formatFileSize(size int64) string {
if size == 0 {
return "0B"
}

units := []string{"B", "KB", "MB", "GB", "TB", "PB", "EB"}

unitIndex := int(math.Floor(math.Log(float64(size)) / math.Log(1024)))
adjustedSize := float64(size) / math.Pow(1024, float64(unitIndex))

return fmt.Sprintf("%.2f %s", adjustedSize, units[unitIndex])
}

func dirSize(path string) int64 {
var size int64
filepath.Walk(path, func(_ string, info os.FileInfo, err error) error {
Expand Down
15 changes: 15 additions & 0 deletions src/internal/string_function.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package internal

import (
"fmt"
"math"
"strings"
"unicode/utf8"

Expand Down Expand Up @@ -77,3 +79,16 @@ func fileNameWithoutExtension(fileName string) string {
}
return fileName
}

func formatFileSize(size int64) string {
if size == 0 {
return "0B"
}

units := []string{"B", "KB", "MB", "GB", "TB", "PB", "EB"}

unitIndex := int(math.Floor(math.Log(float64(size)) / math.Log(1024)))
adjustedSize := float64(size) / math.Pow(1024, float64(unitIndex))

return fmt.Sprintf("%.2f %s", adjustedSize, units[unitIndex])
}
4 changes: 0 additions & 4 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (

internal "github.com/MHNightCat/superfile/internal"
tea "github.com/charmbracelet/bubbletea"
"github.com/muesli/termenv"
"github.com/rkoesters/xdg/basedir"
"github.com/urfave/cli/v2"
)
Expand Down Expand Up @@ -53,8 +52,6 @@ const (
)

func main() {
output := termenv.NewOutput(os.Stdout)
terminalBackgroundColor := output.BackgroundColor()
app := &cli.App{
Name: "superfile",
Version: currentVersion,
Expand All @@ -72,7 +69,6 @@ func main() {

p := tea.NewProgram(internal.InitialModel(path, firstUse), tea.WithAltScreen())
if _, err := p.Run(); err != nil {
output.SetBackgroundColor(terminalBackgroundColor)
log.Fatalf("Alas, there's been an error: %v", err)
os.Exit(1)
}
Expand Down

0 comments on commit 2bdef60

Please sign in to comment.