Skip to content

Commit

Permalink
support prompt theme
Browse files Browse the repository at this point in the history
  • Loading branch information
lonnywong committed Jan 21, 2024
1 parent 4159412 commit f9f77a3
Show file tree
Hide file tree
Showing 9 changed files with 838 additions and 286 deletions.
300 changes: 197 additions & 103 deletions README.cn.md

Large diffs are not rendered by default.

297 changes: 196 additions & 101 deletions README.en.md

Large diffs are not rendered by default.

24 changes: 14 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
[![WebSite](https://img.shields.io/badge/WebSite-https%3A%2F%2Ftrzsz.github.io%2Fssh-blue?style=flat)](https://trzsz.github.io/ssh)
[![中文文档](https://img.shields.io/badge/%E4%B8%AD%E6%96%87%E6%96%87%E6%A1%A3-https%3A%2F%2Ftrzsz.github.io%2Fcn%2Fssh-blue?style=flat)](https://trzsz.github.io/cn/ssh)

## Introduction

trzsz-ssh ( tssh ) is an open-source project written in golang, designed as a drop-in replacement for the openssh client. It aims to provide complete compatibility with openssh, mirroring all its features, while also offering additional useful features not found in the openssh client.
trzsz-ssh ( tssh ) is an ssh client designed as a drop-in replacement for the openssh client. It aims to provide complete compatibility with openssh, mirroring all its features, while also offering additional useful features not found in the openssh client.

## Basic Features

Expand All @@ -30,16 +28,16 @@ trzsz-ssh ( tssh ) offers additional useful features:

| English | 中文 |
| :---------------------------------------------------------: | :-----------------------------------------------------------: |
| [trzsz ( trz / tsz )](https://trzsz.github.io/) | [trzsz ( trz / tsz )](https://trzsz.github.io/cn/) |
| [Login Prompt](README.en.md#how-to-use) | [界面登录](README.cn.md#%E4%BD%BF%E7%94%A8%E6%96%B9%E6%B3%95) |
| [Login Prompt](README.en.md#login-prompt) | [登录界面](README.cn.md#%E7%99%BB%E5%BD%95%E7%95%8C%E9%9D%A2) |
| [Custom Theme](README.en.md#custom-theme) | [主题风格](README.cn.md#%E4%B8%BB%E9%A2%98%E9%A3%8E%E6%A0%BC) |
| [trzsz ( trz / tsz )](README.en.md#support-trzsz) | [trzsz ( trz / tsz )](README.cn.md#%E6%94%AF%E6%8C%81-trzsz) |
| [zmodem ( rz / sz )](README.en.md#support-zmodem) | [zmodem ( rz / sz )](README.cn.md#%E6%94%AF%E6%8C%81-zmodem) |
| [Batch Login](README.en.md#batch-login) | [批量登录](README.cn.md#%E6%89%B9%E9%87%8F%E7%99%BB%E5%BD%95) |
| [Group Labels](README.en.md#group-labels) | [分组标签](README.cn.md#%E5%88%86%E7%BB%84%E6%A0%87%E7%AD%BE) |
| [Automated Interaction](README.en.md#automated-interaction) | [自动交互](README.cn.md#%E8%87%AA%E5%8A%A8%E4%BA%A4%E4%BA%92) |
| [Remember Password](README.en.md#remember-password) | [记住密码](README.cn.md#%E8%AE%B0%E4%BD%8F%E5%AF%86%E7%A0%81) |
| [Personal Configuration](README.en.md#configuration) | [个性配置](README.cn.md#%E5%8F%AF%E9%80%89%E9%85%8D%E7%BD%AE) |
| [Custom Configuration](README.en.md#custom-configuration) | [个性配置](README.cn.md#%E4%B8%AA%E6%80%A7%E9%85%8D%E7%BD%AE) |
| [Other Features](README.en.md#other-features) | [其他功能](README.cn.md#%E5%85%B6%E4%BB%96%E5%8A%9F%E8%83%BD) |
| [Prompt Shortcuts](README.en.md#shortcuts) | [界面快捷键](README.cn.md#%E5%BF%AB%E6%8D%B7%E9%94%AE) |
| [Trouble Shooting](README.en.md#trouble-shooting) | [故障排除](README.cn.md#%E6%95%85%E9%9A%9C%E6%8E%92%E9%99%A4) |

## Installation

Expand Down Expand Up @@ -180,9 +178,15 @@ Welcome and thank you for considering contributing. We appreciate all forms of s
## Screenshot
![tssh login demo](https://trzsz.github.io/images/tssh.gif)
![tssh tiny](https://trzsz.github.io/images/tssh_tiny.gif)
![tssh simple](https://trzsz.github.io/images/tssh_simple.gif)
![tssh table](https://trzsz.github.io/images/tssh_table.gif)
![tssh trzsz](https://trzsz.github.io/images/tssh_trzsz.gif)
![tssh batch login](https://trzsz.github.io/images/batch_ssh.gif)
![tssh batch](https://trzsz.github.io/images/tssh_batch.gif)
## Contact
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ require (
github.com/creack/pty v1.1.21
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
github.com/mattn/go-isatty v0.0.20
github.com/mattn/go-runewidth v0.0.15
github.com/mitchellh/go-homedir v1.1.0
github.com/skeema/knownhosts v1.2.1
github.com/stretchr/testify v1.8.4
github.com/trzsz/go-arg v1.5.3
github.com/trzsz/iterm2 v0.1.2
github.com/trzsz/promptui v0.10.5
github.com/trzsz/promptui v0.10.6
github.com/trzsz/ssh_config v1.3.4
github.com/trzsz/trzsz-go v1.1.8-0.20240113105526-ca0b2b345ee3
github.com/trzsz/trzsz-go v1.1.8-0.20240121141752-82a3e0a97899
golang.org/x/crypto v0.18.0
golang.org/x/sys v0.16.0
golang.org/x/term v0.16.0
Expand All @@ -41,7 +42,6 @@ require (
github.com/klauspost/compress v1.17.4 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/reflow v0.3.0 // indirect
Expand Down
9 changes: 4 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ github.com/trzsz/go-arg v1.5.3 h1:eIDwDEmvSahtr5HpQOLrSa+YMqWQQ0H20xx60XgXQJw=
github.com/trzsz/go-arg v1.5.3/go.mod h1:IC6Z/FiVH7uYvcbp1/gJhDYCFPS/GkL0APYakVvgY4I=
github.com/trzsz/iterm2 v0.1.2 h1:VwfLzr2fKeaLf+p4tS0ms+kqdiQQxVLbTJUoyuQXmK8=
github.com/trzsz/iterm2 v0.1.2/go.mod h1:PMI+3JcT7J9D0T6e3mOWv8ICYdrrNZwuge3Tm7zDLws=
github.com/trzsz/promptui v0.10.5 h1:tlzJkx+JOeE0sqKWmqgaoToZiYqj5G1Mz+QDV97VFu8=
github.com/trzsz/promptui v0.10.5/go.mod h1:GMZtu6ZTzU73CBFkzGtmB4wnTROIAbv4GFA74fV8V8g=
github.com/trzsz/promptui v0.10.6 h1:VlC7PeW2en4OHOOHId6FSErPoLSgq/3RsCyB4y3srgY=
github.com/trzsz/promptui v0.10.6/go.mod h1:9dp59ixe32qBV9GjDxQ1PDWwbzHjTzveZenQwEoVHbg=
github.com/trzsz/ssh_config v1.3.4 h1:7of+6rUmdWdqfgXnH9csgJe1kNkriS9xOiFGx4KCkEw=
github.com/trzsz/ssh_config v1.3.4/go.mod h1:Dl1okTjVVfsrtTA8nqkJ1OnjiCrZY6DUEI2DGT2/YoQ=
github.com/trzsz/trzsz-go v1.1.8-0.20240113105526-ca0b2b345ee3 h1:0uX54IyGzTIN5lCrPd58uG1HbJHZqqxMXpboEWZvS9c=
github.com/trzsz/trzsz-go v1.1.8-0.20240113105526-ca0b2b345ee3/go.mod h1:ZphYYsobieFQ/uALzXcGHecaVuq+PhfhKUUyNYOfp2k=
github.com/trzsz/trzsz-go v1.1.8-0.20240121141752-82a3e0a97899 h1:zZ4S8oKTA5r64790DVfMtQe6umzmswFdjGrlBUHmhNk=
github.com/trzsz/trzsz-go v1.1.8-0.20240121141752-82a3e0a97899/go.mod h1:JhyLKPkYA2LPagRn6xjnNdk06rNecTHgM29s5J3cGKA=
go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A=
golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc=
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
Expand All @@ -107,7 +107,6 @@ golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.16.0 h1:m+B6fahuftsE9qjo0VWp2FW0mB3MTJvR0BaMQrq0pmE=
Expand Down
89 changes: 63 additions & 26 deletions internal/table/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,39 @@ import (
// })
type StyleFunc func(row, col int) lipgloss.Style

// BorderType contains a series of values which comprise the various parts of a border.
type BorderType int

// A series of BorderType which comprise the various parts of a border.
const (
BorderTop BorderType = iota
BorderBottom
BorderLeft
BorderRight
BorderTopLeft
BorderTopRight
BorderBottomLeft
BorderBottomRight
BorderMiddleLeft
BorderMiddleRight
BorderMiddle
BorderMiddleTop
BorderMiddleBottom
)

// BorderStyleFunc is the style function that determines the style of a cell border.
type BorderStyleFunc func(row, col int, borderType BorderType) lipgloss.Style

// DefaultStyles is a TableStyleFunc that returns a new Style with no attributes.
func DefaultStyles(_, _ int) lipgloss.Style {
return lipgloss.NewStyle()
}

// Table is a type for rendering tables.
type Table struct {
styleFunc StyleFunc
border lipgloss.Border
styleFunc StyleFunc
borderStyleFunc BorderStyleFunc
border lipgloss.Border

borderTop bool
borderBottom bool
Expand Down Expand Up @@ -102,6 +126,20 @@ func (t *Table) style(row, col int) lipgloss.Style {
return t.styleFunc(row, col)
}

// BorderStyleFunc sets the style for a cell border based on it's position (row, column).
func (t *Table) BorderStyleFunc(style BorderStyleFunc) *Table {
t.borderStyleFunc = style
return t
}

// getBorderStyle returns the style for a cell border based on it's position (row, column).
func (t *Table) getBorderStyle(row, col int, borderType BorderType) lipgloss.Style {
if t.borderStyleFunc == nil {
return t.borderStyle
}
return t.borderStyleFunc(row, col, borderType)
}

// Data sets the table data.
func (t *Table) Data(data Data) *Table {
t.data = data
Expand Down Expand Up @@ -392,16 +430,16 @@ func (t *Table) Render() string {
func (t *Table) constructTopBorder() string {
var s strings.Builder
if t.borderLeft {
s.WriteString(t.borderStyle.Render(t.border.TopLeft))
s.WriteString(t.getBorderStyle(0, 0, BorderTopLeft).Render(t.border.TopLeft))
}
for i := 0; i < len(t.widths); i++ {
s.WriteString(t.borderStyle.Render(strings.Repeat(t.border.Top, t.widths[i])))
s.WriteString(t.getBorderStyle(0, i, BorderTop).Render(strings.Repeat(t.border.Top, t.widths[i])))
if i < len(t.widths)-1 && t.borderColumn {
s.WriteString(t.borderStyle.Render(t.border.MiddleTop))
s.WriteString(t.getBorderStyle(0, i, BorderMiddleTop).Render(t.border.MiddleTop))
}
}
if t.borderRight {
s.WriteString(t.borderStyle.Render(t.border.TopRight))
s.WriteString(t.getBorderStyle(0, len(t.widths)-1, BorderTopRight).Render(t.border.TopRight))
}
return s.String()
}
Expand All @@ -411,16 +449,16 @@ func (t *Table) constructTopBorder() string {
func (t *Table) constructBottomBorder() string {
var s strings.Builder
if t.borderLeft {
s.WriteString(t.borderStyle.Render(t.border.BottomLeft))
s.WriteString(t.getBorderStyle(t.data.Rows(), 0, BorderBottomLeft).Render(t.border.BottomLeft))
}
for i := 0; i < len(t.widths); i++ {
s.WriteString(t.borderStyle.Render(strings.Repeat(t.border.Bottom, t.widths[i])))
s.WriteString(t.getBorderStyle(t.data.Rows(), i, BorderBottom).Render(strings.Repeat(t.border.Bottom, t.widths[i])))
if i < len(t.widths)-1 && t.borderColumn {
s.WriteString(t.borderStyle.Render(t.border.MiddleBottom))
s.WriteString(t.getBorderStyle(t.data.Rows(), i, BorderMiddleBottom).Render(t.border.MiddleBottom))
}
}
if t.borderRight {
s.WriteString(t.borderStyle.Render(t.border.BottomRight))
s.WriteString(t.getBorderStyle(t.data.Rows(), len(t.widths)-1, BorderBottomRight).Render(t.border.BottomRight))
}
return s.String()
}
Expand All @@ -430,7 +468,7 @@ func (t *Table) constructBottomBorder() string {
func (t *Table) constructHeaders() string {
var s strings.Builder
if t.borderLeft {
s.WriteString(t.borderStyle.Render(t.border.Left))
s.WriteString(t.getBorderStyle(0, 0, BorderLeft).Render(t.border.Left))
}
for i, header := range t.headers {
s.WriteString(t.style(0, i).
Expand All @@ -439,29 +477,29 @@ func (t *Table) constructHeaders() string {
MaxWidth(t.widths[i]).
Render(runewidth.Truncate(header, t.widths[i], "…")))
if i < len(t.headers)-1 && t.borderColumn {
s.WriteString(t.borderStyle.Render(t.border.Left))
s.WriteString(t.getBorderStyle(0, i+1, BorderLeft).Render(t.border.Left))
}
}
if t.borderHeader {
if t.borderRight {
s.WriteString(t.borderStyle.Render(t.border.Right))
s.WriteString(t.getBorderStyle(0, len(t.headers)-1, BorderRight).Render(t.border.Right))
}
s.WriteString("\n")
if t.borderLeft {
s.WriteString(t.borderStyle.Render(t.border.MiddleLeft))
s.WriteString(t.getBorderStyle(0, 0, BorderMiddleLeft).Render(t.border.MiddleLeft))
}
for i := 0; i < len(t.headers); i++ {
s.WriteString(t.borderStyle.Render(strings.Repeat(t.border.Top, t.widths[i])))
s.WriteString(t.getBorderStyle(0, i, BorderBottom).Render(strings.Repeat(t.border.Bottom, t.widths[i])))
if i < len(t.headers)-1 && t.borderColumn {
s.WriteString(t.borderStyle.Render(t.border.Middle))
s.WriteString(t.getBorderStyle(0, i, BorderMiddle).Render(t.border.Middle))
}
}
if t.borderRight {
s.WriteString(t.borderStyle.Render(t.border.MiddleRight))
s.WriteString(t.getBorderStyle(0, len(t.headers)-1, BorderMiddleRight).Render(t.border.MiddleRight))
}
}
if t.borderRight && !t.borderHeader {
s.WriteString(t.borderStyle.Render(t.border.Right))
s.WriteString(t.getBorderStyle(0, len(t.headers)-1, BorderRight).Render(t.border.Right))
}
return s.String()
}
Expand All @@ -475,9 +513,8 @@ func (t *Table) constructRow(index int) string {
height := t.heights[index+btoi(hasHeaders)]

var cells []string
left := strings.Repeat(t.borderStyle.Render(t.border.Left)+"\n", height)
if t.borderLeft {
cells = append(cells, left)
cells = append(cells, strings.Repeat(t.getBorderStyle(index+1, 0, BorderLeft).Render(t.border.Left)+"\n", height))
}

for c := 0; c < t.data.Columns(); c++ {
Expand All @@ -491,12 +528,12 @@ func (t *Table) constructRow(index int) string {
Render(runewidth.Truncate(cell, t.widths[c]*height, "…")))

if c < t.data.Columns()-1 && t.borderColumn {
cells = append(cells, left)
cells = append(cells, strings.Repeat(t.getBorderStyle(index+1, c+1, BorderLeft).Render(t.border.Left)+"\n", height))
}
}

if t.borderRight {
right := strings.Repeat(t.borderStyle.Render(t.border.Right)+"\n", height)
right := strings.Repeat(t.getBorderStyle(index+1, t.data.Columns()-1, BorderRight).Render(t.border.Right)+"\n", height)
cells = append(cells, right)
}

Expand All @@ -507,14 +544,14 @@ func (t *Table) constructRow(index int) string {
s.WriteString(lipgloss.JoinHorizontal(lipgloss.Top, cells...) + "\n")

if t.borderRow && index < t.data.Rows()-1 {
s.WriteString(t.borderStyle.Render(t.border.MiddleLeft))
s.WriteString(t.getBorderStyle(index+1, 0, BorderMiddleLeft).Render(t.border.MiddleLeft))
for i := 0; i < len(t.widths); i++ {
s.WriteString(t.borderStyle.Render(strings.Repeat(t.border.Bottom, t.widths[i])))
s.WriteString(t.getBorderStyle(index+1, i, BorderBottom).Render(strings.Repeat(t.border.Bottom, t.widths[i])))
if i < len(t.widths)-1 && t.borderColumn {
s.WriteString(t.borderStyle.Render(t.border.Middle))
s.WriteString(t.getBorderStyle(index+1, i, BorderMiddle).Render(t.border.Middle))
}
}
s.WriteString(t.borderStyle.Render(t.border.MiddleRight) + "\n")
s.WriteString(t.getBorderStyle(index+1, len(t.widths)-1, BorderMiddleRight).Render(t.border.MiddleRight) + "\n")
}

return s.String()
Expand Down
Loading

0 comments on commit f9f77a3

Please sign in to comment.