Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix clipped icon colors in Windows Terminal #1777

Merged
merged 2 commits into from
Jul 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 33 additions & 31 deletions ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,20 +445,21 @@ func (win *win) printDir(ui *ui, dir *dir, context *dirContext, dirStyle *dirSty
maxWidth -= 1
}

var s []rune

// leave space for displaying the tag
s = append(s, ' ')

var icon iconDef
tag := ' '
if val, ok := context.tags[path]; ok && len(val) > 0 {
tag = rune(val[0])
}

var icon []rune
var iconDef iconDef
if gOpts.icons {
icon = dirStyle.icons.get(f)
s = append(s, []rune(icon.icon)...)
s = append(s, ' ')
iconDef = dirStyle.icons.get(f)
icon = append(icon, []rune(iconDef.icon)...)
icon = append(icon, ' ')
}

maxFilenameWidth := maxWidth - runeSliceWidth(s)
// subtract space for tag and icon
maxFilenameWidth := maxWidth - 1 - runeSliceWidth(icon)

info := fileInfo(f, dir)
showInfo := len(info) > 0 && 2*len(info) < maxWidth
Expand All @@ -477,40 +478,41 @@ func (win *win) printDir(ui *ui, dir *dir, context *dirContext, dirStyle *dirSty
for j := runeSliceWidth(filename); j < maxFilenameWidth; j++ {
filename = append(filename, ' ')
}
s = append(s, filename...)

if showInfo {
s = append(s, []rune(info)...)
filename = append(filename, []rune(info)...)
}

ce := ""
if i == dir.pos {
var cursorFmt string
switch dirStyle.role {
case Active:
ce = gOpts.cursoractivefmt
cursorFmt = optionToFmtstr(gOpts.cursoractivefmt)
case Parent:
ce = gOpts.cursorparentfmt
cursorFmt = optionToFmtstr(gOpts.cursorparentfmt)
case Preview:
ce = gOpts.cursorpreviewfmt
cursorFmt = optionToFmtstr(gOpts.cursorpreviewfmt)
}
}
cursorescapefmt := optionToFmtstr(ce)

s = append(s, ' ')
styledFilename := fmt.Sprintf(cursorescapefmt, string(s))
win.print(ui.screen, lnwidth+1, i, st, styledFilename)
line := append([]rune{tag}, icon...)
line = append(line, filename...)
line = append(line, ' ')
win.print(ui.screen, lnwidth+1, i, st, fmt.Sprintf(cursorFmt, string(line)))

if icon.hasStyle && i != dir.pos {
win.print(ui.screen, lnwidth+2, i, icon.style, icon.icon)
}
} else {
if tag != ' ' {
tagStr := fmt.Sprintf(optionToFmtstr(gOpts.tagfmt), string(tag))
win.print(ui.screen, lnwidth+1, i, tcell.StyleDefault, tagStr)
}

tag, ok := context.tags[path]
if ok {
if i == dir.pos {
win.print(ui.screen, lnwidth+1, i, st, fmt.Sprintf(cursorescapefmt, tag))
} else {
win.print(ui.screen, lnwidth+1, i, tcell.StyleDefault, fmt.Sprintf(optionToFmtstr(gOpts.tagfmt), tag))
if len(icon) > 0 {
iconStyle := st
if iconDef.hasStyle {
iconStyle = iconDef.style
}
win.print(ui.screen, lnwidth+2, i, iconStyle, string(icon))
}

win.print(ui.screen, lnwidth+2+runeSliceWidth(icon), i, st, string(filename))
}
}
}
Expand Down