Skip to content

Commit

Permalink
Turn repetition into a function
Browse files Browse the repository at this point in the history
Fixed missing section-header-num.
  • Loading branch information
noborus committed Dec 26, 2023
1 parent a7967bc commit fdb88e4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ You can specify the number of lines using the `--section-header-num` option or k
```gitconfig
[pager]
diff = "ov -F --section-delimiter '^diff' --section-header"
log = "ov -F --section-delimiter '^commit' --section-header --section-header-num 3"
log = "ov -F --section-delimiter '^commit' --section-header --section-header-num 3"
```

### 3.10. <a name='follow-mode'></a>Follow mode
Expand Down
2 changes: 2 additions & 0 deletions ov.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ KeyBind:
section_start:
- "ctrl+F3"
- "alt+s"
section_header_num:
- "F7"
next_section:
- "space"
last_section:
Expand Down
34 changes: 14 additions & 20 deletions oviewer/keybind.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,7 @@ func defaultKeyBinds() KeyBind {
// String returns keybind as a string for help.
func (k KeyBind) String() string {
var b strings.Builder
fmt.Fprint(&b, "\n\tKey binding\n")
fmt.Fprint(&b, "\n")
writeHeader(&b, "Key binding")
k.writeKeyBind(&b, actionExit, "quit")
k.writeKeyBind(&b, actionCancel, "cancel")
k.writeKeyBind(&b, actionWriteExit, "output screen and quit")
Expand All @@ -272,8 +271,7 @@ func (k KeyBind) String() string {
k.writeKeyBind(&b, actionToggleMouse, "enable/disable mouse")
k.writeKeyBind(&b, actionSaveBuffer, "save buffer to file")

fmt.Fprint(&b, "\n\tMoving\n")
fmt.Fprint(&b, "\n")
writeHeader(&b, "Moving")
k.writeKeyBind(&b, actionMoveDown, "forward by one line")
k.writeKeyBind(&b, actionMoveUp, "backward by one line")
k.writeKeyBind(&b, actionMoveTop, "go to top of document")
Expand All @@ -292,29 +290,25 @@ func (k KeyBind) String() string {
k.writeKeyBind(&b, actionMoveEndRight, "go to end of line")
k.writeKeyBind(&b, actionGoLine, "go to line(input number or `.n` or `n%` allowed)")

fmt.Fprint(&b, "\n\tMove document\n")
fmt.Fprint(&b, "\n")
writeHeader(&b, "Move document")
k.writeKeyBind(&b, actionNextDoc, "next document")
k.writeKeyBind(&b, actionPreviousDoc, "previous document")
k.writeKeyBind(&b, actionCloseDoc, "close current document")

fmt.Fprint(&b, "\n\tMark position\n")
fmt.Fprint(&b, "\n")
writeHeader(&b, "Mark position")
k.writeKeyBind(&b, actionMark, "mark current position")
k.writeKeyBind(&b, actionRemoveMark, "remove mark current position")
k.writeKeyBind(&b, actionRemoveAllMark, "remove all mark")
k.writeKeyBind(&b, actionMoveMark, "move to next marked position")
k.writeKeyBind(&b, actionMovePrevMark, "move to previous marked position")

fmt.Fprint(&b, "\n\tSearch\n")
fmt.Fprint(&b, "\n")
writeHeader(&b, "Search")
k.writeKeyBind(&b, actionSearch, "forward search mode")
k.writeKeyBind(&b, actionBackSearch, "backward search mode")
k.writeKeyBind(&b, actionNextSearch, "repeat forward search")
k.writeKeyBind(&b, actionNextBackSearch, "repeat backward search")

fmt.Fprint(&b, "\n\tChange display\n")
fmt.Fprint(&b, "\n")
writeHeader(&b, "Change display")
k.writeKeyBind(&b, actionWrap, "wrap/nowrap toggle")
k.writeKeyBind(&b, actionColumnMode, "column mode toggle")
k.writeKeyBind(&b, actionColumnWidth, "column width toggle")
Expand All @@ -323,8 +317,7 @@ func (k KeyBind) String() string {
k.writeKeyBind(&b, actionLineNumMode, "line number toggle")
k.writeKeyBind(&b, actionPlain, "original decoration toggle(plain)")

fmt.Fprint(&b, "\n\tChange Display with Input\n")
fmt.Fprint(&b, "\n")
writeHeader(&b, "Change Display with Input")
k.writeKeyBind(&b, actionViewMode, "view mode selection")
k.writeKeyBind(&b, actionDelimiter, "column delimiter string")
k.writeKeyBind(&b, actionHeader, "number of header lines")
Expand All @@ -333,8 +326,7 @@ func (k KeyBind) String() string {
k.writeKeyBind(&b, actionMultiColor, "multi color highlight")
k.writeKeyBind(&b, actionJumpTarget, "jump target(`.n` or `n%` or `section` allowed)")

fmt.Fprint(&b, "\n\tSection\n")
fmt.Fprint(&b, "\n")
writeHeader(&b, "Section")
k.writeKeyBind(&b, actionSection, "section delimiter regular expression")
k.writeKeyBind(&b, actionSectionStart, "section start position")
k.writeKeyBind(&b, actionNextSection, "next section")
Expand All @@ -343,15 +335,13 @@ func (k KeyBind) String() string {
k.writeKeyBind(&b, actionFollowSection, "follow section mode toggle")
k.writeKeyBind(&b, actionSectionNum, "section header number")

fmt.Fprint(&b, "\n\tClose and reload\n")
fmt.Fprint(&b, "\n")
writeHeader(&b, "Close and reload")
k.writeKeyBind(&b, actionCloseFile, "close file")
k.writeKeyBind(&b, actionReload, "reload file")
k.writeKeyBind(&b, actionWatch, "watch mode")
k.writeKeyBind(&b, actionWatchInterval, "set watch interval")

fmt.Fprint(&b, "\n\tKey binding when typing\n")
fmt.Fprint(&b, "\n")
writeHeader(&b, "Key binding when typing")
k.writeKeyBind(&b, inputCaseSensitive, "case-sensitive toggle")
k.writeKeyBind(&b, inputSmartCaseSensitive, "smart case-sensitive toggle")
k.writeKeyBind(&b, inputRegexpSearch, "regular expression search toggle")
Expand All @@ -363,6 +353,10 @@ func (k KeyBind) String() string {
return b.String()
}

func writeHeader(w io.Writer, header string) {
fmt.Fprintf(w, "\n\t%s\n", header)
}

func (k KeyBind) writeKeyBind(w io.Writer, action string, detail string) {
fmt.Fprintf(w, " %-28s * %s\n", "["+strings.Join(k[action], "], [")+"]", detail)
}
Expand Down

0 comments on commit fdb88e4

Please sign in to comment.