forked from toolshed/abra
chore: deps and vendor
This commit is contained in:
10
vendor/github.com/charmbracelet/x/ansi/cursor.go
generated
vendored
10
vendor/github.com/charmbracelet/x/ansi/cursor.go
generated
vendored
@ -77,6 +77,7 @@ const CUU1 = "\x1b[A"
|
||||
// CursorUp1 is a sequence for moving the cursor up one cell.
|
||||
//
|
||||
// This is equivalent to CursorUp(1).
|
||||
//
|
||||
// Deprecated: use [CUU1] instead.
|
||||
const CursorUp1 = "\x1b[A"
|
||||
|
||||
@ -104,6 +105,7 @@ const CUD1 = "\x1b[B"
|
||||
// CursorDown1 is a sequence for moving the cursor down one cell.
|
||||
//
|
||||
// This is equivalent to CursorDown(1).
|
||||
//
|
||||
// Deprecated: use [CUD1] instead.
|
||||
const CursorDown1 = "\x1b[B"
|
||||
|
||||
@ -133,6 +135,7 @@ const CUF1 = "\x1b[C"
|
||||
// CSI n C
|
||||
//
|
||||
// See: https://vt100.net/docs/vt510-rm/CUF.html
|
||||
//
|
||||
// Deprecated: use [CursorForward] instead.
|
||||
func CursorRight(n int) string {
|
||||
return CursorForward(n)
|
||||
@ -141,6 +144,7 @@ func CursorRight(n int) string {
|
||||
// CursorRight1 is a sequence for moving the cursor right one cell.
|
||||
//
|
||||
// This is equivalent to CursorRight(1).
|
||||
//
|
||||
// Deprecated: use [CUF1] instead.
|
||||
const CursorRight1 = CUF1
|
||||
|
||||
@ -170,6 +174,7 @@ const CUB1 = "\x1b[D"
|
||||
// CSI n D
|
||||
//
|
||||
// See: https://vt100.net/docs/vt510-rm/CUB.html
|
||||
//
|
||||
// Deprecated: use [CursorBackward] instead.
|
||||
func CursorLeft(n int) string {
|
||||
return CursorBackward(n)
|
||||
@ -178,6 +183,7 @@ func CursorLeft(n int) string {
|
||||
// CursorLeft1 is a sequence for moving the cursor left one cell.
|
||||
//
|
||||
// This is equivalent to CursorLeft(1).
|
||||
//
|
||||
// Deprecated: use [CUB1] instead.
|
||||
const CursorLeft1 = CUB1
|
||||
|
||||
@ -278,6 +284,7 @@ const CursorHomePosition = "\x1b[H"
|
||||
// CSI n ; m H
|
||||
//
|
||||
// See: https://vt100.net/docs/vt510-rm/CUP.html
|
||||
//
|
||||
// Deprecated: use [CursorPosition] instead.
|
||||
func SetCursorPosition(col, row int) string {
|
||||
if row <= 0 && col <= 0 {
|
||||
@ -296,6 +303,7 @@ func SetCursorPosition(col, row int) string {
|
||||
|
||||
// HomeCursorPosition is a sequence for moving the cursor to the upper left
|
||||
// corner of the scrolling region. This is equivalent to `SetCursorPosition(1, 1)`.
|
||||
//
|
||||
// Deprecated: use [CursorHomePosition] instead.
|
||||
const HomeCursorPosition = CursorHomePosition
|
||||
|
||||
@ -482,6 +490,7 @@ const (
|
||||
// not saved.
|
||||
//
|
||||
// See: https://vt100.net/docs/vt510-rm/SCOSC.html
|
||||
//
|
||||
// Deprecated: use [SaveCurrentCursorPosition] instead.
|
||||
const SaveCursorPosition = "\x1b[s"
|
||||
|
||||
@ -508,6 +517,7 @@ const (
|
||||
// cursor was saved.
|
||||
//
|
||||
// See: https://vt100.net/docs/vt510-rm/SCORC.html
|
||||
//
|
||||
// Deprecated: use [RestoreCurrentCursorPosition] instead.
|
||||
const RestoreCursorPosition = "\x1b[u"
|
||||
|
||||
|
71
vendor/github.com/charmbracelet/x/ansi/modes.go
generated
vendored
Normal file
71
vendor/github.com/charmbracelet/x/ansi/modes.go
generated
vendored
Normal file
@ -0,0 +1,71 @@
|
||||
package ansi
|
||||
|
||||
// Modes represents the terminal modes that can be set or reset. By default,
|
||||
// all modes are [ModeNotRecognized].
|
||||
type Modes map[Mode]ModeSetting
|
||||
|
||||
// NewModes creates a new Modes map. By default, all modes are
|
||||
// [ModeNotRecognized].
|
||||
func NewModes() Modes {
|
||||
return make(Modes)
|
||||
}
|
||||
|
||||
// Get returns the setting of a terminal mode. If the mode is not set, it
|
||||
// returns [ModeNotRecognized].
|
||||
func (m Modes) Get(mode Mode) ModeSetting {
|
||||
return m[mode]
|
||||
}
|
||||
|
||||
// Delete deletes a terminal mode. This has the same effect as setting the mode
|
||||
// to [ModeNotRecognized].
|
||||
func (m Modes) Delete(mode Mode) {
|
||||
delete(m, mode)
|
||||
}
|
||||
|
||||
// Set sets a terminal mode to [ModeSet].
|
||||
func (m Modes) Set(modes ...Mode) {
|
||||
for _, mode := range modes {
|
||||
m[mode] = ModeSet
|
||||
}
|
||||
}
|
||||
|
||||
// PermanentlySet sets a terminal mode to [ModePermanentlySet].
|
||||
func (m Modes) PermanentlySet(modes ...Mode) {
|
||||
for _, mode := range modes {
|
||||
m[mode] = ModePermanentlySet
|
||||
}
|
||||
}
|
||||
|
||||
// Reset sets a terminal mode to [ModeReset].
|
||||
func (m Modes) Reset(modes ...Mode) {
|
||||
for _, mode := range modes {
|
||||
m[mode] = ModeReset
|
||||
}
|
||||
}
|
||||
|
||||
// PermanentlyReset sets a terminal mode to [ModePermanentlyReset].
|
||||
func (m Modes) PermanentlyReset(modes ...Mode) {
|
||||
for _, mode := range modes {
|
||||
m[mode] = ModePermanentlyReset
|
||||
}
|
||||
}
|
||||
|
||||
// IsSet returns true if the mode is set to [ModeSet] or [ModePermanentlySet].
|
||||
func (m Modes) IsSet(mode Mode) bool {
|
||||
return m[mode].IsSet()
|
||||
}
|
||||
|
||||
// IsPermanentlySet returns true if the mode is set to [ModePermanentlySet].
|
||||
func (m Modes) IsPermanentlySet(mode Mode) bool {
|
||||
return m[mode].IsPermanentlySet()
|
||||
}
|
||||
|
||||
// IsReset returns true if the mode is set to [ModeReset] or [ModePermanentlyReset].
|
||||
func (m Modes) IsReset(mode Mode) bool {
|
||||
return m[mode].IsReset()
|
||||
}
|
||||
|
||||
// IsPermanentlyReset returns true if the mode is set to [ModePermanentlyReset].
|
||||
func (m Modes) IsPermanentlyReset(mode Mode) bool {
|
||||
return m[mode].IsPermanentlyReset()
|
||||
}
|
135
vendor/github.com/charmbracelet/x/ansi/mouse.go
generated
vendored
135
vendor/github.com/charmbracelet/x/ansi/mouse.go
generated
vendored
@ -4,6 +4,134 @@ import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// MouseButton represents the button that was pressed during a mouse message.
|
||||
type MouseButton byte
|
||||
|
||||
// Mouse event buttons
|
||||
//
|
||||
// This is based on X11 mouse button codes.
|
||||
//
|
||||
// 1 = left button
|
||||
// 2 = middle button (pressing the scroll wheel)
|
||||
// 3 = right button
|
||||
// 4 = turn scroll wheel up
|
||||
// 5 = turn scroll wheel down
|
||||
// 6 = push scroll wheel left
|
||||
// 7 = push scroll wheel right
|
||||
// 8 = 4th button (aka browser backward button)
|
||||
// 9 = 5th button (aka browser forward button)
|
||||
// 10
|
||||
// 11
|
||||
//
|
||||
// Other buttons are not supported.
|
||||
const (
|
||||
MouseNone MouseButton = iota
|
||||
MouseLeft
|
||||
MouseMiddle
|
||||
MouseRight
|
||||
MouseWheelUp
|
||||
MouseWheelDown
|
||||
MouseWheelLeft
|
||||
MouseWheelRight
|
||||
MouseBackward
|
||||
MouseForward
|
||||
MouseButton10
|
||||
MouseButton11
|
||||
|
||||
MouseRelease = MouseNone
|
||||
)
|
||||
|
||||
var mouseButtons = map[MouseButton]string{
|
||||
MouseNone: "none",
|
||||
MouseLeft: "left",
|
||||
MouseMiddle: "middle",
|
||||
MouseRight: "right",
|
||||
MouseWheelUp: "wheelup",
|
||||
MouseWheelDown: "wheeldown",
|
||||
MouseWheelLeft: "wheelleft",
|
||||
MouseWheelRight: "wheelright",
|
||||
MouseBackward: "backward",
|
||||
MouseForward: "forward",
|
||||
MouseButton10: "button10",
|
||||
MouseButton11: "button11",
|
||||
}
|
||||
|
||||
// String returns a string representation of the mouse button.
|
||||
func (b MouseButton) String() string {
|
||||
return mouseButtons[b]
|
||||
}
|
||||
|
||||
// Button returns a byte representing a mouse button.
|
||||
// The button is a bitmask of the following leftmost values:
|
||||
//
|
||||
// - The first two bits are the button number:
|
||||
// 0 = left button, wheel up, or button no. 8 aka (backwards)
|
||||
// 1 = middle button, wheel down, or button no. 9 aka (forwards)
|
||||
// 2 = right button, wheel left, or button no. 10
|
||||
// 3 = release event, wheel right, or button no. 11
|
||||
//
|
||||
// - The third bit indicates whether the shift key was pressed.
|
||||
//
|
||||
// - The fourth bit indicates the alt key was pressed.
|
||||
//
|
||||
// - The fifth bit indicates the control key was pressed.
|
||||
//
|
||||
// - The sixth bit indicates motion events. Combined with button number 3, i.e.
|
||||
// release event, it represents a drag event.
|
||||
//
|
||||
// - The seventh bit indicates a wheel event.
|
||||
//
|
||||
// - The eighth bit indicates additional buttons.
|
||||
//
|
||||
// If button is [MouseNone], and motion is false, this returns a release event.
|
||||
// If button is undefined, this function returns 0xff.
|
||||
func (b MouseButton) Button(motion, shift, alt, ctrl bool) (m byte) {
|
||||
// mouse bit shifts
|
||||
const (
|
||||
bitShift = 0b0000_0100
|
||||
bitAlt = 0b0000_1000
|
||||
bitCtrl = 0b0001_0000
|
||||
bitMotion = 0b0010_0000
|
||||
bitWheel = 0b0100_0000
|
||||
bitAdd = 0b1000_0000 // additional buttons 8-11
|
||||
|
||||
bitsMask = 0b0000_0011
|
||||
)
|
||||
|
||||
if b == MouseNone {
|
||||
m = bitsMask
|
||||
} else if b >= MouseLeft && b <= MouseRight {
|
||||
m = byte(b - MouseLeft)
|
||||
} else if b >= MouseWheelUp && b <= MouseWheelRight {
|
||||
m = byte(b - MouseWheelUp)
|
||||
m |= bitWheel
|
||||
} else if b >= MouseBackward && b <= MouseButton11 {
|
||||
m = byte(b - MouseBackward)
|
||||
m |= bitAdd
|
||||
} else {
|
||||
m = 0xff // invalid button
|
||||
}
|
||||
|
||||
if shift {
|
||||
m |= bitShift
|
||||
}
|
||||
if alt {
|
||||
m |= bitAlt
|
||||
}
|
||||
if ctrl {
|
||||
m |= bitCtrl
|
||||
}
|
||||
if motion {
|
||||
m |= bitMotion
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// x10Offset is the offset for X10 mouse events.
|
||||
// See https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#Mouse%20Tracking
|
||||
const x10Offset = 32
|
||||
|
||||
// MouseX10 returns an escape sequence representing a mouse event in X10 mode.
|
||||
// Note that this requires the terminal support X10 mouse modes.
|
||||
//
|
||||
@ -11,7 +139,6 @@ import (
|
||||
//
|
||||
// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#Mouse%20Tracking
|
||||
func MouseX10(b byte, x, y int) string {
|
||||
const x10Offset = 32
|
||||
return "\x1b[M" + string(b+x10Offset) + string(byte(x)+x10Offset+1) + string(byte(y)+x10Offset+1)
|
||||
}
|
||||
|
||||
@ -22,9 +149,9 @@ func MouseX10(b byte, x, y int) string {
|
||||
//
|
||||
// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#Mouse%20Tracking
|
||||
func MouseSgr(b byte, x, y int, release bool) string {
|
||||
s := "M"
|
||||
s := 'M'
|
||||
if release {
|
||||
s = "m"
|
||||
s = 'm'
|
||||
}
|
||||
if x < 0 {
|
||||
x = -x
|
||||
@ -32,5 +159,5 @@ func MouseSgr(b byte, x, y int, release bool) string {
|
||||
if y < 0 {
|
||||
y = -y
|
||||
}
|
||||
return fmt.Sprintf("\x1b[<%d;%d;%d%s", b, x+1, y+1, s)
|
||||
return fmt.Sprintf("\x1b[<%d;%d;%d%c", b, x+1, y+1, s)
|
||||
}
|
||||
|
78
vendor/github.com/charmbracelet/x/ansi/truncate.go
generated
vendored
78
vendor/github.com/charmbracelet/x/ansi/truncate.go
generated
vendored
@ -105,3 +105,81 @@ func Truncate(s string, length int, tail string) string {
|
||||
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
// TruncateLeft truncates a string from the left side to a given length, adding
|
||||
// a prefix to the beginning if the string is longer than the given length.
|
||||
// This function is aware of ANSI escape codes and will not break them, and
|
||||
// accounts for wide-characters (such as East Asians and emojis).
|
||||
func TruncateLeft(s string, length int, prefix string) string {
|
||||
if length == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
var cluster []byte
|
||||
var buf bytes.Buffer
|
||||
curWidth := 0
|
||||
ignoring := true
|
||||
pstate := parser.GroundState
|
||||
b := []byte(s)
|
||||
i := 0
|
||||
|
||||
for i < len(b) {
|
||||
if !ignoring {
|
||||
buf.Write(b[i:])
|
||||
break
|
||||
}
|
||||
|
||||
state, action := parser.Table.Transition(pstate, b[i])
|
||||
if state == parser.Utf8State {
|
||||
var width int
|
||||
cluster, _, width, _ = uniseg.FirstGraphemeCluster(b[i:], -1)
|
||||
|
||||
i += len(cluster)
|
||||
curWidth += width
|
||||
|
||||
if curWidth > length && ignoring {
|
||||
ignoring = false
|
||||
buf.WriteString(prefix)
|
||||
}
|
||||
|
||||
if ignoring {
|
||||
continue
|
||||
}
|
||||
|
||||
if curWidth > length {
|
||||
buf.Write(cluster)
|
||||
}
|
||||
|
||||
pstate = parser.GroundState
|
||||
continue
|
||||
}
|
||||
|
||||
switch action {
|
||||
case parser.PrintAction:
|
||||
curWidth++
|
||||
|
||||
if curWidth > length && ignoring {
|
||||
ignoring = false
|
||||
buf.WriteString(prefix)
|
||||
}
|
||||
|
||||
if ignoring {
|
||||
i++
|
||||
continue
|
||||
}
|
||||
|
||||
fallthrough
|
||||
default:
|
||||
buf.WriteByte(b[i])
|
||||
i++
|
||||
}
|
||||
|
||||
pstate = state
|
||||
if curWidth > length && ignoring {
|
||||
ignoring = false
|
||||
buf.WriteString(prefix)
|
||||
}
|
||||
}
|
||||
|
||||
return buf.String()
|
||||
}
|
||||
|
13
vendor/github.com/charmbracelet/x/ansi/wrap.go
generated
vendored
13
vendor/github.com/charmbracelet/x/ansi/wrap.go
generated
vendored
@ -378,14 +378,17 @@ func Wrap(s string, limit int, breakpoints string) string {
|
||||
i++
|
||||
}
|
||||
|
||||
if word.Len() != 0 {
|
||||
// Preserve ANSI wrapped spaces at the end of string
|
||||
if wordLen == 0 {
|
||||
if curWidth+space.Len() > limit {
|
||||
buf.WriteByte('\n')
|
||||
curWidth = 0
|
||||
} else {
|
||||
// preserve whitespaces
|
||||
buf.Write(space.Bytes())
|
||||
}
|
||||
addSpace()
|
||||
space.Reset()
|
||||
}
|
||||
buf.Write(word.Bytes())
|
||||
|
||||
addWord()
|
||||
|
||||
return buf.String()
|
||||
}
|
||||
|
Reference in New Issue
Block a user