general

package
v1.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 30, 2024 License: GPL-3.0 Imports: 27 Imported by: 0

Documentation

Overview

File: define_system_linux.go Author: YJ Email: [email protected] Created Time: 2024-07-19 15:27:08

Description: 操作系统相关方法

Index

Constants

View Source
const (
	TabLightColor        = "#874BFD"
	TabDarkColor         = "#7D56F4"
	TabContentLightColor = "#87CEEB"
	TabContentDarkColor  = "#C3FFFF"
)

Tab 专用

View Source
const (
	HeaderColor    = lipgloss.Color("#CCCCCC") // 表头颜色
	BorderColor    = lipgloss.Color("#6C757D") // 边框颜色
	ColumnOneColor = lipgloss.Color("#555555") // 第一列颜色

	DefaultColor = lipgloss.Color("#FFFFFF") // 默认颜色
)

Notice: NEW

View Source
const (
	Name    string = "Eniac"                 // 程序名
	Version string = "v1.10.0"               // 程序版本
	Project string = "github.com/yhyj/eniac" // 项目地址
)

Variables

View Source
var (
	FgBlackText        = color.FgBlack.Render        // 前景色 - 黑色
	FgWhiteText        = color.FgWhite.Render        // 前景色 - 白色
	FgLightWhiteText   = color.FgLightWhite.Render   // 前景色 - 亮白色
	FgGrayText         = color.FgGray.Render         // 前景色 - 灰色
	FgRedText          = color.FgRed.Render          // 前景色 - 红色
	FgLightRedText     = color.FgLightRed.Render     // 前景色 - 亮红色
	FgGreenText        = color.FgGreen.Render        // 前景色 - 绿色
	FgLightGreenText   = color.FgLightGreen.Render   // 前景色 - 亮绿色
	FgYellowText       = color.FgYellow.Render       // 前景色 - 黄色
	FgLightYellowText  = color.FgLightYellow.Render  // 前景色 - 亮黄色
	FgBlueText         = color.FgBlue.Render         // 前景色 - 蓝色
	FgLightBlueText    = color.FgLightBlue.Render    // 前景色 - 亮蓝色
	FgMagentaText      = color.FgMagenta.Render      // 前景色 - 品红
	FgLightMagentaText = color.FgLightMagenta.Render // 前景色 - 亮品红
	FgCyanText         = color.FgCyan.Render         // 前景色 - 青色
	FgLightCyanText    = color.FgLightCyan.Render    // 前景色 - 亮青色

	BgBlackText        = color.BgBlack.Render        // 背景色 - 黑色
	BgWhiteText        = color.BgWhite.Render        // 背景色 - 白色
	BgLightWhiteText   = color.BgLightWhite.Render   // 背景色 - 亮白色
	BgGrayText         = color.BgGray.Render         // 背景色 - 灰色
	BgRedText          = color.BgRed.Render          // 背景色 - 红色
	BgLightRedText     = color.BgLightRed.Render     // 背景色 - 亮红色
	BgGreenText        = color.BgGreen.Render        // 背景色 - 绿色
	BgLightGreenText   = color.BgLightGreen.Render   // 背景色 - 亮绿色
	BgYellowText       = color.BgYellow.Render       // 背景色 - 黄色
	BgLightYellowText  = color.BgLightYellow.Render  // 背景色 - 亮黄色
	BgBlueText         = color.BgBlue.Render         // 背景色 - 蓝色
	BgLightBlueText    = color.BgLightBlue.Render    // 背景色 - 亮蓝色
	BgMagentaText      = color.BgMagenta.Render      // 背景色 - 品红
	BgLightMagentaText = color.BgLightMagenta.Render // 背景色 - 亮品红
	BgCyanText         = color.BgCyan.Render         // 背景色 - 青色
	BgLightCyanText    = color.BgLightCyan.Render    // 背景色 - 亮青色

	InfoText      = color.Info.Render      // Info 文本
	NoteText      = color.Note.Render      // Note 文本
	LightText     = color.Light.Render     // Light 文本
	ErrorText     = color.Error.Render     // Error 文本
	DangerText    = color.Danger.Render    // Danger 文本
	NoticeText    = color.Notice.Render    // Notice 文本
	SuccessText   = color.Success.Render   // Success 文本
	CommentText   = color.Comment.Render   // Comment 文本
	PrimaryText   = color.Primary.Render   // Primary 文本
	WarnText      = color.Warn.Render      // Warn 文本
	QuestionText  = color.Question.Render  // Question 文本
	SecondaryText = color.Secondary.Render // Secondary 文本
)
View Source
var (
	Separator1st = "=" // 分隔符 - 1级
	Separator2st = "-" // 分隔符 - 2级
	Separator3st = "·" // 分隔符 - 3级
)
View Source
var (
	OverWriteTips     = "%s file already exists, do you want to overwrite it?" // 提示词 - 文件已存在是否覆写
	SetConfigItemTips = "Please set '%s' item"                                 // 提示词 - 设置配置项
)
View Source
var (
	TabExPaddingUD         = 0 // 标签页外部上下边距
	TabExPaddingLR         = 1 // 标签页外部左右边距
	InactiveTabInPaddingUD = 0 // 不活跃标签页内部上下边距
	InactiveTabInPaddingLR = 2 // 不活跃标签页内部左右边距
	ActiveTabInPaddingUD   = 0 // 活跃标签页内部上下边距
	ActiveTabInPaddingLR   = 3 // 活跃标签页内部左右边距
	TableInPaddingUD       = 0 // 数据表内部上下边距
	TableInPaddingLR       = 1 // 数据表内部左右边距
	TableExPaddingUD       = 1 // 数据表外部上下边距
	TableExPaddingLR       = 0 // 数据表外部左右边距

	HeaderStyle = renderer.NewStyle().Align(lipgloss.Center).Padding(TableInPaddingUD, TableInPaddingLR).Bold(true).Foreground(HeaderColor) // 表头样式
	BorderStyle = renderer.NewStyle().Foreground(BorderColor)                                                                               // 边框样式
	CellStyle   = renderer.NewStyle().Align(lipgloss.Center).Padding(TableInPaddingUD, TableInPaddingLR).Bold(false)                        // 单元格样式
)
View Source
var (
	UpdateBasis          = "update-checker.timer"  // 更新检测服务状态判断依据
	ArchUpdateRecordFile = "/tmp/checker-arch.log" // Arch Linux 官方仓库可更新包记录文件
	AurUpdateRecordFile  = "/tmp/checker-aur.log"  // AUR 可更新包记录文件
)
View Source
var (
	GitCommitHash string = "Unknown" // Git 提交 Hash
	BuildTime     string = "Unknown" // 编译时间
	BuildBy       string = "Unknown" // 编译者
)
View Source
var Arch = runtime.GOARCH // 系统架构
View Source
var (
	ConfigFile = filepath.Join(configDir, programDir, configFile) // 配置文件路径
)
View Source
var (
	ErrorInfoFlag = "•" // 身份符号 - 报错信息
)
View Source
var GenealogyName = map[string]map[string]string{
	"BIOSVendor":               {"zh": "BIOS 厂商", "en": "Vendor"},
	"BIOSVersion":              {"zh": "BIOS 版本", "en": "Version"},
	"BIOSDate":                 {"zh": "BIOS 发布日期", "en": "Release Date"},
	"BoardVendor":              {"zh": "主板厂商", "en": "Vendor"},
	"BoardName":                {"zh": "主板名称", "en": "Name"},
	"BoardVersion":             {"zh": "主板版本", "en": "Version"},
	"CPUModel":                 {"zh": "处理器型号", "en": "Model"},
	"CPUNumber":                {"zh": "处理器数量", "en": "Number"},
	"CPUCores":                 {"zh": "处理器核心", "en": "Cores"},
	"CPUThreads":               {"zh": "处理器线程", "en": "Threads"},
	"CPUCache":                 {"zh": "处理器缓存", "en": "Cache"},
	"GPUAddress":               {"zh": "显卡地址", "en": "Address"},
	"GPUDriver":                {"zh": "显卡驱动", "en": "Driver"},
	"GPUProduct":               {"zh": "显卡型号", "en": "Product"},
	"GPUVendor":                {"zh": "显卡厂商", "en": "Vendor"},
	"OS":                       {"zh": "操作系统", "en": "OS"},
	"Arch":                     {"zh": "系统架构", "en": "Arch"},
	"Kernel":                   {"zh": "内核版本", "en": "Kernel"},
	"CurrentKernel":            {"zh": "当前内核版本", "en": "Current Kernel"},
	"LatestKernel":             {"zh": "最新内核版本", "en": "Latest Kernel"},
	"Platform":                 {"zh": "系统类型", "en": "Platform"},
	"Hostname":                 {"zh": "主机名称", "en": "Hostname"},
	"TimeZone":                 {"zh": "时区", "en": "Time zone"},
	"Load1":                    {"zh": "1分钟平均负载", "en": "Load average (1 min)"},
	"Load5":                    {"zh": "5分钟平均负载", "en": "Load average (5 min)"},
	"Load15":                   {"zh": "15分钟平均负载", "en": "Load average (15 min)"},
	"NicName":                  {"zh": "网卡名称", "en": "Name"},
	"NicPCIAddress":            {"zh": "PCI 地址", "en": "PCI Address"},
	"NicMacAddress":            {"zh": "MAC 地址", "en": "MAC Address"},
	"NicSpeed":                 {"zh": "网卡速率", "en": "Speed"},
	"NicDuplex":                {"zh": "工作模式", "en": "Duplex"},
	"NicDriver":                {"zh": "网卡驱动", "en": "Driver"},
	"NicProduct":               {"zh": "网卡型号", "en": "Product"},
	"NicVendor":                {"zh": "网卡厂商", "en": "Vendor"},
	"MemoryTotal":              {"zh": "内存大小", "en": "Total"},
	"MemoryUsed":               {"zh": "已用内存", "en": "Used"},
	"MemoryUsedPercent":        {"zh": "内存占用", "en": "Used Percent"},
	"MemoryFree":               {"zh": "空闲内存", "en": "Free"},
	"MemoryShared":             {"zh": "共享内存", "en": "Shared"},
	"MemoryBuffCache":          {"zh": "缓冲内存", "en": "Buff Cache"},
	"MemoryAvail":              {"zh": "可用内存", "en": "Avail"},
	"SwapStatus":               {"zh": "交换空间状态", "en": "Swap Status"},
	"SwapTotal":                {"zh": "交换空间大小", "en": "Total"},
	"SwapFree":                 {"zh": "空闲交换空间", "en": "Free"},
	"Process":                  {"zh": "进程数", "en": "Process"},
	"PackageTotalCount":        {"zh": "已安装包总数", "en": "Installed Package Total Count"},
	"PackageTotalSize":         {"zh": "已安装包总大小", "en": "Installed Package Total Size"},
	"PackageAsExplicitCount":   {"zh": "单独指定安装包数量", "en": "As Explicit Package Count"},
	"PackageAsDependencyCount": {"zh": "作为依赖安装包数量", "en": "As Dependency Package Count"},
	"ProductVendor":            {"zh": "设备厂商", "en": "Vendor"},
	"ProductName":              {"zh": "设备名称", "en": "Name"},
	"StorageName":              {"zh": "磁盘名称", "en": "Name"},
	"StorageType":              {"zh": "磁盘类型", "en": "Type"},
	"StorageDriver":            {"zh": "磁盘驱动", "en": "Driver"},
	"StorageVendor":            {"zh": "磁盘厂商", "en": "Vendor"},
	"StorageModel":             {"zh": "磁盘型号", "en": "Model"},
	"StorageSerial":            {"zh": "磁盘序列号", "en": "Serial"},
	"StorageRemovable":         {"zh": "磁盘可移除", "en": "Removable"},
	"StorageSize":              {"zh": "磁盘容量", "en": "Size"},
	"BootTime":                 {"zh": "系统启动时间", "en": "Boot Time"},
	"Uptime":                   {"zh": "系统运行时长", "en": "Uptime"},
	"StartTime":                {"zh": "系统启动用时", "en": "Startup Time"},
	"User":                     {"zh": "用户名称", "en": "User"},
	"UserName":                 {"zh": "用户昵称", "en": "Username"},
	"UserUid":                  {"zh": "用户标识", "en": "UID"},
	"UserGid":                  {"zh": "用户组标识", "en": "GID"},
	"UserHomeDir":              {"zh": "用户主目录", "en": "Home Dir"},
	"UpdateCheckDaemonStatus":  {"zh": "更新检测服务", "en": "Update Check Daemon"},
	"LastCheckTime":            {"zh": "最后检查时间", "en": "Last Check Time"},
	"UpdatablePackageList":     {"zh": "可更新包列表", "en": "Updatable Package List"},
	"UpdatablePackageQuantity": {"zh": "可更新包数量", "en": "Updatable Package Quantity"},
}

各部分.条目的名称

View Source
var Language = GetLanguage() // 系统语言
View Source
var Notifier []string // 通知器
View Source
var PartName = map[string]map[string]string{
	"Product": {"zh": "设备", "en": "Product"},
	"Board":   {"zh": "主板", "en": "Board"},
	"BIOS":    {"zh": "BIOS", "en": "BIOS"},
	"CPU":     {"zh": "处理器", "en": "CPU"},
	"GPU":     {"zh": "显卡", "en": "GPU"},
	"Memory":  {"zh": "内存", "en": "Memory"},
	"Swap":    {"zh": "交换空间", "en": "Swap"},
	"Disk":    {"zh": "磁盘", "en": "Disk"},
	"NIC":     {"zh": "网卡", "en": "NIC"},
	"OS":      {"zh": "系统", "en": "OS"},
	"Package": {"zh": "安装包", "en": "Package"},
	"Load":    {"zh": "负载", "en": "Load"},
	"Time":    {"zh": "时间", "en": "Time"},
	"User":    {"zh": "用户", "en": "User"},
	"Update":  {"zh": "更新", "en": "Update"},
}

各部分的名称

View Source
var Platform = runtime.GOOS // 操作系统
View Source
var Sep = string(filepath.Separator) // 路径分隔符
View Source
var UserInfo, _ = GetUserInfoByName(UserName) // 用户信息
View Source
var UserName = func() string {
	if GetVariable("SUDO_USER") != "" {
		return GetVariable("SUDO_USER")
	}
	return GetVariable("USER")
}()

