mirror of
https://github.com/Adembc/lazyssh.git
synced 2026-07-14 12:13:34 +02:00
feat: add makefile and fix lint issues (#2)
This commit is contained in:
@@ -1,14 +1,28 @@
|
||||
// Copyright 2025.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package memory
|
||||
|
||||
import (
|
||||
"github.com/Adembc/lazyssh/internal/core/domain"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/Adembc/lazyssh/internal/core/domain"
|
||||
)
|
||||
|
||||
type serverRepository struct {
|
||||
}
|
||||
type serverRepository struct{}
|
||||
|
||||
var servers = []domain.Server{
|
||||
{Alias: "web-01", Host: "192.168.1.10", User: "root", Port: 22, Key: "~/.ssh/id_rsa", Tags: []string{"prod", "web"}, Status: "online", LastSeen: time.Now().Add(-2 * time.Hour)},
|
||||
@@ -58,7 +72,6 @@ func (r *serverRepository) ListServers(query string) ([]domain.Server, error) {
|
||||
}
|
||||
}
|
||||
return filteredServers, nil
|
||||
return servers, nil
|
||||
}
|
||||
|
||||
// UpdateServer updates an existing server with new details.
|
||||
|
||||
@@ -1,10 +1,23 @@
|
||||
// Copyright 2025.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package ui
|
||||
|
||||
import "time"
|
||||
|
||||
const (
|
||||
AppName = "lazyssh"
|
||||
AppVersion = "v0.0.1"
|
||||
RepoURL = "github.com/adembc/lazyssh"
|
||||
SplashScreenDuration = 1 * time.Second
|
||||
Banner = `
|
||||
|
||||
@@ -1,7 +1,22 @@
|
||||
// Copyright 2025.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package ui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/Adembc/lazyssh/internal/core/domain"
|
||||
"github.com/gdamore/tcell/v2"
|
||||
"github.com/rivo/tview"
|
||||
@@ -87,10 +102,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()
|
||||
@@ -182,7 +197,7 @@ func (t *tui) hideSearchBar() {
|
||||
func (t *tui) refreshServerList() {
|
||||
query := ""
|
||||
if t.searchVisible {
|
||||
query = t.searchBar.GetText()
|
||||
query = t.searchBar.InputField.GetText()
|
||||
}
|
||||
filtered, _ := t.serverService.ListServers(query)
|
||||
t.serverList.UpdateServers(filtered)
|
||||
|
||||
@@ -1,23 +1,42 @@
|
||||
// Copyright 2025.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
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
|
||||
@@ -37,7 +56,7 @@ func (h *AppHeader) build() {
|
||||
|
||||
separator := h.createSeparator()
|
||||
|
||||
h.SetDirection(tview.FlexRow).
|
||||
h.Flex.SetDirection(tview.FlexRow).
|
||||
AddItem(headerBar, 1, 0, false).
|
||||
AddItem(separator, 1, 0, false)
|
||||
}
|
||||
@@ -57,7 +76,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 +113,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 + " [-]"
|
||||
}
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
// Copyright 2025.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package ui
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
// Copyright 2025.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package ui
|
||||
|
||||
import (
|
||||
@@ -20,7 +34,7 @@ func NewSearchBar() *SearchBar {
|
||||
}
|
||||
|
||||
func (s *SearchBar) build() {
|
||||
s.SetLabel(" 🔍 Search: ").
|
||||
s.InputField.SetLabel(" 🔍 Search: ").
|
||||
SetFieldBackgroundColor(tcell.Color233).
|
||||
SetFieldTextColor(tcell.Color252).
|
||||
SetFieldWidth(30).
|
||||
@@ -29,13 +43,13 @@ func (s *SearchBar) build() {
|
||||
SetBorderColor(tcell.Color238).
|
||||
SetTitleColor(tcell.Color250)
|
||||
|
||||
s.SetChangedFunc(func(text string) {
|
||||
s.InputField.SetChangedFunc(func(text string) {
|
||||
if s.onSearch != nil {
|
||||
s.onSearch(text)
|
||||
}
|
||||
})
|
||||
|
||||
s.SetDoneFunc(func(key tcell.Key) {
|
||||
s.InputField.SetDoneFunc(func(key tcell.Key) {
|
||||
if key == tcell.KeyEsc || key == tcell.KeyEnter {
|
||||
if s.onEscape != nil {
|
||||
s.onEscape()
|
||||
|
||||
@@ -1,7 +1,22 @@
|
||||
// Copyright 2025.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package ui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/Adembc/lazyssh/internal/core/domain"
|
||||
"github.com/gdamore/tcell/v2"
|
||||
"github.com/rivo/tview"
|
||||
@@ -20,7 +35,7 @@ func NewServerDetails() *ServerDetails {
|
||||
}
|
||||
|
||||
func (sd *ServerDetails) build() {
|
||||
sd.SetDynamicColors(true).
|
||||
sd.TextView.SetDynamicColors(true).
|
||||
SetWrap(true).
|
||||
SetBorder(true).
|
||||
SetTitle("Details").
|
||||
@@ -34,9 +49,9 @@ func (sd *ServerDetails) UpdateServer(server domain.Server) {
|
||||
server.Alias, server.Host, server.User, server.Port,
|
||||
server.Key, joinTags(server.Tags), statusIcon(server.Status),
|
||||
server.LastSeen.Format("2006-01-02 15:04"))
|
||||
sd.SetText(text)
|
||||
sd.TextView.SetText(text)
|
||||
}
|
||||
|
||||
func (sd *ServerDetails) ShowEmpty() {
|
||||
sd.SetText("No servers match the current filter.")
|
||||
sd.TextView.SetText("No servers match the current filter.")
|
||||
}
|
||||
|
||||
@@ -1,13 +1,28 @@
|
||||
// Copyright 2025.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
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
|
||||
@@ -41,7 +56,7 @@ func (sf *ServerForm) build() {
|
||||
title = "Edit Server"
|
||||
}
|
||||
|
||||
sf.SetBorder(true).
|
||||
sf.Form.SetBorder(true).
|
||||
SetTitle(title).
|
||||
SetTitleAlign(tview.AlignLeft).
|
||||
SetBorderColor(tcell.Color238).
|
||||
@@ -49,9 +64,9 @@ func (sf *ServerForm) build() {
|
||||
|
||||
sf.addFormFields()
|
||||
|
||||
sf.AddButton("Save", sf.handleSave)
|
||||
sf.AddButton("Cancel", sf.handleCancel)
|
||||
sf.SetCancelFunc(sf.handleCancel)
|
||||
sf.Form.AddButton("Save", sf.handleSave)
|
||||
sf.Form.AddButton("Cancel", sf.handleCancel)
|
||||
sf.Form.SetCancelFunc(sf.handleCancel)
|
||||
}
|
||||
|
||||
func (sf *ServerForm) addFormFields() {
|
||||
@@ -75,12 +90,12 @@ func (sf *ServerForm) addFormFields() {
|
||||
}
|
||||
}
|
||||
|
||||
sf.AddInputField("Alias:", defaultValues.Alias, 20, nil, nil)
|
||||
sf.AddInputField("Host/IP:", defaultValues.Host, 20, nil, nil)
|
||||
sf.AddInputField("User:", defaultValues.User, 20, nil, nil)
|
||||
sf.AddInputField("Port:", defaultValues.Port, 20, nil, nil)
|
||||
sf.AddInputField("Key:", defaultValues.Key, 40, nil, nil)
|
||||
sf.AddInputField("Tags (comma):", defaultValues.Tags, 30, nil, nil)
|
||||
sf.Form.AddInputField("Alias:", defaultValues.Alias, 20, nil, nil)
|
||||
sf.Form.AddInputField("Host/IP:", defaultValues.Host, 20, nil, nil)
|
||||
sf.Form.AddInputField("User:", defaultValues.User, 20, nil, nil)
|
||||
sf.Form.AddInputField("Port:", defaultValues.Port, 20, nil, nil)
|
||||
sf.Form.AddInputField("Key:", defaultValues.Key, 40, nil, nil)
|
||||
sf.Form.AddInputField("Tags (comma):", defaultValues.Tags, 30, nil, nil)
|
||||
|
||||
statusDD := tview.NewDropDown().SetLabel("Status: ")
|
||||
statusOptions := []string{"online", "warn", "offline"}
|
||||
@@ -92,7 +107,7 @@ func (sf *ServerForm) addFormFields() {
|
||||
break
|
||||
}
|
||||
}
|
||||
sf.AddFormItem(statusDD)
|
||||
sf.Form.AddFormItem(statusDD)
|
||||
}
|
||||
|
||||
type ServerFormData struct {
|
||||
@@ -107,12 +122,12 @@ type ServerFormData struct {
|
||||
|
||||
func (sf *ServerForm) getFormData() ServerFormData {
|
||||
return ServerFormData{
|
||||
Alias: strings.TrimSpace(sf.GetFormItem(0).(*tview.InputField).GetText()),
|
||||
Host: strings.TrimSpace(sf.GetFormItem(1).(*tview.InputField).GetText()),
|
||||
User: strings.TrimSpace(sf.GetFormItem(2).(*tview.InputField).GetText()),
|
||||
Port: strings.TrimSpace(sf.GetFormItem(3).(*tview.InputField).GetText()),
|
||||
Key: strings.TrimSpace(sf.GetFormItem(4).(*tview.InputField).GetText()),
|
||||
Tags: strings.TrimSpace(sf.GetFormItem(5).(*tview.InputField).GetText()),
|
||||
Alias: strings.TrimSpace(sf.Form.GetFormItem(0).(*tview.InputField).GetText()),
|
||||
Host: strings.TrimSpace(sf.Form.GetFormItem(1).(*tview.InputField).GetText()),
|
||||
User: strings.TrimSpace(sf.Form.GetFormItem(2).(*tview.InputField).GetText()),
|
||||
Port: strings.TrimSpace(sf.Form.GetFormItem(3).(*tview.InputField).GetText()),
|
||||
Key: strings.TrimSpace(sf.Form.GetFormItem(4).(*tview.InputField).GetText()),
|
||||
Tags: strings.TrimSpace(sf.Form.GetFormItem(5).(*tview.InputField).GetText()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,7 +169,7 @@ func (sf *ServerForm) dataToServer(data ServerFormData) domain.Server {
|
||||
}
|
||||
}
|
||||
|
||||
_, status := sf.GetFormItem(6).(*tview.DropDown).GetCurrentOption()
|
||||
_, status := sf.Form.GetFormItem(6).(*tview.DropDown).GetCurrentOption()
|
||||
return domain.Server{
|
||||
Alias: data.Alias,
|
||||
Host: data.Host,
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
// Copyright 2025.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package ui
|
||||
|
||||
import (
|
||||
@@ -22,17 +36,17 @@ func NewServerList() *ServerList {
|
||||
}
|
||||
|
||||
func (sl *ServerList) build() {
|
||||
sl.ShowSecondaryText(false)
|
||||
sl.SetBorder(true).
|
||||
sl.List.ShowSecondaryText(false)
|
||||
sl.List.SetBorder(true).
|
||||
SetTitle("Servers").
|
||||
SetBorderColor(tcell.Color238).
|
||||
SetTitleColor(tcell.Color250)
|
||||
sl.
|
||||
sl.List.
|
||||
SetSelectedBackgroundColor(tcell.Color24).
|
||||
SetSelectedTextColor(tcell.Color255).
|
||||
SetHighlightFullLine(true)
|
||||
|
||||
sl.SetChangedFunc(func(index int, mainText string, secondaryText string, shortcut rune) {
|
||||
sl.List.SetChangedFunc(func(index int, mainText string, secondaryText string, shortcut rune) {
|
||||
if index >= 0 && index < len(sl.servers) && sl.onSelectionChange != nil {
|
||||
sl.onSelectionChange(sl.servers[index])
|
||||
}
|
||||
@@ -41,20 +55,20 @@ func (sl *ServerList) build() {
|
||||
|
||||
func (sl *ServerList) UpdateServers(servers []domain.Server) {
|
||||
sl.servers = servers
|
||||
sl.Clear()
|
||||
sl.List.Clear()
|
||||
|
||||
for i := range servers {
|
||||
primary, secondary := formatServerLine(servers[i])
|
||||
idx := i
|
||||
sl.AddItem(primary, secondary, 0, func() {
|
||||
sl.List.AddItem(primary, secondary, 0, func() {
|
||||
if sl.onSelection != nil {
|
||||
sl.onSelection(sl.servers[idx])
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
if sl.GetItemCount() > 0 {
|
||||
sl.SetCurrentItem(0)
|
||||
if sl.List.GetItemCount() > 0 {
|
||||
sl.List.SetCurrentItem(0)
|
||||
if sl.onSelectionChange != nil {
|
||||
sl.onSelectionChange(sl.servers[0])
|
||||
}
|
||||
@@ -62,7 +76,7 @@ func (sl *ServerList) UpdateServers(servers []domain.Server) {
|
||||
}
|
||||
|
||||
func (sl *ServerList) GetSelectedServer() (domain.Server, bool) {
|
||||
idx := sl.GetCurrentItem()
|
||||
idx := sl.List.GetCurrentItem()
|
||||
if idx >= 0 && idx < len(sl.servers) {
|
||||
return sl.servers[idx], true
|
||||
}
|
||||
|
||||
@@ -1,10 +1,25 @@
|
||||
// Copyright 2025.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
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,3 +1,17 @@
|
||||
// Copyright 2025.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package ui
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,13 +1,32 @@
|
||||
// Copyright 2025.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
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 +44,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 +72,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 +85,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 +104,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 +127,4 @@ func (t *tui) loadSplashScreen() *tui {
|
||||
})
|
||||
})
|
||||
return t
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +1,25 @@
|
||||
// Copyright 2025.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
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 {
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
// Copyright 2025.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package domain
|
||||
|
||||
import "time"
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
// Copyright 2025.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package ports
|
||||
|
||||
import "github.com/Adembc/lazyssh/internal/core/domain"
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
// Copyright 2025.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package ports
|
||||
|
||||
import "github.com/Adembc/lazyssh/internal/core/domain"
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
// Copyright 2025.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package services
|
||||
|
||||
import (
|
||||
@@ -18,7 +32,6 @@ func NewServerService(sr ports.ServerRepository) *serverService {
|
||||
|
||||
// ListServers returns a list of servers.
|
||||
func (s *serverService) ListServers(query string) ([]domain.Server, error) {
|
||||
|
||||
// do any relevant business logic here if needed
|
||||
servers, err := s.serverRepository.ListServers(query)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user