Fix clipped icon colors in Windows Terminal (#1777)
* Fix clipped icon colors in Windows Terminal * Only print components if necessary
This commit is contained in:
1 parent
26dc2f1ebd
commit
b819d90be2
1 file changed
+36
-34
@@ -445,20 +445,21 @@ func (win *win) printDir(ui *ui, dir *dir, context *dirContext, dirStyle *dirSty
|
|||||||
maxWidth -= 1
|
maxWidth -= 1
|
||||||
}
|
}
|
||||||
|
|
||||||
var s []rune
|
tag := ' '
|
||||||
|
if val, ok := context.tags[path]; ok && len(val) > 0 {
|
||||||
// leave space for displaying the tag
|
tag = rune(val[0])
|
||||||
s = append(s, ' ')
|
|
||||||
|
|
||||||
var icon iconDef
|
|
||||||
|
|
||||||
if gOpts.icons {
|
|
||||||
icon = dirStyle.icons.get(f)
|
|
||||||
s = append(s, []rune(icon.icon)...)
|
|
||||||
s = append(s, ' ')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
maxFilenameWidth := maxWidth - runeSliceWidth(s)
|
var icon []rune
|
||||||
|
var iconDef iconDef
|
||||||
|
if gOpts.icons {
|
||||||
|
iconDef = dirStyle.icons.get(f)
|
||||||
|
icon = append(icon, []rune(iconDef.icon)...)
|
||||||
|
icon = append(icon, ' ')
|
||||||
|
}
|
||||||
|
|
||||||
|
// subtract space for tag and icon
|
||||||
|
maxFilenameWidth := maxWidth - 1 - runeSliceWidth(icon)
|
||||||
|
|
||||||
info := fileInfo(f, dir)
|
info := fileInfo(f, dir)
|
||||||
showInfo := len(info) > 0 && 2*len(info) < maxWidth
|
showInfo := len(info) > 0 && 2*len(info) < maxWidth
|
||||||
@@ -477,40 +478,41 @@ func (win *win) printDir(ui *ui, dir *dir, context *dirContext, dirStyle *dirSty
|
|||||||
for j := runeSliceWidth(filename); j < maxFilenameWidth; j++ {
|
for j := runeSliceWidth(filename); j < maxFilenameWidth; j++ {
|
||||||
filename = append(filename, ' ')
|
filename = append(filename, ' ')
|
||||||
}
|
}
|
||||||
s = append(s, filename...)
|
|
||||||
|
|
||||||
if showInfo {
|
if showInfo {
|
||||||
s = append(s, []rune(info)...)
|
filename = append(filename, []rune(info)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
ce := ""
|
|
||||||
if i == dir.pos {
|
if i == dir.pos {
|
||||||
|
var cursorFmt string
|
||||||
switch dirStyle.role {
|
switch dirStyle.role {
|
||||||
case Active:
|
case Active:
|
||||||
ce = gOpts.cursoractivefmt
|
cursorFmt = optionToFmtstr(gOpts.cursoractivefmt)
|
||||||
case Parent:
|
case Parent:
|
||||||
ce = gOpts.cursorparentfmt
|
cursorFmt = optionToFmtstr(gOpts.cursorparentfmt)
|
||||||
case Preview:
|
case Preview:
|
||||||
ce = gOpts.cursorpreviewfmt
|
cursorFmt = optionToFmtstr(gOpts.cursorpreviewfmt)
|
||||||
}
|
}
|
||||||
}
|
line := append([]rune{tag}, icon...)
|
||||||
cursorescapefmt := optionToFmtstr(ce)
|
line = append(line, filename...)
|
||||||
|
line = append(line, ' ')
|
||||||
|
win.print(ui.screen, lnwidth+1, i, st, fmt.Sprintf(cursorFmt, string(line)))
|
||||||
|
|
||||||
s = append(s, ' ')
|
} else {
|
||||||
styledFilename := fmt.Sprintf(cursorescapefmt, string(s))
|
if tag != ' ' {
|
||||||
win.print(ui.screen, lnwidth+1, i, st, styledFilename)
|
tagStr := fmt.Sprintf(optionToFmtstr(gOpts.tagfmt), string(tag))
|
||||||
|
win.print(ui.screen, lnwidth+1, i, tcell.StyleDefault, tagStr)
|
||||||
if icon.hasStyle && i != dir.pos {
|
|
||||||
win.print(ui.screen, lnwidth+2, i, icon.style, icon.icon)
|
|
||||||
}
|
|
||||||
|
|
||||||
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))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user