mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-12 04:45:47 +02:00
fix truncation
This commit is contained in:
parent
72bce201df
commit
f91892b8f1
3 changed files with 88 additions and 28 deletions
|
@ -68,33 +68,6 @@ func ModuloWithWrap(n, max int) int {
|
|||
}
|
||||
}
|
||||
|
||||
// TruncateWithEllipsis returns a string, truncated to a certain length, with an ellipsis
|
||||
func TruncateWithEllipsis(str string, limit int) string {
|
||||
if limit == 1 && len(str) > 1 {
|
||||
return "."
|
||||
}
|
||||
|
||||
if limit == 2 && len(str) > 2 {
|
||||
return ".."
|
||||
}
|
||||
|
||||
ellipsis := "..."
|
||||
if len(str) <= limit {
|
||||
return str
|
||||
}
|
||||
|
||||
remainingLength := limit - len(ellipsis)
|
||||
return str[0:remainingLength] + "..."
|
||||
}
|
||||
|
||||
func SafeTruncate(str string, limit int) string {
|
||||
if len(str) > limit {
|
||||
return str[0:limit]
|
||||
} else {
|
||||
return str
|
||||
}
|
||||
}
|
||||
|
||||
func FindStringSubmatch(str string, regexpStr string) (bool, []string) {
|
||||
re := regexp.MustCompile(regexpStr)
|
||||
match := re.FindStringSubmatch(str)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue