mirror of
https://github.com/makeworld-the-better-one/amfora.git
synced 2024-11-23 09:43:33 +03:00
92 lines
2.7 KiB
Go
92 lines
2.7 KiB
Go
package display
|
|
|
|
import (
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/gdamore/tcell"
|
|
"gitlab.com/tslocum/cview"
|
|
)
|
|
|
|
var helpCells = strings.TrimSpace(`
|
|
?|Bring up this help.
|
|
Esc|Leave the help
|
|
Arrow keys, h/j/k/l|Scroll and move a page.
|
|
Tab|Navigate to the next item in a popup.
|
|
Shift-Tab|Navigate to the previous item in a popup.
|
|
b, Alt-Left|Go back in the history
|
|
f, Alt-Right|Go forward in the history
|
|
g|Go to top of document
|
|
G|Go to bottom of document
|
|
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.
|
|
Enter, Tab|On a page this will start link highlighting.
|
|
|Press Tab and Shift-Tab to pick different links.
|
|
|Press Enter again to go to one, or Esc to stop.
|
|
Shift-NUMBER|Go to a specific tab.
|
|
Shift-0, )|Go to the last tab.
|
|
Ctrl-H|Go home
|
|
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.
|
|
|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.
|
|
Ctrl-S|Save the current page to your downloads.
|
|
q, Ctrl-Q, Ctrl-C|Quit
|
|
`)
|
|
|
|
var helpTable = cview.NewTable().
|
|
SetSelectable(false, false).
|
|
SetBorders(false).
|
|
SetBordersColor(tcell.ColorGray)
|
|
|
|
// Help displays the help and keybindings.
|
|
func Help() {
|
|
helpTable.ScrollToBeginning()
|
|
tabPages.SwitchToPage("help")
|
|
App.Draw()
|
|
}
|
|
|
|
func helpInit() {
|
|
// Populate help table
|
|
helpTable.SetDoneFunc(func(key tcell.Key) {
|
|
if key == tcell.KeyEsc {
|
|
tabPages.SwitchToPage(strconv.Itoa(curTab))
|
|
}
|
|
})
|
|
rows := strings.Count(helpCells, "\n") + 1
|
|
cells := strings.Split(
|
|
strings.ReplaceAll(helpCells, "\n", "|"),
|
|
"|")
|
|
cell := 0
|
|
extraRows := 0 // Rows continued from the previous, without spacing
|
|
for r := 0; r < rows; r++ {
|
|
for c := 0; c < 2; c++ {
|
|
var tableCell *cview.TableCell
|
|
if c == 0 {
|
|
// First column, the keybinding
|
|
tableCell = cview.NewTableCell(" " + cells[cell]).
|
|
SetAttributes(tcell.AttrBold).
|
|
SetAlign(cview.AlignLeft)
|
|
} else {
|
|
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
|
|
}
|
|
cell++
|
|
}
|
|
}
|
|
tabPages.AddPage("help", helpTable, true, false)
|
|
}
|