mirror of
https://github.com/db9979/sshtermy.git
synced 2026-12-06 12:44:08 +01:00
main eingearbeitet: Schnellbefehle und Spickzettel als frei belegbare Tasten
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018i4GUjUNGmakK3fVPSY2i2
This commit is contained in:
30 files changed
+2016
-94
No files matched your search
+10
-3
@@ -15,7 +15,7 @@ const aiInputMaxRows = 8
|
||||
|
||||
// aiInput ist das Eingabefeld für Ziele, Fragen und die Palette: Der Text
|
||||
// bricht automatisch um und das Feld wächst mit, statt horizontal zu
|
||||
// scrollen. ⏎ wertet der Aufrufer aus (senden), Shift+⏎ / Alt+⏎ / Strg+J
|
||||
// scrollen. ⏎ wertet der Aufrufer aus (senden), Shift+⏎ / Strg+J (frei belegbar)
|
||||
// fügt eine neue Zeile ein.
|
||||
type aiInput struct {
|
||||
textarea.Model
|
||||
@@ -33,9 +33,16 @@ func newAIInput(placeholder string) aiInput {
|
||||
ta.MaxHeight = aiInputMaxRows
|
||||
ta.MaxContentHeight = 400
|
||||
ta.EndOfBufferCharacter = ' '
|
||||
ta.KeyMap.InsertNewline = key.NewBinding(key.WithKeys("shift+enter", "alt+enter", "ctrl+j"))
|
||||
// Kein Alt+⏎: das schaltet Windows Terminal auf Vollbild.
|
||||
ta.KeyMap.InsertNewline = key.NewBinding(key.WithKeys(activeKeys.keys[actNewline]...))
|
||||
|
||||
sty := textarea.DefaultDarkStyles()
|
||||
t := activeTheme
|
||||
sty := textarea.DefaultStyles(t.Dark)
|
||||
sty.Focused.Text = lipgloss.NewStyle().Foreground(t.Text)
|
||||
sty.Blurred.Text = lipgloss.NewStyle().Foreground(t.Muted)
|
||||
sty.Focused.Placeholder = lipgloss.NewStyle().Foreground(t.Muted)
|
||||
sty.Blurred.Placeholder = sty.Focused.Placeholder
|
||||
sty.Cursor.Color = t.Accent
|
||||
plain := lipgloss.NewStyle()
|
||||
sty.Focused.CursorLine = plain
|
||||
sty.Focused.EndOfBuffer = plain
|
||||
|
||||
@@ -34,9 +34,27 @@ func TestAIInputNewlineKeys(t *testing.T) {
|
||||
t.Fatalf("⏎ darf keine Zeile einfügen: %q", in.Value())
|
||||
}
|
||||
in, _ = in.Update(tea.KeyPressMsg{Code: tea.KeyEnter, Mod: tea.ModShift})
|
||||
in, _ = in.Update(tea.KeyPressMsg{Code: 'j', Mod: tea.ModCtrl})
|
||||
if in.Value() != "a\n\n" {
|
||||
t.Fatalf("Shift+⏎ / Strg+J sollte Zeilen einfügen: %q", in.Value())
|
||||
}
|
||||
// Alt+⏎ gehört Windows Terminal (Vollbild) und ist nicht mehr belegt.
|
||||
in, _ = in.Update(tea.KeyPressMsg{Code: tea.KeyEnter, Mod: tea.ModAlt})
|
||||
if in.Value() != "a\n\n" {
|
||||
t.Fatalf("Shift/Alt+⏎ sollte Zeilen einfügen: %q", in.Value())
|
||||
t.Fatalf("Alt+⏎ darf keine Zeile einfügen: %q", in.Value())
|
||||
}
|
||||
}
|
||||
|
||||
func TestAIInputNewlineRebind(t *testing.T) {
|
||||
old := activeKeys
|
||||
defer func() { activeKeys = old }()
|
||||
activeKeys = newKeymap(map[string]string{"newline": "ctrl+n"})
|
||||
in := newAIInput("")
|
||||
in.Focus()
|
||||
in.SetValue("a")
|
||||
in, _ = in.Update(tea.KeyPressMsg{Code: 'n', Mod: tea.ModCtrl})
|
||||
if in.Value() != "a\n" {
|
||||
t.Fatalf("eigene Taste für neue Zeile: %q", in.Value())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+29
-9
@@ -44,6 +44,8 @@ const (
|
||||
scrTerminal
|
||||
scrSync
|
||||
scrQuickForm
|
||||
scrImport
|
||||
scrKeys
|
||||
)
|
||||
|
||||
// App ist das Wurzel-Modell.
|
||||
@@ -79,8 +81,13 @@ type App struct {
|
||||
restart bool // nach dem Beenden neu starten (siehe Restart)
|
||||
lastKey time.Time
|
||||
|
||||
sync syncState
|
||||
wiz *syncWizard
|
||||
sync syncState
|
||||
wiz *syncWizard
|
||||
imp importState // Import aus ssh-config, PuTTY, MobaXterm
|
||||
keyEd keyEditor // Tastenkürzel anpassen
|
||||
keys keymap // aktuelle Tastenbelegung
|
||||
lookSig string // Theme+Tasten, zuletzt übernommen
|
||||
|
||||
z zones // klickbare Bereiche des letzten Bildes
|
||||
click clickState // für Doppel-/Dreifachklick
|
||||
}
|
||||
@@ -90,7 +97,7 @@ func New(st *store.Store) (*App, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
a := &App{st: st, hostKeys: hk, s: NewStyles(Nacht), events: make(chan tea.Msg, 256), lastKey: time.Now()}
|
||||
a := &App{st: st, hostKeys: hk, s: NewStyles(Nacht), events: make(chan tea.Msg, 256), lastKey: time.Now(), keys: newKeymap(nil)}
|
||||
a.unlock = newUnlock(st)
|
||||
a.hookSync()
|
||||
return a, nil
|
||||
@@ -209,7 +216,7 @@ func (a *App) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
case updateMsg:
|
||||
if m.rel != nil {
|
||||
a.rel = m.rel
|
||||
a.flash("Update auf v" + m.rel.Version + " verfügbar (F12)")
|
||||
a.flash("Update auf v" + m.rel.Version + " verfügbar (" + a.keys.label(actAbout) + ")")
|
||||
}
|
||||
return a, nil
|
||||
case applyDoneMsg:
|
||||
@@ -243,20 +250,23 @@ func (a *App) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
|
||||
if k, ok := msg.(tea.KeyPressMsg); ok {
|
||||
a.lastKey = time.Now()
|
||||
if k.String() == "ctrl+q" {
|
||||
if a.scr == scrKeys && a.keyEd.capturing && a.modal == nil {
|
||||
return a, a.updateKeys(k) // neue Taste: nichts anderes darf sie abfangen
|
||||
}
|
||||
if a.keys.is(actQuit, k.String()) {
|
||||
return a, a.quit()
|
||||
}
|
||||
if a.modal != nil {
|
||||
return a, a.modalKey(k)
|
||||
}
|
||||
if k.String() == "f1" && (a.pal != nil || a.scr == scrConnForm || a.scr == scrSettings || a.scr == scrTunnelForm || a.scr == scrQuickForm) {
|
||||
if a.keys.is(actHelp, k.String()) && (a.pal != nil || a.scr == scrConnForm || a.scr == scrSettings || a.scr == scrTunnelForm || a.scr == scrImport || a.scr == scrKeys || a.scr == scrQuickForm) {
|
||||
a.modal = a.helpModal()
|
||||
return a, nil
|
||||
}
|
||||
if a.pal != nil {
|
||||
return a, a.paletteKey(k)
|
||||
}
|
||||
if isPaletteKey(k.String()) && (a.scr == scrTerminal || a.scr == scrManager) {
|
||||
if a.keys.is(actPalette, k.String()) && (a.scr == scrTerminal || a.scr == scrManager) {
|
||||
return a, a.openPalette()
|
||||
}
|
||||
}
|
||||
@@ -278,6 +288,10 @@ func (a *App) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
return a, a.updateTerminal(msg)
|
||||
case scrSync:
|
||||
return a, a.updateSync(msg)
|
||||
case scrImport:
|
||||
return a, a.updateImport(msg)
|
||||
case scrKeys:
|
||||
return a, a.updateKeys(msg)
|
||||
}
|
||||
return a, nil
|
||||
}
|
||||
@@ -292,6 +306,7 @@ func (a *App) quit() tea.Cmd {
|
||||
|
||||
func (a *App) onTick() tea.Cmd {
|
||||
var cmds []tea.Cmd
|
||||
a.applyLook() // Theme/Tasten können per Sync von einem anderen Rechner kommen
|
||||
// Auto-Sperre nur ohne offene Sitzungen (sonst würden Shells hängen bleiben).
|
||||
if set := a.st.Settings(); set.LockAfterMin > 0 && a.scr != scrUnlock && len(a.sessions) == 0 &&
|
||||
time.Since(a.lastKey) > time.Duration(set.LockAfterMin)*time.Minute {
|
||||
@@ -338,6 +353,10 @@ func (a *App) View() tea.View {
|
||||
body, cur = a.viewTerminal()
|
||||
case scrSync:
|
||||
body = a.frame(a.viewSync(), a.syncKeys())
|
||||
case scrImport:
|
||||
body = a.frame(a.viewImport(), a.importKeys())
|
||||
case scrKeys:
|
||||
body = a.frame(a.viewKeys(), a.keysKeys())
|
||||
}
|
||||
body = a.z.scan(body, 0, 0)
|
||||
if a.modal != nil {
|
||||
@@ -356,6 +375,7 @@ func (a *App) View() tea.View {
|
||||
v.WindowTitle = version.Name + " · " + s.conn.Alias
|
||||
}
|
||||
v.BackgroundColor = a.s.T.Bg
|
||||
v.ForegroundColor = a.s.T.Text // sonst bliebe ungefärbter Text auf Hell unsichtbar
|
||||
return v
|
||||
}
|
||||
|
||||
@@ -365,9 +385,9 @@ func (a *App) header(right string) string {
|
||||
if a.toast != "" && time.Now().Before(a.toastUntil) {
|
||||
right = a.s.Header.Foreground(a.s.T.Warn).Render(" " + a.toast + " ")
|
||||
} else if a.rel != nil && right == "" {
|
||||
right = a.keyZone("F12", a.s.Header.Foreground(a.s.T.OK).Render(" ⬆ v"+a.rel.Version+" verfügbar · F12 "))
|
||||
right = a.keyZone(a.keys.label(actAbout), a.s.Header.Foreground(a.s.T.OK).Render(" ⬆ v"+a.rel.Version+" verfügbar · "+a.keys.label(actAbout)+" "))
|
||||
} else if a.restartPending != "" && right == "" {
|
||||
right = a.keyZone("F12", a.s.Header.Foreground(a.s.T.OK).Render(" ⟳ v"+a.restartPending+" installiert · Neustart F12 "))
|
||||
right = a.keyZone(a.keys.label(actAbout), a.s.Header.Foreground(a.s.T.OK).Render(" ⟳ v"+a.restartPending+" installiert · Neustart "+a.keys.label(actAbout)+" "))
|
||||
}
|
||||
gap := a.w - lipgloss.Width(left) - lipgloss.Width(right)
|
||||
if gap < 0 {
|
||||
|
||||
@@ -259,7 +259,7 @@ func (a *App) filesKey(s *session, k tea.KeyPressMsg) tea.Cmd {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if key == "esc" || key == "f5" {
|
||||
if key == "esc" || a.keys.is(actFiles, key) {
|
||||
f.open = false
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ func newInput(val string, secret bool) textinput.Model {
|
||||
ti.SetValue(val)
|
||||
ti.CharLimit = 4096
|
||||
ti.SetWidth(40)
|
||||
ti.SetStyles(inputStyles(activeTheme))
|
||||
if secret {
|
||||
ti.EchoMode = textinput.EchoPassword
|
||||
ti.EchoCharacter = '•'
|
||||
|
||||
+12
-4
@@ -55,6 +55,9 @@ var helpSections = []helpSection{
|
||||
{"q", "Schnellbefehle"},
|
||||
{"s", "KI-Einstellungen"},
|
||||
{"y", "Sync zwischen Rechnern"},
|
||||
{"i", "Verbindungen importieren"},
|
||||
{"a", "Aussehen wechseln"},
|
||||
{"b", "Tastenkürzel anpassen"},
|
||||
{"F10", "zurück zum Terminal"},
|
||||
}},
|
||||
{hcSettings, "⚙", "KI-Einstellungen", "s", true, [][2]string{
|
||||
@@ -75,7 +78,7 @@ var helpSections = []helpSection{
|
||||
}},
|
||||
{hcGoal, "◎", "Ziel-Modus", "F2", true, [][2]string{
|
||||
{"⏎", "Ziel starten / ausführen"},
|
||||
{"⇧⏎ / Alt+⏎", "neue Zeile im Ziel"},
|
||||
{"⇧⏎ / Strg+J", "neue Zeile im Ziel"},
|
||||
{"i", "nur einfügen (Dry-Run)"},
|
||||
{"e", "bearbeiten"},
|
||||
{"s", "überspringen"},
|
||||
@@ -87,7 +90,7 @@ var helpSections = []helpSection{
|
||||
}},
|
||||
{hcAsk, "✦", "KI fragen", "F3", true, [][2]string{
|
||||
{"⏎", "Frage senden"},
|
||||
{"⇧⏎ / Alt+⏎", "neue Zeile"},
|
||||
{"⇧⏎ / Strg+J", "neue Zeile"},
|
||||
{"1…9", "Befehl einfügen"},
|
||||
{"n", "neue Frage"},
|
||||
}},
|
||||
@@ -114,6 +117,11 @@ var helpSections = []helpSection{
|
||||
{"Tab", "KI fragen"},
|
||||
{"Esc", "schließen"},
|
||||
}},
|
||||
{hcNone, "◐", "Aussehen & Tasten", "", false, [][2]string{
|
||||
{"a", "Dunkel · Hell · Kontrast"},
|
||||
{"b", "Tastenkürzel belegen"},
|
||||
{"Strg +/−", "Schrift (Terminalfenster)"},
|
||||
}},
|
||||
{hcNone, "⌖", "Maus", "", false, [][2]string{
|
||||
{"Klick", "Tabs, Listen, Felder"},
|
||||
{"Doppelklick", "öffnen / Wort"},
|
||||
@@ -170,14 +178,14 @@ func (s Styles) helpSection(sec helpSection, ctx helpCtx) []string {
|
||||
}
|
||||
title := head.Render(sec.icon + " " + sec.title)
|
||||
if sec.key != "" {
|
||||
title += " " + s.Muted.Render(sec.key)
|
||||
title += " " + s.Muted.Render(relabelDefault(sec.key, sec.ctx))
|
||||
}
|
||||
if sec.ctx != hcNone && sec.ctx == ctx {
|
||||
title += " " + s.Badge.Render("hier")
|
||||
}
|
||||
lines := []string{title}
|
||||
for _, r := range sec.rows {
|
||||
k := s.Key.Render(r[0])
|
||||
k := s.Key.Render(relabelDefault(r[0], sec.ctx))
|
||||
k += strings.Repeat(" ", max(0, helpKeyW-lipgloss.Width(k)))
|
||||
lines = append(lines, k+s.Text.Render(ansi.Truncate(r[1], helpColW-helpKeyW, "…")))
|
||||
}
|
||||
|
||||
@@ -0,0 +1,302 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"charm.land/bubbles/v2/textinput"
|
||||
tea "charm.land/bubbletea/v2"
|
||||
"charm.land/lipgloss/v2"
|
||||
|
||||
"github.com/db9979/sshtermy/internal/domain"
|
||||
"github.com/db9979/sshtermy/internal/importer"
|
||||
"github.com/db9979/sshtermy/internal/store"
|
||||
)
|
||||
|
||||
// Import (i im Manager): sucht beim Öffnen selbst nach ~/.ssh/config,
|
||||
// PuTTY-Sitzungen und MobaXterm. Neue Funde sind vorausgewählt, ⏎ übernimmt
|
||||
// alle auf einmal. Schon vorhandene Ziele sind abgewählt und markiert.
|
||||
|
||||
type importItem struct {
|
||||
e importer.Entry
|
||||
on bool
|
||||
known bool
|
||||
}
|
||||
|
||||
type importState struct {
|
||||
results []importer.Result
|
||||
items []importItem
|
||||
sel int
|
||||
asking bool
|
||||
path textinput.Model
|
||||
err string
|
||||
}
|
||||
|
||||
func (a *App) openImport() tea.Cmd {
|
||||
a.imp = importState{path: newInput("", false)}
|
||||
a.imp.path.Placeholder = `Pfad: ~/.ssh/config, putty.reg, MobaXterm.ini, *.mxtsessions`
|
||||
for _, r := range importer.Scan() {
|
||||
a.addImport(r)
|
||||
}
|
||||
a.scr = scrImport
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) addImport(r importer.Result) {
|
||||
a.imp.results = append(a.imp.results, r)
|
||||
existing := a.st.Connections()
|
||||
for _, e := range r.Entries {
|
||||
known := importer.IsKnown(e.Conn, existing)
|
||||
for _, it := range a.imp.items { // doppelt in zwei Quellen
|
||||
if importer.IsKnown(e.Conn, []domain.Connection{it.e.Conn}) {
|
||||
known = true
|
||||
}
|
||||
}
|
||||
a.imp.items = append(a.imp.items, importItem{e: e, on: !known, known: known})
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) importKeys() [][2]string {
|
||||
if a.imp.asking {
|
||||
return [][2]string{{"⏎", "Datei lesen"}, {"Esc", "abbrechen"}}
|
||||
}
|
||||
return [][2]string{{"⏎", fmt.Sprintf("%d übernehmen", a.importCount())}, {"Space", "an/aus"}, {"a", "alle/keine"}, {"f", "Datei laden"}, {"Esc", "zurück"}}
|
||||
}
|
||||
|
||||
func (a *App) importCount() int {
|
||||
n := 0
|
||||
for _, it := range a.imp.items {
|
||||
if it.on {
|
||||
n++
|
||||
}
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (a *App) updateImport(msg tea.Msg) tea.Cmd {
|
||||
m := &a.imp
|
||||
if p, ok := msg.(tea.PasteMsg); ok && m.asking {
|
||||
var cmd tea.Cmd
|
||||
m.path, cmd = m.path.Update(p)
|
||||
return cmd
|
||||
}
|
||||
k, ok := msg.(tea.KeyPressMsg)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
if m.asking {
|
||||
switch k.String() {
|
||||
case "esc":
|
||||
m.asking = false
|
||||
m.path.Blur()
|
||||
case "enter":
|
||||
m.asking = false
|
||||
m.path.Blur()
|
||||
p := strings.TrimSpace(m.path.Value())
|
||||
if p == "" {
|
||||
return nil
|
||||
}
|
||||
r := importer.File(p)
|
||||
if r.Err != nil {
|
||||
m.err = r.Path + ": " + r.Err.Error()
|
||||
return nil
|
||||
}
|
||||
before := len(m.items)
|
||||
a.addImport(r)
|
||||
m.err = ""
|
||||
a.flash(fmt.Sprintf("%s: %d Verbindungen gefunden", r.Source.Label(), len(m.items)-before))
|
||||
default:
|
||||
var cmd tea.Cmd
|
||||
m.path, cmd = m.path.Update(k)
|
||||
return cmd
|
||||
}
|
||||
return nil
|
||||
}
|
||||
switch k.String() {
|
||||
case "esc", "q":
|
||||
a.scr = scrManager
|
||||
case "up", "k":
|
||||
m.sel = max(0, m.sel-1)
|
||||
case "down", "j":
|
||||
m.sel = min(len(m.items)-1, m.sel+1)
|
||||
case "space", " ", "x":
|
||||
if m.sel < len(m.items) {
|
||||
m.items[m.sel].on = !m.items[m.sel].on
|
||||
}
|
||||
case "a":
|
||||
on := a.importCount() < len(m.items)
|
||||
for i := range m.items {
|
||||
m.items[i].on = on
|
||||
}
|
||||
case "f", "/":
|
||||
m.asking = true
|
||||
return m.path.Focus()
|
||||
case "enter":
|
||||
n, unresolved, err := a.commitImport()
|
||||
if err != nil {
|
||||
m.err = err.Error()
|
||||
return nil
|
||||
}
|
||||
a.scr = scrManager
|
||||
msg := fmt.Sprintf("%s importiert", plural(n, "Verbindung", "Verbindungen"))
|
||||
if unresolved > 0 {
|
||||
msg += fmt.Sprintf(" · %d Sprung-Host(s) nicht gefunden", unresolved)
|
||||
}
|
||||
a.flash(msg)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// commitImport legt die gewählten Funde an und verknüpft Sprung-Hosts.
|
||||
func (a *App) commitImport() (n, unresolved int, err error) {
|
||||
var cs []domain.Connection
|
||||
var jumps []string
|
||||
for _, it := range a.imp.items {
|
||||
if !it.on {
|
||||
continue
|
||||
}
|
||||
c := it.e.Conn
|
||||
c.ID = store.NewID()
|
||||
cs = append(cs, c)
|
||||
jumps = append(jumps, it.e.Jump)
|
||||
}
|
||||
if len(cs) == 0 {
|
||||
return 0, 0, errors.New("nichts ausgewählt (Space wählt aus)")
|
||||
}
|
||||
pool := append(append([]domain.Connection(nil), cs...), a.st.Connections()...)
|
||||
for i, j := range jumps {
|
||||
if j == "" {
|
||||
continue
|
||||
}
|
||||
if id := findJump(j, pool); id != "" && id != cs[i].ID {
|
||||
cs[i].JumpHostID = id
|
||||
} else {
|
||||
unresolved++
|
||||
}
|
||||
}
|
||||
if _, err := a.st.AddConnections(cs); err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
return len(cs), unresolved, nil
|
||||
}
|
||||
|
||||
// findJump: „alias“, „host“, „user@host“ oder „user@host:port“.
|
||||
func findJump(j string, pool []domain.Connection) string {
|
||||
user, host, port := "", j, 0
|
||||
if i := strings.LastIndex(host, "@"); i >= 0 {
|
||||
user, host = host[:i], host[i+1:]
|
||||
}
|
||||
if i := strings.LastIndex(host, ":"); i >= 0 && !strings.Contains(host[:i], ":") {
|
||||
port, _ = strconv.Atoi(host[i+1:])
|
||||
host = host[:i]
|
||||
}
|
||||
for _, c := range pool {
|
||||
if strings.EqualFold(c.Alias, j) {
|
||||
return c.ID
|
||||
}
|
||||
}
|
||||
for _, c := range pool {
|
||||
if (strings.EqualFold(c.Host, host) || strings.EqualFold(c.Alias, host)) &&
|
||||
(user == "" || c.Username == user) && (port == 0 || c.Port == port) {
|
||||
return c.ID
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (a *App) viewImport() string {
|
||||
s := a.s
|
||||
m := &a.imp
|
||||
w := min(110, a.w-2)
|
||||
var b strings.Builder
|
||||
b.WriteString(s.Accent.Render(" ⇩ Verbindungen importieren") + "\n\n")
|
||||
for _, r := range m.results {
|
||||
state := s.OK.Render(plural(len(r.Entries), "Verbindung", "Verbindungen"))
|
||||
switch {
|
||||
case errors.Is(r.Err, importer.ErrNotFound):
|
||||
state = s.Muted.Render("nicht gefunden")
|
||||
case r.Err != nil:
|
||||
state = s.Danger.Render(r.Err.Error())
|
||||
}
|
||||
b.WriteString(" " + s.Label.Render(r.Source.Label()) + state + s.Muted.Render(" "+trunc(r.Path, w-50)) + "\n")
|
||||
}
|
||||
b.WriteString("\n")
|
||||
if m.asking {
|
||||
m.path.SetWidth(w - 12)
|
||||
b.WriteString(" " + s.Accent.Render("Datei: ") + m.path.View() + "\n\n")
|
||||
}
|
||||
if m.err != "" {
|
||||
b.WriteString(" " + s.Danger.Render(m.err) + "\n\n")
|
||||
}
|
||||
if len(m.items) == 0 {
|
||||
b.WriteString(s.Muted.Render(" Nichts gefunden. f = Datei laden (PuTTY-.reg-Export, MobaXterm.ini, .mxtsessions oder ssh_config).\n" +
|
||||
" PuTTY exportieren: reg export HKCU\\Software\\SimonTatham\\PuTTY putty.reg"))
|
||||
return b.String()
|
||||
}
|
||||
// Liste mit Fenster um die Auswahl
|
||||
head := lipgloss.Height(b.String())
|
||||
rows := max(3, a.h-2-head-3)
|
||||
start := 0
|
||||
if m.sel >= rows {
|
||||
start = m.sel - rows + 1
|
||||
}
|
||||
for i := start; i < len(m.items) && i < start+rows; i++ {
|
||||
it := m.items[i]
|
||||
c := it.e.Conn
|
||||
box := "[ ]"
|
||||
if it.on {
|
||||
box = "[x]"
|
||||
}
|
||||
target := c.Username + "@" + c.Host
|
||||
if c.Port != 22 {
|
||||
target += ":" + strconv.Itoa(c.Port)
|
||||
}
|
||||
extra := it.e.Source.Label()
|
||||
if c.Group != "" {
|
||||
extra += " · " + c.Group
|
||||
}
|
||||
if it.e.Jump != "" {
|
||||
extra += " · über " + it.e.Jump
|
||||
}
|
||||
note := ""
|
||||
if it.known {
|
||||
note = "schon vorhanden"
|
||||
} else if len(it.e.Notes) > 0 {
|
||||
note = it.e.Notes[0]
|
||||
}
|
||||
line := fmt.Sprintf(" %s %-22s %-32s %s", box, trunc(c.Alias, 22), trunc(target, 32), extra)
|
||||
line = trunc(line, w-2)
|
||||
var out string
|
||||
if i == m.sel {
|
||||
full := line
|
||||
if note != "" {
|
||||
full = trunc(line+" ⚑ "+note, w-2)
|
||||
}
|
||||
out = s.Selected.Width(w - 1).Render(full)
|
||||
} else {
|
||||
st := s.Text
|
||||
if it.known {
|
||||
st = s.Muted
|
||||
}
|
||||
out = st.Render(line)
|
||||
if note != "" && lipgloss.Width(line)+4 < w-2 {
|
||||
ns := s.Warn
|
||||
if it.known {
|
||||
ns = s.Muted
|
||||
}
|
||||
out += ns.Render(" ⚑ " + trunc(note, w-6-lipgloss.Width(line)))
|
||||
}
|
||||
}
|
||||
i := i
|
||||
out = a.z.click(out, func(_ tea.Mouse, double bool) tea.Cmd {
|
||||
m.sel = i
|
||||
m.items[i].on = !m.items[i].on
|
||||
return nil
|
||||
})
|
||||
b.WriteString(out + "\n")
|
||||
}
|
||||
b.WriteString("\n" + s.Muted.Render(" Passwörter werden nicht übernommen; sshTermy fragt beim ersten Verbinden danach."))
|
||||
return b.String()
|
||||
}
|
||||
@@ -0,0 +1,262 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
// Frei belegbare Tastenkürzel. Jede Aktion hat Standardtasten; in den
|
||||
// Einstellungen (Settings.Keys) lässt sich pro Aktion eine eigene Taste
|
||||
// hinterlegen, die dann die Standardtasten ersetzt.
|
||||
//
|
||||
// Standard ohne Alt+⏎: Windows Terminal schaltet damit in den Vollbildmodus,
|
||||
// die Taste kommt bei sshTermy gar nicht an.
|
||||
|
||||
type action string
|
||||
|
||||
const (
|
||||
actPalette action = "palette"
|
||||
actHelp action = "help"
|
||||
actAbout action = "about"
|
||||
actQuit action = "quit"
|
||||
actGoal action = "goal"
|
||||
actAsk action = "ask"
|
||||
actTunnels action = "tunnels"
|
||||
actFiles action = "files"
|
||||
actPrevTab action = "prev_tab"
|
||||
actNextTab action = "next_tab"
|
||||
actManager action = "manager"
|
||||
actChip1 action = "chip1"
|
||||
actChip2 action = "chip2"
|
||||
actChip3 action = "chip3"
|
||||
actChip4 action = "chip4"
|
||||
actNewline action = "newline"
|
||||
actImport action = "import"
|
||||
actKeys action = "keys"
|
||||
actNextLook action = "theme"
|
||||
actCheat action = "cheat"
|
||||
actQuickEdit action = "quick_edit"
|
||||
)
|
||||
|
||||
// Schnellbefehle ⇧F1 … ⇧F8 (manche Terminals senden dafür F13 … F20).
|
||||
var actQuick = [maxQuick]action{"quick1", "quick2", "quick3", "quick4", "quick5", "quick6", "quick7", "quick8"}
|
||||
|
||||
type actionDef struct {
|
||||
id action
|
||||
label string
|
||||
area string
|
||||
def []string // bubbletea-Tastennamen; die erste wird angezeigt
|
||||
}
|
||||
|
||||
var actionDefs = []actionDef{
|
||||
{actPalette, "Befehlspalette", "Überall", []string{"ctrl+space", "ctrl+@"}},
|
||||
{actHelp, "Hilfe", "Überall", []string{"f1"}},
|
||||
{actAbout, "Über & Update", "Überall", []string{"f12"}},
|
||||
{actQuit, "Beenden", "Überall", []string{"ctrl+q"}},
|
||||
{actManager, "Manager ↔ Terminal", "Überall", []string{"f10"}},
|
||||
{actCheat, "Spickzettel an/aus", "Überall", []string{"f9"}},
|
||||
{actGoal, "Ziel-Modus (Agent)", "Terminal", []string{"f2"}},
|
||||
{actAsk, "KI fragen", "Terminal", []string{"f3"}},
|
||||
{actTunnels, "Tunnel", "Terminal", []string{"f4"}},
|
||||
{actFiles, "Dateien (SFTP)", "Terminal", []string{"f5"}},
|
||||
{actPrevTab, "Tab zurück", "Terminal", []string{"f7"}},
|
||||
{actNextTab, "Tab vor", "Terminal", []string{"f8"}},
|
||||
{actChip1, "Folgebefehl 1 einfügen", "Terminal", []string{"alt+1"}},
|
||||
{actChip2, "Folgebefehl 2 einfügen", "Terminal", []string{"alt+2"}},
|
||||
{actChip3, "Folgebefehl 3 einfügen", "Terminal", []string{"alt+3"}},
|
||||
{actChip4, "Folgebefehl 4 einfügen", "Terminal", []string{"alt+4"}},
|
||||
{actQuick[0], "Schnellbefehl 1", "Terminal", []string{"shift+f1", "f13"}},
|
||||
{actQuick[1], "Schnellbefehl 2", "Terminal", []string{"shift+f2", "f14"}},
|
||||
{actQuick[2], "Schnellbefehl 3", "Terminal", []string{"shift+f3", "f15"}},
|
||||
{actQuick[3], "Schnellbefehl 4", "Terminal", []string{"shift+f4", "f16"}},
|
||||
{actQuick[4], "Schnellbefehl 5", "Terminal", []string{"shift+f5", "f17"}},
|
||||
{actQuick[5], "Schnellbefehl 6", "Terminal", []string{"shift+f6", "f18"}},
|
||||
{actQuick[6], "Schnellbefehl 7", "Terminal", []string{"shift+f7", "f19"}},
|
||||
{actQuick[7], "Schnellbefehl 8", "Terminal", []string{"shift+f8", "f20"}},
|
||||
{actNewline, "Neue Zeile in KI-Eingabe", "KI-Eingabe", []string{"shift+enter", "ctrl+j"}},
|
||||
{actImport, "Verbindungen importieren", "Manager", []string{"i"}},
|
||||
{actNextLook, "Aussehen wechseln", "Manager", []string{"a"}},
|
||||
{actKeys, "Tastenkürzel anpassen", "Manager", []string{"b"}},
|
||||
{actQuickEdit, "Schnellbefehle bearbeiten", "Manager", []string{"q"}},
|
||||
}
|
||||
|
||||
func defOf(id action) actionDef {
|
||||
for _, d := range actionDefs {
|
||||
if d.id == id {
|
||||
return d
|
||||
}
|
||||
}
|
||||
return actionDef{id: id}
|
||||
}
|
||||
|
||||
// keymap: aktuelle Belegung Aktion → Tasten.
|
||||
type keymap struct {
|
||||
keys map[action][]string
|
||||
}
|
||||
|
||||
func newKeymap(over map[string]string) keymap {
|
||||
km := keymap{keys: map[action][]string{}}
|
||||
for _, d := range actionDefs {
|
||||
km.keys[d.id] = d.def
|
||||
if k := strings.TrimSpace(over[string(d.id)]); k != "" {
|
||||
km.keys[d.id] = []string{k}
|
||||
}
|
||||
}
|
||||
return km
|
||||
}
|
||||
|
||||
// activeKeys: Belegung für Stellen ohne App-Zugriff (Hilfe, Eingabefelder).
|
||||
var activeKeys = newKeymap(nil)
|
||||
|
||||
func (km keymap) is(id action, key string) bool {
|
||||
for _, k := range km.keys[id] {
|
||||
if k == key {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// which: welche Aktion liegt auf der Taste (oder "")?
|
||||
func (km keymap) which(key string, among ...action) action {
|
||||
for _, id := range among {
|
||||
if km.is(id, key) {
|
||||
return id
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// label: angezeigte Taste der Aktion, z. B. „F2“ oder „Strg+G“.
|
||||
func (km keymap) label(id action) string {
|
||||
ks := km.keys[id]
|
||||
if len(ks) == 0 {
|
||||
return "—"
|
||||
}
|
||||
return keyLabel(ks[0])
|
||||
}
|
||||
|
||||
// conflicts: Aktionen, die sich eine Taste teilen (nur im selben oder im
|
||||
// globalen Bereich ein Problem).
|
||||
func (km keymap) conflicts() map[action]action {
|
||||
out := map[action]action{}
|
||||
for i, a := range actionDefs {
|
||||
for _, b := range actionDefs[i+1:] {
|
||||
if a.area != b.area && a.area != "Überall" && b.area != "Überall" {
|
||||
continue
|
||||
}
|
||||
for _, ka := range km.keys[a.id] {
|
||||
if km.is(b.id, ka) {
|
||||
out[a.id], out[b.id] = b.id, a.id
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// keyLabel macht aus „ctrl+g“ die Anzeige „Strg+G“ (umkehrbar mit keyFromLabel).
|
||||
func keyLabel(k string) string {
|
||||
parts := strings.Split(k, "+")
|
||||
if len(parts) > 1 && parts[len(parts)-1] == "" { // „ctrl++“
|
||||
parts = append(parts[:len(parts)-2], "+")
|
||||
}
|
||||
for i, p := range parts {
|
||||
if i < len(parts)-1 {
|
||||
parts[i] = map[string]string{"ctrl": "Strg", "alt": "Alt", "shift": "Shift", "super": "Super", "meta": "Meta"}[p]
|
||||
if parts[i] == "" {
|
||||
parts[i] = p
|
||||
}
|
||||
continue
|
||||
}
|
||||
switch {
|
||||
case p == "enter":
|
||||
parts[i] = "⏎"
|
||||
case p == "space":
|
||||
parts[i] = "Space"
|
||||
case p == "esc":
|
||||
parts[i] = "Esc"
|
||||
case p == "tab":
|
||||
parts[i] = "Tab"
|
||||
case p == "backspace":
|
||||
parts[i] = "⌫"
|
||||
case p == "delete":
|
||||
parts[i] = "Entf"
|
||||
case p == "@":
|
||||
parts[i] = "@"
|
||||
case len(p) >= 2 && p[0] == 'f' && p[1] >= '0' && p[1] <= '9':
|
||||
parts[i] = strings.ToUpper(p)
|
||||
case utf8.RuneCountInString(p) == 1 && i > 0:
|
||||
parts[i] = strings.ToUpper(p)
|
||||
default:
|
||||
parts[i] = p
|
||||
}
|
||||
}
|
||||
return strings.Join(parts, "+")
|
||||
}
|
||||
|
||||
// reservedKey: Tasten, die sich nicht sinnvoll belegen lassen.
|
||||
func reservedKey(k string) string {
|
||||
switch k {
|
||||
case "esc", "enter", "tab", "backspace", "up", "down", "left", "right", "space":
|
||||
return "wird zum Bedienen gebraucht"
|
||||
case "alt+enter":
|
||||
return "Windows Terminal schaltet damit auf Vollbild"
|
||||
case "alt+f4":
|
||||
return "schließt unter Windows das Fenster"
|
||||
case "ctrl+c", "ctrl+d", "ctrl+z", "ctrl+v":
|
||||
return "gehört der Shell bzw. dem Einfügen"
|
||||
}
|
||||
if utf8.RuneCountInString(k) == 1 {
|
||||
return "einzelne Zeichen braucht die Shell (nur im Manager sinnvoll)"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// overrides: nur die Abweichungen vom Standard (für Settings.Keys).
|
||||
func (km keymap) overrides() map[string]string {
|
||||
out := map[string]string{}
|
||||
for _, d := range actionDefs {
|
||||
ks := km.keys[d.id]
|
||||
if len(ks) == 1 && (len(d.def) != 1 || d.def[0] != ks[0]) {
|
||||
out[string(d.id)] = ks[0]
|
||||
}
|
||||
}
|
||||
if len(out) == 0 {
|
||||
return nil
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// relabelDefault ersetzt eine Standard-Tastenbeschriftung (Hilfe-Tabelle)
|
||||
// durch die aktuelle Belegung. Einzelne Buchstaben (Manager-Aktionen) nur
|
||||
// im Manager-Abschnitt, sonst würde z. B. „i“ im Ziel-Modus umbenannt.
|
||||
func relabelDefault(lbl string, ctx helpCtx) string {
|
||||
switch lbl {
|
||||
case "Alt+1…4":
|
||||
if activeKeys.label(actChip1) == "Alt+1" && activeKeys.label(actChip4) == "Alt+4" {
|
||||
return lbl
|
||||
}
|
||||
return activeKeys.label(actChip1) + "…"
|
||||
case "F7 / F8":
|
||||
return activeKeys.label(actPrevTab) + " / " + activeKeys.label(actNextTab)
|
||||
case "⇧⏎ / Strg+J":
|
||||
ks := activeKeys.keys[actNewline]
|
||||
if len(ks) == 2 && ks[0] == "shift+enter" && ks[1] == "ctrl+j" {
|
||||
return lbl // passt in die Spalte
|
||||
}
|
||||
if len(ks) == 2 {
|
||||
return keyLabel(ks[0]) + " / " + keyLabel(ks[1])
|
||||
}
|
||||
return activeKeys.label(actNewline)
|
||||
}
|
||||
for _, d := range actionDefs {
|
||||
if d.area == "Manager" && ctx != hcManager {
|
||||
continue
|
||||
}
|
||||
if len(d.def) > 0 && keyLabel(d.def[0]) == lbl {
|
||||
return activeKeys.label(d.id)
|
||||
}
|
||||
}
|
||||
return lbl
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestKeyLabelRoundTrip(t *testing.T) {
|
||||
for _, k := range []string{"f2", "ctrl+g", "alt+1", "ctrl+space", "shift+enter", "ctrl+j", "i", "ctrl+shift+p"} {
|
||||
lbl := keyLabel(k)
|
||||
m, ok := keyFromLabel(lbl)
|
||||
if !ok || m.String() != k {
|
||||
t.Errorf("%s → %q → %q (%v)", k, lbl, m.String(), ok)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestKeymapOverride(t *testing.T) {
|
||||
km := newKeymap(map[string]string{"goal": "ctrl+g"})
|
||||
if !km.is(actGoal, "ctrl+g") || km.is(actGoal, "f2") || km.label(actGoal) != "Strg+G" {
|
||||
t.Fatal("Überschreiben wirkt nicht")
|
||||
}
|
||||
if !km.is(actPalette, "ctrl+@") {
|
||||
t.Fatal("Standard-Aliase verloren")
|
||||
}
|
||||
if o := km.overrides(); len(o) != 1 || o["goal"] != "ctrl+g" {
|
||||
t.Fatalf("overrides: %v", o)
|
||||
}
|
||||
for _, d := range actionDefs {
|
||||
for _, k := range d.def {
|
||||
if k == "alt+enter" {
|
||||
t.Fatal("Alt+⏎ darf nicht Standard sein (Windows Terminal Vollbild)")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestKeymapConflicts(t *testing.T) {
|
||||
if c := newKeymap(nil).conflicts(); len(c) != 0 {
|
||||
t.Fatalf("Standardbelegung hat Konflikte: %v", c)
|
||||
}
|
||||
c := newKeymap(map[string]string{"goal": "f3"}).conflicts()
|
||||
if c[actGoal] != actAsk || c[actAsk] != actGoal {
|
||||
t.Fatalf("Konflikt F3 nicht erkannt: %v", c)
|
||||
}
|
||||
if reservedKey("alt+enter") == "" || reservedKey("ctrl+g") != "" {
|
||||
t.Fatal("reservedKey")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRelabelHelp(t *testing.T) {
|
||||
old := activeKeys
|
||||
defer func() { activeKeys = old }()
|
||||
activeKeys = newKeymap(map[string]string{"goal": "ctrl+g", "import": "I"})
|
||||
if relabelDefault("F2", hcTerminal) != "Strg+G" || relabelDefault("F3", hcTerminal) != "F3" {
|
||||
t.Fatal("Hilfe zeigt nicht die eigene Taste")
|
||||
}
|
||||
if relabelDefault("i", hcGoal) != "i" {
|
||||
t.Fatal("„i“ im Ziel-Modus darf nicht umbenannt werden")
|
||||
}
|
||||
}
|
||||
|
||||
func TestThemes(t *testing.T) {
|
||||
if ThemeByName("hell").Name != "hell" || ThemeByName("").Name != "nacht" || ThemeByName("kontrast").Dark != true {
|
||||
t.Fatal("ThemeByName")
|
||||
}
|
||||
for _, th := range Themes {
|
||||
_ = NewStyles(th)
|
||||
if th.Bg == nil || th.Text == nil || th.Danger == nil {
|
||||
t.Fatalf("%s unvollständig", th.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,217 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
tea "charm.land/bubbletea/v2"
|
||||
|
||||
"github.com/db9979/sshtermy/internal/domain"
|
||||
)
|
||||
|
||||
// Aussehen (Theme) und eigene Tastenkürzel. Beides liegt in den
|
||||
// Einstellungen und wird mit dem Sync auf andere Rechner übertragen.
|
||||
|
||||
// fontHint: Die Schriftgröße gehört dem Terminalfenster, nicht dem Programm
|
||||
// darin; ein TUI kann sie nicht ändern.
|
||||
const fontHint = "Schriftgröße: Strg + Plus/Minus im Terminalfenster (macOS: ⌘ + / −)"
|
||||
|
||||
// applyLook übernimmt Theme und Tasten aus den Einstellungen.
|
||||
func (a *App) applyLook() {
|
||||
set := a.st.Settings()
|
||||
sig, _ := json.Marshal([]any{set.Theme, set.Keys})
|
||||
if string(sig) == a.lookSig {
|
||||
return
|
||||
}
|
||||
a.lookSig = string(sig)
|
||||
t := ThemeByName(set.Theme)
|
||||
activeTheme = t
|
||||
a.s = NewStyles(t)
|
||||
a.keys = newKeymap(set.Keys)
|
||||
activeKeys = a.keys
|
||||
// Felder, die schon existieren, bekommen die neuen Farben.
|
||||
a.mgr.search.SetStyles(inputStyles(t))
|
||||
}
|
||||
|
||||
func (a *App) setTheme(name string) tea.Cmd {
|
||||
if err := a.st.UpdateSettings(func(s *domain.Settings) { s.Theme = name }); err != nil {
|
||||
a.flash(err.Error())
|
||||
return nil
|
||||
}
|
||||
a.applyLook()
|
||||
a.flash("Aussehen: " + ThemeByName(name).Label + " · " + fontHint)
|
||||
return nil
|
||||
}
|
||||
|
||||
// cycleTheme: Dunkel → Hell → Hochkontrast → Dunkel.
|
||||
func (a *App) cycleTheme() tea.Cmd {
|
||||
cur := ThemeByName(a.st.Settings().Theme).Name
|
||||
for i, t := range Themes {
|
||||
if t.Name == cur {
|
||||
return a.setTheme(Themes[(i+1)%len(Themes)].Name)
|
||||
}
|
||||
}
|
||||
return a.setTheme(Nacht.Name)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- Tasten-Editor
|
||||
|
||||
type keyEditor struct {
|
||||
sel int
|
||||
capturing bool
|
||||
err string
|
||||
}
|
||||
|
||||
func (a *App) openKeys() tea.Cmd {
|
||||
a.keyEd = keyEditor{}
|
||||
a.scr = scrKeys
|
||||
return nil
|
||||
}
|
||||
|
||||
// managerLetters: Tasten, die der Manager selbst braucht.
|
||||
var managerLetters = "nedtsy/jkq"
|
||||
|
||||
func (a *App) setKey(id action, key string) error {
|
||||
d := defOf(id)
|
||||
if key != "" {
|
||||
if why := reservedKey(key); why != "" && !(d.area == "Manager" && len([]rune(key)) == 1) {
|
||||
return fmt.Errorf("%s %s", keyLabel(key), why)
|
||||
}
|
||||
if d.area == "Manager" && len([]rune(key)) == 1 && strings.Contains(managerLetters, key) {
|
||||
return fmt.Errorf("%s ist im Manager schon belegt", key)
|
||||
}
|
||||
}
|
||||
over := a.keys.overrides()
|
||||
if over == nil {
|
||||
over = map[string]string{}
|
||||
}
|
||||
delete(over, string(id))
|
||||
if key != "" && !(len(d.def) == 1 && d.def[0] == key) {
|
||||
over[string(id)] = key
|
||||
}
|
||||
if len(over) == 0 {
|
||||
over = nil
|
||||
}
|
||||
if err := a.st.UpdateSettings(func(s *domain.Settings) { s.Keys = over }); err != nil {
|
||||
return err
|
||||
}
|
||||
a.applyLook()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) keysKeys() [][2]string {
|
||||
if a.keyEd.capturing {
|
||||
return [][2]string{{"neue Taste", "drücken"}, {"Esc", "abbrechen"}}
|
||||
}
|
||||
return [][2]string{{"⏎", "neu belegen"}, {"Entf", "Standard"}, {"r", "alle zurücksetzen"}, {"Esc", "zurück"}}
|
||||
}
|
||||
|
||||
func (a *App) updateKeys(msg tea.Msg) tea.Cmd {
|
||||
k, ok := msg.(tea.KeyPressMsg)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
e := &a.keyEd
|
||||
key := k.String()
|
||||
if e.capturing {
|
||||
e.capturing = false
|
||||
if key == "esc" {
|
||||
e.err = ""
|
||||
return nil
|
||||
}
|
||||
id := actionDefs[e.sel].id
|
||||
if err := a.setKey(id, key); err != nil {
|
||||
e.err = err.Error()
|
||||
return nil
|
||||
}
|
||||
e.err = ""
|
||||
if other, ok := a.keys.conflicts()[id]; ok {
|
||||
e.err = "Achtung: " + keyLabel(key) + " ist auch „" + defOf(other).label + "“"
|
||||
}
|
||||
return nil
|
||||
}
|
||||
switch key {
|
||||
case "esc", "q":
|
||||
a.scr = scrManager
|
||||
case "up", "k":
|
||||
e.sel = max(0, e.sel-1)
|
||||
case "down", "j":
|
||||
e.sel = min(len(actionDefs)-1, e.sel+1)
|
||||
case "enter":
|
||||
e.capturing, e.err = true, ""
|
||||
case "delete", "backspace":
|
||||
if err := a.setKey(actionDefs[e.sel].id, ""); err != nil {
|
||||
e.err = err.Error()
|
||||
}
|
||||
case "r":
|
||||
a.modal = confirmModal("Tastenkürzel", "Alle Tastenkürzel auf Standard zurücksetzen?", func() tea.Cmd {
|
||||
if err := a.st.UpdateSettings(func(s *domain.Settings) { s.Keys = nil }); err != nil {
|
||||
a.flash(err.Error())
|
||||
}
|
||||
a.applyLook()
|
||||
return nil
|
||||
})
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) viewKeys() string {
|
||||
s := a.s
|
||||
e := &a.keyEd
|
||||
var lines []string
|
||||
selLine := 0
|
||||
conf := a.keys.conflicts()
|
||||
area := ""
|
||||
for i, d := range actionDefs {
|
||||
if d.area != area {
|
||||
area = d.area
|
||||
lines = append(lines, s.Muted.Render(" "+strings.ToUpper(area)))
|
||||
}
|
||||
cur := a.keys.label(d.id)
|
||||
if len(a.keys.keys[d.id]) > 1 {
|
||||
cur += " / " + keyLabel(a.keys.keys[d.id][1])
|
||||
}
|
||||
mark := ""
|
||||
if _, ok := a.keys.overrides()[string(d.id)]; ok {
|
||||
mark = s.AI.Render(" ●") + s.Muted.Render(" Standard: "+keyLabel(d.def[0]))
|
||||
}
|
||||
if o, ok := conf[d.id]; ok {
|
||||
mark += s.Danger.Render(" ⚠ auch „" + defOf(o).label + "“")
|
||||
}
|
||||
keyTxt := s.Key.Render(cur)
|
||||
if i == e.sel && e.capturing {
|
||||
keyTxt = s.BadgeAI.Render("Taste drücken …")
|
||||
}
|
||||
line := fmt.Sprintf(" %-28s ", d.label)
|
||||
if i == e.sel {
|
||||
line = s.Selected.Render("▶"+line[1:]) + keyTxt + mark
|
||||
} else {
|
||||
line = s.Text.Render(line) + keyTxt + mark
|
||||
}
|
||||
i := i
|
||||
if i == e.sel {
|
||||
selLine = len(lines)
|
||||
}
|
||||
lines = append(lines, a.z.click(line, func(_ tea.Mouse, double bool) tea.Cmd {
|
||||
e.sel = i
|
||||
if double {
|
||||
e.capturing = true
|
||||
}
|
||||
return nil
|
||||
}))
|
||||
}
|
||||
var b strings.Builder
|
||||
b.WriteString(s.Accent.Render(" ⌨ Tastenkürzel anpassen") + s.Muted.Render(" ⏎ oder Doppelklick belegt neu · werden mit dem Sync übernommen") + "\n\n")
|
||||
rows := max(5, a.h-2-2-4)
|
||||
start := 0
|
||||
if selLine >= rows {
|
||||
start = selLine - rows + 1
|
||||
}
|
||||
b.WriteString(strings.Join(lines[start:min(len(lines), start+rows)], "\n") + "\n\n")
|
||||
if e.err != "" {
|
||||
b.WriteString(" " + s.Danger.Render(e.err) + "\n")
|
||||
}
|
||||
b.WriteString(s.Muted.Render(" Alt+⏎ ist gesperrt: Windows Terminal schaltet damit auf Vollbild.\n " + fontHint))
|
||||
return b.String()
|
||||
}
|
||||
+31
-17
@@ -42,10 +42,12 @@ func (a *App) filtered() []domain.Connection {
|
||||
}
|
||||
|
||||
func (a *App) managerKeys() [][2]string {
|
||||
k := [][2]string{{"Strg+Space", "Palette"}, {"⏎", "verbinden"}, {"n", "neu"}, {"e", "bearbeiten"}, {"d", "löschen"}, {"/", "suchen"},
|
||||
{"t", "Tunnel"}, {"q", "Schnellbefehle"}, {"s", "KI"}, {"y", "Sync"}, {"F1", "Hilfe"}, {"F12", "Über"}, {"Strg+Q", "beenden"}}
|
||||
km := a.keys
|
||||
k := [][2]string{{km.label(actPalette), "Palette"}, {"⏎", "verbinden"}, {"n", "neu"}, {"e", "bearbeiten"}, {"d", "löschen"}, {"/", "suchen"},
|
||||
{"t", "Tunnel"}, {km.label(actImport), "Import"}, {km.label(actQuickEdit), "Schnellbefehle"}, {"s", "KI"}, {"y", "Sync"},
|
||||
{km.label(actHelp), "Hilfe"}, {km.label(actAbout), "Über"}, {km.label(actQuit), "beenden"}}
|
||||
if len(a.sessions) > 0 {
|
||||
k = append([][2]string{{"F10", "zum Terminal"}}, k...)
|
||||
k = append([][2]string{{km.label(actManager), "zum Terminal"}}, k...)
|
||||
}
|
||||
return k
|
||||
}
|
||||
@@ -74,6 +76,32 @@ func (a *App) updateManager(msg tea.Msg) tea.Cmd {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
switch a.keys.which(k.String(), actManager, actHelp, actAbout, actImport, actNextLook, actKeys, actCheat, actQuickEdit) {
|
||||
case actCheat:
|
||||
return a.toggleCheat()
|
||||
case actQuickEdit:
|
||||
if m.sel < len(list) {
|
||||
return a.openQuickForm(list[m.sel], "")
|
||||
}
|
||||
return nil
|
||||
case actManager:
|
||||
if len(a.sessions) > 0 {
|
||||
a.scr = scrTerminal
|
||||
}
|
||||
return nil
|
||||
case actHelp:
|
||||
a.modal = a.helpModal()
|
||||
return nil
|
||||
case actAbout:
|
||||
a.modal = a.aboutModal()
|
||||
return nil
|
||||
case actImport:
|
||||
return a.openImport()
|
||||
case actNextLook:
|
||||
return a.cycleTheme()
|
||||
case actKeys:
|
||||
return a.openKeys()
|
||||
}
|
||||
switch k.String() {
|
||||
case "up", "k":
|
||||
m.sel = max(0, m.sel-1)
|
||||
@@ -103,12 +131,6 @@ func (a *App) updateManager(msg tea.Msg) tea.Cmd {
|
||||
if m.sel < len(list) {
|
||||
return a.openTunnelForm(domain.Tunnel{ConnectionID: list[m.sel].ID, Kind: domain.TunnelLocal, TargetHost: "127.0.0.1"})
|
||||
}
|
||||
case "q":
|
||||
if m.sel < len(list) {
|
||||
return a.openQuickForm(list[m.sel], "")
|
||||
}
|
||||
case "f9":
|
||||
return a.toggleCheat()
|
||||
case "s":
|
||||
return a.openSettings()
|
||||
case "y":
|
||||
@@ -117,14 +139,6 @@ func (a *App) updateManager(msg tea.Msg) tea.Cmd {
|
||||
if m.sel < len(list) {
|
||||
return a.connect(list[m.sel])
|
||||
}
|
||||
case "f10":
|
||||
if len(a.sessions) > 0 {
|
||||
a.scr = scrTerminal
|
||||
}
|
||||
case "f1":
|
||||
a.modal = a.helpModal()
|
||||
case "f12":
|
||||
a.modal = a.aboutModal()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
+17
-7
@@ -47,7 +47,7 @@ type palette struct {
|
||||
armed int
|
||||
}
|
||||
|
||||
func isPaletteKey(k string) bool { return k == "ctrl+space" || k == "ctrl+@" }
|
||||
func isPaletteKey(k string) bool { return activeKeys.is(actPalette, k) }
|
||||
|
||||
func (a *App) openPalette() tea.Cmd {
|
||||
in := newAIInput("Ziel, Frage, Befehl, Tunnel oder Verbindung …")
|
||||
@@ -141,7 +141,7 @@ func (a *App) paletteItems() []palItem {
|
||||
}})
|
||||
}
|
||||
actions := []palItem{
|
||||
{icon: "◎", label: "Ziel-Modus öffnen", hint: "F2", run: func() tea.Cmd {
|
||||
{icon: "◎", label: "Ziel-Modus öffnen", hint: a.keys.label(actGoal), run: func() tea.Cmd {
|
||||
if inTerm {
|
||||
withPanel(s, panelGoal)
|
||||
a.resize(s)
|
||||
@@ -149,7 +149,7 @@ func (a *App) paletteItems() []palItem {
|
||||
}
|
||||
return nil
|
||||
}},
|
||||
{icon: "⇄", label: "Tunnel-Panel", hint: "F4", run: func() tea.Cmd {
|
||||
{icon: "⇄", label: "Tunnel-Panel", hint: a.keys.label(actTunnels), run: func() tea.Cmd {
|
||||
if inTerm {
|
||||
withPanel(s, panelTunnels)
|
||||
a.resize(s)
|
||||
@@ -162,17 +162,27 @@ func (a *App) paletteItems() []palItem {
|
||||
}
|
||||
return nil
|
||||
}},
|
||||
{icon: "≡", label: "Verbindungs-Manager", hint: "F10", run: func() tea.Cmd { a.scr = scrManager; return nil }},
|
||||
{icon: "≡", label: "Verbindungs-Manager", hint: a.keys.label(actManager), run: func() tea.Cmd { a.scr = scrManager; return nil }},
|
||||
{icon: "+", label: "Neue Verbindung", hint: "n", run: func() tea.Cmd { return a.openConnForm(newConnDefaults()) }},
|
||||
{icon: "✦", label: "KI-Einstellungen", hint: "s", run: func() tea.Cmd { return a.openSettings() }},
|
||||
{icon: "⇅", label: "Sync zwischen Rechnern einrichten", hint: "y", run: func() tea.Cmd { return a.openSync() }},
|
||||
{icon: "?", label: "Tastenkürzel", hint: "F1", run: func() tea.Cmd { a.modal = a.helpModal(); return nil }},
|
||||
{icon: "i", label: "Über sshTermy / Update", hint: "F12", run: func() tea.Cmd { a.modal = a.aboutModal(); return nil }},
|
||||
{icon: "★", label: "Was ist neu (Changelog)", hint: "F12 w", run: func() tea.Cmd { a.modal = a.changelogModal(nil); return nil }},
|
||||
{icon: "⇩", label: "Verbindungen importieren (ssh-config, PuTTY, MobaXterm)", hint: a.keys.label(actImport), run: func() tea.Cmd { return a.openImport() }},
|
||||
{icon: "?", label: "Tastenkürzel anzeigen", hint: a.keys.label(actHelp), run: func() tea.Cmd { a.modal = a.helpModal(); return nil }},
|
||||
{icon: "⌨", label: "Tastenkürzel anpassen", hint: a.keys.label(actKeys), run: func() tea.Cmd { return a.openKeys() }},
|
||||
{icon: "i", label: "Über sshTermy / Update", hint: a.keys.label(actAbout), run: func() tea.Cmd { a.modal = a.aboutModal(); return nil }},
|
||||
{icon: "★", label: "Was ist neu (Changelog)", hint: a.keys.label(actAbout) + " w", run: func() tea.Cmd { a.modal = a.changelogModal(nil); return nil }},
|
||||
{icon: "↖", label: mouseLabel(a.mouseEnabled()), hint: "Maus", run: func() tea.Cmd { return a.toggleMouse() }},
|
||||
{icon: "▶", label: "Einführungstour", hint: "5 Schritte", run: func() tea.Cmd { a.modal = a.tourModal(); return nil }},
|
||||
{icon: "?", label: cheatLabel(a.cheatOn()), hint: "F9", run: func() tea.Cmd { return a.toggleCheat() }},
|
||||
}
|
||||
for _, t := range Themes {
|
||||
t := t
|
||||
hint := ""
|
||||
if ThemeByName(a.st.Settings().Theme).Name == t.Name {
|
||||
hint = "aktiv"
|
||||
}
|
||||
actions = append(actions, palItem{icon: "◐", label: "Aussehen: " + t.Label, hint: hint, run: func() tea.Cmd { return a.setTheme(t.Name) }})
|
||||
}
|
||||
if a.restartPending != "" {
|
||||
actions = append(actions, palItem{icon: "⟳", label: "Neu starten (v" + a.restartPending + " aktivieren)", hint: "Update", run: func() tea.Cmd { return a.askRestart() }})
|
||||
}
|
||||
|
||||
@@ -499,9 +499,9 @@ func (a *App) panelKeys(s *session) [][2]string {
|
||||
g := s.goal
|
||||
if !g.active {
|
||||
if g.done {
|
||||
return [][2]string{{"Strg+S", "als Runbook merken"}, {"⏎", "neues Ziel"}, {"Esc", "Terminal"}, {"F2", "schließen"}}
|
||||
return [][2]string{{"Strg+S", "als Runbook merken"}, {"⏎", "neues Ziel"}, {"Esc", "Terminal"}, {a.keys.label(actGoal), "schließen"}}
|
||||
}
|
||||
return [][2]string{{"⏎", "Ziel starten"}, {"↑↓", "Runbook"}, {"Strg+D", "Runbook löschen"}, {"Esc", "Terminal"}, {"F2", "schließen"}}
|
||||
return [][2]string{{"⏎", "Ziel starten"}, {"↑↓", "Runbook"}, {"Strg+D", "Runbook löschen"}, {"Esc", "Terminal"}, {a.keys.label(actGoal), "schließen"}}
|
||||
}
|
||||
if g.cur != nil && g.cur.Question != "" {
|
||||
return [][2]string{{"⏎", "antworten"}, {"Esc", "Terminal"}}
|
||||
@@ -616,7 +616,7 @@ func (a *App) viewGoal(b *strings.Builder, s *session, w int) {
|
||||
b.WriteString("\n")
|
||||
switch {
|
||||
case g.done:
|
||||
b.WriteString(st.OK.Render("✓ Ziel erreicht") + "\n" + wrap(st.Text.Render(g.doneReason), w) + "\n\n" + st.Muted.Render("Strg+S als Runbook merken · ⏎ neues Ziel · F2 schließen"))
|
||||
b.WriteString(st.OK.Render("✓ Ziel erreicht") + "\n" + wrap(st.Text.Render(g.doneReason), w) + "\n\n" + st.Muted.Render("Strg+S als Runbook merken · ⏎ neues Ziel · "+a.keys.label(actGoal)+" schließen"))
|
||||
if s.panelFocus && g.done {
|
||||
g.active = false
|
||||
}
|
||||
|
||||
+16
-13
@@ -99,18 +99,21 @@ func (a *App) remoteText(s *session) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// quickIndex: ⇧F1 … ⇧F8 (manche Terminals senden dafür F13 … F20).
|
||||
func quickIndex(key string) (int, bool) {
|
||||
var n int
|
||||
if _, err := fmt.Sscanf(key, "shift+f%d", &n); err == nil && n >= 1 && n <= maxQuick && key == fmt.Sprintf("shift+f%d", n) {
|
||||
return n - 1, true
|
||||
}
|
||||
if _, err := fmt.Sscanf(key, "f%d", &n); err == nil && n >= 13 && n < 13+maxQuick && key == fmt.Sprintf("f%d", n) {
|
||||
return n - 13, true
|
||||
// quickIndex: liegt auf der Taste ein Schnellbefehl (Standard ⇧F1 … ⇧F8)?
|
||||
func (a *App) quickIndex(key string) (int, bool) {
|
||||
for i, id := range actQuick {
|
||||
if a.keys.is(id, key) {
|
||||
return i, true
|
||||
}
|
||||
}
|
||||
return 0, false
|
||||
}
|
||||
|
||||
// quickLabel: angezeigte Taste von Schnellbefehl i, z. B. „⇧F1“.
|
||||
func (a *App) quickLabel(i int) string {
|
||||
return strings.Replace(a.keys.label(actQuick[i]), "Shift+", "⇧", 1)
|
||||
}
|
||||
|
||||
// runQuick führt Schnellbefehl i aus (mit ⏎). Rote Befehle erst beim
|
||||
// zweiten Druck.
|
||||
func (a *App) runQuick(s *session, i int) tea.Cmd {
|
||||
@@ -119,13 +122,13 @@ func (a *App) runQuick(s *session, i int) tea.Cmd {
|
||||
}
|
||||
cmds, _ := a.quickCmds(s)
|
||||
if i < 0 || i >= len(cmds) || strings.TrimSpace(cmds[i]) == "" {
|
||||
a.flash(fmt.Sprintf("⇧F%d ist nicht belegt · Palette „Schnellbefehle bearbeiten“", i+1))
|
||||
a.flash(a.quickLabel(i) + " ist nicht belegt · Palette „Schnellbefehle bearbeiten“")
|
||||
return nil
|
||||
}
|
||||
cmd := cmds[i]
|
||||
if f := safety.Check(cmd, safety.Kind(a.remoteText(s))); len(f) > 0 && s.quickArmed != i {
|
||||
s.quickArmed = i
|
||||
a.flash(fmt.Sprintf("Vorsicht: %s. Nochmal ⇧F%d zum Ausführen", f[0].Reason, i+1))
|
||||
a.flash("Vorsicht: " + f[0].Reason + ". Nochmal " + a.quickLabel(i) + " zum Ausführen")
|
||||
return nil
|
||||
}
|
||||
s.quickArmed = -1
|
||||
@@ -154,7 +157,7 @@ func (a *App) quickBar(s *session) string {
|
||||
if len(safety.Check(c, safety.Kind(a.remoteText(s)))) > 0 {
|
||||
style = st.ChipDanger
|
||||
}
|
||||
chip := st.Key.Render(fmt.Sprintf("⇧F%d", i+1)) + style.Render(trunc(c, 22))
|
||||
chip := st.Key.Render(a.quickLabel(i)) + style.Render(trunc(c, 22))
|
||||
if used+lipgloss.Width(chip)+1 > a.w {
|
||||
continue // passt nicht mehr, kürzere dahinter evtl. schon
|
||||
}
|
||||
@@ -173,7 +176,7 @@ func (a *App) quickPaletteItems(s *session, match func(string) bool) []palItem {
|
||||
continue
|
||||
}
|
||||
i, c := i, c
|
||||
it := palItem{group: pgQuick, icon: "↯", label: c, hint: fmt.Sprintf("⇧F%d", i+1),
|
||||
it := palItem{group: pgQuick, icon: "↯", label: c, hint: a.quickLabel(i),
|
||||
run: func() tea.Cmd { s.panelFocus = false; return a.runQuick(s, i) }}
|
||||
if f := safety.Check(c, safety.Kind(a.remoteText(s))); len(f) > 0 {
|
||||
it.danger = f[0].Reason
|
||||
@@ -205,7 +208,7 @@ func (a *App) openQuickForm(c domain.Connection, remote string) tea.Cmd {
|
||||
if i == 0 {
|
||||
h = "Strg+R = Vorbelegung „" + p.name + "“ wiederherstellen · Strg+S speichern"
|
||||
}
|
||||
f.text(fmt.Sprintf("q%d", i), fmt.Sprintf("⇧F%d", i+1), v, h)
|
||||
f.text(fmt.Sprintf("q%d", i), a.quickLabel(i), v, h)
|
||||
}
|
||||
a.form, a.formID, a.scr = f, c.ID, scrQuickForm
|
||||
a.formBase = c
|
||||
|
||||
@@ -10,6 +10,11 @@ import (
|
||||
)
|
||||
|
||||
func TestQuickIndex(t *testing.T) {
|
||||
a := &App{keys: newKeymap(nil)}
|
||||
quickIndex := a.quickIndex
|
||||
if l := a.quickLabel(0); l != "⇧F1" {
|
||||
t.Errorf("Anzeige %q, erwartet ⇧F1", l)
|
||||
}
|
||||
cases := map[string]int{"shift+f1": 0, "shift+f8": 7, "f13": 0, "f20": 7}
|
||||
for k, want := range cases {
|
||||
if i, ok := quickIndex(k); !ok || i != want {
|
||||
|
||||
+27
-24
@@ -96,30 +96,30 @@ func (a *App) updateTerminal(msg tea.Msg) tea.Cmd {
|
||||
if !s.panelFocus && !s.files.open && !(m.Code >= tea.KeyF1 && m.Code <= tea.KeyF12) {
|
||||
s.scroll = 0
|
||||
}
|
||||
// globale Tasten der Terminal-Ansicht
|
||||
switch key {
|
||||
case "f1":
|
||||
// globale Tasten der Terminal-Ansicht (frei belegbar, siehe keymap.go)
|
||||
switch a.keys.which(key, actHelp, actAbout, actManager, actPrevTab, actNextTab, actFiles, actCheat) {
|
||||
case actHelp:
|
||||
a.modal = a.helpModal()
|
||||
return nil
|
||||
case "f12":
|
||||
case actAbout:
|
||||
a.modal = a.aboutModal()
|
||||
return nil
|
||||
case "f10":
|
||||
case actManager:
|
||||
a.scr = scrManager
|
||||
return nil
|
||||
case "f9":
|
||||
case actCheat:
|
||||
return a.toggleCheat()
|
||||
case "f7", "f8":
|
||||
case actPrevTab, actNextTab:
|
||||
if len(a.sessions) > 1 {
|
||||
d := 1
|
||||
if key == "f7" {
|
||||
if a.keys.is(actPrevTab, key) {
|
||||
d = -1
|
||||
}
|
||||
a.cur = (a.cur + d + len(a.sessions)) % len(a.sessions)
|
||||
a.resize(a.current())
|
||||
}
|
||||
return nil
|
||||
case "f5":
|
||||
case actFiles:
|
||||
if s.state == stConnected {
|
||||
return a.toggleFiles(s)
|
||||
}
|
||||
@@ -128,12 +128,12 @@ func (a *App) updateTerminal(msg tea.Msg) tea.Cmd {
|
||||
if s.files.open {
|
||||
return a.filesKey(s, m)
|
||||
}
|
||||
if i, ok := quickIndex(key); ok {
|
||||
if i, ok := a.quickIndex(key); ok {
|
||||
return a.runQuick(s, i)
|
||||
}
|
||||
switch key {
|
||||
case "f2", "f3", "f4":
|
||||
kind := map[string]panelKind{"f2": panelGoal, "f3": panelAsk, "f4": panelTunnels}[key]
|
||||
switch id := a.keys.which(key, actGoal, actAsk, actTunnels); id {
|
||||
case actGoal, actAsk, actTunnels:
|
||||
kind := map[action]panelKind{actGoal: panelGoal, actAsk: panelAsk, actTunnels: panelTunnels}[id]
|
||||
if s.panel == kind && s.panelFocus {
|
||||
s.panel, s.panelFocus = panelNone, false
|
||||
} else {
|
||||
@@ -194,13 +194,13 @@ func (a *App) terminalKey(s *session, k tea.KeyPressMsg) tea.Cmd {
|
||||
return nil
|
||||
}
|
||||
// Folgebefehle einfügen (ohne Enter)
|
||||
if strings.HasPrefix(key, "alt+") && len(key) == 5 && key[4] >= '1' && key[4] <= '4' {
|
||||
i := int(key[4] - '1')
|
||||
if id := a.keys.which(key, actChip1, actChip2, actChip3, actChip4); id != "" {
|
||||
i := int(id[len(id)-1] - '1')
|
||||
if i < len(s.chips) {
|
||||
c := s.chips[i]
|
||||
if len(c.Danger) > 0 && s.chipArmed != i {
|
||||
s.chipArmed = i
|
||||
a.flash("Vorsicht: " + c.Danger[0].Reason + ". Nochmal Alt+" + string(key[4]) + " zum Einfügen")
|
||||
a.flash("Vorsicht: " + c.Danger[0].Reason + ". Nochmal " + a.keys.label(id) + " zum Einfügen")
|
||||
return nil
|
||||
}
|
||||
s.chipArmed = -1
|
||||
@@ -353,10 +353,10 @@ func (a *App) viewTerminal() (string, *tea.Cursor) {
|
||||
ai = st.Badge.Foreground(st.T.Muted).Render("✦ aus")
|
||||
}
|
||||
ai = a.z.click(ai, func(tea.Mouse, bool) tea.Cmd { a.returnToTerminal = true; return a.openSettings() })
|
||||
tun := a.keyZone("F4", st.Badge.Render("⇄ "+plural(nT, "Tunnel", "Tunnel")))
|
||||
tun := a.keyZone(a.keys.label(actTunnels), st.Badge.Render("⇄ "+plural(nT, "Tunnel", "Tunnel")))
|
||||
goal := ""
|
||||
if s.goal.active {
|
||||
goal = a.keyZone("F2", st.Badge.Foreground(st.T.AI).Render("◎ Ziel aktiv"))
|
||||
goal = a.keyZone(a.keys.label(actGoal), st.Badge.Foreground(st.T.AI).Render("◎ Ziel aktiv"))
|
||||
}
|
||||
if s.scroll > 0 {
|
||||
goal = a.z.click(st.Badge.Foreground(st.T.Warn).Render(fmt.Sprintf("⇡ Verlauf −%d · Esc", s.scroll)),
|
||||
@@ -378,7 +378,7 @@ func (a *App) viewTerminal() (string, *tea.Cursor) {
|
||||
case s.state == stClosed:
|
||||
msg := st.Danger.Render("✗ " + orDefault(s.err, "getrennt"))
|
||||
body = lipgloss.Place(cols, rows, lipgloss.Center, lipgloss.Center,
|
||||
msg+"\n\n"+st.Muted.Render("⏎ neu verbinden · x Tab schließen · F10 Manager"))
|
||||
msg+"\n\n"+st.Muted.Render("⏎ neu verbinden · x Tab schließen · "+a.keys.label(actManager)+" Manager"))
|
||||
case s.scroll > 0 || s.sel != nil:
|
||||
// Rückblick im Verlauf und/oder Markierung
|
||||
if sb := s.term.ScrollbackLen(); s.scroll > 0 && sb > s.sbSeen {
|
||||
@@ -428,9 +428,10 @@ func (a *App) chipBar(s *session) string {
|
||||
if len(c.Danger) > 0 {
|
||||
style = st.ChipDanger
|
||||
}
|
||||
key := fmt.Sprintf("alt+%d", i+1)
|
||||
b.WriteString(a.z.click(st.Key.Render(fmt.Sprintf("Alt+%d", i+1))+style.Render(trunc(c.Command, 34)),
|
||||
func(tea.Mouse, bool) tea.Cmd { s.panelFocus = false; return a.pressKey(key) }) + " ")
|
||||
id := []action{actChip1, actChip2, actChip3, actChip4}[min(i, 3)]
|
||||
lbl := a.keys.label(id)
|
||||
b.WriteString(a.z.click(st.Key.Render(lbl)+style.Render(trunc(c.Command, 34)),
|
||||
func(tea.Mouse, bool) tea.Cmd { s.panelFocus = false; return a.pressKey(lbl) }) + " ")
|
||||
}
|
||||
if len(s.chips) > 0 && s.chips[0].Reason != "" {
|
||||
b.WriteString(st.Muted.Render(trunc(s.chips[0].Reason, 40)))
|
||||
@@ -452,6 +453,8 @@ func (a *App) terminalKeys(s *session) [][2]string {
|
||||
if s.panelFocus {
|
||||
return a.panelKeys(s)
|
||||
}
|
||||
return [][2]string{{"Strg+Space", "Palette"}, {"F2", "Ziel/Agent"}, {"F3", "KI fragen"}, {"F4", "Tunnel"}, {"F5", "Dateien"}, {"F7/F8", "Tabs"},
|
||||
{"F10", "Manager"}, {"F1", "Hilfe"}, {"Strg+Q", "beenden"}}
|
||||
k := a.keys
|
||||
return [][2]string{{k.label(actPalette), "Palette"}, {k.label(actGoal), "Ziel/Agent"}, {k.label(actAsk), "KI fragen"}, {k.label(actTunnels), "Tunnel"},
|
||||
{k.label(actFiles), "Dateien"}, {k.label(actPrevTab) + "/" + k.label(actNextTab), "Tabs"},
|
||||
{k.label(actManager), "Manager"}, {k.label(actHelp), "Hilfe"}, {k.label(actQuit), "beenden"}}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package ui
|
||||
import (
|
||||
"image/color"
|
||||
|
||||
"charm.land/bubbles/v2/textinput"
|
||||
"charm.land/lipgloss/v2"
|
||||
)
|
||||
|
||||
@@ -10,10 +11,13 @@ import (
|
||||
// eine für die KI (Violett), Ampelfarben nur für Zustände. So bleibt sofort
|
||||
// erkennbar, was vom Modell kommt (violett) und was gefährlich ist (rot).
|
||||
type Theme struct {
|
||||
Name, Label string
|
||||
Dark bool
|
||||
Bg, Surface, Surface2, Border, Text, Muted, Accent, AI, OK, Warn, Danger color.Color
|
||||
}
|
||||
|
||||
var Nacht = Theme{
|
||||
Name: "nacht", Label: "Dunkel (Nacht)", Dark: true,
|
||||
Bg: lipgloss.Color("#1a1b26"),
|
||||
Surface: lipgloss.Color("#1f2335"),
|
||||
Surface2: lipgloss.Color("#292e42"),
|
||||
@@ -27,6 +31,56 @@ var Nacht = Theme{
|
||||
Danger: lipgloss.Color("#f7768e"),
|
||||
}
|
||||
|
||||
// Hell: für helle Umgebungen und Beamer. Gleiche Bedeutung der Farben,
|
||||
// aber dunkle, kräftige Töne auf hellem Grund.
|
||||
var Hell = Theme{
|
||||
Name: "hell", Label: "Hell", Dark: false,
|
||||
Bg: lipgloss.Color("#f5f5f7"),
|
||||
Surface: lipgloss.Color("#e4e6ee"),
|
||||
Surface2: lipgloss.Color("#d2d6e4"),
|
||||
Border: lipgloss.Color("#a4aac4"),
|
||||
Text: lipgloss.Color("#1f2335"),
|
||||
Muted: lipgloss.Color("#5a607e"),
|
||||
Accent: lipgloss.Color("#2e59c9"),
|
||||
AI: lipgloss.Color("#7a3cc4"),
|
||||
OK: lipgloss.Color("#3a7a12"),
|
||||
Warn: lipgloss.Color("#8f5a00"),
|
||||
Danger: lipgloss.Color("#c4122f"),
|
||||
}
|
||||
|
||||
// Kontrast: Schwarz/Weiß mit reinen Signalfarben (WCAG AAA für Text),
|
||||
// für schlechte Displays, Sonnenlicht und Sehschwäche.
|
||||
var Kontrast = Theme{
|
||||
Name: "kontrast", Label: "Hochkontrast", Dark: true,
|
||||
Bg: lipgloss.Color("#000000"),
|
||||
Surface: lipgloss.Color("#000000"),
|
||||
Surface2: lipgloss.Color("#303030"),
|
||||
Border: lipgloss.Color("#ffffff"),
|
||||
Text: lipgloss.Color("#ffffff"),
|
||||
Muted: lipgloss.Color("#d0d0d0"),
|
||||
Accent: lipgloss.Color("#00e5ff"),
|
||||
AI: lipgloss.Color("#ff80ff"),
|
||||
OK: lipgloss.Color("#00ff5f"),
|
||||
Warn: lipgloss.Color("#ffff00"),
|
||||
Danger: lipgloss.Color("#ff3030"),
|
||||
}
|
||||
|
||||
// Themes in der Reihenfolge der Auswahl.
|
||||
var Themes = []Theme{Nacht, Hell, Kontrast}
|
||||
|
||||
// ThemeByName: unbekannte oder leere Namen ergeben „Nacht“.
|
||||
func ThemeByName(name string) Theme {
|
||||
for _, t := range Themes {
|
||||
if t.Name == name {
|
||||
return t
|
||||
}
|
||||
}
|
||||
return Nacht
|
||||
}
|
||||
|
||||
// activeTheme: für Eingabefelder, die ohne App-Zugriff gebaut werden.
|
||||
var activeTheme = Nacht
|
||||
|
||||
// Styles, abgeleitet aus dem Theme.
|
||||
type Styles struct {
|
||||
T Theme
|
||||
@@ -74,3 +128,17 @@ func NewStyles(t Theme) Styles {
|
||||
s.Code = lipgloss.NewStyle().Foreground(t.OK)
|
||||
return s
|
||||
}
|
||||
|
||||
// inputStyles: Textfelder passend zum Theme (sonst wäre Text auf Hell
|
||||
// unsichtbar, weil bubbles Standardfarben für dunkle Terminals setzt).
|
||||
func inputStyles(t Theme) textinput.Styles {
|
||||
s := textinput.DefaultStyles(t.Dark)
|
||||
s.Focused.Text = lipgloss.NewStyle().Foreground(t.Text)
|
||||
s.Blurred.Text = lipgloss.NewStyle().Foreground(t.Muted)
|
||||
s.Focused.Placeholder = lipgloss.NewStyle().Foreground(t.Muted)
|
||||
s.Blurred.Placeholder = s.Focused.Placeholder
|
||||
s.Focused.Prompt = lipgloss.NewStyle().Foreground(t.Accent)
|
||||
s.Blurred.Prompt = s.Focused.Prompt
|
||||
s.Cursor.Color = t.Accent
|
||||
return s
|
||||
}
|
||||
+3
-2
@@ -126,7 +126,7 @@ func (a *App) toggleCheat() tea.Cmd {
|
||||
a.resize(s)
|
||||
}
|
||||
if on {
|
||||
a.flash("Spickzettel aus · F9 blendet ihn wieder ein")
|
||||
a.flash("Spickzettel aus · " + a.keys.label(actCheat) + " blendet ihn wieder ein")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -190,7 +190,8 @@ func (a *App) cheatLine() string {
|
||||
}
|
||||
out += a.keyZone(t[0], st.Accent.Render(t[0])) + " " + st.Text.Render(t[1])
|
||||
}
|
||||
hide := a.keyZone("F9", st.Muted.Render("F9 ausblenden "))
|
||||
k := a.keys.label(actCheat)
|
||||
hide := a.keyZone(k, st.Muted.Render(k+" ausblenden "))
|
||||
gap := a.w - lipgloss.Width(out) - lipgloss.Width(hide)
|
||||
if gap < 1 {
|
||||
return ansi.Truncate(out, a.w, "")
|
||||
|
||||
@@ -61,6 +61,8 @@ func (a *App) updateUnlock(msg tea.Msg) tea.Cmd {
|
||||
return nil
|
||||
}
|
||||
a.scr = scrManager
|
||||
a.lookSig = ""
|
||||
a.applyLook()
|
||||
a.mgr = newManager()
|
||||
a.showWhatsNew(u.setup)
|
||||
a.maybeTour(u.setup)
|
||||
|
||||
Reference in new issue
Block a user