mirror of
https://github.com/Adembc/lazyssh.git
synced 2026-07-14 12:13:34 +02:00
add makefile
This commit is contained in:
@@ -4,7 +4,6 @@ import "time"
|
||||
|
||||
const (
|
||||
AppName = "lazyssh"
|
||||
AppVersion = "v0.0.1"
|
||||
RepoURL = "github.com/adembc/lazyssh"
|
||||
SplashScreenDuration = 1 * time.Second
|
||||
Banner = `
|
||||
|
||||
@@ -2,6 +2,7 @@ package ui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/Adembc/lazyssh/internal/core/domain"
|
||||
"github.com/gdamore/tcell/v2"
|
||||
"github.com/rivo/tview"
|
||||
@@ -87,10 +88,10 @@ func (t *tui) handleServerEdit() {
|
||||
func (t *tui) handleServerSave(server domain.Server, original *domain.Server) {
|
||||
if original != nil {
|
||||
// Edit mode
|
||||
t.serverService.UpdateServer(*original, server)
|
||||
_ = t.serverService.UpdateServer(*original, server)
|
||||
} else {
|
||||
// Add mode
|
||||
t.serverService.AddServer(server)
|
||||
_ = t.serverService.AddServer(server)
|
||||
}
|
||||
|
||||
t.refreshServerList()
|
||||
|
||||
@@ -1,23 +1,28 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"github.com/gdamore/tcell/v2"
|
||||
"github.com/rivo/tview"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gdamore/tcell/v2"
|
||||
"github.com/rivo/tview"
|
||||
)
|
||||
|
||||
type AppHeader struct {
|
||||
*tview.Flex
|
||||
version string
|
||||
repoURL string
|
||||
version string
|
||||
buildTime string
|
||||
gitCommit string
|
||||
repoURL string
|
||||
}
|
||||
|
||||
func NewAppHeader(version, repoURL string) *AppHeader {
|
||||
func NewAppHeader(version, gitCommit, buildTime, repoURL string) *AppHeader {
|
||||
header := &AppHeader{
|
||||
Flex: tview.NewFlex(),
|
||||
version: version,
|
||||
repoURL: repoURL,
|
||||
Flex: tview.NewFlex(),
|
||||
version: version,
|
||||
repoURL: repoURL,
|
||||
buildTime: buildTime,
|
||||
gitCommit: gitCommit,
|
||||
}
|
||||
header.build()
|
||||
return header
|
||||
@@ -57,7 +62,24 @@ func (h *AppHeader) buildCenterSection(bg tcell.Color) *tview.TextView {
|
||||
SetDynamicColors(true).
|
||||
SetTextAlign(tview.AlignCenter)
|
||||
center.SetBackgroundColor(bg)
|
||||
center.SetText("[black:#2ECC71::b] " + h.version + " [-] [black:#3B82F6::b] TUI [-]")
|
||||
|
||||
commit := shortCommit(h.gitCommit)
|
||||
|
||||
// Build tag-like chips for version, commit, and build time
|
||||
versionTag := makeTag(h.version, "#22C55E") // green
|
||||
commitTag := ""
|
||||
if commit != "" {
|
||||
commitTag = makeTag(commit, "#A78BFA") // violet
|
||||
}
|
||||
timeTag := makeTag(formatBuildTime(h.buildTime), "#3B82F6") // blue
|
||||
|
||||
text := versionTag
|
||||
if commitTag != "" {
|
||||
text += " " + commitTag
|
||||
}
|
||||
text += " " + timeTag
|
||||
|
||||
center.SetText(text)
|
||||
return center
|
||||
}
|
||||
|
||||
@@ -77,3 +99,48 @@ func (h *AppHeader) createSeparator() *tview.TextView {
|
||||
separator.SetText("[#444444]" + strings.Repeat("─", 200) + "[-]")
|
||||
return separator
|
||||
}
|
||||
|
||||
// shortCommit returns first 7 chars of commit if it looks valid; otherwise empty string.
|
||||
func shortCommit(c string) string {
|
||||
c = strings.TrimSpace(c)
|
||||
if c == "" || c == "unknown" || c == "(devel)" {
|
||||
return ""
|
||||
}
|
||||
if len(c) > 7 {
|
||||
return c[:7]
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
// formatBuildTime tries to parse common time formats and returns a concise human-readable string.
|
||||
func formatBuildTime(s string) string {
|
||||
s = strings.TrimSpace(s)
|
||||
if s == "" {
|
||||
return "unknown"
|
||||
}
|
||||
layouts := []string{
|
||||
"2006-01-02 15:04:05",
|
||||
time.RFC3339,
|
||||
time.RFC1123,
|
||||
time.RFC1123Z,
|
||||
}
|
||||
var t time.Time
|
||||
var err error
|
||||
for _, l := range layouts {
|
||||
t, err = time.Parse(l, s)
|
||||
if err == nil {
|
||||
return t.Format("Mon, 02 Jan 2006 15:04")
|
||||
}
|
||||
}
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
// makeTag returns a rectangular-looking colored chip for the given text.
|
||||
func makeTag(text, bg string) string {
|
||||
text = strings.TrimSpace(text)
|
||||
if text == "" {
|
||||
return ""
|
||||
}
|
||||
return "[black:" + bg + "::b] " + text + " [-]"
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package ui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/Adembc/lazyssh/internal/core/domain"
|
||||
"github.com/gdamore/tcell/v2"
|
||||
"github.com/rivo/tview"
|
||||
|
||||
@@ -2,12 +2,13 @@ package ui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/Adembc/lazyssh/internal/core/domain"
|
||||
"github.com/gdamore/tcell/v2"
|
||||
"github.com/rivo/tview"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/Adembc/lazyssh/internal/core/domain"
|
||||
"github.com/gdamore/tcell/v2"
|
||||
"github.com/rivo/tview"
|
||||
)
|
||||
|
||||
type ServerFormMode int
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"github.com/gdamore/tcell/v2"
|
||||
"github.com/rivo/tview"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gdamore/tcell/v2"
|
||||
"github.com/rivo/tview"
|
||||
)
|
||||
|
||||
// buildSplash creates a splash screen with a spinner; returns primitive and a stop function
|
||||
|
||||
@@ -1,13 +1,18 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/Adembc/lazyssh/internal/core/ports"
|
||||
"github.com/gdamore/tcell/v2"
|
||||
"github.com/rivo/tview"
|
||||
"time"
|
||||
)
|
||||
|
||||
type tui struct {
|
||||
version string
|
||||
commit string
|
||||
buildDate string
|
||||
|
||||
app *tview.Application
|
||||
serverService ports.ServerService
|
||||
|
||||
@@ -25,21 +30,23 @@ type tui struct {
|
||||
searchVisible bool
|
||||
}
|
||||
|
||||
func NewTUI(ss ports.ServerService) *tui {
|
||||
func NewTUI(ss ports.ServerService, version, commit, buildDate string) *tui {
|
||||
return &tui{
|
||||
app: tview.NewApplication(),
|
||||
serverService: ss,
|
||||
version: version,
|
||||
commit: commit,
|
||||
buildDate: buildDate,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (t *tui) Run() error {
|
||||
|
||||
t.app.EnableMouse(true)
|
||||
t.initializeTheme().buildComponents().buildLayout().bindEvents().loadInitialData().loadSplashScreen()
|
||||
|
||||
return t.app.Run()
|
||||
}
|
||||
|
||||
func (t *tui) initializeTheme() *tui {
|
||||
tview.Styles.PrimitiveBackgroundColor = tcell.Color232
|
||||
tview.Styles.ContrastBackgroundColor = tcell.Color235
|
||||
@@ -51,8 +58,9 @@ func (t *tui) initializeTheme() *tui {
|
||||
tview.Styles.GraphicsColor = tcell.Color238
|
||||
return t
|
||||
}
|
||||
|
||||
func (t *tui) buildComponents() *tui {
|
||||
t.header = NewAppHeader(AppVersion, RepoURL)
|
||||
t.header = NewAppHeader(t.version, t.commit, t.buildDate, RepoURL)
|
||||
t.searchBar = NewSearchBar().
|
||||
OnSearch(t.handleSearchInput).
|
||||
OnEscape(t.hideSearchBar)
|
||||
@@ -63,8 +71,8 @@ func (t *tui) buildComponents() *tui {
|
||||
t.statusBar = NewStatusBar()
|
||||
return t
|
||||
}
|
||||
func (t *tui) buildLayout() *tui {
|
||||
|
||||
func (t *tui) buildLayout() *tui {
|
||||
t.left = tview.NewFlex().SetDirection(tview.FlexRow).
|
||||
AddItem(t.hintBar, 1, 0, false).
|
||||
AddItem(t.serverList, 0, 1, true)
|
||||
@@ -82,10 +90,12 @@ func (t *tui) buildLayout() *tui {
|
||||
AddItem(t.statusBar, 1, 0, false)
|
||||
return t
|
||||
}
|
||||
|
||||
func (t *tui) bindEvents() *tui {
|
||||
t.root.SetInputCapture(t.handleGlobalKeys)
|
||||
return t
|
||||
}
|
||||
|
||||
func (t *tui) loadInitialData() *tui {
|
||||
servers, _ := t.serverService.ListServers("")
|
||||
t.serverList.UpdateServers(servers)
|
||||
@@ -103,5 +113,4 @@ func (t *tui) loadSplashScreen() *tui {
|
||||
})
|
||||
})
|
||||
return t
|
||||
|
||||
}
|
||||
|
||||
@@ -2,9 +2,10 @@ package ui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/Adembc/lazyssh/internal/core/domain"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/Adembc/lazyssh/internal/core/domain"
|
||||
)
|
||||
|
||||
func statusIcon(s string) string {
|
||||
|
||||
Reference in New Issue
Block a user