MCPcopy
hub / github.com/cli/cli / writeTable

Function writeTable

pkg/cmd/repo/read-dir/read_dir.go:166–200  ·  view source on GitHub ↗

writeTable writes the TTY listing as a TYPE/NAME/SIZE table. Names are colored by entry type and directories and submodules show "-" since git reports no size for them.

(io *iostreams.IOStreams, dir *repoDir)

Source from the content-addressed store, hash-verified

164// by entry type and directories and submodules show "-" since git reports no size
165// for them.
166func writeTable(io *iostreams.IOStreams, dir *repoDir) error {
167 cs := io.ColorScheme()
168 tp := tableprinter.New(io, tableprinter.WithHeader("TYPE", "NAME", "SIZE"))
169 for _, e := range dir.Entries {
170 entryType := e.Type
171 if e.Type == "file" && e.isExecutable() {
172 entryType = "file*"
173 }
174
175 var color string
176 switch e.Type {
177 case "dir":
178 color = "blue"
179 case "symlink":
180 color = "cyan"
181 case "submodule":
182 color = "yellow"
183 case "file":
184 if e.isExecutable() {
185 color = "green"
186 }
187 }
188
189 size := "-"
190 if e.Type == "file" || e.Type == "symlink" {
191 size = text.FormatSize(int64(e.Size))
192 }
193
194 tp.AddField(entryType)
195 tp.AddField(e.Name, tableprinter.WithColor(cs.ColorFromString(color)))
196 tp.AddField(size)
197 tp.EndRow()
198 }
199 return tp.Render()
200}

Callers 1

readDirRunFunction · 0.85

Calls 7

NewFunction · 0.92
WithHeaderFunction · 0.92
FormatSizeFunction · 0.92
ColorSchemeMethod · 0.80
isExecutableMethod · 0.80
ColorFromStringMethod · 0.80
RenderMethod · 0.65

Tested by

no test coverage detected