mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-19 15:04:50 +02:00
Work on conversion of args parsing to go code
This commit is contained in:
40
tools/cmd/at/scroll_window.go
Normal file
40
tools/cmd/at/scroll_window.go
Normal file
@@ -0,0 +1,40 @@
|
||||
// License: GPLv3 Copyright: 2022, Kovid Goyal, <kovid at kovidgoyal.net>
|
||||
|
||||
package at
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func parse_scroll_amount(amt string) ([2]interface{}, error) {
|
||||
var ans [2]interface{}
|
||||
if amt == "start" || amt == "end" {
|
||||
ans[0] = amt
|
||||
ans[1] = nil
|
||||
} else {
|
||||
pages := strings.Contains(amt, "p")
|
||||
unscroll := strings.Contains(amt, "u")
|
||||
var mult float64 = 1
|
||||
if strings.HasSuffix(amt, "-") && !unscroll {
|
||||
mult = -1
|
||||
q, err := strconv.ParseFloat(strings.TrimRight(amt, "+-plu"), 64)
|
||||
if err != nil {
|
||||
return ans, err
|
||||
}
|
||||
if !pages && q != float64(int(q)) {
|
||||
return ans, fmt.Errorf("The number must be an integer")
|
||||
}
|
||||
ans[0] = q * mult
|
||||
if pages {
|
||||
ans[1] = "p"
|
||||
} else if unscroll {
|
||||
ans[1] = "u"
|
||||
} else {
|
||||
ans[1] = "l"
|
||||
}
|
||||
}
|
||||
}
|
||||
return ans, nil
|
||||
}
|
||||
Reference in New Issue
Block a user