]> git.lizzy.rs Git - micro.git/commitdiff
Added hybrid line numbers (#1690)
authorColin Hughes <34290000+Semi-Colin@users.noreply.github.com>
Fri, 29 May 2020 02:24:09 +0000 (19:24 -0700)
committerGitHub <noreply@github.com>
Fri, 29 May 2020 02:24:09 +0000 (22:24 -0400)
* Added hybrid line numbers

* Changed rulerhybrid to relativeruler, modified documentation accordingly.

* Reverted go.mod and go.sum
I don't know how they got changed but they are good now.

Co-authored-by: Colin Hughes <semilin@pop-os.localdomain>
internal/config/settings.go
internal/display/bufwindow.go
runtime/help/options.md

index c8a280f2944e4a508b8b90fe30bd26b03eba4698..92b4fa033fffa93b0ada2267ec9a7354814b48dd 100644 (file)
@@ -203,6 +203,7 @@ var defaultCommonSettings = map[string]interface{}{
        "readonly":       false,
        "rmtrailingws":   false,
        "ruler":          true,
+       "relativeruler":  false,
        "savecursor":     false,
        "saveundo":       false,
        "scrollbar":      false,
index b054bfeed49540babe30bede3c6c99c1c50b6714..de688ddda5150bf56d0e6085343fa504e622a91d 100644 (file)
@@ -335,7 +335,14 @@ func (w *BufWindow) drawDiffGutter(backgroundStyle tcell.Style, softwrapped bool
 }
 
 func (w *BufWindow) drawLineNum(lineNumStyle tcell.Style, softwrapped bool, maxLineNumLength int, vloc *buffer.Loc, bloc *buffer.Loc) {
-       lineNum := strconv.Itoa(bloc.Y + 1)
+       cursorLine := w.Buf.GetActiveCursor().Loc.Y
+       var lineInt int
+       if w.Buf.Settings["relativeruler"] == false || cursorLine == bloc.Y {
+               lineInt = bloc.Y + 1
+       } else {
+               lineInt = bloc.Y - cursorLine
+       }
+       lineNum := strconv.Itoa(util.Abs(lineInt))
 
        // Write the spaces before the line number if necessary
        for i := 0; i < maxLineNumLength-len(lineNum); i++ {
index a8cadba2acda3061db61158cd62dca91cae582a9..5e5d4f868b5209873c5b3dac937d156a3da7c406 100644 (file)
@@ -214,6 +214,12 @@ Here are the available options:
 
        default value: `true`
 
+* `relativeruler`: make line numbers display relatively. If set to true, all lines except
+       for the line that the cursor is located will display the distance from the 
+       cursor's line. 
+
+       default value: `false` 
+
 * `savecursor`: remember where the cursor was last time the file was opened and
    put it there when you open the file again. Information is saved to
    `~/.config/micro/buffers/`