Skip to content

Commit

Permalink
pass fileInfo to diritem
Browse files Browse the repository at this point in the history
  • Loading branch information
mistakenelf committed Sep 6, 2021
1 parent f63526f commit a28e453
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions internal/dirtree/dirtree.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,36 +85,31 @@ func (m *Model) ToggleHidden() {
}

// dirItem returns a string representation of a directory item.
func (m Model) dirItem(selected bool, file fs.DirEntry) string {
fileInfo, err := file.Info()
if err != nil {
return err.Error()
}

func (m Model) dirItem(selected bool, fileInfo fs.FileInfo) string {
// Get the icon and color based on the current file.
icon, color := icons.GetIcon(file.Name(), filepath.Ext(file.Name()), icons.GetIndicator(fileInfo.Mode()))
icon, color := icons.GetIcon(fileInfo.Name(), filepath.Ext(fileInfo.Name()), icons.GetIndicator(fileInfo.Mode()))
fileIcon := fmt.Sprintf("%s%s", color, icon)

if m.ShowIcons && selected {
return fmt.Sprintf("%s\033[0m %s", fileIcon, lipgloss.NewStyle().
Bold(true).
Foreground(lipgloss.Color(m.SelectedItemColor)).
Render(file.Name()))
Render(fileInfo.Name()))
} else if m.ShowIcons && !selected {
return fmt.Sprintf("%s\033[0m %s", fileIcon, lipgloss.NewStyle().
Bold(true).
Foreground(lipgloss.Color(m.UnselectedItemColor)).
Render(file.Name()))
Render(fileInfo.Name()))
} else if !m.ShowIcons && selected {
return lipgloss.NewStyle().
Bold(true).
Foreground(lipgloss.Color(m.SelectedItemColor)).
Render(file.Name())
Render(fileInfo.Name())
} else {
return lipgloss.NewStyle().
Bold(true).
Foreground(lipgloss.Color(m.UnselectedItemColor)).
Render(file.Name())
Render(fileInfo.Name())
}
}

Expand Down Expand Up @@ -145,7 +140,7 @@ func (m Model) View() string {

dirItem := lipgloss.NewStyle().Width(m.Width - lipgloss.Width(modTime) - 2).Render(
truncate.StringWithTail(
m.dirItem(m.Cursor == i, file), uint(m.Width-lipgloss.Width(modTime)-constants.Dimensions.PanePadding), "...",
m.dirItem(m.Cursor == i, fileInfo), uint(m.Width-lipgloss.Width(modTime)-constants.Dimensions.PanePadding), "...",
),
)

Expand Down

0 comments on commit a28e453

Please sign in to comment.