1 Star 0 Fork 0

vcjia/nssh

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
theme.go 3.88 KB
一键复制 编辑 原始数据 按行查看 历史
vcjia 提交于 2025-03-18 23:47 +08:00 . add *
/*
MIT License
Copyright (c) 2023-2024 The Trzsz SSH Authors.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
package tssh
import (
"fmt"
"strings"
)
type promptTheme struct {
Help string
Label string
Active string
Inactive string
Details string
Shortcuts string
HideLabel bool
ItemsRenderer func(items []interface{}, idx int) string
DetailsRenderer func(item interface{}) string
}
func getDefaultHelpTipsTemplate() string {
return fmt.Sprintf(`{{ "Use ← ↓ ↑ → h j k l to navigate, / toggles search, ? toggles help" | %s }}`, getThemeColor("help_tips"))
}
func getDefaultShortcutsTemplate() string {
return fmt.Sprintf(`{{ . | %s }}`, getThemeColor("shortcuts"))
}
func getDefaultDetailsTemplate() string {
var builder strings.Builder
builder.WriteString(fmt.Sprintf(`{{ "--------- SSH Details ----------\n" | %s }}`, getThemeColor("details_title")))
addItem := func(name string) {
builder.WriteString(fmt.Sprintf(`{{- if .%s }}{{ "%s:" | %s }}{{ "\t" }}{{ .%s | %s }}{{ "\n" }}{{ end }}`,
name, name, getThemeColor("details_name"), name, getThemeColor("details_value")))
}
for _, item := range getPromptDetailItems() {
switch strings.ToLower(item) {
case "alias":
addItem("Alias")
case "host":
addItem("Host")
case "port":
builder.WriteString(fmt.Sprintf(
`{{- if ne .Port "22" }}{{ "Port:" | %s }}{{ "\t" }}{{ .Port | %s }}{{ "\n" }}{{ end }}`,
getThemeColor("details_name"), getThemeColor("details_value")))
case "user":
addItem("User")
case "grouplabels":
addItem("GroupLabels")
case "identityfile":
addItem("IdentityFile")
case "proxycommand":
addItem("ProxyCommand")
case "proxyjump":
addItem("ProxyJump")
case "remotecommand":
addItem("RemoteCommand")
default:
warning("Unknown prompt detail item: %s", item)
}
}
return builder.String()
}
func getTinyTheme() *promptTheme {
return &promptTheme{
Label: fmt.Sprintf(`{{ "? " | %s }}{{ . | %s }}{{ ":" | %s }}`,
getThemeColor("label_icon"), getThemeColor("label_text"), getThemeColor("label_text")),
Active: fmt.Sprintf(`{{ "%s" | %s }} {{ if .Selected }}{{ "✔ " | %s }}{{ else }}{{ " " }}{{ end }}`+
`{{ .Alias | %s }} ({{ .Host | %s }}){{ "\t" }}{{ .GroupLabels | %s }}`,
promptCursorIcon, getThemeColor("cursor_icon"), getThemeColor("active_selected"),
getThemeColor("active_alias"), getThemeColor("active_host"), getThemeColor("active_group")),
Inactive: fmt.Sprintf(` {{ if .Selected }}{{ "✔ " | %s }}{{ else }}{{ " " }}{{ end }}`+
`{{ .Alias | %s }} ({{ .Host | %s }}){{ "\t" }}{{ .GroupLabels | %s }}`,
getThemeColor("inactive_selected"),
getThemeColor("inactive_alias"), getThemeColor("inactive_host"), getThemeColor("inactive_group")),
Details: getDefaultDetailsTemplate(),
Help: getDefaultHelpTipsTemplate(),
Shortcuts: getDefaultShortcutsTemplate(),
}
}
func getPromptTheme() *promptTheme {
return getTinyTheme()
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/vcjia/nssh.git
git@gitee.com:vcjia/nssh.git
vcjia
nssh
nssh
a91954a6fea0

搜索帮助