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)
| 164 | // by entry type and directories and submodules show "-" since git reports no size |
| 165 | // for them. |
| 166 | func 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 | } |
no test coverage detected