用户名,当程序提权运行时,使用 SUDO_USER 变量获取提权前的用户名

Functions

func AreYouSure added in v1.10.0

func AreYouSure(question string, defaultAnswer bool) (bool, error)

AreYouSure 获取用户二次确认

参数:

  • question: 问题
  • defaultAnswer: 默认回答,true 或 false

返回:

  • true/false
  • 错误信息

func CreateFile

func CreateFile(file string) error

CreateFile 创建文件,包括其父目录

参数:

  • file: 文件路径

返回:

  • 错误信息

func DeleteFile

func DeleteFile(file string) error

DeleteFile 删除文件,如果目标是文件夹则包括其下所有文件

参数:

  • file: 文件路径

返回:

  • 错误信息

func FileExist

func FileExist(file string) bool

FileExist 判断文件是否存在

参数:

  • file: 文件路径

返回:

  • 文件存在返回 true,否则返回 false

func GetBIOSInfo added in v1.3.9

func GetBIOSInfo(sysInfo sysinfo.SysInfo) map[string]interface{}

GetBIOSInfo 获取 BIOS 信息

参数:

  • sysInfo: 总的系统信息

返回:

  • BIOS 信息

func GetBoardInfo added in v1.3.9

func GetBoardInfo(sysInfo sysinfo.SysInfo) map[string]interface{}

