diff --git a/README.md b/README.md index d95961d..8a8d7db 100644 --- a/README.md +++ b/README.md @@ -129,7 +129,7 @@ Run `tg` with no arguments. | `ctrl+v` (`cmd+v` on a Mac) | Attach the image in the clipboard, the message becomes its caption | | `backspace` | Remove the attachment, when the message is empty | | `ctrl+c` | Clear the composer or cancel the edit, quit when it is empty | -| `esc` | In the chat list, open the settings: theme, spacing of messages and chats, how shortcuts are written | +| `esc` | In the chat list, open the menu: settings (theme, spacing of messages and chats, how shortcuts are written), help and quit | | `q` | Quit, from the chat list | The mouse works too: click a chat, scroll either pane, right click a message to reply, edit, copy its text or copy its ID. Copying uses OSC 52, so it also works over SSH; inside tmux it needs `set -g set-clipboard on`. Edits are sent as plain text, so bold and links made in another app are lost, and messages the composer cannot hold as they are (several lines, special characters) are edited elsewhere. New messages arrive live. What you type and leave unsent stays with its chat, shown in the list as a `[draft]`. @@ -142,11 +142,11 @@ To send a picture, copy it and paste it into the composer, or press `ctrl+v`, or ### Themes -`tg config theme ` picks the colors: the Catppuccin flavors `mocha` (the default), `macchiato`, `frappe` and `latte`, or Telegram's `dark` and `light`. `tg config theme` lists them. The theme paints the terminal's background while tg runs, and is stored as `"theme"` in `config.json`. +`tg config theme ` picks the colors: the Catppuccin flavors `mocha`, `macchiato`, `frappe` (the default) and `latte`, or Telegram's `dark` and `light`. `tg config theme` lists them. The theme paints the terminal's background while tg runs, and is stored as `"theme"` in `config.json`. `tg config spacing on` sets messages apart in the conversation: a blank line before a new sender, a pause of more than five minutes, or a new day. Off, the default, packs them together. It is stored as `"spaced_messages"` in `config.json`. -Both can also be changed in the settings, with `esc` from the chat list. There "Shortcuts" picks how keys are written: `⌘V` and `⌥↑↓` on a Mac, `ctrl+v` and `ctrl+↑↓` elsewhere. It follows the system tg runs on, so over SSH from a Mac set it once. It is stored as `"keys"` in `config.json`. +Both can also be changed in the settings, in the menu `esc` opens from the chat list. There "Shortcuts" picks how keys are written: `⌘V` and `⌥↑↓` on a Mac, `ctrl+v` and `ctrl+↑↓` elsewhere. It follows the system tg runs on, so over SSH from a Mac set it once. It is stored as `"keys"` in `config.json`. Bots' inline buttons are drawn under their messages. Click one to press it, the bot's answer shows at the bottom. A link button copies its link. Buttons that need Telegram's own apps, like games and payments, say so. diff --git a/internal/tui/panel.go b/internal/tui/panel.go new file mode 100644 index 0000000..70c3a29 --- /dev/null +++ b/internal/tui/panel.go @@ -0,0 +1,306 @@ +package tui + +import ( + "runtime" + "slices" + "strings" + + tea "charm.land/bubbletea/v2" + "charm.land/lipgloss/v2" + "github.com/charmbracelet/x/ansi" +) + +// The panel esc opens from the chat list, as in btop: the tg logo over a +// short menu. Settings and Help open in its place, and esc goes back to it. +// A setting changes at once and is saved to config.json. + +// page is what the panel shows. +type page int + +const ( + pageMain page = iota + pageSettings + pageHelp + pageQuit // not a page: picking it quits +) + +// panel is the open panel, sel the highlighted line of its page. +type panel struct { + page page + sel int +} + +// mainItems are the lines of the main page, each opening its page. +var mainItems = []page{pageSettings, pageHelp, pageQuit} + +var pageNames = map[page]string{pageSettings: "Settings", pageHelp: "Help", pageQuit: "Quit"} + +// items is how many lines of the page can be picked. +func (p *panel) items() int { + switch p.page { + case pageMain: + return len(mainItems) + case pageSettings: + return len(settingsItems) + } + return 0 +} + +// panelKey handles a key while the panel is open. +func (m *model) panelKey(key string) tea.Cmd { + p := m.panel + n := p.items() + switch key { + case "up", "k", "shift+tab": + if n > 0 { + p.sel = (p.sel + n - 1) % n + } + case "down", "j", "tab": + if n > 0 { + p.sel = (p.sel + 1) % n + } + case "left", "h": + if p.page == pageSettings { + return m.changeSetting(-1) + } + case "right", "l", "enter", "space": + return m.pick() + case "esc", "q": + m.back() + } + return nil +} + +// pick acts on the highlighted line: it opens a page, changes a setting or +// quits. On the help page it goes back. +func (m *model) pick() tea.Cmd { + switch p := m.panel; p.page { + case pageMain: + if mainItems[p.sel] == pageQuit { + return tea.Quit + } + *p = panel{page: mainItems[p.sel]} + case pageSettings: + return m.changeSetting(1) + case pageHelp: + m.back() + } + return nil +} + +// back goes from a page to the main one, on the line that opened it. From +// the main page it closes the panel. +func (m *model) back() { + if m.panel.page == pageMain { + m.panel = nil + return + } + m.panel = &panel{sel: slices.Index(mainItems, m.panel.page)} +} + +// setting is one line of the settings page. +type setting struct { + name string + value func(Look) string + // next returns the change that moves the setting from its value in l to + // the next (1) or previous (-1) one. It sets the value outright, so + // saving it over config.json leaves the other settings as they are there. + next func(l Look, delta int) func(*Look) +} + +var settingsItems = []setting{ + {"Theme", func(l Look) string { t, _ := FindTheme(l.Theme); return t.Name }, func(l Look, delta int) func(*Look) { + t, _ := FindTheme(l.Theme) + i := slices.IndexFunc(Themes, func(o Theme) bool { return o.Name == t.Name }) + name := Themes[(i+delta+len(Themes))%len(Themes)].Name + return func(l *Look) { l.Theme = name } + }}, + {"Message spacing", func(l Look) string { return onOff[l.Spaced] }, func(l Look, _ int) func(*Look) { + on := !l.Spaced + return func(l *Look) { l.Spaced = on } + }}, + {"Chat spacing", func(l Look) string { return onOff[!l.PackedChats] }, func(l Look, _ int) func(*Look) { + packed := !l.PackedChats + return func(l *Look) { l.PackedChats = packed } + }}, + {"Shortcuts", func(l Look) string { return map[bool]string{true: "macOS", false: "PC"}[l.mac()] }, func(l Look, _ int) func(*Look) { + keys := map[bool]string{true: "pc", false: "mac"}[l.mac()] + return func(l *Look) { l.Keys = keys } + }}, +} + +var onOff = map[bool]string{true: "on", false: "off"} + +// mac reports whether shortcuts are written the way Mac keyboards label them. +// Over SSH tg runs on another system than the keyboard, so it can be set. +func (l Look) mac() bool { return l.Keys == "mac" || l.Keys == "" && runtime.GOOS == "darwin" } + +// changeSetting moves the highlighted setting by delta, shows it and saves it. +func (m *model) changeSetting(delta int) tea.Cmd { + change := settingsItems[m.panel.sel].next(m.look, delta) + change(&m.look) + t, _ := FindTheme(m.look.Theme) + if t.Name != m.st.theme.Name { + m.st = newStyles(t) + m.paint(&m.input) + m.paint(&m.filter) + // Initials badges are pictures, drawn in the old colors. + for key := range m.images { + if c := m.chat(key.chat); key.msg == 0 && (c == nil || c.PhotoID == 0) { + m.drop(key) + } + } + } + if m.save != nil { + if err := m.save(change); err != nil { + m.status = "the setting is not saved: " + err.Error() + } + } + // Spacing changes how many lines there are, and how many chats fit. + return tea.Batch(m.afterMove(), m.afterScroll()) +} + +// logo is drawn on the main page: blocks in a gradient, their shadow muted. +var logo = []string{ + "████████╗ ██████╗ ██████╗██╗ ██╗", + "╚══██╔══╝██╔════╝ ██╔════╝██║ ██║", + " ██║ ██║ ███╗█████╗██║ ██║ ██║", + " ██║ ██║ ██║╚════╝██║ ██║ ██║", + " ██║ ╚██████╔╝ ╚██████╗███████╗██║", + " ╚═╝ ╚═════╝ ╚═════╝╚══════╝╚═╝", +} + +// panelView renders the open page as a box centered over the panes: where +// the box goes, its lines, and the row of the box its first item is on. +func (m *model) panelView() (x, y int, lines []string, first int) { + // Lines are laid out for the box's width, narrower on small terminals. + w, title := min(38, m.width), "" + var body []string + switch m.panel.page { + case pageMain: + // The logo, the version and a blank row go when they do not fit, + // so the items always show. + if lw := len([]rune(logo[0])) + 6; m.width >= lw && m.bodyRows() >= len(logo)+2+len(mainItems)+4 { + w = lw + body = append(m.logoLines(w-2), "") + } else { + title = "tg-cli" + } + for i, p := range mainItems { + body = append(body, m.item(center(pageNames[p], w-3), "", i == m.panel.sel, w-2)) + } + first = len(body) - len(mainItems) + case pageSettings: + title = pageNames[pageSettings] + for i, s := range settingsItems { + value := m.st.muted.Render(s.value(m.look)) + " " + if i == m.panel.sel { + value = m.st.text.Render("‹ "+s.value(m.look)+" ›") + " " + } + body = append(body, m.item(" "+s.name, value, i == m.panel.sel, w-2)) + } + case pageHelp: + w, title = min(46, m.width), pageNames[pageHelp] + body = m.helpLines() + } + lines = m.box(title, body, w) + return max(0, (m.width-w)/2), max(0, (m.bodyRows()-len(lines))/2), lines, first + 2 +} + +// logoLines centers the logo in w cells, with the version under its right +// end as btop has it. +func (m *model) logoLines(w int) []string { + t := m.st.theme + // Peers[5] is blue in every theme. + shades := lipgloss.Blend1D(len(logo), t.Accent, t.Peers[5]) + lw := len([]rune(logo[0])) + var lines []string + for i, row := range logo { + var line strings.Builder + block := lipgloss.NewStyle().Foreground(shades[i]) + for _, r := range row { + if r == '█' { + line.WriteString(block.Render(string(r))) + } else { + line.WriteString(m.st.muted.Render(string(r))) + } + } + lines = append(lines, center(line.String(), w)) + } + pad := (w-lw)/2 + lw + return append(lines, fit(spread("", m.st.muted.Render(m.version), pad), w)) +} + +// helpLines lists the shortcuts, written as the keyboard labels them. +func (m *model) helpLines() []string { + reply := "ctrl+↑↓" + if m.look.mac() { + reply = "alt+↑↓" + } + keys := [][2]string{ + {"↑↓ jk", "move in the chat list"}, + {"enter", "open a chat, send a message"}, + {"/", "filter chats"}, + {"tab", "chats or composer"}, + {"pgup pgdn", "scroll the conversation"}, + {reply, "pick a message to reply to"}, + {"↑", "edit your last message"}, + {"ctrl+v", "attach the copied image"}, + {"right click", "reply, edit, copy a message"}, + {"ctrl+c", "clear the composer, quit"}, + {"esc", "back, and this menu"}, + {"q", "quit, from the chat list"}, + } + var lines []string + for _, k := range keys { + key := m.keyName(k[0]) + if k[0] == "ctrl+v" && m.look.mac() { + key = m.keyName("cmd+v") + } + lines = append(lines, " "+m.st.key.Render(key)+strings.Repeat(" ", max(1, 13-len([]rune(key))))+m.st.text.Render(k[1])) + } + return lines +} + +// item renders a line that can be picked, w cells wide: name on the left, +// value on the right, marked with a bar like the selected chat. +func (m *model) item(name, value string, selected bool, w int) string { + bar, style := " ", m.st.text + if selected { + bar, style = m.st.accent.Render("▌"), m.st.accent.Bold(true) + } + return bar + spread(style.Render(name), value, max(0, w-1)) +} + +// box draws body in a rounded border w cells wide, with title in its top +// edge and a blank row above and below the body. +func (m *model) box(title string, body []string, w int) []string { + inner := max(0, w-2) + side := m.st.border.Render("│") + top := m.st.border.Render("╭" + strings.Repeat("─", inner) + "╮") + if title != "" { + title = " " + title + " " + top = m.st.border.Render("╭─") + m.st.accent.Bold(true).Render(title) + + m.st.border.Render(strings.Repeat("─", max(0, inner-1-len(title)))+"╮") + } + blank := side + strings.Repeat(" ", inner) + side + lines := []string{ansi.Truncate(top, w, ""), blank} + for _, line := range body { + lines = append(lines, side+fit(line, inner)+side) + } + return append(lines, blank, m.st.border.Render("╰"+strings.Repeat("─", inner)+"╯")) +} + +// keyName writes a key the way the keyboard labels it. On a Mac option and +// command are symbols, followed by an upper case letter: "cmd+v" is ⌘V, +// "alt+↑↓" is ⌥↑↓. ctrl stays a word, as on the key. +func (m *model) keyName(key string) string { + if !m.look.mac() { + return key + } + out := strings.NewReplacer("alt+", "⌥", "cmd+", "⌘").Replace(key) + if last := len(out) - 1; out != key && out[last] >= 'a' && out[last] <= 'z' && out[last-1] >= 0x80 { + out = out[:last] + strings.ToUpper(out[last:]) + } + return out +} diff --git a/internal/tui/settings.go b/internal/tui/settings.go deleted file mode 100644 index efa36a1..0000000 --- a/internal/tui/settings.go +++ /dev/null @@ -1,130 +0,0 @@ -package tui - -import ( - "runtime" - "slices" - "strings" - - tea "charm.land/bubbletea/v2" - "github.com/charmbracelet/x/ansi" -) - -// The settings menu opens with esc from the chat list, as in btop. A change -// shows at once and is saved to config.json. - -// settingsMenu is the open settings menu, sel the highlighted setting. -type settingsMenu struct{ sel int } - -// setting is one line of the settings menu. -type setting struct { - name string - value func(Look) string - // next returns the change that moves the setting from its value in l to - // the next (1) or previous (-1) one. It sets the value outright, so - // saving it over config.json leaves the other settings as they are there. - next func(l Look, delta int) func(*Look) -} - -var settingsItems = []setting{ - {"Theme", func(l Look) string { t, _ := FindTheme(l.Theme); return t.Name }, func(l Look, delta int) func(*Look) { - t, _ := FindTheme(l.Theme) - i := slices.IndexFunc(Themes, func(o Theme) bool { return o.Name == t.Name }) - name := Themes[(i+delta+len(Themes))%len(Themes)].Name - return func(l *Look) { l.Theme = name } - }}, - {"Message spacing", func(l Look) string { return onOff[l.Spaced] }, func(l Look, _ int) func(*Look) { - on := !l.Spaced - return func(l *Look) { l.Spaced = on } - }}, - {"Chat spacing", func(l Look) string { return onOff[!l.PackedChats] }, func(l Look, _ int) func(*Look) { - packed := !l.PackedChats - return func(l *Look) { l.PackedChats = packed } - }}, - {"Shortcuts", func(l Look) string { return map[bool]string{true: "macOS", false: "PC"}[l.mac()] }, func(l Look, _ int) func(*Look) { - keys := map[bool]string{true: "pc", false: "mac"}[l.mac()] - return func(l *Look) { l.Keys = keys } - }}, -} - -var onOff = map[bool]string{true: "on", false: "off"} - -// mac reports whether shortcuts are written the way Mac keyboards label them. -// Over SSH tg runs on another system than the keyboard, so it can be set. -func (l Look) mac() bool { return l.Keys == "mac" || l.Keys == "" && runtime.GOOS == "darwin" } - -// changeSetting moves the highlighted setting by delta, shows it and saves it. -func (m *model) changeSetting(delta int) tea.Cmd { - change := settingsItems[m.settings.sel].next(m.look, delta) - change(&m.look) - t, _ := FindTheme(m.look.Theme) - if t.Name != m.st.theme.Name { - m.st = newStyles(t) - m.paint(&m.input) - m.paint(&m.filter) - // Initials badges are pictures, drawn in the old colors. - for key := range m.images { - if c := m.chat(key.chat); key.msg == 0 && (c == nil || c.PhotoID == 0) { - m.drop(key) - } - } - } - if m.save != nil { - if err := m.save(change); err != nil { - m.status = "the setting is not saved: " + err.Error() - } - } - // Spacing changes how many lines there are, and how many chats fit. - return tea.Batch(m.afterMove(), m.afterScroll()) -} - -// settingsWidth is the width of the settings box, borders included. -const settingsWidth = 38 - -// The settings box is a rounded border with the title in its top edge and a -// blank row above and below the settings: setting i is on row settingsTop+i. -const settingsTop = 2 - -// settingsBox is where the settings box is drawn, centered over the panes. -func (m *model) settingsBox() (x, y, w int) { - w = min(settingsWidth, m.width) - h := len(settingsItems) + 2*settingsTop - return max(0, (m.width-w)/2), max(0, (m.bodyRows()-h)/2), w -} - -// settingsLines renders the settings box, w cells wide. The highlighted -// setting is marked with a bar, as the selected chat is, and shows arrows -// around its value, which change it. -func (m *model) settingsLines(w int) []string { - inner := max(0, w-2) - side := m.st.border.Render("│") - title := " Settings " - top := m.st.border.Render("╭─") + m.st.accent.Bold(true).Render(title) + - m.st.border.Render(strings.Repeat("─", max(0, inner-1-len(title)))+"╮") - blank := side + strings.Repeat(" ", inner) + side - - lines := []string{ansi.Truncate(top, w, ""), blank} - for i, s := range settingsItems { - bar, name, value := " ", m.st.text.Render(s.name), m.st.muted.Render(s.value(m.look))+" " - if i == m.settings.sel { - bar = m.st.accent.Render("▌") - name = m.st.accent.Bold(true).Render(s.name) - value = m.st.text.Render("‹ "+s.value(m.look)+" ›") + " " - } - lines = append(lines, side+bar+spread(" "+name, value, max(0, inner-1))+side) - } - return append(lines, blank, m.st.border.Render("╰"+strings.Repeat("─", inner)+"╯")) -} - -// keyName writes a key the way the keyboard labels it. On a Mac option and -// command are symbols, followed by an upper case letter: "cmd+v" is ⌘V, -// "alt+↑↓" is ⌥↑↓. ctrl stays a word, as on the key. -func (m *model) keyName(key string) string { - if !m.look.mac() { - return key - } - out := strings.NewReplacer("alt+", "⌥", "cmd+", "⌘").Replace(key) - if last := len(out) - 1; out != key && out[last] >= 'a' && out[last] <= 'z' && out[last-1] >= 0x80 { - out = out[:last] + strings.ToUpper(out[last:]) - } - return out -} diff --git a/internal/tui/theme.go b/internal/tui/theme.go index c75d565..9e092a9 100644 --- a/internal/tui/theme.go +++ b/internal/tui/theme.go @@ -23,7 +23,7 @@ type Theme struct { } // DefaultTheme is used when config.json names none. -const DefaultTheme = "mocha" +const DefaultTheme = "frappe" // Themes lists every theme, in the order `tg config` shows them. The four // Catppuccin flavors use their base, text, subtext0, surface1, sky and red, diff --git a/internal/tui/tui.go b/internal/tui/tui.go index 494a092..cd48e03 100644 --- a/internal/tui/tui.go +++ b/internal/tui/tui.go @@ -68,10 +68,10 @@ type model struct { graphics bool st styles look Look - // save writes a change of the settings menu to config.json, nil when + // save writes a change made in the settings to config.json, nil when // there is nowhere to save it. - save func(change func(*Look)) error - settings *settingsMenu // the open settings menu, nil when there is none + save func(change func(*Look)) error + panel *panel // the menu esc opens, nil when it is closed width, height int focus focus @@ -366,7 +366,7 @@ func (m *model) update(msg tea.Msg) tea.Cmd { return m.key(msg) case tea.MouseWheelMsg: - if m.settings != nil { + if m.panel != nil { return nil } m.menu = nil @@ -383,14 +383,14 @@ func (m *model) update(msg tea.Msg) tea.Cmd { case tea.MouseClickMsg: lw, _ := m.layout() - if m.settings != nil { - // A click on a setting changes it, anywhere else closes the menu. - x, y, w := m.settingsBox() - if i := msg.Y - y - settingsTop; msg.Button == tea.MouseLeft && i >= 0 && i < len(settingsItems) && msg.X >= x && msg.X < x+w { - m.settings.sel = i - return m.changeSetting(1) + if m.panel != nil { + // A click on a line picks it, anywhere else closes the panel. + x, y, lines, first := m.panelView() + if i := msg.Y - y - first; msg.Button == tea.MouseLeft && i >= 0 && i < m.panel.items() && msg.X >= x && msg.X < x+ansi.StringWidth(lines[0]) { + m.panel.sel = i + return m.pick() } - m.settings = nil + m.panel = nil return nil } if m.menu != nil { @@ -680,21 +680,8 @@ func (m *model) key(msg tea.KeyPressMsg) tea.Cmd { return tea.Quit } - if m.settings != nil { - n := len(settingsItems) - switch key { - case "up", "k", "shift+tab": - m.settings.sel = (m.settings.sel + n - 1) % n - case "down", "j", "tab": - m.settings.sel = (m.settings.sel + 1) % n - case "left", "h": - return m.changeSetting(-1) - case "right", "l", "enter", "space": - return m.changeSetting(1) - case "esc", "q": - m.settings = nil - } - return nil + if m.panel != nil { + return m.panelKey(key) } if m.menu != nil { @@ -747,7 +734,7 @@ func (m *model) key(msg tea.KeyPressMsg) tea.Cmd { return m.setFocus(focusFilter) case "esc": if m.filter.Value() == "" { - m.settings = &settingsMenu{} + m.panel = &panel{} return nil } m.filter.Reset() diff --git a/internal/tui/tui_test.go b/internal/tui/tui_test.go index d2d906b..b2a3307 100644 --- a/internal/tui/tui_test.go +++ b/internal/tui/tui_test.go @@ -79,7 +79,7 @@ func upload(m *model, cmd tea.Cmd) { func TestViewFillsTheTerminal(t *testing.T) { for _, size := range [][2]int{{120, 30}, {80, 24}, {72, 10}, {50, 20}, {20, 6}} { m := loaded(t, size[0], size[1]) - for _, state := range []string{"list", "opened", "replying with a menu open", "settings"} { + for _, state := range []string{"list", "opened", "replying with a menu open", "panel", "settings", "help"} { switch state { case "opened": open(t, m, 1) @@ -89,9 +89,16 @@ func TestViewFillsTheTerminal(t *testing.T) { if m.menu == nil && size[1] >= 10 { t.Errorf("%v: no menu opened on the newest message", size) } - case "settings": + case "panel": m.menu = nil - m.settings = &settingsMenu{} + m.panel = &panel{} + case "settings": + m.panel = &panel{page: pageSettings} + case "help": + m.panel = &panel{page: pageHelp} + } + if state == "panel" && size[1] >= 10 && screenRow(m, "Quit") < 0 { + t.Errorf("%v: the menu items do not show", size) } rows := strings.Split(m.View().Content, "\n") if len(rows) != size[1] { @@ -1017,11 +1024,12 @@ func TestSettingsShowAndSaveOneChange(t *testing.T) { m.save = func(change func(*Look)) error { saved = append(saved, change); return nil } m.Update(tea.KeyPressMsg{Code: tea.KeyEscape}) - if m.settings == nil || screenRow(m, "Settings") < 0 { - t.Fatal("esc on the chat list did not open the settings") + m.Update(tea.KeyPressMsg{Code: tea.KeyEnter}) // Settings, first in the menu + if m.panel == nil || m.panel.page != pageSettings || screenRow(m, "Message spacing") < 0 { + t.Fatal("esc on the chat list, then enter, did not open the settings") } m.Update(tea.KeyPressMsg{Code: tea.KeyRight}) // Theme - if m.look.Theme != "macchiato" || m.st.theme.Name != "macchiato" { + if m.look.Theme != "latte" || m.st.theme.Name != "latte" { t.Fatalf("theme is %q, drawn with %q", m.look.Theme, m.st.theme.Name) } m.Update(tea.KeyPressMsg{Code: tea.KeyDown}) @@ -1036,16 +1044,20 @@ func TestSettingsShowAndSaveOneChange(t *testing.T) { t.Fatalf("chats are %d rows apart, %d before chat spacing turned off", packed, stride) } - file := Look{Theme: "latte", Keys: "mac"} // changed elsewhere meanwhile + file := Look{Theme: "mocha", Keys: "mac"} // changed elsewhere meanwhile for _, change := range saved { change(&file) } - if want := (Look{Theme: "macchiato", Spaced: true, Keys: "mac", PackedChats: true}); file != want { + if want := (Look{Theme: "latte", Spaced: true, Keys: "mac", PackedChats: true}); file != want { t.Fatalf("config.json holds %+v, want %+v", file, want) } m.Update(tea.KeyPressMsg{Code: tea.KeyEscape}) - if m.settings != nil { - t.Fatal("esc did not close the settings") + if m.panel == nil || m.panel.page != pageMain || m.panel.sel != 0 { + t.Fatal("esc did not go back from the settings to the menu, on Settings") + } + m.Update(tea.KeyPressMsg{Code: tea.KeyEscape}) + if m.panel != nil { + t.Fatal("esc did not close the menu") } } diff --git a/internal/tui/view.go b/internal/tui/view.go index a26e4ce..cce72ea 100644 --- a/internal/tui/view.go +++ b/internal/tui/view.go @@ -196,9 +196,9 @@ func (m *model) View() tea.View { } } } - if m.settings != nil { - x, y, w := m.settingsBox() - for i, line := range m.settingsLines(w) { + if m.panel != nil { + x, y, lines, _ := m.panelView() + for i, line := range lines { if y+i < len(rows) { rows[y+i] = overlay(rows[y+i], line, x, m.width) } @@ -336,7 +336,8 @@ func (m *model) conversation(w, h int) ([]string, int) { for len(rows) < h { rows = append(rows, strings.Repeat(" ", w)) } - if h > 2 { + // The panel would cover the hint all but its ends. + if h > 2 && m.panel == nil { rows[h/2] = center(m.st.muted.Render("select a chat and press enter"), w) } return rows, -1 @@ -619,7 +620,7 @@ func (m *model) buttonLines(keyboard [][]core.Button, w int) []msgLine { func (m *model) statusLine() string { // Each hint is a key and what it does. - hints := [][2]string{{"↑↓", "move"}, {"enter", "open"}, {"/", "filter"}, {"tab", "compose"}, {"esc", "settings"}, {"q", "quit"}} + hints := [][2]string{{"↑↓", "move"}, {"enter", "open"}, {"/", "filter"}, {"tab", "compose"}, {"esc", "menu"}, {"q", "quit"}} if m.filter.Value() != "" { hints[4] = [2]string{"esc", "clear filter"} } @@ -634,8 +635,12 @@ func (m *model) statusLine() string { quit = "clear" } switch { - case m.settings != nil: - hints = [][2]string{{"↑↓", "move"}, {"←→", "change"}, {"esc", "close"}} + case m.panel != nil && m.panel.page == pageSettings: + hints = [][2]string{{"↑↓", "move"}, {"←→", "change"}, {"esc", "back"}} + case m.panel != nil && m.panel.page == pageHelp: + hints = [][2]string{{"esc", "back"}} + case m.panel != nil: + hints = [][2]string{{"↑↓", "move"}, {"enter", "pick"}, {"esc", "close"}} case m.menu != nil: hints = [][2]string{{"↑↓", "move"}, {"enter", "pick"}, {"esc", "close"}} case m.focus == focusInput && m.editing != 0: diff --git a/site/public/img/tui-phone.mp4 b/site/public/img/tui-phone.mp4 index 06b1342..ce0a936 100644 Binary files a/site/public/img/tui-phone.mp4 and b/site/public/img/tui-phone.mp4 differ diff --git a/site/public/img/tui-phone.webp b/site/public/img/tui-phone.webp index 5611810..3821b3e 100644 Binary files a/site/public/img/tui-phone.webp and b/site/public/img/tui-phone.webp differ diff --git a/site/public/img/tui.png b/site/public/img/tui.png index 9f54fd2..0477a1c 100644 Binary files a/site/public/img/tui.png and b/site/public/img/tui.png differ diff --git a/site/public/index.html b/site/public/index.html index 03559c6..4f2d21f 100644 --- a/site/public/index.html +++ b/site/public/index.html @@ -5,7 +5,7 @@ tg · Telegram for agents and humans - + @@ -26,7 +26,7 @@