44 "fmt"
55 "os"
66 "os/exec"
7+ "path"
78 "strings"
89 "time"
910
@@ -13,8 +14,8 @@ import (
1314 "charm.land/bubbles/v2/viewport"
1415 tea "charm.land/bubbletea/v2"
1516 "charm.land/lipgloss/v2"
17+ "charm.land/log/v2"
1618 "github.com/bluekeyes/go-gitdiff/gitdiff"
17- "github.com/charmbracelet/log"
1819 zone "github.com/lrstanley/bubblezone/v2"
1920
2021 "github.com/dlvhdr/diffnav/pkg/config"
@@ -25,6 +26,8 @@ import (
2526 "github.com/dlvhdr/diffnav/pkg/ui/panes/filetree"
2627 "github.com/dlvhdr/diffnav/pkg/ui/panes/help"
2728 "github.com/dlvhdr/diffnav/pkg/utils"
29+ "github.com/lrstanley/go-nf/glyphs/md"
30+ "github.com/lrstanley/go-nf/glyphs/neo"
2831)
2932
3033const (
@@ -510,41 +513,18 @@ func (m mainModel) fetchFileTree() tea.Msg {
510513 return fileTreeMsg {files : files , preamble : preamble , branch : branch }
511514}
512515
513- func relativeTime (t time.Time ) string {
514- d := time .Since (t )
515- switch {
516- case d < time .Minute :
517- return "now"
518- case d < time .Hour :
519- m := int (d .Minutes ())
520- return fmt .Sprintf ("%dm" , m )
521- case d < 24 * time .Hour :
522- h := int (d .Hours ())
523- return fmt .Sprintf ("%dh" , h )
524- case d < 30 * 24 * time .Hour :
525- days := int (d .Hours () / 24 )
526- return fmt .Sprintf ("%dD" , days )
527- case d < 365 * 24 * time .Hour :
528- months := int (d .Hours () / 24 / 30 )
529- return fmt .Sprintf ("%dM" , months )
530- default :
531- years := int (d .Hours () / 24 / 365 )
532- return fmt .Sprintf ("%dY" , years )
533- }
534- }
535-
536516// resolveBranch finds branches pointing at the preamble commit.
537517func resolveBranch (preamble string ) string {
538518 // Check for decoration in commit line: "commit abc123 (HEAD -> branch)"
539- for _ , line := range strings .Split (preamble , "\n " ) {
519+ for line := range strings .SplitSeq (preamble , "\n " ) {
540520 trimmed := strings .TrimSpace (line )
541521 if strings .HasPrefix (trimmed , "commit " ) {
542522 if idx := strings .Index (trimmed , " (" ); idx > 0 {
543523 refs := trimmed [idx + 2 :]
544524 if end := strings .Index (refs , ")" ); end > 0 {
545525 refs = refs [:end ]
546526 }
547- for _ , ref := range strings .Split (refs , "," ) {
527+ for ref := range strings .SplitSeq (refs , "," ) {
548528 ref = strings .TrimSpace (ref )
549529 if strings .HasPrefix (ref , "HEAD -> " ) {
550530 return strings .TrimPrefix (ref , "HEAD -> " )
@@ -563,7 +543,7 @@ func resolveBranch(preamble string) string {
563543 if err != nil {
564544 return ""
565545 }
566- for _ , l := range strings .Split (strings .TrimSpace (string (out )), "\n " ) {
546+ for l := range strings .SplitSeq (strings .TrimSpace (string (out )), "\n " ) {
567547 b := strings .TrimLeft (l , " *+" )
568548 if b != "" {
569549 return b
@@ -586,7 +566,7 @@ func (m mainModel) parseCommitMeta() commitMeta {
586566 if m .preamble == "" {
587567 return meta
588568 }
589- for _ , line := range strings .Split (m .preamble , "\n " ) {
569+ for line := range strings .SplitSeq (m .preamble , "\n " ) {
590570 trimmed := strings .TrimSpace (line )
591571 if strings .HasPrefix (trimmed , "commit " ) && meta .hash == "" {
592572 h := strings .TrimPrefix (trimmed , "commit " )
@@ -637,7 +617,7 @@ func (m mainModel) commitSubject() string {
637617 if m .preamble == "" {
638618 return ""
639619 }
640- for _ , line := range strings .Split (m .preamble , "\n " ) {
620+ for line := range strings .SplitSeq (m .preamble , "\n " ) {
641621 trimmed := strings .TrimSpace (line )
642622 if trimmed == "" {
643623 continue
@@ -676,18 +656,26 @@ func (m mainModel) viewHeader() string {
676656 var infoParts []string
677657 infoParts = append (infoParts , hashStyle .Render (meta .hash ))
678658 if meta .date != "" {
679- infoParts = append (infoParts , dateStyle .Render (meta .date ))
659+ if m .iconStyle != filenode .IconsASCII && m .iconStyle != filenode .IconsUnicode {
660+ infoParts = append (infoParts , dateStyle .Render (string (md .ClockOutline ) + " " + meta .date ))
661+ } else {
662+ infoParts = append (infoParts , dateStyle .Render (meta .date ))
663+ }
680664 }
681665 if meta .author != "" {
666+ if m .iconStyle != filenode .IconsASCII && m .iconStyle != filenode .IconsUnicode {
667+ infoParts = append (infoParts , authorStyle .Render (string (md .AccountCircleOutline ) + " " + meta .author ))
668+ } else {
682669 infoParts = append (infoParts , authorStyle .Render (meta .author ))
670+ }
683671 }
684- headerParts = headerParts + sep + strings .Join (infoParts , " " )
672+ headerParts = headerParts + sep + strings .Join (infoParts , sep )
685673
686674 // Branch ref.
687675 if m .commitBranch != "" {
688676 branchLabel := "[" + m .commitBranch + "]"
689677 if m .iconStyle != filenode .IconsASCII && m .iconStyle != filenode .IconsUnicode {
690- branchLabel = " \ue0a0 " + m .commitBranch
678+ branchLabel = string ( md . SourceBranch ) + " " + m .commitBranch
691679 }
692680 headerParts = headerParts + sep + refStyle .Render (branchLabel )
693681 }
@@ -733,7 +721,7 @@ func (m *mainModel) messageView() string {
733721 var out []string
734722
735723 // Render preamble lines.
736- for _ , line := range strings .Split (m .preamble , "\n " ) {
724+ for line := range strings .SplitSeq (m .preamble , "\n " ) {
737725 switch {
738726 case strings .HasPrefix (line , "commit " ):
739727 out = append (out , dim .Render ("commit " )+ yellow .Render (strings .TrimPrefix (line , "commit " )))
@@ -755,10 +743,7 @@ func (m *mainModel) messageView() string {
755743func (m * mainModel ) updateMessageVp () {
756744 s := overlayStyle ()
757745 maxWidth := min (m .width * 3 / 4 , 80 )
758- maxHeight := m .height / 2 - s .GetVerticalFrameSize ()
759- if maxHeight < 5 {
760- maxHeight = 5
761- }
746+ maxHeight := max (m .height / 2 - s .GetVerticalFrameSize (), 5 )
762747 content := lipgloss .NewStyle ().Width (maxWidth ).Render (m .messageView ())
763748 m .messageVp .SetWidth (maxWidth )
764749 m .messageVp .SetHeight (maxHeight )
@@ -786,7 +771,7 @@ func (m mainModel) renderScrollbar() string {
786771 thumb := lipgloss .NewStyle ().Foreground (lipgloss .Blue )
787772
788773 var sb strings.Builder
789- for i := 0 ; i < trackHeight ; i ++ {
774+ for i := range trackHeight {
790775 if i > 0 {
791776 sb .WriteByte ('\n' )
792777 }
@@ -801,17 +786,33 @@ func (m mainModel) renderScrollbar() string {
801786
802787func (m mainModel ) resultsView () string {
803788 sb := strings.Builder {}
789+ baseStyle := lipgloss .NewStyle ().Foreground (lipgloss .Color ("#F7F7F7" ))
790+ dirStyle := lipgloss .NewStyle ().Bold (false ).Foreground (lipgloss .Color ("#B8B8B8" ))
804791 for i , f := range m .filtered {
805- fName := utils .TruncateString (" " + f , m .config .UI .SearchTreeWidth - 2 )
792+ icon := neo .ByPath (f )
793+ if icon == nil {
794+ icon = neo .ByFileExtension ("txt" )
795+ }
796+ base := utils .RemoveReset (lipgloss .NewStyle ().
797+ Foreground (icon .Color (true )).
798+ Render (icon .Glyph ().String ()) + " " + baseStyle .Render (path .Base (f )))
799+ dir := utils .TruncateString (
800+ dirStyle .Render (path .Dir (f )),
801+ m .config .UI .SearchTreeWidth - 2 - lipgloss .Width (base ),
802+ )
803+ if path .Dir (f ) == "." {
804+ dir = ""
805+ }
806806 if i == m .resultsCursor {
807- sb . WriteString (
808- lipgloss .NewStyle ().
809- Background ( lipgloss . Color ( "#1b1b33" )) .
810- Bold ( true ).
811- Render (fName ) +
812- "\n " ,
807+ bg := lipgloss . NewStyle (). Background ( lipgloss . Color ( "#1b1b33" ))
808+ fName := lipgloss .NewStyle ().Bold ( true ). Render ( bg . Render ( base )) + bg . Render ( " " ) + bg . Render ( dir )
809+ sb . WriteString ( bg .
810+ Width ( m . config . UI . SearchTreeWidth ).
811+ Render (fName ) +
812+ "\n " ,
813813 )
814814 } else {
815+ fName := base + " " + dir
815816 sb .WriteString (fName + "\n " )
816817 }
817818 }
0 commit comments