GetBoardInfo 获取主板信息

参数:

  • sysInfo: 总的系统信息

返回:

  • 主板信息

func GetCPUInfo added in v1.3.9

func GetCPUInfo(sysInfo sysinfo.SysInfo, dataUnit string) map[string]interface{}

GetCPUInfo 获取 CPU 信息

参数:

  • sysInfo: 总的系统信息
  • dataUnit: 存储数据单位

返回:

  • CPU 信息

func GetCallerInfo added in v1.6.5

func GetCallerInfo() (string, int)

GetCallerInfo 获取调用者信息

返回:

  • 调用者所在文件名(不带后缀)
  • 调用者所在行号

func GetCheckUpdateDaemonInfo added in v1.7.9

func GetCheckUpdateDaemonInfo(basis string, owner string) (map[string]interface{}, error)

GetCheckUpdateDaemonInfo 获取更新检测服务的信息

参数:

  • basis: 判断更新检测服务状态的依据

返回:

  • 更新检测服务的信息
  • 错误信息

func GetColor added in v1.2.1

func GetColor(count int) []lipgloss.Color

GetColor 随机获取多个颜色

参数:

  • count: 颜色数量

返回:

  • 颜色代码

func GetCurrentUserInfo

func GetCurrentUserInfo() (*user.User, error)

GetCurrentUserInfo 获取当前用户信息

返回:

  • 用户信息
  • 错误信息

func GetFileModTime added in v1.8.9

func GetFileModTime(file string) string

GetFileModTime 获取文件的最后修改时间

参数:

  • file: 文件路径

返回:

  • 最后修改时间

func GetGPUInfo added in v1.3.9

func GetGPUInfo() map[string]interface{}

GetGPUInfo 获取显卡信息

返回:

  • 显卡信息

func GetHostname

func GetHostname() string

GetHostname 获取系统 HOSTNAME

返回:

  • HOSTNAME 或空字符串

func GetLanguage added in v1.2.5

func GetLanguage() string

GetLanguage 获取系统语言

返回:

  • 系统语言,目前仅支持 zh 或 en

func GetLatestKernelVersion added in v1.6.4

func GetLatestKernelVersion() string

GetLatestKernelVersion 获取本地最新内核版本

返回:

  • 最新内核版本号

func GetLoadInfo added in v1.3.9

func GetLoadInfo() map[string]interface{}

GetLoadInfo 获取负载信息

返回:

  • 系统负载信息

func GetMemoryInfo added in v1.3.9

func GetMemoryInfo(dataUnit string, percentUnit string) map[string]interface{}

GetMemoryInfo 获取内存信息

参数:

  • dataUnit: 存储数据单位
  • percentUnit: 百分比数据单位

返回:

  • 内存信息

func GetNicInfo added in v1.3.9

func GetNicInfo() map[string]interface{}

GetNicInfo 获取网卡信息

返回:

  • 网卡信息

func GetOSInfo added in v1.3.9

func GetOSInfo(sysInfo sysinfo.SysInfo) map[string]interface{}

GetOSInfo 获取系统信息

参数:

  • sysInfo: 总的系统信息 (System Info)

返回:

  • 系统信息 (OS Info)

func GetPackageInfo added in v1.5.0

func GetPackageInfo() (map[string]interface{}, error)

GetPackageInfo 获取安装包信息

返回:

  • 安装包信息
  • 错误信息

func GetProductInfo added in v1.3.9

func GetProductInfo(sysInfo sysinfo.SysInfo) map[string]interface{}

GetProductInfo 获取产品信息

参数:

  • sysInfo: 总的系统信息

返回:

  • 产品信息

func GetStorageInfo added in v1.3.9

func GetStorageInfo() map[string]interface{}

GetStorageInfo 获取存储设备信息

返回:

  • 存储设备信息

func GetSwapInfo added in v1.3.9

func GetSwapInfo(dataUnit string) map[string]interface{}

GetSwapInfo 获取交换分区信息

参数:

  • dataUnit: 存储数据单位

返回:

  • 交换分区信息

func GetSystemID added in v1.7.9

func GetSystemID() (string, error)

GetSystemID 获取系统 ID_LIKE 或 ID

返回:

  • 系统 ID_LIKE 或 ID
  • 错误信息

func GetTerminalSize added in v1.8.7

func GetTerminalSize() (width, height int, err error)

GetTerminalSize 获取终端尺寸

返回:

  • 终端宽度(列)
  • 终端高度(行)
  • 错误信息

func GetTimeInfo added in v1.3.9

func GetTimeInfo() (map[string]interface{}, error)

GetTimeInfo 获取时间信息

返回:

  • 时间信息
  • 错误信息

func GetTimeZoneOriginal added in v1.6.4

func GetTimeZoneOriginal() string

GetTimeZoneOriginal 获取时区信息的原始方法(检测 /etc/localtime 实际指向的文件)

返回:

  • 时区信息

func GetTomlConfig added in v1.3.9

func GetTomlConfig(filePath string) (*toml.Tree, error)

GetTomlConfig 读取 toml 配置文件

参数:

  • filePath: toml 配置文件路径

返回:

  • toml 配置树
  • 错误信息

func GetUpdatablePackageInfo added in v1.7.9

func GetUpdatablePackageInfo(archFilePath, archDividing string, aurFilePath, aurDividing string, line int) (map[string]interface{}, error)

GetUpdatablePackageInfo 读取可更新包信息

参数:

  • archFilePath: Arch Linux 官方仓库更新信息记录文件路径
  • archDividing: 记录文件中 Arch Linux 官方仓库更新信息的开始符
  • aurFilePath: AUR 更新信息记录文件路径
  • aurDividing: 记录文件中 AUR 更新信息的开始符
  • line: 读取指定行,等于 0 时读取全部行

返回:

  • 可更新包信息
  • 错误信息

func GetUserInfo added in v1.3.9

func GetUserInfo() map[string]interface{}

GetUserInfo 获取用户信息

返回:

  • 用户信息

func GetUserInfoById

func GetUserInfoById(userId int) (*user.User, error)

GetUserInfoById 根据 ID 获取用户信息

参数:

  • userId: 用户 ID

返回:

  • 用户信息
  • 错误信息

func GetUserInfoByName

func GetUserInfoByName(userName string) (*user.User, error)

GetUserInfoByName 根据用户名获取用户信息

参数:

  • userName: 用户名

返回:

  • 用户信息
  • 错误信息

func GetUserInput added in v1.10.0

func GetUserInput(tips string, defaultValue string) (string, error)

GetUserInput 获取用户输入

参数:

  • tips: 提示信息
  • defaultValue: 用户未输入时的默认值

返回:

  • 用户输入(去掉了最后的换行符)
  • 错误信息

func GetVariable

func GetVariable(key string) string

GetVariable 获取环境变量

参数:

  • key: 变量名

返回:

  • 变量值

func Human added in v1.1.7

func Human(size float64, initialUnit string) (float64, string)

Human 存储数据转换为人类可读的格式

参数:

  • size: 需要转换的存储数据
  • initialUnit: 初始单位

返回:

  • 转换后的数据
  • 转换后的单位

func MapBoolCounter added in v1.6.0

func MapBoolCounter(elements map[string]bool, target bool) int

MapBoolCounter 统计指定布尔值在映射中出现的次数

参数:

  • elements: 目标映射
  • target: 目标元素

返回:

  • 出现次数

func Max added in v1.6.0

func Max(x, y int) int

Max 返回两个数中的最大值

参数:

  • x: 第一个数
  • y: 第二个数

返回:

  • 两个数中的最大值

func Min added in v1.6.0

func Min(x, y int) int

Min 返回两个数中的最小值

参数:

  • x: 第一个数
  • y: 第二个数

返回:

  • 两个数中的最小值

func Notification added in v1.7.0

func Notification()

Notification 显示通知

func ProgramInfo

func ProgramInfo() map[string]string

ProgramInfo 返回程序信息

返回:

  • 程序信息

func ReadFileKey added in v1.1.6

func ReadFileKey(file, key string) string

ReadFileKey 读取文件包含关键字的行

参数:

  • file: 文件路径
  • key: 关键字

返回:

  • 包含关键字的行的内容
func ReadFileLink(file string) (string, error)

ReadFileLink 如果文件是软链接文件,返回其指向的文件路径

参数:

  • file: 文件路径

返回:

  • 软链接文件所指向文件的路径
  • 报错信息

func RunCommandToBuffer added in v1.7.4

func RunCommandToBuffer(command string, args []string) (string, string, error)

RunCommandToBuffer 运行命令,将命令的 Stdout 和 Stderr 定向到字节缓冲区

  • 命令的 Stdout 和 Stderr 末尾自带的换行符已去除

参数:

  • command: 命令
  • args: 命令参数(每个以空格分隔的参数作为切片的一个元素)

返回:

  • Stdout 缓冲区内容
  • Stderr 缓冲区内容
  • 错误信息

func RunCommandToOS added in v1.7.4

func RunCommandToOS(command string, args []string) error

RunCommandToOS 运行命令,将命令的 Stdin, Stdout 和 Stderr 定向到系统标准输入、标准输出和标准错误

参数:

  • command: 命令
  • args: 命令参数(每个以空格分隔的参数作为切片的一个元素)

返回:

  • 错误信息

func SetVariable

func SetVariable(key, value string) error

SetVariable 设置环境变量

参数:

  • key: 变量名
  • value: 变量值

返回:

  • 错误信息

func TabSelector added in v1.6.0

func TabSelector(tabs, contents []string, cycle bool) error

TabSelector 标签选择器,接受一个标签切片和一个标签内容切片,显示选中的标签的内容

参数:

  • tabs: 所有标签
  • contents: 所有标签对应的内容
  • cycle: 是否允许循环切换

返回:

  • 错误信息

func UnixTime2DayHourMinuteSecond added in v1.2.3

func UnixTime2DayHourMinuteSecond(unixTime int64) (day, hour, minute, second int64)

UnixTime2DayHourMinuteSecond Unix 时间戳转换为天、小时、分钟、秒

参数:

  • totalSeconds: Unix 时间戳

返回:

  • day: 天
  • hour: 小时
  • minute: 分钟
  • second: 秒

func UnixTime2TimeString added in v1.2.3

func UnixTime2TimeString(unixTime int64) string

UnixTime2TimeString Unix 时间戳转换为字符串格式

参数:

  • timeStamp: Unix 时间戳

返回:

  • 格式化的 Unix 时间戳字符串

func UpperFirstChar added in v1.7.2

func UpperFirstChar(str string) string

UpperFirstChar 最大化字符串的第一个字母

参数:

  • str: 需要处理的字符串

返回:

  • 处理后的字符串

func WriteTomlConfig added in v1.3.9

func WriteTomlConfig(filePath string) (int64, error)

WriteTomlConfig 写入 toml 配置文件

参数:

  • filePath: toml 配置文件路径

返回:

  • 写入的字节数
  • 错误信息

Types

type BiosConfig added in v1.5.1

type BiosConfig struct {
	Items []string `toml:"items"`
}

type BoardConfig added in v1.5.1

type BoardConfig struct {
	Items []string `toml:"items"`
}

type CPUConfig added in v1.5.1

type CPUConfig struct {
	Items     []string `toml:"items"`
	CacheUnit string   `toml:"cache_unit"`
}

