MCPcopy Create free account
hub / github.com/cli/cli / truncateMiddle

Function truncateMiddle

pkg/cmd/ssh-key/list/list.go:106–119  ·  view source on GitHub ↗
(maxWidth int, t string)

Source from the content-addressed store, hash-verified

104}
105
106func truncateMiddle(maxWidth int, t string) string {
107 if len(t) <= maxWidth {
108 return t
109 }
110
111 ellipsis := "..."
112 if maxWidth < len(ellipsis)+2 {
113 return t[0:maxWidth]
114 }
115
116 halfWidth := (maxWidth - len(ellipsis)) / 2
117 remainder := (maxWidth - len(ellipsis)) % 2
118 return t[0:halfWidth+remainder] + ellipsis + t[len(t)-halfWidth:]
119}
120
121func printError(w io.Writer, err error) {
122 fmt.Fprintln(w, "warning: ", err)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected