filetype 实验性
实验性
本包属于实验层:任何 0.x 版本都可能有不兼容变化(docs/release.md「API 稳定性」)。
import "github.com/tangoui/tango/ui/icon/filetype"本页由
site/tools/apigen从源码注释生成(按 darwin 构建标签选文件),请勿手改。
Package filetype picks icons for files and folders, the way an IDE's file tree does: a file name resolves to a Kind (code, image, archive, …) by its exact name or extension, and a Set maps kinds to icons. Sets for the three design systems are provided; a Theme layers a file icon theme (for example one contributed by a plugin, with bitmap icons made by icon.FromImage) over a fallback.
ic := filetype.ForFlavor(c.Theme.Flavor).Icon("main.go", false, false)
nodes = append(nodes, ui.TreeNode{Key: path, Title: "main.go", Icon: ic})
Experimental: this package's API may change in any 0.x release (see docs/release.md, "API 稳定性").
变量
var Ant = &Set{FolderOpen: antd.FolderOpenOutlined, Kinds: [numKinds]*icon.Icon{
Document: antd.FileOutlined, Folder: antd.FolderOutlined, Code: antd.CodeOutlined,
TypeScript: antd.CodeOutlined, JavaScript: antd.CodeOutlined, Vue: antd.CodeOutlined,
Markup: antd.Html5Outlined, Style: antd.BgColorsOutlined, Data: antd.DatabaseOutlined,
Config: antd.SettingOutlined, Markdown: antd.FileMarkdownOutlined, Text: antd.FileTextOutlined,
Image: antd.FileImageOutlined, Video: antd.VideoCameraOutlined, Audio: antd.CustomerServiceOutlined,
Database: antd.DatabaseOutlined, Archive: antd.FileZipOutlined, Terminal: antd.DesktopOutlined,
PDF: antd.FilePdfOutlined, Word: antd.FileWordOutlined, Excel: antd.FileExcelOutlined,
Slides: antd.FilePptOutlined,
}}Ant uses Ant Design Outlined icons.
var Element = &Set{FolderOpen: element.FolderOpened, Kinds: [numKinds]*icon.Icon{
Document: element.Document, Folder: element.Folder, Code: element.Operation,
TypeScript: element.Tickets, JavaScript: element.Operation, Vue: element.Grid,
Markup: element.ChromeFilled, Style: element.Brush, Data: element.DataAnalysis,
Config: element.Setting, Markdown: element.Notebook, Text: element.Document,
Image: element.Picture, Video: element.VideoCamera, Audio: element.Headset,
Database: element.Coin, Archive: element.Box, Terminal: element.Monitor,
PDF: element.Reading, Word: element.Document, Excel: element.Grid, Slides: element.DataBoard,
}}Element uses Element Plus icons (MinCode's file tree mapping).
var Lucide = &Set{FolderOpen: lucide.FolderOpen, Kinds: [numKinds]*icon.Icon{
Document: lucide.File, Folder: lucide.Folder, Code: lucide.FileCode,
TypeScript: lucide.FileCode, JavaScript: lucide.FileCode, Vue: lucide.FileCode,
Markup: lucide.FileCode, Style: lucide.FileType, Data: lucide.FileBraces,
Config: lucide.FileCog, Markdown: lucide.FileText, Text: lucide.FileText,
Image: lucide.FileImage, Video: lucide.FileVideoCamera, Audio: lucide.FileMusic,
Database: lucide.FileDatabase, Archive: lucide.FileArchive, Terminal: lucide.FileTerminal,
PDF: lucide.FileText, Word: lucide.FileText, Excel: lucide.FileSpreadsheet, Slides: lucide.Presentation,
}}Lucide uses Lucide file icons (shadcn/ui).
类型
Kind
type Kind uint8Kind is a file category.
const (
Document Kind = iota // anything not recognized
Folder
Code
TypeScript
JavaScript
Vue
Markup // HTML, XML
Style // CSS and preprocessors
Data // JSON, YAML, TOML, CSV
Config // dotfiles, .ini, lock files
Markdown
Text
Image
Video
Audio
Database
Archive
Terminal // shell scripts, Dockerfile, Makefile
PDF
Word
Excel
Slides
)The kinds, after MinCode's project tree.
func KindOf
func KindOf(name string, isDir bool) KindKindOf returns the kind of a file (by its base name; separators of either kind are accepted) or Folder for a directory.
func (Kind) String
func (k Kind) String() stringResolver
type Resolver interface {
Icon(name string, isDir, open bool) *icon.Icon
}Resolver picks the icon of a file or folder.
Set
type Set struct {
Kinds [numKinds]*icon.Icon
FolderOpen *icon.Icon // an expanded folder; nil uses Kinds[Folder]
}Set maps kinds to icons. Kinds left nil use Kinds[Document].
func ForFlavor
func ForFlavor(f theme.Flavor) *SetForFlavor returns the set of a design system.
func (*Set) Icon
func (s *Set) Icon(name string, isDir, open bool) *icon.IconIcon implements Resolver.
Theme
type Theme struct {
FileNames map[string]*icon.Icon
Extensions map[string]*icon.Icon
FolderNames map[string]*icon.Icon
// FolderNamesOpen are the expanded variants of FolderNames.
FolderNamesOpen map[string]*icon.Icon
Kinds map[Kind]*icon.Icon
// File, Folder and FolderOpen are the theme's defaults; nil defers to
// Fallback.
File, Folder, FolderOpen *icon.Icon
// Fallback resolves what the theme leaves out; nil means Ant.
Fallback Resolver
}Theme is a file icon theme in the shape of VS Code's (and MinCode's plugin contribution point): icons by exact file or folder name, by extension and by kind, over a fallback. Map keys are lower case; extensions have no leading dot and may be compound ("d.ts", matched before "ts"). Icons may be bitmaps (icon.FromImage).
func (*Theme) Icon
func (t *Theme) Icon(name string, isDir, open bool) *icon.IconIcon implements Resolver.