type Config added in v1.3.9

type Config struct {
	Main      MainConfig      `toml:"main"`
	Genealogy GenealogyConfig `toml:"genealogy"`
}

用于转换 Toml 配置树的结构体

func LoadConfigToStruct added in v1.3.9

func LoadConfigToStruct(configTree *toml.Tree) (*Config, error)

LoadConfigToStruct 将 Toml 配置树加载到结构体

参数:

  • configTree: 解析 toml 配置文件得到的配置树

返回:

  • 结构体
  • 错误信息

type GPUConfig added in v1.5.1

type GPUConfig struct {
	Items []string `toml:"items"`
}

type GenealogyConfig added in v1.3.9

type GenealogyConfig struct {
	Bios    BiosConfig    `toml:"bios"`
	Board   BoardConfig   `toml:"board"`
	CPU     CPUConfig     `toml:"cpu"`
	GPU     GPUConfig     `toml:"gpu"`
	Load    LoadConfig    `toml:"load"`
	Memory  MemoryConfig  `toml:"memory"`
	Nic     NicConfig     `toml:"nic"`
	OS      OSConfig      `toml:"os"`
	Package PackageConfig `toml:"package"`
	Product ProductConfig `toml:"product"`
	Storage StorageConfig `toml:"storage"`
	Swap    SwapConfig    `toml:"swap"`
	Time    TimeConfig    `toml:"time"`
	Update  UpdateConfig  `toml:"update"`
	User    UserConfig    `toml:"user"`
}

type LoadConfig added in v1.5.1

type LoadConfig struct {
	Items []string `toml:"items"`
}

type MainConfig added in v1.3.9

type MainConfig struct {
	Colorful bool `toml:"colorful"`
	Cycle    bool `toml:"cycle"`
}

type MemoryConfig added in v1.3.9

type MemoryConfig struct {
	Items       []string `toml:"items"`
	DataUnit    string   `toml:"data_unit"`
	PercentUnit string   `toml:"percent_unit"`
}

type NicConfig added in v1.5.1

type NicConfig struct {
	Items []string `toml:"items"`
}

type OSConfig added in v1.5.1

type OSConfig struct {
	Items []string `toml:"items"`
}

type PackageConfig added in v1.7.9

type PackageConfig struct {
	Items []string `toml:"items"`
}

type PackageData added in v1.7.9

type PackageData struct {
	PackageTotalCount int
	AsDependencyCount int
	AsExplicitCount   int
	PackageTotalSize  float64
	PackageTotalUnit  string
}

func GetInstalledPackageData added in v1.7.9

func GetInstalledPackageData() (PackageData, error)

GetInstalledPackageData 获取已安装包的数据

返回:

  • 最新内核版本号

type ProductConfig added in v1.5.1

type ProductConfig struct {
	Items []string `toml:"items"`
}

type StorageConfig added in v1.5.1

type StorageConfig struct {
	Items []string `toml:"items"`
}

type SwapConfig added in v1.5.1

type SwapConfig struct {
	Items       SwapItemsConfig `toml:"items"`
	DataUnit    string          `toml:"data_unit"`
	PercentUnit string          `toml:"percent_unit"`
}

type SwapItemsConfig added in v1.5.1

type SwapItemsConfig struct {
	Available   []string `toml:"available"`
	Unavailable []string `toml:"unavailable"`
}

type TimeConfig added in v1.5.1

type TimeConfig struct {
	Items []string `toml:"items"`
}

type UpdateConfig added in v1.3.9

type UpdateConfig struct {
	Items          []string `toml:"items"`
	Basis          string   `toml:"basis"`
	ArchRecordFile string   `toml:"arch_record_file"`
	AurRecordFile  string   `toml:"aur_record_file"`
	ArchDividing   string   `toml:"arch_dividing"`
	AurDividing    string   `toml:"aur_dividing"`
}

type UserConfig added in v1.5.1

type UserConfig struct {
	Items []string `toml:"items"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