Skip to content

Commit

Permalink
PR fix: Remove additional log lines
Browse files Browse the repository at this point in the history
  • Loading branch information
lazysegtree committed Feb 4, 2025
1 parent ae9a586 commit da3c86e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 34 deletions.
31 changes: 13 additions & 18 deletions src/internal/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,15 @@ func returnFocusType(focusPanel focusPanelType) filePanelFocusType {
return secondFocus
}

// Need to rename folder to directory.
func returnDirectoryElement(location string, displayDotFile bool, sortOptions sortOptionsModelData) (directoryElement []element) {
slog.Debug("returnFolderElement() called.")
func returnDirElement(location string, displayDotFile bool, sortOptions sortOptionsModelData) (directoryElement []element) {
dirEntries, err := os.ReadDir(location)
if err != nil {
outPutLog("Return folder element function error", err)
return directoryElement
}

dirEntries = slices.DeleteFunc(dirEntries, func(e os.DirEntry) bool {
// Should be deleted
// Entries not needed to be considered
_, err := e.Info()
return err != nil || (strings.HasPrefix(e.Name(), ".") && !displayDotFile)
})
Expand All @@ -66,16 +64,17 @@ func returnDirectoryElement(location string, displayDotFile bool, sortOptions so
var order func(i, j int) bool
reversed := sortOptions.reversed

// Todo : These strings should not be hardcoded here, but defined as constants
switch sortOptions.options[sortOptions.selected] {
case "Name":
order = func(i, j int) bool {
slog.Debug("sort func", "i", i, "j", j)

// One of them is a directory, and other is not
if dirEntries[i].IsDir() != dirEntries[j].IsDir() {
return dirEntries[i].IsDir()
}

if Config.CaseSensitiveSort {
return dirEntries[i].Name() < dirEntries[j].Name() != reversed
} else {
Expand All @@ -86,12 +85,12 @@ func returnDirectoryElement(location string, displayDotFile bool, sortOptions so
order = func(i, j int) bool {
// Directories at the top sorted by direct child count (not recursive)
// Files sorted by size

// One of them is a directory, and other is not
if dirEntries[i].IsDir() != dirEntries[j].IsDir() {
return dirEntries[i].IsDir()
}

// This needs to be improved, and we should sort by actual size only
// Repeated recursive read would be slow, so we could cache
if dirEntries[i].IsDir() && dirEntries[j].IsDir() {
Expand All @@ -112,7 +111,7 @@ func returnDirectoryElement(location string, displayDotFile bool, sortOptions so
fileInfoJ, _ := dirEntries[j].Info()
return fileInfoI.Size() < fileInfoJ.Size() != reversed
}

}
case "Date Modified":
order = func(i, j int) bool {
Expand All @@ -124,21 +123,17 @@ func returnDirectoryElement(location string, displayDotFile bool, sortOptions so
}

sort.Slice(dirEntries, order)

for _, item := range dirEntries {
directoryElement = append(directoryElement, element{
name: item.Name(),
directory: item.IsDir(),
location: filepath.Join(location, item.Name()),
})
}

slog.Debug("returnFolderElement() returning.", "directoryElement", directoryElement)

return directoryElement
}

func returnFolderElementBySearchString(location string, displayDotFile bool, searchString string) (folderElement []element) {
func returnDirElementBySearchString(location string, displayDotFile bool, searchString string) (dirElement []element) {

items, err := os.ReadDir(location)
if err != nil {
Expand Down Expand Up @@ -182,15 +177,15 @@ func returnFolderElementBySearchString(location string, displayDotFile bool, sea
for _, item := range result.Matches {
resultItem := folderElementMap[item.Key]
resultItem.matchRate = float64(item.Score)
folderElement = append(folderElement, resultItem)
dirElement = append(dirElement, resultItem)
}

// Sort folders and files by match rate
sort.Slice(folderElement, func(i, j int) bool {
return folderElement[i].matchRate > folderElement[j].matchRate
sort.Slice(dirElement, func(i, j int) bool {
return dirElement[i].matchRate > dirElement[j].matchRate
})

return folderElement
return dirElement
}

func panelElementHeight(mainPanelHeight int) int {
Expand Down
4 changes: 0 additions & 4 deletions src/internal/get_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package internal

import (
"encoding/json"
"log/slog"
"os"
"path/filepath"

Expand All @@ -14,7 +13,6 @@ import (

// Return all sidebar directories
func getDirectories() []directory {
slog.Debug("getDirectories() called")
directories := []directory{}

directories = append(directories, getWellKnownDirectories()...)
Expand All @@ -28,7 +26,6 @@ func getDirectories() []directory {
location: "Disks+-*/=?",
})
directories = append(directories, getExternalMediaFolders()...)
slog.Debug("getDirectories() returning", "directories", directories)
return directories
}

Expand Down Expand Up @@ -68,7 +65,6 @@ func getPinnedDirectories() []directory {
jsonData, err := os.ReadFile(variable.PinnedFile)
if err != nil {
outPutLog("Read superfile data error", err)
// Should exit here
return directories
}

Expand Down
14 changes: 2 additions & 12 deletions src/internal/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ func (m model) Init() tea.Cmd {
// Update function for bubble tea to provide internal communication to the
// application
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
slog.Debug("model.Update() called.", "current width", m.fullWidth,
"current height", m.fullHeight)
var cmd tea.Cmd

switch msg := msg.(type) {
Expand All @@ -72,15 +70,11 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {

// check if there already have listening message
if !ListeningMessage {
slog.Debug("ListeningMessage is false in model Update()")
cmd = tea.Batch(cmd, listenForChannelMessage(channel))
}

m.getFilePanelItems()

slog.Debug("model.Update() returning.", "current width", m.fullWidth,
"current height", m.fullHeight)

return m, tea.Batch(cmd)
}

Expand All @@ -101,7 +95,6 @@ func (m *model) handleChannelMessage(msg channelMessage) {

// Adjust window size based on msg information
func (m *model) handleWindowResize(msg tea.WindowSizeMsg) {
slog.Debug("model.Update() called with handleWindowResize msg.", "msg.Width", msg.Width, "msg.Height", msg.Height)
m.fullHeight = msg.Height
m.fullWidth = msg.Width

Expand Down Expand Up @@ -254,7 +247,6 @@ func (m *model) handleKeyInput(msg tea.KeyMsg, cmd tea.Cmd) tea.Cmd {
// Update the file panel state. Change name of renamed files, filter out files
// in search, update typingb bar, etc
func (m *model) updateFilePanelsState(msg tea.Msg, cmd *tea.Cmd) {
slog.Debug("updateFilePanelsState() called")
focusPanel := &m.fileModel.filePanels[m.filePanelFocusIndex]
if m.firstTextInput {
m.firstTextInput = false
Expand All @@ -275,7 +267,6 @@ func (m *model) updateFilePanelsState(msg tea.Msg, cmd *tea.Cmd) {

// Update the sidebar state. Change name of the renaming pinned directory.
func (m *model) updateSidebarState(msg tea.Msg, cmd *tea.Cmd) {
slog.Debug("updateSidebarState() is called")
sidebar := &m.sidebarModel
if sidebar.renaming {
sidebar.rename, *cmd = sidebar.rename.Update(msg)
Expand Down Expand Up @@ -305,7 +296,6 @@ func (m *model) warnModalForQuit() {

// Implement View function for bubble tea model to handle visualization.
func (m model) View() string {
slog.Debug("model.View() called.", "h", m.fullHeight, "w", m.fullWidth)
panel := m.fileModel.filePanels[m.filePanelFocusIndex]
// check is the terminal size enough
if m.fullHeight < minimumHeight || m.fullWidth < minimumWidth {
Expand Down Expand Up @@ -443,9 +433,9 @@ func (m *model) getFilePanelItems() {

// Get file names based on search bar filter
if filePanel.searchBar.Value() != "" {
fileElement = returnFolderElementBySearchString(filePanel.location, m.toggleDotFile, filePanel.searchBar.Value())
fileElement = returnDirElementBySearchString(filePanel.location, m.toggleDotFile, filePanel.searchBar.Value())
} else {
fileElement = returnDirectoryElement(filePanel.location, m.toggleDotFile, filePanel.sortOptions.data)
fileElement = returnDirElement(filePanel.location, m.toggleDotFile, filePanel.sortOptions.data)
}
// Update file panel list
filePanel.element = fileElement
Expand Down

0 comments on commit da3c86e

Please sign in to comment.