1
0
mirror of https://github.com/makew0rld/amfora.git synced 2024-06-29 20:05:23 +00:00
amfora/display/help.go

105 lines
3.1 KiB
Go
Raw Normal View History

2020-06-18 20:54:48 +00:00
package display
import (
2020-07-01 17:39:13 +00:00
"strconv"
"strings"
"github.com/gdamore/tcell"
"gitlab.com/tslocum/cview"
)
2020-06-18 20:54:48 +00:00
var helpCells = strings.TrimSpace(`
2020-07-28 20:58:32 +00:00
?|Bring up this help. You can scroll!
2020-06-18 20:54:48 +00:00
Esc|Leave the help
Arrow keys, h/j/k/l|Scroll and move a page.
PgUp, u|Go up a page in document
PgDn, d|Go down a page in document
g|Go to top of document
G|Go to bottom of document
2020-06-18 20:54:48 +00:00
Tab|Navigate to the next item in a popup.
Shift-Tab|Navigate to the previous item in a popup.
2020-07-01 17:39:13 +00:00
b, Alt-Left|Go back in the history
f, Alt-Right|Go forward in the history
2020-07-02 00:08:07 +00:00
spacebar|Open bar at the bottom - type a URL, link number, search term.
|You can also type two dots (..) to go up a directory in the URL.
|Typing new:N will open link number N in a new tab
|instead of the current one.
2020-07-28 20:58:32 +00:00
Numbers|Go to links 1-10 respectively.
e|Edit current URL
Enter, Tab|On a page this will start link highlighting.
2020-07-02 00:08:07 +00:00
|Press Tab and Shift-Tab to pick different links.
|Press Enter again to go to one, or Esc to stop.
2020-06-18 20:54:48 +00:00
Shift-NUMBER|Go to a specific tab.
Shift-0, )|Go to the last tab.
2020-08-06 19:08:19 +00:00
F1|Previous tab
F2|Next tab
Ctrl-H|Go home
2020-07-02 00:08:07 +00:00
Ctrl-T|New tab, or if a link is selected,
|this will open the link in a new tab.
Ctrl-W|Close tab. For now, only the right-most tab can be closed.
Ctrl-R, R|Reload a page, discarding the cached version.
2020-07-02 00:37:34 +00:00
|This can also be used if you resize your terminal.
Ctrl-B|View bookmarks
Ctrl-D|Add, change, or remove a bookmark for the current page.
2020-07-10 23:16:13 +00:00
Ctrl-S|Save the current page to your downloads.
2020-11-27 22:01:29 +00:00
Ctrl-A|View subscriptions
Ctrl-X|Add or update a subscription
2020-07-26 20:25:37 +00:00
q, Ctrl-Q|Quit
2020-07-28 20:58:32 +00:00
Ctrl-C|Hard quit. This can be used when in the middle of downloading,
|for example.
2020-06-18 20:54:48 +00:00
`)
var helpTable = cview.NewTable().
SetSelectable(false, false).
2020-07-02 00:08:07 +00:00
SetBorders(false).
2020-07-28 20:58:32 +00:00
SetScrollBarVisibility(cview.ScrollBarNever)
// Help displays the help and keybindings.
func Help() {
helpTable.ScrollToBeginning()
tabPages.SwitchToPage("help")
App.SetFocus(helpTable)
App.Draw()
}
2020-07-01 17:39:13 +00:00
func helpInit() {
// Populate help table
helpTable.SetDoneFunc(func(key tcell.Key) {
if key == tcell.KeyEsc || key == tcell.KeyEnter {
2020-07-01 17:39:13 +00:00
tabPages.SwitchToPage(strconv.Itoa(curTab))
App.SetFocus(tabs[curTab].view)
App.Draw()
2020-07-01 17:39:13 +00:00
}
})
rows := strings.Count(helpCells, "\n") + 1
cells := strings.Split(
strings.ReplaceAll(helpCells, "\n", "|"),
"|")
cell := 0
2020-07-02 00:08:07 +00:00
extraRows := 0 // Rows continued from the previous, without spacing
2020-07-01 17:39:13 +00:00
for r := 0; r < rows; r++ {
for c := 0; c < 2; c++ {
var tableCell *cview.TableCell
if c == 0 {
2020-07-02 00:08:07 +00:00
// First column, the keybinding
tableCell = cview.NewTableCell(" " + cells[cell]).
2020-07-01 17:39:13 +00:00
SetAttributes(tcell.AttrBold).
2020-07-02 00:08:07 +00:00
SetAlign(cview.AlignLeft)
2020-07-01 17:39:13 +00:00
} else {
2020-07-02 00:08:07 +00:00
tableCell = cview.NewTableCell(" " + cells[cell])
}
if c == 0 && cells[cell] == "" || (cell > 0 && cells[cell-1] == "" && c == 1) {
// The keybinding column for this row was blank, meaning the explanation
// column is continued from the previous row.
// The row should be added without any spacing rows
helpTable.SetCell(((2*r)-extraRows/2)-1, c, tableCell)
extraRows++
} else {
helpTable.SetCell((2*r)-extraRows/2, c, tableCell) // Every other row, for readability
2020-07-01 17:39:13 +00:00
}
cell++
}
}
tabPages.AddPage("help", helpTable, true, false)
}