trim command prefix when it is longer than width

cc #648
This commit is contained in:
Gokcehan 2021-06-13 01:09:19 +03:00
parent 29aa77aa27
commit 9885c4be7a

24
ui.go
View File

@ -836,22 +836,24 @@ func (ui *ui) draw(nav *nav) {
ui.drawStatLine(nav) ui.drawStatLine(nav)
ui.screen.HideCursor() ui.screen.HideCursor()
case ">": case ">":
pos := min(runeSliceWidth(ui.cmdAccLeft), ui.msgWin.w-len(ui.cmdPrefix)-1) prefix := ui.cmdPrefix[:min(ui.msgWin.w-1, len(ui.cmdPrefix))]
pos := min(runeSliceWidth(ui.cmdAccLeft), ui.msgWin.w-len(prefix)-1)
left := ui.cmdAccLeft[runeSliceWidth(ui.cmdAccLeft)-pos:] left := ui.cmdAccLeft[runeSliceWidth(ui.cmdAccLeft)-pos:]
right := ui.cmdAccRight right := ui.cmdAccRight
ui.msgWin.printLine(ui.screen, 0, 0, st, ui.cmdPrefix) ui.msgWin.printLine(ui.screen, 0, 0, st, prefix)
ui.msgWin.print(ui.screen, len(ui.cmdPrefix), 0, st, ui.msg) ui.msgWin.print(ui.screen, len(prefix), 0, st, ui.msg)
ui.msgWin.print(ui.screen, len(ui.cmdPrefix)+printLength(ui.msg), 0, st, string(left)) ui.msgWin.print(ui.screen, len(prefix)+printLength(ui.msg), 0, st, string(left))
ui.msgWin.print(ui.screen, len(ui.cmdPrefix)+printLength(ui.msg)+runeSliceWidth(left), 0, st, string(right)) ui.msgWin.print(ui.screen, len(prefix)+printLength(ui.msg)+runeSliceWidth(left), 0, st, string(right))
ui.screen.ShowCursor(ui.msgWin.x+len(ui.cmdPrefix)+printLength(ui.msg)+runeSliceWidth(left), ui.msgWin.y) ui.screen.ShowCursor(ui.msgWin.x+len(prefix)+printLength(ui.msg)+runeSliceWidth(left), ui.msgWin.y)
default: default:
pos := min(runeSliceWidth(ui.cmdAccLeft), ui.msgWin.w-len(ui.cmdPrefix)-1) prefix := ui.cmdPrefix[:min(ui.msgWin.w-1, len(ui.cmdPrefix))]
pos := min(runeSliceWidth(ui.cmdAccLeft), ui.msgWin.w-len(prefix)-1)
left := ui.cmdAccLeft[runeSliceWidth(ui.cmdAccLeft)-pos:] left := ui.cmdAccLeft[runeSliceWidth(ui.cmdAccLeft)-pos:]
right := ui.cmdAccRight right := ui.cmdAccRight
ui.msgWin.printLine(ui.screen, 0, 0, st, ui.cmdPrefix) ui.msgWin.printLine(ui.screen, 0, 0, st, prefix)
ui.msgWin.print(ui.screen, len(ui.cmdPrefix), 0, st, string(left)) ui.msgWin.print(ui.screen, len(prefix), 0, st, string(left))
ui.msgWin.print(ui.screen, len(ui.cmdPrefix)+runeSliceWidth(left), 0, st, string(right)) ui.msgWin.print(ui.screen, len(prefix)+runeSliceWidth(left), 0, st, string(right))
ui.screen.ShowCursor(ui.msgWin.x+len(ui.cmdPrefix)+runeSliceWidth(left), ui.msgWin.y) ui.screen.ShowCursor(ui.msgWin.x+len(prefix)+runeSliceWidth(left), ui.msgWin.y)
} }
if gOpts.preview { if gOpts.preview {