diff --git a/core/blockchain_reader.go b/core/blockchain_reader.go index 9aad5aa90c..6f71d3108f 100644 --- a/core/blockchain_reader.go +++ b/core/blockchain_reader.go @@ -229,6 +229,14 @@ func (bc *BlockChain) GetReceiptsByHash(hash common.Hash) types.Receipts { return receipts } +func (bc *BlockChain) GetRawReceiptsByHash(hash common.Hash) types.Receipts { + number := rawdb.ReadHeaderNumber(bc.db, hash) + if number == nil { + return nil + } + return rawdb.ReadRawReceipts(bc.db, hash, *number) +} + // GetUnclesInChain retrieves all the uncles from a given block backwards until // a specific distance is reached. func (bc *BlockChain) GetUnclesInChain(block *types.Block, length int) []*types.Header { diff --git a/core/filtermaps/chain_view.go b/core/filtermaps/chain_view.go index 4580f6b687..66dff87292 100644 --- a/core/filtermaps/chain_view.go +++ b/core/filtermaps/chain_view.go @@ -29,6 +29,7 @@ type blockchain interface { GetHeader(hash common.Hash, number uint64) *types.Header GetCanonicalHash(number uint64) common.Hash GetReceiptsByHash(hash common.Hash) types.Receipts + GetRawReceiptsByHash(hash common.Hash) types.Receipts } // ChainView represents an immutable view of a chain with a block id and a set @@ -102,10 +103,23 @@ func (cv *ChainView) Receipts(number uint64) types.Receipts { blockHash := cv.BlockHash(number) if blockHash == (common.Hash{}) { log.Error("Chain view: block hash unavailable", "number", number, "head", cv.headNumber) + return nil } return cv.chain.GetReceiptsByHash(blockHash) } +// RawReceipts returns the set of receipts belonging to the block at the given +// block number. Does not derive the fields of the receipts, should only be +// used during creation of the filter maps, please use cv.Receipts during querying. +func (cv *ChainView) RawReceipts(number uint64) types.Receipts { + blockHash := cv.BlockHash(number) + if blockHash == (common.Hash{}) { + log.Error("Chain view: block hash unavailable", "number", number, "head", cv.headNumber) + return nil + } + return cv.chain.GetRawReceiptsByHash(blockHash) +} + // SharedRange returns the block range shared by two chain views. func (cv *ChainView) SharedRange(cv2 *ChainView) common.Range[uint64] { cv.lock.Lock() diff --git a/core/filtermaps/map_renderer.go b/core/filtermaps/map_renderer.go index a98e80ab99..81ab215701 100644 --- a/core/filtermaps/map_renderer.go +++ b/core/filtermaps/map_renderer.go @@ -693,7 +693,7 @@ func (f *FilterMaps) newLogIteratorFromMapBoundary(mapIndex uint32, startBlock, return nil, fmt.Errorf("iterator entry point %d after target chain head block %d", startBlock, f.targetView.HeadNumber()) } // get block receipts - receipts := f.targetView.Receipts(startBlock) + receipts := f.targetView.RawReceipts(startBlock) if receipts == nil { return nil, fmt.Errorf("receipts not found for start block %d", startBlock) } @@ -760,7 +760,7 @@ func (l *logIterator) next() error { if l.delimiter { l.delimiter = false l.blockNumber++ - l.receipts = l.chainView.Receipts(l.blockNumber) + l.receipts = l.chainView.RawReceipts(l.blockNumber) if l.receipts == nil { return fmt.Errorf("receipts not found for block %d", l.blockNumber) } diff --git a/ctxc/filters/filter_system_test.go b/ctxc/filters/filter_system_test.go index 0a1e528c19..2666085db6 100644 --- a/ctxc/filters/filter_system_test.go +++ b/ctxc/filters/filter_system_test.go @@ -190,6 +190,13 @@ func (b *testBackend) CurrentView() *filtermaps.ChainView { return filtermaps.NewChainView(b, head.Number.Uint64(), head.Hash()) } +func (b *testBackend) GetRawReceiptsByHash(hash common.Hash) types.Receipts { + if number := rawdb.ReadHeaderNumber(b.db, hash); number != nil { + return rawdb.ReadRawReceipts(b.db, hash, *number) + } + return nil +} + func newTestFilterSystem(t testing.TB, db ctxcdb.Database, cfg Config) (*testBackend, *FilterSystem) { backend := &testBackend{db: db} sys := NewFilterSystem(backend, cfg) diff --git a/go.mod b/go.mod index 15c282fe48..b3d8a8456c 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( github.com/aws/aws-sdk-go-v2/credentials v1.17.67 github.com/aws/aws-sdk-go-v2/service/route53 v1.51.1 github.com/cespare/cp v1.1.1 - github.com/charmbracelet/bubbletea v1.3.4 + github.com/charmbracelet/bubbletea v1.3.5 github.com/cloudflare/cloudflare-go v0.115.0 github.com/cockroachdb/pebble v1.1.5 github.com/consensys/gnark-crypto v0.17.0 @@ -129,14 +129,14 @@ require ( github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/charmbracelet/colorprofile v0.3.1 // indirect github.com/charmbracelet/lipgloss v1.1.0 // indirect - github.com/charmbracelet/x/ansi v0.8.0 // indirect + github.com/charmbracelet/x/ansi v0.9.2 // indirect github.com/charmbracelet/x/cellbuf v0.0.13 // indirect github.com/charmbracelet/x/term v0.2.1 // indirect github.com/cockroachdb/errors v1.11.3 // indirect github.com/cockroachdb/fifo v0.0.0-20240816210425-c5d0cb0b6fc0 // indirect github.com/cockroachdb/logtags v0.0.0-20241215232642-bb51bb14a506 // indirect github.com/cockroachdb/redact v1.1.6 // indirect - github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect + github.com/cockroachdb/tokenbucket v0.0.0-20250429170803-42689b6311bb // indirect github.com/common-nighthawk/go-figure v0.0.0-20210622060536-734e95fb86be // indirect github.com/consensys/bavard v0.1.30 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect @@ -251,7 +251,7 @@ require ( gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect lukechampine.com/blake3 v1.4.0 // indirect - modernc.org/libc v1.64.0 // indirect + modernc.org/libc v1.64.1 // indirect modernc.org/mathutil v1.7.1 // indirect modernc.org/memory v1.10.0 // indirect modernc.org/sqlite v1.37.0 // indirect diff --git a/go.sum b/go.sum index a6af42c0de..f4387522dd 100644 --- a/go.sum +++ b/go.sum @@ -338,14 +338,14 @@ github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XL github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= -github.com/charmbracelet/bubbletea v1.3.4 h1:kCg7B+jSCFPLYRA52SDZjr51kG/fMUEoPoZrkaDHyoI= -github.com/charmbracelet/bubbletea v1.3.4/go.mod h1:dtcUCyCGEX3g9tosuYiut3MXgY/Jsv9nKVdibKKRRXo= +github.com/charmbracelet/bubbletea v1.3.5 h1:JAMNLTbqMOhSwoELIr0qyP4VidFq72/6E9j7HHmRKQc= +github.com/charmbracelet/bubbletea v1.3.5/go.mod h1:TkCnmH+aBd4LrXhXcqrKiYwRs7qyQx5rBgH5fVY3v54= github.com/charmbracelet/colorprofile v0.3.1 h1:k8dTHMd7fgw4bnFd7jXTLZrSU/CQrKnL3m+AxCzDz40= github.com/charmbracelet/colorprofile v0.3.1/go.mod h1:/GkGusxNs8VB/RSOh3fu0TJmQ4ICMMPApIIVn0KszZ0= github.com/charmbracelet/lipgloss v1.1.0 h1:vYXsiLHVkK7fp74RkV7b2kq9+zDLoEU4MZoFqR/noCY= github.com/charmbracelet/lipgloss v1.1.0/go.mod h1:/6Q8FR2o+kj8rz4Dq0zQc3vYf7X+B0binUUBwA0aL30= -github.com/charmbracelet/x/ansi v0.8.0 h1:9GTq3xq9caJW8ZrBTe0LIe2fvfLR/bYXKTx2llXn7xE= -github.com/charmbracelet/x/ansi v0.8.0/go.mod h1:wdYl/ONOLHLIVmQaxbIYEC/cRKOQyjTkowiI4blgS9Q= +github.com/charmbracelet/x/ansi v0.9.2 h1:92AGsQmNTRMzuzHEYfCdjQeUzTrgE1vfO5/7fEVoXdY= +github.com/charmbracelet/x/ansi v0.9.2/go.mod h1:3RQDQ6lDnROptfpWuUVIUG64bD2g2BgntdxH0Ya5TeE= github.com/charmbracelet/x/cellbuf v0.0.13 h1:/KBBKHuVRbq1lYx5BzEHBAFBP8VcQzJejZ/IA3iR28k= github.com/charmbracelet/x/cellbuf v0.0.13/go.mod h1:xe0nKWGd3eJgtqZRaN9RjMtK7xUYchjzPr7q6kcvCCs= github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ= @@ -375,8 +375,8 @@ github.com/cockroachdb/pebble v1.1.5 h1:5AAWCBWbat0uE0blr8qzufZP5tBjkRyy/jWe1QWL github.com/cockroachdb/pebble v1.1.5/go.mod h1:17wO9el1YEigxkP/YtV8NtCivQDgoCyBg5c4VR/eOWo= github.com/cockroachdb/redact v1.1.6 h1:zXJBwDZ84xJNlHl1rMyCojqyIxv+7YUpQiJLQ7n4314= github.com/cockroachdb/redact v1.1.6/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg= -github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 h1:zuQyyAKVxetITBuuhv3BI9cMrmStnpT18zmgmTxunpo= -github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06/go.mod h1:7nc4anLGjupUW/PeY5qiNYsdNXj7zopG+eqsS7To5IQ= +github.com/cockroachdb/tokenbucket v0.0.0-20250429170803-42689b6311bb h1:3bCgBvB8PbJVMX1ouCcSIxvsqKPYM7gs72o0zC76n9g= +github.com/cockroachdb/tokenbucket v0.0.0-20250429170803-42689b6311bb/go.mod h1:7nc4anLGjupUW/PeY5qiNYsdNXj7zopG+eqsS7To5IQ= github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI= github.com/common-nighthawk/go-figure v0.0.0-20190529165535-67e0ed34491a/go.mod h1:mk5IQ+Y0ZeO87b858TlA645sVcEcbiX6YqP98kt+7+w= github.com/common-nighthawk/go-figure v0.0.0-20210622060536-734e95fb86be h1:J5BL2kskAlV9ckgEsNQXscjIaLiOYiZ75d4e94E6dcQ= @@ -1823,8 +1823,8 @@ modernc.org/libc v1.19.0/go.mod h1:ZRfIaEkgrYgZDl6pa4W39HgN5G/yDW+NRmNKZBDFrk0= modernc.org/libc v1.20.3/go.mod h1:ZRfIaEkgrYgZDl6pa4W39HgN5G/yDW+NRmNKZBDFrk0= modernc.org/libc v1.21.4/go.mod h1:przBsL5RDOZajTVslkugzLBj1evTue36jEomFQOoYuI= modernc.org/libc v1.21.5/go.mod h1:przBsL5RDOZajTVslkugzLBj1evTue36jEomFQOoYuI= -modernc.org/libc v1.64.0 h1:U0k8BD2d3cD3e9I8RLcZgJBHAcsJzbXx5mKGSb5pyJA= -modernc.org/libc v1.64.0/go.mod h1:7m9VzGq7APssBTydds2zBcxGREwvIGpuUBaKTXdm2Qs= +modernc.org/libc v1.64.1 h1:EnFXu9N9epQohXMH+h1/w3SxHVGozuPjbux5KVFf5bM= +modernc.org/libc v1.64.1/go.mod h1:7m9VzGq7APssBTydds2zBcxGREwvIGpuUBaKTXdm2Qs= modernc.org/mathutil v1.5.0/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E= modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU= modernc.org/mathutil v1.7.1/go.mod h1:4p5IwJITfppl0G4sUEDtCr4DthTaT47/N3aT6MhfgJg= diff --git a/trie/proof_test.go b/trie/proof_test.go index 82dc7a671f..f3de98147d 100644 --- a/trie/proof_test.go +++ b/trie/proof_test.go @@ -1004,12 +1004,12 @@ func TestRangeProofKeysWithSharedPrefix(t *testing.T) { // to exit with errors func TestRangeProofErrors(t *testing.T) { // Different number of keys to values - _, err := VerifyRangeProof((common.Hash{}), []byte{}, make([][]byte, 5), make([][]byte, 4), nil) + _, _, _, _, err := VerifyRangeProof((common.Hash{}), []byte{}, []byte{}, make([][]byte, 5), make([][]byte, 4), nil) if have, want := err.Error(), "inconsistent proof data, keys: 5, values: 4"; have != want { t.Fatalf("wrong error, have %q, want %q", err.Error(), want) } // Non-increasing paths - _, err = VerifyRangeProof((common.Hash{}), []byte{}, + _, _, _, _, err = VerifyRangeProof((common.Hash{}), []byte{}, []byte{}, [][]byte{[]byte{2, 1}, []byte{2, 1}}, make([][]byte, 2), nil) if have, want := err.Error(), "range is not monotonically increasing"; have != want { t.Fatalf("wrong error, have %q, want %q", err.Error(), want) @@ -1017,14 +1017,14 @@ func TestRangeProofErrors(t *testing.T) { // A prefixed path is never motivated. Inserting the second element will // require rewriting/overwriting the previous value-node, thus can only // happen if the data is corrupt. - _, err = VerifyRangeProof((common.Hash{}), []byte{}, + _, _, _, _, err = VerifyRangeProof((common.Hash{}), []byte{}, []byte{}, [][]byte{[]byte{2, 1}, []byte{2, 1, 2}}, [][]byte{[]byte{1}, []byte{1}}, nil) if have, want := err.Error(), "range contains path prefixes"; have != want { t.Fatalf("wrong error, have %q, want %q", err.Error(), want) } // Empty values (deletions) - _, err = VerifyRangeProof((common.Hash{}), []byte{}, + _, _, _, _, err = VerifyRangeProof((common.Hash{}), []byte{}, []byte{}, [][]byte{[]byte{2, 1}, []byte{2, 2}}, [][]byte{[]byte{1}, []byte{}}, nil) if have, want := err.Error(), "range contains deletion"; have != want { diff --git a/vendor/github.com/charmbracelet/bubbletea/.golangci-soft.yml b/vendor/github.com/charmbracelet/bubbletea/.golangci-soft.yml deleted file mode 100644 index d325d4fcc6..0000000000 --- a/vendor/github.com/charmbracelet/bubbletea/.golangci-soft.yml +++ /dev/null @@ -1,40 +0,0 @@ -run: - tests: false - issues-exit-code: 0 - -issues: - include: - - EXC0001 - - EXC0005 - - EXC0011 - - EXC0012 - - EXC0013 - - max-issues-per-linter: 0 - max-same-issues: 0 - -linters: - enable: - - exhaustive - - goconst - - godot - - godox - - mnd - - gomoddirectives - - goprintffuncname - - misspell - - nakedret - - nestif - - noctx - - nolintlint - - prealloc - - wrapcheck - - # disable default linters, they are already enabled in .golangci.yml - disable: - - errcheck - - gosimple - - govet - - ineffassign - - staticcheck - - unused diff --git a/vendor/github.com/charmbracelet/bubbletea/.golangci.yml b/vendor/github.com/charmbracelet/bubbletea/.golangci.yml index d6789e014c..be61d89ba1 100644 --- a/vendor/github.com/charmbracelet/bubbletea/.golangci.yml +++ b/vendor/github.com/charmbracelet/bubbletea/.golangci.yml @@ -1,24 +1,23 @@ +version: "2" run: tests: false - -issues: - include: - - EXC0001 - - EXC0005 - - EXC0011 - - EXC0012 - - EXC0013 - - max-issues-per-linter: 0 - max-same-issues: 0 - linters: enable: - bodyclose - - gofumpt - - goimports + - exhaustive + - goconst + - godot + - godox + - gomoddirectives + - goprintffuncname - gosec + - misspell + - nakedret + - nestif - nilerr + - noctx + - nolintlint + - prealloc - revive - rowserrcheck - sqlclosecheck @@ -26,3 +25,17 @@ linters: - unconvert - unparam - whitespace + - wrapcheck + exclusions: + generated: lax + presets: + - common-false-positives +issues: + max-issues-per-linter: 0 + max-same-issues: 0 +formatters: + enable: + - gofumpt + - goimports + exclusions: + generated: lax diff --git a/vendor/github.com/charmbracelet/bubbletea/README.md b/vendor/github.com/charmbracelet/bubbletea/README.md index 58dd1828e2..8f5b1c47a9 100644 --- a/vendor/github.com/charmbracelet/bubbletea/README.md +++ b/vendor/github.com/charmbracelet/bubbletea/README.md @@ -1,7 +1,12 @@ # Bubble Tea
-
+
+
diff --git a/vendor/github.com/charmbracelet/bubbletea/Taskfile.yaml b/vendor/github.com/charmbracelet/bubbletea/Taskfile.yaml
new file mode 100644
index 0000000000..35072035df
--- /dev/null
+++ b/vendor/github.com/charmbracelet/bubbletea/Taskfile.yaml
@@ -0,0 +1,14 @@
+# https://taskfile.dev
+
+version: '3'
+
+tasks:
+ lint:
+ desc: Run lint
+ cmds:
+ - golangci-lint run
+
+ test:
+ desc: Run tests
+ cmds:
+ - go test ./... {{.CLI_ARGS}}
diff --git a/vendor/github.com/charmbracelet/bubbletea/inputreader_other.go b/vendor/github.com/charmbracelet/bubbletea/inputreader_other.go
index 3426a177c7..1d1b176101 100644
--- a/vendor/github.com/charmbracelet/bubbletea/inputreader_other.go
+++ b/vendor/github.com/charmbracelet/bubbletea/inputreader_other.go
@@ -4,11 +4,16 @@
package tea
import (
+ "fmt"
"io"
"github.com/muesli/cancelreader"
)
func newInputReader(r io.Reader, _ bool) (cancelreader.CancelReader, error) {
- return cancelreader.NewReader(r)
+ cr, err := cancelreader.NewReader(r)
+ if err != nil {
+ return nil, fmt.Errorf("bubbletea: error creating cancel reader: %w", err)
+ }
+ return cr, nil
}
diff --git a/vendor/github.com/charmbracelet/bubbletea/key.go b/vendor/github.com/charmbracelet/bubbletea/key.go
index ab4792ac63..12a161a799 100644
--- a/vendor/github.com/charmbracelet/bubbletea/key.go
+++ b/vendor/github.com/charmbracelet/bubbletea/key.go
@@ -622,7 +622,7 @@ func detectOneMsg(b []byte, canHaveMoreData bool) (w int, msg Msg) {
case '<':
if matchIndices := mouseSGRRegex.FindSubmatchIndex(b[3:]); matchIndices != nil {
// SGR mouse events length is the length of the match plus the length of the escape sequence
- mouseEventSGRLen := matchIndices[1] + 3 //nolint:gomnd
+ mouseEventSGRLen := matchIndices[1] + 3 //nolint:mnd
return mouseEventSGRLen, MouseMsg(parseSGRMouseEvent(b))
}
}
diff --git a/vendor/github.com/charmbracelet/bubbletea/key_sequences.go b/vendor/github.com/charmbracelet/bubbletea/key_sequences.go
index 15483ef528..dce9bf4857 100644
--- a/vendor/github.com/charmbracelet/bubbletea/key_sequences.go
+++ b/vendor/github.com/charmbracelet/bubbletea/key_sequences.go
@@ -119,13 +119,12 @@ func detectBracketedPaste(input []byte) (hasBp bool, width int, msg Msg) {
}
// detectReportFocus detects a focus report sequence.
-// nolint: gomnd
func detectReportFocus(input []byte) (hasRF bool, width int, msg Msg) {
switch {
case bytes.Equal(input, []byte("\x1b[I")):
- return true, 3, FocusMsg{}
+ return true, 3, FocusMsg{} //nolint:mnd
case bytes.Equal(input, []byte("\x1b[O")):
- return true, 3, BlurMsg{}
+ return true, 3, BlurMsg{} //nolint:mnd
}
return false, 0, nil
}
diff --git a/vendor/github.com/charmbracelet/bubbletea/key_windows.go b/vendor/github.com/charmbracelet/bubbletea/key_windows.go
index d59ff1c462..c977fb842f 100644
--- a/vendor/github.com/charmbracelet/bubbletea/key_windows.go
+++ b/vendor/github.com/charmbracelet/bubbletea/key_windows.go
@@ -87,7 +87,7 @@ func readConInputs(ctx context.Context, msgsch chan<- Msg, con *conInputReader)
if err != nil {
return fmt.Errorf("coninput context error: %w", err)
}
- return err
+ return nil
}
}
}
@@ -114,7 +114,7 @@ func mouseEventButton(p, s coninput.ButtonState) (button MouseButton, action Mou
case s&coninput.FROM_LEFT_4TH_BUTTON_PRESSED > 0:
button = MouseButtonForward
}
- return
+ return button, action
}
switch {
@@ -147,7 +147,7 @@ func mouseEvent(p coninput.ButtonState, e coninput.MouseEventRecord) MouseMsg {
if ev.Action == MouseActionRelease {
ev.Type = MouseRelease
}
- switch ev.Button {
+ switch ev.Button { //nolint:exhaustive
case MouseButtonLeft:
ev.Type = MouseLeft
case MouseButtonMiddle:
@@ -190,7 +190,7 @@ func keyType(e coninput.KeyEventRecord) KeyType {
shiftPressed := e.ControlKeyState.Contains(coninput.SHIFT_PRESSED)
ctrlPressed := e.ControlKeyState.Contains(coninput.LEFT_CTRL_PRESSED | coninput.RIGHT_CTRL_PRESSED)
- switch code {
+ switch code { //nolint:exhaustive
case coninput.VK_RETURN:
return KeyEnter
case coninput.VK_BACK:
@@ -276,6 +276,46 @@ func keyType(e coninput.KeyEventRecord) KeyType {
return KeyPgDown
case coninput.VK_DELETE:
return KeyDelete
+ case coninput.VK_F1:
+ return KeyF1
+ case coninput.VK_F2:
+ return KeyF2
+ case coninput.VK_F3:
+ return KeyF3
+ case coninput.VK_F4:
+ return KeyF4
+ case coninput.VK_F5:
+ return KeyF5
+ case coninput.VK_F6:
+ return KeyF6
+ case coninput.VK_F7:
+ return KeyF7
+ case coninput.VK_F8:
+ return KeyF8
+ case coninput.VK_F9:
+ return KeyF9
+ case coninput.VK_F10:
+ return KeyF10
+ case coninput.VK_F11:
+ return KeyF11
+ case coninput.VK_F12:
+ return KeyF12
+ case coninput.VK_F13:
+ return KeyF13
+ case coninput.VK_F14:
+ return KeyF14
+ case coninput.VK_F15:
+ return KeyF15
+ case coninput.VK_F16:
+ return KeyF16
+ case coninput.VK_F17:
+ return KeyF17
+ case coninput.VK_F18:
+ return KeyF18
+ case coninput.VK_F19:
+ return KeyF19
+ case coninput.VK_F20:
+ return KeyF20
default:
switch {
case e.ControlKeyState.Contains(coninput.LEFT_CTRL_PRESSED) && e.ControlKeyState.Contains(coninput.RIGHT_ALT_PRESSED):
@@ -348,7 +388,7 @@ func keyType(e coninput.KeyEventRecord) KeyType {
return KeyCtrlUnderscore
}
- switch code {
+ switch code { //nolint:exhaustive
case coninput.VK_OEM_4:
return KeyCtrlOpenBracket
case coninput.VK_OEM_6:
diff --git a/vendor/github.com/charmbracelet/bubbletea/logging.go b/vendor/github.com/charmbracelet/bubbletea/logging.go
index a53118193c..349758cbce 100644
--- a/vendor/github.com/charmbracelet/bubbletea/logging.go
+++ b/vendor/github.com/charmbracelet/bubbletea/logging.go
@@ -33,7 +33,7 @@ type LogOptionsSetter interface {
// LogToFileWith does allows to call LogToFile with a custom LogOptionsSetter.
func LogToFileWith(path string, prefix string, log LogOptionsSetter) (*os.File, error) {
- f, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0o600) //nolint:gomnd
+ f, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0o600) //nolint:mnd
if err != nil {
return nil, fmt.Errorf("error opening file for logging: %w", err)
}
diff --git a/vendor/github.com/charmbracelet/bubbletea/mouse.go b/vendor/github.com/charmbracelet/bubbletea/mouse.go
index 6ec51cc0c0..490f49acbe 100644
--- a/vendor/github.com/charmbracelet/bubbletea/mouse.go
+++ b/vendor/github.com/charmbracelet/bubbletea/mouse.go
@@ -172,7 +172,7 @@ const (
func parseSGRMouseEvent(buf []byte) MouseEvent {
str := string(buf[3:])
matches := mouseSGRRegex.FindStringSubmatch(str)
- if len(matches) != 5 { //nolint:gomnd
+ if len(matches) != 5 { //nolint:mnd
// Unreachable, we already checked the regex in `detectOneMsg`.
panic("invalid mouse event")
}
diff --git a/vendor/github.com/charmbracelet/bubbletea/options.go b/vendor/github.com/charmbracelet/bubbletea/options.go
index c509353b18..49cf378b59 100644
--- a/vendor/github.com/charmbracelet/bubbletea/options.go
+++ b/vendor/github.com/charmbracelet/bubbletea/options.go
@@ -19,7 +19,7 @@ type ProgramOption func(*Program)
// cancelled it will exit with an error ErrProgramKilled.
func WithContext(ctx context.Context) ProgramOption {
return func(p *Program) {
- p.ctx = ctx
+ p.externalCtx = ctx
}
}
diff --git a/vendor/github.com/charmbracelet/bubbletea/tea.go b/vendor/github.com/charmbracelet/bubbletea/tea.go
index 0bc915e5b3..c4866f220b 100644
--- a/vendor/github.com/charmbracelet/bubbletea/tea.go
+++ b/vendor/github.com/charmbracelet/bubbletea/tea.go
@@ -27,6 +27,9 @@ import (
"golang.org/x/sync/errgroup"
)
+// ErrProgramPanic is returned by [Program.Run] when the program recovers from a panic.
+var ErrProgramPanic = errors.New("program experienced a panic")
+
// ErrProgramKilled is returned by [Program.Run] when the program gets killed.
var ErrProgramKilled = errors.New("program was killed")
@@ -147,6 +150,12 @@ type Program struct {
inputType inputType
+ // externalCtx is a context that was passed in via WithContext, otherwise defaulting
+ // to ctx.Background() (in case it was not), the internal context is derived from it.
+ externalCtx context.Context
+
+ // ctx is the programs's internal context for signalling internal teardown.
+ // It is built and derived from the externalCtx in NewProgram().
ctx context.Context
cancel context.CancelFunc
@@ -243,11 +252,11 @@ func NewProgram(model Model, opts ...ProgramOption) *Program {
// A context can be provided with a ProgramOption, but if none was provided
// we'll use the default background context.
- if p.ctx == nil {
- p.ctx = context.Background()
+ if p.externalCtx == nil {
+ p.externalCtx = context.Background()
}
// Initialize context and teardown channel.
- p.ctx, p.cancel = context.WithCancel(p.ctx)
+ p.ctx, p.cancel = context.WithCancel(p.externalCtx)
// if no output was set, set it to stdout
if p.output == nil {
@@ -346,7 +355,11 @@ func (p *Program) handleCommands(cmds chan Cmd) chan struct{} {
go func() {
// Recover from panics.
if !p.startupOptions.has(withoutCatchPanics) {
- defer p.recoverFromPanic()
+ defer func() {
+ if r := recover(); r != nil {
+ p.recoverFromGoPanic(r)
+ }
+ }()
}
msg := cmd() // this can be long.
@@ -422,7 +435,7 @@ func (p *Program) eventLoop(model Model, cmds chan Cmd) (Model, error) {
// work.
if runtime.GOOS == "windows" && !p.mouseMode {
p.mouseMode = true
- p.initCancelReader(true) //nolint:errcheck
+ p.initCancelReader(true) //nolint:errcheck,gosec
}
case disableMouseMsg:
@@ -433,7 +446,7 @@ func (p *Program) eventLoop(model Model, cmds chan Cmd) (Model, error) {
// mouse events.
if runtime.GOOS == "windows" && p.mouseMode {
p.mouseMode = false
- p.initCancelReader(true) //nolint:errcheck
+ p.initCancelReader(true) //nolint:errcheck,gosec
}
case showCursorMsg:
@@ -460,7 +473,11 @@ func (p *Program) eventLoop(model Model, cmds chan Cmd) (Model, error) {
case BatchMsg:
for _, cmd := range msg {
- cmds <- cmd
+ select {
+ case <-p.ctx.Done():
+ return model, nil
+ case cmds <- cmd:
+ }
}
continue
@@ -483,7 +500,7 @@ func (p *Program) eventLoop(model Model, cmds chan Cmd) (Model, error) {
})
}
- //nolint:errcheck
+ //nolint:errcheck,gosec
g.Wait() // wait for all commands from batch msg to finish
continue
}
@@ -506,7 +523,13 @@ func (p *Program) eventLoop(model Model, cmds chan Cmd) (Model, error) {
var cmd Cmd
model, cmd = model.Update(msg) // run update
- cmds <- cmd // process command (if any)
+
+ select {
+ case <-p.ctx.Done():
+ return model, nil
+ case cmds <- cmd: // process command (if any)
+ }
+
p.renderer.write(model.View()) // send view to renderer
}
}
@@ -515,11 +538,15 @@ func (p *Program) eventLoop(model Model, cmds chan Cmd) (Model, error) {
// Run initializes the program and runs its event loops, blocking until it gets
// terminated by either [Program.Quit], [Program.Kill], or its signal handler.
// Returns the final model.
-func (p *Program) Run() (Model, error) {
+func (p *Program) Run() (returnModel Model, returnErr error) {
p.handlers = channelHandlers{}
cmds := make(chan Cmd)
- p.errs = make(chan error)
- p.finished = make(chan struct{}, 1)
+ p.errs = make(chan error, 1)
+
+ p.finished = make(chan struct{})
+ defer func() {
+ close(p.finished)
+ }()
defer p.cancel()
@@ -568,7 +595,12 @@ func (p *Program) Run() (Model, error) {
// Recover from panics.
if !p.startupOptions.has(withoutCatchPanics) {
- defer p.recoverFromPanic()
+ defer func() {
+ if r := recover(); r != nil {
+ returnErr = fmt.Errorf("%w: %w", ErrProgramKilled, ErrProgramPanic)
+ p.recoverFromPanic(r)
+ }
+ }()
}
// If no renderer is set use the standard one.
@@ -645,11 +677,27 @@ func (p *Program) Run() (Model, error) {
// Run event loop, handle updates and draw.
model, err := p.eventLoop(model, cmds)
- killed := p.ctx.Err() != nil || err != nil
- if killed && err == nil {
- err = fmt.Errorf("%w: %s", ErrProgramKilled, p.ctx.Err())
+
+ if err == nil && len(p.errs) > 0 {
+ err = <-p.errs // Drain a leftover error in case eventLoop crashed
}
- if err == nil {
+
+ killed := p.externalCtx.Err() != nil || p.ctx.Err() != nil || err != nil
+ if killed {
+ if err == nil && p.externalCtx.Err() != nil {
+ // Return also as context error the cancellation of an external context.
+ // This is the context the user knows about and should be able to act on.
+ err = fmt.Errorf("%w: %w", ErrProgramKilled, p.externalCtx.Err())
+ } else if err == nil && p.ctx.Err() != nil {
+ // Return only that the program was killed (not the internal mechanism).
+ // The user does not know or need to care about the internal program context.
+ err = ErrProgramKilled
+ } else {
+ // Return that the program was killed and also the error that caused it.
+ err = fmt.Errorf("%w: %w", ErrProgramKilled, err)
+ }
+ } else {
+ // Graceful shutdown of the program (not killed):
// Ensure we rendered the final state of the model.
p.renderer.write(model.View())
}
@@ -704,11 +752,11 @@ func (p *Program) Quit() {
p.Send(Quit())
}
-// Kill stops the program immediately and restores the former terminal state.
+// Kill signals the program to stop immediately and restore the former terminal state.
// The final render that you would normally see when quitting will be skipped.
// [program.Run] returns a [ErrProgramKilled] error.
func (p *Program) Kill() {
- p.shutdown(true)
+ p.cancel()
}
// Wait waits/blocks until the underlying Program finished shutting down.
@@ -717,7 +765,11 @@ func (p *Program) Wait() {
}
// shutdown performs operations to free up resources and restore the terminal
-// to its original state.
+// to its original state. It is called once at the end of the program's lifetime.
+//
+// This method should not be called to signal the program to be killed/shutdown.
+// Doing so can lead to race conditions with the eventual call at the program's end.
+// As alternatives, the [Quit] or [Kill] convenience methods should be used instead.
func (p *Program) shutdown(kill bool) {
p.cancel()
@@ -744,19 +796,30 @@ func (p *Program) shutdown(kill bool) {
}
_ = p.restoreTerminalState()
- if !kill {
- p.finished <- struct{}{}
- }
}
// recoverFromPanic recovers from a panic, prints the stack trace, and restores
// the terminal to a usable state.
-func (p *Program) recoverFromPanic() {
- if r := recover(); r != nil {
- p.shutdown(true)
- fmt.Printf("Caught panic:\n\n%s\n\nRestoring terminal...\n\n", r)
- debug.PrintStack()
+func (p *Program) recoverFromPanic(r interface{}) {
+ select {
+ case p.errs <- ErrProgramPanic:
+ default:
}
+ p.shutdown(true) // Ok to call here, p.Run() cannot do it anymore.
+ fmt.Printf("Caught panic:\n\n%s\n\nRestoring terminal...\n\n", r)
+ debug.PrintStack()
+}
+
+// recoverFromGoPanic recovers from a goroutine panic, prints a stack trace and
+// signals for the program to be killed and terminal restored to a usable state.
+func (p *Program) recoverFromGoPanic(r interface{}) {
+ select {
+ case p.errs <- ErrProgramPanic:
+ default:
+ }
+ p.cancel()
+ fmt.Printf("Caught goroutine panic:\n\n%s\n\nRestoring terminal...\n\n", r)
+ debug.PrintStack()
}
// ReleaseTerminal restores the original terminal state and cancels the input
diff --git a/vendor/github.com/charmbracelet/bubbletea/tty.go b/vendor/github.com/charmbracelet/bubbletea/tty.go
index 9490facacb..6812bfc58d 100644
--- a/vendor/github.com/charmbracelet/bubbletea/tty.go
+++ b/vendor/github.com/charmbracelet/bubbletea/tty.go
@@ -52,7 +52,7 @@ func (p *Program) restoreTerminalState() error {
p.renderer.exitAltScreen()
// give the terminal a moment to catch up
- time.Sleep(time.Millisecond * 10) //nolint:gomnd
+ time.Sleep(time.Millisecond * 10) //nolint:mnd
}
}
@@ -109,7 +109,7 @@ func (p *Program) readLoop() {
func (p *Program) waitForReadLoop() {
select {
case <-p.readLoopDone:
- case <-time.After(500 * time.Millisecond): //nolint:gomnd
+ case <-time.After(500 * time.Millisecond): //nolint:mnd
// The read loop hangs, which means the input
// cancelReader's cancel function has returned true even
// though it was not able to cancel the read.
diff --git a/vendor/github.com/charmbracelet/bubbletea/tty_windows.go b/vendor/github.com/charmbracelet/bubbletea/tty_windows.go
index a3a2525bc6..154491a6a1 100644
--- a/vendor/github.com/charmbracelet/bubbletea/tty_windows.go
+++ b/vendor/github.com/charmbracelet/bubbletea/tty_windows.go
@@ -19,7 +19,7 @@ func (p *Program) initInput() (err error) {
p.ttyInput = f
p.previousTtyInputState, err = term.MakeRaw(p.ttyInput.Fd())
if err != nil {
- return err
+ return fmt.Errorf("error making raw: %w", err)
}
// Enable VT input
@@ -38,7 +38,7 @@ func (p *Program) initInput() (err error) {
p.ttyOutput = f
p.previousOutputState, err = term.GetState(f.Fd())
if err != nil {
- return err
+ return fmt.Errorf("error getting state: %w", err)
}
var mode uint32
@@ -51,14 +51,14 @@ func (p *Program) initInput() (err error) {
}
}
- return
+ return nil
}
// Open the Windows equivalent of a TTY.
func openInputTTY() (*os.File, error) {
f, err := os.OpenFile("CONIN$", os.O_RDWR, 0o644)
if err != nil {
- return nil, err
+ return nil, fmt.Errorf("error opening file: %w", err)
}
return f, nil
}
diff --git a/vendor/github.com/charmbracelet/x/ansi/color.go b/vendor/github.com/charmbracelet/x/ansi/color.go
index 77f8a08d1f..09feb97597 100644
--- a/vendor/github.com/charmbracelet/x/ansi/color.go
+++ b/vendor/github.com/charmbracelet/x/ansi/color.go
@@ -2,34 +2,9 @@ package ansi
import (
"image/color"
-)
-// Technically speaking, the 16 basic ANSI colors are arbitrary and can be
-// customized at the terminal level. Given that, we're returning what we feel
-// are good defaults.
-//
-// This could also be a slice, but we use a map to make the mappings very
-// explicit.
-//
-// See: https://www.ditig.com/publications/256-colors-cheat-sheet
-var lowANSI = map[uint32]uint32{
- 0: 0x000000, // black
- 1: 0x800000, // red
- 2: 0x008000, // green
- 3: 0x808000, // yellow
- 4: 0x000080, // blue
- 5: 0x800080, // magenta
- 6: 0x008080, // cyan
- 7: 0xc0c0c0, // white
- 8: 0x808080, // bright black
- 9: 0xff0000, // bright red
- 10: 0x00ff00, // bright green
- 11: 0xffff00, // bright yellow
- 12: 0x0000ff, // bright blue
- 13: 0xff00ff, // bright magenta
- 14: 0x00ffff, // bright cyan
- 15: 0xffffff, // bright white
-}
+ "github.com/lucasb-eyer/go-colorful"
+)
// Color is a color that can be used in a terminal. ANSI (including
// ANSI256) and 24-bit "true colors" fall under this category.
@@ -100,28 +75,33 @@ func (c BasicColor) RGBA() (uint32, uint32, uint32, uint32) {
return 0, 0, 0, 0xffff
}
- r, g, b := ansiToRGB(ansi)
- return toRGBA(r, g, b)
+ return ansiToRGB(byte(ansi)).RGBA()
}
-// ExtendedColor is an ANSI 256 (8-bit) color with a value from 0 to 255.
-type ExtendedColor uint8
+// IndexedColor is an ANSI 256 (8-bit) color with a value from 0 to 255.
+type IndexedColor uint8
-var _ Color = ExtendedColor(0)
+var _ Color = IndexedColor(0)
// RGBA returns the red, green, blue and alpha components of the color. It
// satisfies the color.Color interface.
-func (c ExtendedColor) RGBA() (uint32, uint32, uint32, uint32) {
- r, g, b := ansiToRGB(uint32(c))
- return toRGBA(r, g, b)
+func (c IndexedColor) RGBA() (uint32, uint32, uint32, uint32) {
+ return ansiToRGB(byte(c)).RGBA()
}
+// ExtendedColor is an ANSI 256 (8-bit) color with a value from 0 to 255.
+//
+// Deprecated: use [IndexedColor] instead.
+type ExtendedColor = IndexedColor
+
// TrueColor is a 24-bit color that can be used in the terminal.
// This can be used to represent RGB colors.
//
// For example, the color red can be represented as:
//
// TrueColor(0xff0000)
+//
+// Deprecated: use [RGBColor] instead.
type TrueColor uint32
var _ Color = TrueColor(0)
@@ -133,44 +113,25 @@ func (c TrueColor) RGBA() (uint32, uint32, uint32, uint32) {
return toRGBA(r, g, b)
}
+// RGBColor is a 24-bit color that can be used in the terminal.
+// This can be used to represent RGB colors.
+type RGBColor struct {
+ R uint8
+ G uint8
+ B uint8
+}
+
+// RGBA returns the red, green, blue and alpha components of the color. It
+// satisfies the color.Color interface.
+func (c RGBColor) RGBA() (uint32, uint32, uint32, uint32) {
+ return toRGBA(uint32(c.R), uint32(c.G), uint32(c.B))
+}
+
// ansiToRGB converts an ANSI color to a 24-bit RGB color.
//
// r, g, b := ansiToRGB(57)
-func ansiToRGB(ansi uint32) (uint32, uint32, uint32) {
- // For out-of-range values return black.
- if ansi > 255 {
- return 0, 0, 0
- }
-
- // Low ANSI.
- if ansi < 16 {
- h, ok := lowANSI[ansi]
- if !ok {
- return 0, 0, 0
- }
- r, g, b := hexToRGB(h)
- return r, g, b
- }
-
- // Grays.
- if ansi > 231 {
- s := (ansi-232)*10 + 8
- return s, s, s
- }
-
- // ANSI256.
- n := ansi - 16
- b := n % 6
- g := (n - b) / 6 % 6
- r := (n - b - g*6) / 36 % 6
- for _, v := range []*uint32{&r, &g, &b} {
- if *v > 0 {
- c := *v*40 + 55
- *v = c
- }
- }
-
- return r, g, b
+func ansiToRGB(ansi byte) color.Color {
+ return ansiHex[ansi]
}
// hexToRGB converts a number in hexadecimal format to red, green, and blue
@@ -194,3 +155,630 @@ func toRGBA(r, g, b uint32) (uint32, uint32, uint32, uint32) {
b |= b << 8
return r, g, b, 0xffff
}
+
+//nolint:unused
+func distSq(r1, g1, b1, r2, g2, b2 int) int {
+ return ((r1-r2)*(r1-r2) + (g1-g2)*(g1-g2) + (b1-b2)*(b1-b2))
+}
+
+func to6Cube[T int | float64](v T) int {
+ if v < 48 {
+ return 0
+ }
+ if v < 115 {
+ return 1
+ }
+ return int((v - 35) / 40)
+}
+
+// Convert256 converts a [color.Color], usually a 24-bit color, to xterm(1) 256
+// color palette.
+//
+// xterm provides a 6x6x6 color cube (16 - 231) and 24 greys (232 - 255). We
+// map our RGB color to the closest in the cube, also work out the closest
+// grey, and use the nearest of the two based on the lightness of the color.
+//
+// Note that the xterm has much lower resolution for darker colors (they are
+// not evenly spread out), so our 6 levels are not evenly spread: 0x0, 0x5f
+// (95), 0x87 (135), 0xaf (175), 0xd7 (215) and 0xff (255). Greys are more
+// evenly spread (8, 18, 28 ... 238).
+func Convert256(c color.Color) IndexedColor {
+ // If the color is already an IndexedColor, return it.
+ if i, ok := c.(IndexedColor); ok {
+ return i
+ }
+
+ // Note: this is mostly ported from tmux/colour.c.
+ col, ok := colorful.MakeColor(c)
+ if !ok {
+ return IndexedColor(0)
+ }
+
+ r := col.R * 255
+ g := col.G * 255
+ b := col.B * 255
+
+ q2c := [6]int{0x00, 0x5f, 0x87, 0xaf, 0xd7, 0xff}
+
+ // Map RGB to 6x6x6 cube.
+ qr := to6Cube(r)
+ cr := q2c[qr]
+ qg := to6Cube(g)
+ cg := q2c[qg]
+ qb := to6Cube(b)
+ cb := q2c[qb]
+
+ // If we have hit the color exactly, return early.
+ ci := (36 * qr) + (6 * qg) + qb
+ if cr == int(r) && cg == int(g) && cb == int(b) {
+ return IndexedColor(16 + ci) //nolint:gosec
+ }
+
+ // Work out the closest grey (average of RGB).
+ greyAvg := int(r+g+b) / 3
+ var greyIdx int
+ if greyAvg > 238 {
+ greyIdx = 23
+ } else {
+ greyIdx = (greyAvg - 3) / 10
+ }
+ grey := 8 + (10 * greyIdx)
+
+ // Return the one which is nearer to the original input rgb value
+ // XXX: This is where it differs from tmux's implementation, we prefer the
+ // closer color to the original in terms of light distances rather than the
+ // cube distance.
+ c2 := colorful.Color{R: float64(cr) / 255.0, G: float64(cg) / 255.0, B: float64(cb) / 255.0}
+ g2 := colorful.Color{R: float64(grey) / 255.0, G: float64(grey) / 255.0, B: float64(grey) / 255.0}
+ colorDist := col.DistanceHSLuv(c2)
+ grayDist := col.DistanceHSLuv(g2)
+
+ if colorDist <= grayDist {
+ return IndexedColor(16 + ci) //nolint:gosec
+ }
+ return IndexedColor(232 + greyIdx) //nolint:gosec
+
+ // // Is grey or 6x6x6 color closest?
+ // d := distSq(cr, cg, cb, int(r), int(g), int(b))
+ // if distSq(grey, grey, grey, int(r), int(g), int(b)) < d {
+ // return IndexedColor(232 + greyIdx) //nolint:gosec
+ // }
+ // return IndexedColor(16 + ci) //nolint:gosec
+}
+
+// Convert16 converts a [color.Color] to a 16-color ANSI color. It will first
+// try to find a match in the 256 xterm(1) color palette, and then map that to
+// the 16-color ANSI palette.
+func Convert16(c color.Color) BasicColor {
+ switch c := c.(type) {
+ case BasicColor:
+ // If the color is already a BasicColor, return it.
+ return c
+ case IndexedColor:
+ // If the color is already an IndexedColor, return the corresponding
+ // BasicColor.
+ return ansi256To16[c]
+ default:
+ c256 := Convert256(c)
+ return ansi256To16[c256]
+ }
+}
+
+// RGB values of ANSI colors (0-255).
+var ansiHex = [...]color.RGBA{
+ 0: {R: 0x00, G: 0x00, B: 0x00, A: 0xff}, // "#000000"
+ 1: {R: 0x80, G: 0x00, B: 0x00, A: 0xff}, // "#800000"
+ 2: {R: 0x00, G: 0x80, B: 0x00, A: 0xff}, // "#008000"
+ 3: {R: 0x80, G: 0x80, B: 0x00, A: 0xff}, // "#808000"
+ 4: {R: 0x00, G: 0x00, B: 0x80, A: 0xff}, // "#000080"
+ 5: {R: 0x80, G: 0x00, B: 0x80, A: 0xff}, // "#800080"
+ 6: {R: 0x00, G: 0x80, B: 0x80, A: 0xff}, // "#008080"
+ 7: {R: 0xc0, G: 0xc0, B: 0xc0, A: 0xff}, // "#c0c0c0"
+ 8: {R: 0x80, G: 0x80, B: 0x80, A: 0xff}, // "#808080"
+ 9: {R: 0xff, G: 0x00, B: 0x00, A: 0xff}, // "#ff0000"
+ 10: {R: 0x00, G: 0xff, B: 0x00, A: 0xff}, // "#00ff00"
+ 11: {R: 0xff, G: 0xff, B: 0x00, A: 0xff}, // "#ffff00"
+ 12: {R: 0x00, G: 0x00, B: 0xff, A: 0xff}, // "#0000ff"
+ 13: {R: 0xff, G: 0x00, B: 0xff, A: 0xff}, // "#ff00ff"
+ 14: {R: 0x00, G: 0xff, B: 0xff, A: 0xff}, // "#00ffff"
+ 15: {R: 0xff, G: 0xff, B: 0xff, A: 0xff}, // "#ffffff"
+ 16: {R: 0x00, G: 0x00, B: 0x00, A: 0xff}, // "#000000"
+ 17: {R: 0x00, G: 0x00, B: 0x5f, A: 0xff}, // "#00005f"
+ 18: {R: 0x00, G: 0x00, B: 0x87, A: 0xff}, // "#000087"
+ 19: {R: 0x00, G: 0x00, B: 0xaf, A: 0xff}, // "#0000af"
+ 20: {R: 0x00, G: 0x00, B: 0xd7, A: 0xff}, // "#0000d7"
+ 21: {R: 0x00, G: 0x00, B: 0xff, A: 0xff}, // "#0000ff"
+ 22: {R: 0x00, G: 0x5f, B: 0x00, A: 0xff}, // "#005f00"
+ 23: {R: 0x00, G: 0x5f, B: 0x5f, A: 0xff}, // "#005f5f"
+ 24: {R: 0x00, G: 0x5f, B: 0x87, A: 0xff}, // "#005f87"
+ 25: {R: 0x00, G: 0x5f, B: 0xaf, A: 0xff}, // "#005faf"
+ 26: {R: 0x00, G: 0x5f, B: 0xd7, A: 0xff}, // "#005fd7"
+ 27: {R: 0x00, G: 0x5f, B: 0xff, A: 0xff}, // "#005fff"
+ 28: {R: 0x00, G: 0x87, B: 0x00, A: 0xff}, // "#008700"
+ 29: {R: 0x00, G: 0x87, B: 0x5f, A: 0xff}, // "#00875f"
+ 30: {R: 0x00, G: 0x87, B: 0x87, A: 0xff}, // "#008787"
+ 31: {R: 0x00, G: 0x87, B: 0xaf, A: 0xff}, // "#0087af"
+ 32: {R: 0x00, G: 0x87, B: 0xd7, A: 0xff}, // "#0087d7"
+ 33: {R: 0x00, G: 0x87, B: 0xff, A: 0xff}, // "#0087ff"
+ 34: {R: 0x00, G: 0xaf, B: 0x00, A: 0xff}, // "#00af00"
+ 35: {R: 0x00, G: 0xaf, B: 0x5f, A: 0xff}, // "#00af5f"
+ 36: {R: 0x00, G: 0xaf, B: 0x87, A: 0xff}, // "#00af87"
+ 37: {R: 0x00, G: 0xaf, B: 0xaf, A: 0xff}, // "#00afaf"
+ 38: {R: 0x00, G: 0xaf, B: 0xd7, A: 0xff}, // "#00afd7"
+ 39: {R: 0x00, G: 0xaf, B: 0xff, A: 0xff}, // "#00afff"
+ 40: {R: 0x00, G: 0xd7, B: 0x00, A: 0xff}, // "#00d700"
+ 41: {R: 0x00, G: 0xd7, B: 0x5f, A: 0xff}, // "#00d75f"
+ 42: {R: 0x00, G: 0xd7, B: 0x87, A: 0xff}, // "#00d787"
+ 43: {R: 0x00, G: 0xd7, B: 0xaf, A: 0xff}, // "#00d7af"
+ 44: {R: 0x00, G: 0xd7, B: 0xd7, A: 0xff}, // "#00d7d7"
+ 45: {R: 0x00, G: 0xd7, B: 0xff, A: 0xff}, // "#00d7ff"
+ 46: {R: 0x00, G: 0xff, B: 0x00, A: 0xff}, // "#00ff00"
+ 47: {R: 0x00, G: 0xff, B: 0x5f, A: 0xff}, // "#00ff5f"
+ 48: {R: 0x00, G: 0xff, B: 0x87, A: 0xff}, // "#00ff87"
+ 49: {R: 0x00, G: 0xff, B: 0xaf, A: 0xff}, // "#00ffaf"
+ 50: {R: 0x00, G: 0xff, B: 0xd7, A: 0xff}, // "#00ffd7"
+ 51: {R: 0x00, G: 0xff, B: 0xff, A: 0xff}, // "#00ffff"
+ 52: {R: 0x5f, G: 0x00, B: 0x00, A: 0xff}, // "#5f0000"
+ 53: {R: 0x5f, G: 0x00, B: 0x5f, A: 0xff}, // "#5f005f"
+ 54: {R: 0x5f, G: 0x00, B: 0x87, A: 0xff}, // "#5f0087"
+ 55: {R: 0x5f, G: 0x00, B: 0xaf, A: 0xff}, // "#5f00af"
+ 56: {R: 0x5f, G: 0x00, B: 0xd7, A: 0xff}, // "#5f00d7"
+ 57: {R: 0x5f, G: 0x00, B: 0xff, A: 0xff}, // "#5f00ff"
+ 58: {R: 0x5f, G: 0x5f, B: 0x00, A: 0xff}, // "#5f5f00"
+ 59: {R: 0x5f, G: 0x5f, B: 0x5f, A: 0xff}, // "#5f5f5f"
+ 60: {R: 0x5f, G: 0x5f, B: 0x87, A: 0xff}, // "#5f5f87"
+ 61: {R: 0x5f, G: 0x5f, B: 0xaf, A: 0xff}, // "#5f5faf"
+ 62: {R: 0x5f, G: 0x5f, B: 0xd7, A: 0xff}, // "#5f5fd7"
+ 63: {R: 0x5f, G: 0x5f, B: 0xff, A: 0xff}, // "#5f5fff"
+ 64: {R: 0x5f, G: 0x87, B: 0x00, A: 0xff}, // "#5f8700"
+ 65: {R: 0x5f, G: 0x87, B: 0x5f, A: 0xff}, // "#5f875f"
+ 66: {R: 0x5f, G: 0x87, B: 0x87, A: 0xff}, // "#5f8787"
+ 67: {R: 0x5f, G: 0x87, B: 0xaf, A: 0xff}, // "#5f87af"
+ 68: {R: 0x5f, G: 0x87, B: 0xd7, A: 0xff}, // "#5f87d7"
+ 69: {R: 0x5f, G: 0x87, B: 0xff, A: 0xff}, // "#5f87ff"
+ 70: {R: 0x5f, G: 0xaf, B: 0x00, A: 0xff}, // "#5faf00"
+ 71: {R: 0x5f, G: 0xaf, B: 0x5f, A: 0xff}, // "#5faf5f"
+ 72: {R: 0x5f, G: 0xaf, B: 0x87, A: 0xff}, // "#5faf87"
+ 73: {R: 0x5f, G: 0xaf, B: 0xaf, A: 0xff}, // "#5fafaf"
+ 74: {R: 0x5f, G: 0xaf, B: 0xd7, A: 0xff}, // "#5fafd7"
+ 75: {R: 0x5f, G: 0xaf, B: 0xff, A: 0xff}, // "#5fafff"
+ 76: {R: 0x5f, G: 0xd7, B: 0x00, A: 0xff}, // "#5fd700"
+ 77: {R: 0x5f, G: 0xd7, B: 0x5f, A: 0xff}, // "#5fd75f"
+ 78: {R: 0x5f, G: 0xd7, B: 0x87, A: 0xff}, // "#5fd787"
+ 79: {R: 0x5f, G: 0xd7, B: 0xaf, A: 0xff}, // "#5fd7af"
+ 80: {R: 0x5f, G: 0xd7, B: 0xd7, A: 0xff}, // "#5fd7d7"
+ 81: {R: 0x5f, G: 0xd7, B: 0xff, A: 0xff}, // "#5fd7ff"
+ 82: {R: 0x5f, G: 0xff, B: 0x00, A: 0xff}, // "#5fff00"
+ 83: {R: 0x5f, G: 0xff, B: 0x5f, A: 0xff}, // "#5fff5f"
+ 84: {R: 0x5f, G: 0xff, B: 0x87, A: 0xff}, // "#5fff87"
+ 85: {R: 0x5f, G: 0xff, B: 0xaf, A: 0xff}, // "#5fffaf"
+ 86: {R: 0x5f, G: 0xff, B: 0xd7, A: 0xff}, // "#5fffd7"
+ 87: {R: 0x5f, G: 0xff, B: 0xff, A: 0xff}, // "#5fffff"
+ 88: {R: 0x87, G: 0x00, B: 0x00, A: 0xff}, // "#870000"
+ 89: {R: 0x87, G: 0x00, B: 0x5f, A: 0xff}, // "#87005f"
+ 90: {R: 0x87, G: 0x00, B: 0x87, A: 0xff}, // "#870087"
+ 91: {R: 0x87, G: 0x00, B: 0xaf, A: 0xff}, // "#8700af"
+ 92: {R: 0x87, G: 0x00, B: 0xd7, A: 0xff}, // "#8700d7"
+ 93: {R: 0x87, G: 0x00, B: 0xff, A: 0xff}, // "#8700ff"
+ 94: {R: 0x87, G: 0x5f, B: 0x00, A: 0xff}, // "#875f00"
+ 95: {R: 0x87, G: 0x5f, B: 0x5f, A: 0xff}, // "#875f5f"
+ 96: {R: 0x87, G: 0x5f, B: 0x87, A: 0xff}, // "#875f87"
+ 97: {R: 0x87, G: 0x5f, B: 0xaf, A: 0xff}, // "#875faf"
+ 98: {R: 0x87, G: 0x5f, B: 0xd7, A: 0xff}, // "#875fd7"
+ 99: {R: 0x87, G: 0x5f, B: 0xff, A: 0xff}, // "#875fff"
+ 100: {R: 0x87, G: 0x87, B: 0x00, A: 0xff}, // "#878700"
+ 101: {R: 0x87, G: 0x87, B: 0x5f, A: 0xff}, // "#87875f"
+ 102: {R: 0x87, G: 0x87, B: 0x87, A: 0xff}, // "#878787"
+ 103: {R: 0x87, G: 0x87, B: 0xaf, A: 0xff}, // "#8787af"
+ 104: {R: 0x87, G: 0x87, B: 0xd7, A: 0xff}, // "#8787d7"
+ 105: {R: 0x87, G: 0x87, B: 0xff, A: 0xff}, // "#8787ff"
+ 106: {R: 0x87, G: 0xaf, B: 0x00, A: 0xff}, // "#87af00"
+ 107: {R: 0x87, G: 0xaf, B: 0x5f, A: 0xff}, // "#87af5f"
+ 108: {R: 0x87, G: 0xaf, B: 0x87, A: 0xff}, // "#87af87"
+ 109: {R: 0x87, G: 0xaf, B: 0xaf, A: 0xff}, // "#87afaf"
+ 110: {R: 0x87, G: 0xaf, B: 0xd7, A: 0xff}, // "#87afd7"
+ 111: {R: 0x87, G: 0xaf, B: 0xff, A: 0xff}, // "#87afff"
+ 112: {R: 0x87, G: 0xd7, B: 0x00, A: 0xff}, // "#87d700"
+ 113: {R: 0x87, G: 0xd7, B: 0x5f, A: 0xff}, // "#87d75f"
+ 114: {R: 0x87, G: 0xd7, B: 0x87, A: 0xff}, // "#87d787"
+ 115: {R: 0x87, G: 0xd7, B: 0xaf, A: 0xff}, // "#87d7af"
+ 116: {R: 0x87, G: 0xd7, B: 0xd7, A: 0xff}, // "#87d7d7"
+ 117: {R: 0x87, G: 0xd7, B: 0xff, A: 0xff}, // "#87d7ff"
+ 118: {R: 0x87, G: 0xff, B: 0x00, A: 0xff}, // "#87ff00"
+ 119: {R: 0x87, G: 0xff, B: 0x5f, A: 0xff}, // "#87ff5f"
+ 120: {R: 0x87, G: 0xff, B: 0x87, A: 0xff}, // "#87ff87"
+ 121: {R: 0x87, G: 0xff, B: 0xaf, A: 0xff}, // "#87ffaf"
+ 122: {R: 0x87, G: 0xff, B: 0xd7, A: 0xff}, // "#87ffd7"
+ 123: {R: 0x87, G: 0xff, B: 0xff, A: 0xff}, // "#87ffff"
+ 124: {R: 0xaf, G: 0x00, B: 0x00, A: 0xff}, // "#af0000"
+ 125: {R: 0xaf, G: 0x00, B: 0x5f, A: 0xff}, // "#af005f"
+ 126: {R: 0xaf, G: 0x00, B: 0x87, A: 0xff}, // "#af0087"
+ 127: {R: 0xaf, G: 0x00, B: 0xaf, A: 0xff}, // "#af00af"
+ 128: {R: 0xaf, G: 0x00, B: 0xd7, A: 0xff}, // "#af00d7"
+ 129: {R: 0xaf, G: 0x00, B: 0xff, A: 0xff}, // "#af00ff"
+ 130: {R: 0xaf, G: 0x5f, B: 0x00, A: 0xff}, // "#af5f00"
+ 131: {R: 0xaf, G: 0x5f, B: 0x5f, A: 0xff}, // "#af5f5f"
+ 132: {R: 0xaf, G: 0x5f, B: 0x87, A: 0xff}, // "#af5f87"
+ 133: {R: 0xaf, G: 0x5f, B: 0xaf, A: 0xff}, // "#af5faf"
+ 134: {R: 0xaf, G: 0x5f, B: 0xd7, A: 0xff}, // "#af5fd7"
+ 135: {R: 0xaf, G: 0x5f, B: 0xff, A: 0xff}, // "#af5fff"
+ 136: {R: 0xaf, G: 0x87, B: 0x00, A: 0xff}, // "#af8700"
+ 137: {R: 0xaf, G: 0x87, B: 0x5f, A: 0xff}, // "#af875f"
+ 138: {R: 0xaf, G: 0x87, B: 0x87, A: 0xff}, // "#af8787"
+ 139: {R: 0xaf, G: 0x87, B: 0xaf, A: 0xff}, // "#af87af"
+ 140: {R: 0xaf, G: 0x87, B: 0xd7, A: 0xff}, // "#af87d7"
+ 141: {R: 0xaf, G: 0x87, B: 0xff, A: 0xff}, // "#af87ff"
+ 142: {R: 0xaf, G: 0xaf, B: 0x00, A: 0xff}, // "#afaf00"
+ 143: {R: 0xaf, G: 0xaf, B: 0x5f, A: 0xff}, // "#afaf5f"
+ 144: {R: 0xaf, G: 0xaf, B: 0x87, A: 0xff}, // "#afaf87"
+ 145: {R: 0xaf, G: 0xaf, B: 0xaf, A: 0xff}, // "#afafaf"
+ 146: {R: 0xaf, G: 0xaf, B: 0xd7, A: 0xff}, // "#afafd7"
+ 147: {R: 0xaf, G: 0xaf, B: 0xff, A: 0xff}, // "#afafff"
+ 148: {R: 0xaf, G: 0xd7, B: 0x00, A: 0xff}, // "#afd700"
+ 149: {R: 0xaf, G: 0xd7, B: 0x5f, A: 0xff}, // "#afd75f"
+ 150: {R: 0xaf, G: 0xd7, B: 0x87, A: 0xff}, // "#afd787"
+ 151: {R: 0xaf, G: 0xd7, B: 0xaf, A: 0xff}, // "#afd7af"
+ 152: {R: 0xaf, G: 0xd7, B: 0xd7, A: 0xff}, // "#afd7d7"
+ 153: {R: 0xaf, G: 0xd7, B: 0xff, A: 0xff}, // "#afd7ff"
+ 154: {R: 0xaf, G: 0xff, B: 0x00, A: 0xff}, // "#afff00"
+ 155: {R: 0xaf, G: 0xff, B: 0x5f, A: 0xff}, // "#afff5f"
+ 156: {R: 0xaf, G: 0xff, B: 0x87, A: 0xff}, // "#afff87"
+ 157: {R: 0xaf, G: 0xff, B: 0xaf, A: 0xff}, // "#afffaf"
+ 158: {R: 0xaf, G: 0xff, B: 0xd7, A: 0xff}, // "#afffd7"
+ 159: {R: 0xaf, G: 0xff, B: 0xff, A: 0xff}, // "#afffff"
+ 160: {R: 0xd7, G: 0x00, B: 0x00, A: 0xff}, // "#d70000"
+ 161: {R: 0xd7, G: 0x00, B: 0x5f, A: 0xff}, // "#d7005f"
+ 162: {R: 0xd7, G: 0x00, B: 0x87, A: 0xff}, // "#d70087"
+ 163: {R: 0xd7, G: 0x00, B: 0xaf, A: 0xff}, // "#d700af"
+ 164: {R: 0xd7, G: 0x00, B: 0xd7, A: 0xff}, // "#d700d7"
+ 165: {R: 0xd7, G: 0x00, B: 0xff, A: 0xff}, // "#d700ff"
+ 166: {R: 0xd7, G: 0x5f, B: 0x00, A: 0xff}, // "#d75f00"
+ 167: {R: 0xd7, G: 0x5f, B: 0x5f, A: 0xff}, // "#d75f5f"
+ 168: {R: 0xd7, G: 0x5f, B: 0x87, A: 0xff}, // "#d75f87"
+ 169: {R: 0xd7, G: 0x5f, B: 0xaf, A: 0xff}, // "#d75faf"
+ 170: {R: 0xd7, G: 0x5f, B: 0xd7, A: 0xff}, // "#d75fd7"
+ 171: {R: 0xd7, G: 0x5f, B: 0xff, A: 0xff}, // "#d75fff"
+ 172: {R: 0xd7, G: 0x87, B: 0x00, A: 0xff}, // "#d78700"
+ 173: {R: 0xd7, G: 0x87, B: 0x5f, A: 0xff}, // "#d7875f"
+ 174: {R: 0xd7, G: 0x87, B: 0x87, A: 0xff}, // "#d78787"
+ 175: {R: 0xd7, G: 0x87, B: 0xaf, A: 0xff}, // "#d787af"
+ 176: {R: 0xd7, G: 0x87, B: 0xd7, A: 0xff}, // "#d787d7"
+ 177: {R: 0xd7, G: 0x87, B: 0xff, A: 0xff}, // "#d787ff"
+ 178: {R: 0xd7, G: 0xaf, B: 0x00, A: 0xff}, // "#d7af00"
+ 179: {R: 0xd7, G: 0xaf, B: 0x5f, A: 0xff}, // "#d7af5f"
+ 180: {R: 0xd7, G: 0xaf, B: 0x87, A: 0xff}, // "#d7af87"
+ 181: {R: 0xd7, G: 0xaf, B: 0xaf, A: 0xff}, // "#d7afaf"
+ 182: {R: 0xd7, G: 0xaf, B: 0xd7, A: 0xff}, // "#d7afd7"
+ 183: {R: 0xd7, G: 0xaf, B: 0xff, A: 0xff}, // "#d7afff"
+ 184: {R: 0xd7, G: 0xd7, B: 0x00, A: 0xff}, // "#d7d700"
+ 185: {R: 0xd7, G: 0xd7, B: 0x5f, A: 0xff}, // "#d7d75f"
+ 186: {R: 0xd7, G: 0xd7, B: 0x87, A: 0xff}, // "#d7d787"
+ 187: {R: 0xd7, G: 0xd7, B: 0xaf, A: 0xff}, // "#d7d7af"
+ 188: {R: 0xd7, G: 0xd7, B: 0xd7, A: 0xff}, // "#d7d7d7"
+ 189: {R: 0xd7, G: 0xd7, B: 0xff, A: 0xff}, // "#d7d7ff"
+ 190: {R: 0xd7, G: 0xff, B: 0x00, A: 0xff}, // "#d7ff00"
+ 191: {R: 0xd7, G: 0xff, B: 0x5f, A: 0xff}, // "#d7ff5f"
+ 192: {R: 0xd7, G: 0xff, B: 0x87, A: 0xff}, // "#d7ff87"
+ 193: {R: 0xd7, G: 0xff, B: 0xaf, A: 0xff}, // "#d7ffaf"
+ 194: {R: 0xd7, G: 0xff, B: 0xd7, A: 0xff}, // "#d7ffd7"
+ 195: {R: 0xd7, G: 0xff, B: 0xff, A: 0xff}, // "#d7ffff"
+ 196: {R: 0xff, G: 0x00, B: 0x00, A: 0xff}, // "#ff0000"
+ 197: {R: 0xff, G: 0x00, B: 0x5f, A: 0xff}, // "#ff005f"
+ 198: {R: 0xff, G: 0x00, B: 0x87, A: 0xff}, // "#ff0087"
+ 199: {R: 0xff, G: 0x00, B: 0xaf, A: 0xff}, // "#ff00af"
+ 200: {R: 0xff, G: 0x00, B: 0xd7, A: 0xff}, // "#ff00d7"
+ 201: {R: 0xff, G: 0x00, B: 0xff, A: 0xff}, // "#ff00ff"
+ 202: {R: 0xff, G: 0x5f, B: 0x00, A: 0xff}, // "#ff5f00"
+ 203: {R: 0xff, G: 0x5f, B: 0x5f, A: 0xff}, // "#ff5f5f"
+ 204: {R: 0xff, G: 0x5f, B: 0x87, A: 0xff}, // "#ff5f87"
+ 205: {R: 0xff, G: 0x5f, B: 0xaf, A: 0xff}, // "#ff5faf"
+ 206: {R: 0xff, G: 0x5f, B: 0xd7, A: 0xff}, // "#ff5fd7"
+ 207: {R: 0xff, G: 0x5f, B: 0xff, A: 0xff}, // "#ff5fff"
+ 208: {R: 0xff, G: 0x87, B: 0x00, A: 0xff}, // "#ff8700"
+ 209: {R: 0xff, G: 0x87, B: 0x5f, A: 0xff}, // "#ff875f"
+ 210: {R: 0xff, G: 0x87, B: 0x87, A: 0xff}, // "#ff8787"
+ 211: {R: 0xff, G: 0x87, B: 0xaf, A: 0xff}, // "#ff87af"
+ 212: {R: 0xff, G: 0x87, B: 0xd7, A: 0xff}, // "#ff87d7"
+ 213: {R: 0xff, G: 0x87, B: 0xff, A: 0xff}, // "#ff87ff"
+ 214: {R: 0xff, G: 0xaf, B: 0x00, A: 0xff}, // "#ffaf00"
+ 215: {R: 0xff, G: 0xaf, B: 0x5f, A: 0xff}, // "#ffaf5f"
+ 216: {R: 0xff, G: 0xaf, B: 0x87, A: 0xff}, // "#ffaf87"
+ 217: {R: 0xff, G: 0xaf, B: 0xaf, A: 0xff}, // "#ffafaf"
+ 218: {R: 0xff, G: 0xaf, B: 0xd7, A: 0xff}, // "#ffafd7"
+ 219: {R: 0xff, G: 0xaf, B: 0xff, A: 0xff}, // "#ffafff"
+ 220: {R: 0xff, G: 0xd7, B: 0x00, A: 0xff}, // "#ffd700"
+ 221: {R: 0xff, G: 0xd7, B: 0x5f, A: 0xff}, // "#ffd75f"
+ 222: {R: 0xff, G: 0xd7, B: 0x87, A: 0xff}, // "#ffd787"
+ 223: {R: 0xff, G: 0xd7, B: 0xaf, A: 0xff}, // "#ffd7af"
+ 224: {R: 0xff, G: 0xd7, B: 0xd7, A: 0xff}, // "#ffd7d7"
+ 225: {R: 0xff, G: 0xd7, B: 0xff, A: 0xff}, // "#ffd7ff"
+ 226: {R: 0xff, G: 0xff, B: 0x00, A: 0xff}, // "#ffff00"
+ 227: {R: 0xff, G: 0xff, B: 0x5f, A: 0xff}, // "#ffff5f"
+ 228: {R: 0xff, G: 0xff, B: 0x87, A: 0xff}, // "#ffff87"
+ 229: {R: 0xff, G: 0xff, B: 0xaf, A: 0xff}, // "#ffffaf"
+ 230: {R: 0xff, G: 0xff, B: 0xd7, A: 0xff}, // "#ffffd7"
+ 231: {R: 0xff, G: 0xff, B: 0xff, A: 0xff}, // "#ffffff"
+ 232: {R: 0x08, G: 0x08, B: 0x08, A: 0xff}, // "#080808"
+ 233: {R: 0x12, G: 0x12, B: 0x12, A: 0xff}, // "#121212"
+ 234: {R: 0x1c, G: 0x1c, B: 0x1c, A: 0xff}, // "#1c1c1c"
+ 235: {R: 0x26, G: 0x26, B: 0x26, A: 0xff}, // "#262626"
+ 236: {R: 0x30, G: 0x30, B: 0x30, A: 0xff}, // "#303030"
+ 237: {R: 0x3a, G: 0x3a, B: 0x3a, A: 0xff}, // "#3a3a3a"
+ 238: {R: 0x44, G: 0x44, B: 0x44, A: 0xff}, // "#444444"
+ 239: {R: 0x4e, G: 0x4e, B: 0x4e, A: 0xff}, // "#4e4e4e"
+ 240: {R: 0x58, G: 0x58, B: 0x58, A: 0xff}, // "#585858"
+ 241: {R: 0x62, G: 0x62, B: 0x62, A: 0xff}, // "#626262"
+ 242: {R: 0x6c, G: 0x6c, B: 0x6c, A: 0xff}, // "#6c6c6c"
+ 243: {R: 0x76, G: 0x76, B: 0x76, A: 0xff}, // "#767676"
+ 244: {R: 0x80, G: 0x80, B: 0x80, A: 0xff}, // "#808080"
+ 245: {R: 0x8a, G: 0x8a, B: 0x8a, A: 0xff}, // "#8a8a8a"
+ 246: {R: 0x94, G: 0x94, B: 0x94, A: 0xff}, // "#949494"
+ 247: {R: 0x9e, G: 0x9e, B: 0x9e, A: 0xff}, // "#9e9e9e"
+ 248: {R: 0xa8, G: 0xa8, B: 0xa8, A: 0xff}, // "#a8a8a8"
+ 249: {R: 0xb2, G: 0xb2, B: 0xb2, A: 0xff}, // "#b2b2b2"
+ 250: {R: 0xbc, G: 0xbc, B: 0xbc, A: 0xff}, // "#bcbcbc"
+ 251: {R: 0xc6, G: 0xc6, B: 0xc6, A: 0xff}, // "#c6c6c6"
+ 252: {R: 0xd0, G: 0xd0, B: 0xd0, A: 0xff}, // "#d0d0d0"
+ 253: {R: 0xda, G: 0xda, B: 0xda, A: 0xff}, // "#dadada"
+ 254: {R: 0xe4, G: 0xe4, B: 0xe4, A: 0xff}, // "#e4e4e4"
+ 255: {R: 0xee, G: 0xee, B: 0xee, A: 0xff}, // "#eeeeee"
+}
+
+var ansi256To16 = [...]BasicColor{
+ 0: 0,
+ 1: 1,
+ 2: 2,
+ 3: 3,
+ 4: 4,
+ 5: 5,
+ 6: 6,
+ 7: 7,
+ 8: 8,
+ 9: 9,
+ 10: 10,
+ 11: 11,
+ 12: 12,
+ 13: 13,
+ 14: 14,
+ 15: 15,
+ 16: 0,
+ 17: 4,
+ 18: 4,
+ 19: 4,
+ 20: 12,
+ 21: 12,
+ 22: 2,
+ 23: 6,
+ 24: 4,
+ 25: 4,
+ 26: 12,
+ 27: 12,
+ 28: 2,
+ 29: 2,
+ 30: 6,
+ 31: 4,
+ 32: 12,
+ 33: 12,
+ 34: 2,
+ 35: 2,
+ 36: 2,
+ 37: 6,
+ 38: 12,
+ 39: 12,
+ 40: 10,
+ 41: 10,
+ 42: 10,
+ 43: 10,
+ 44: 14,
+ 45: 12,
+ 46: 10,
+ 47: 10,
+ 48: 10,
+ 49: 10,
+ 50: 10,
+ 51: 14,
+ 52: 1,
+ 53: 5,
+ 54: 4,
+ 55: 4,
+ 56: 12,
+ 57: 12,
+ 58: 3,
+ 59: 8,
+ 60: 4,
+ 61: 4,
+ 62: 12,
+ 63: 12,
+ 64: 2,
+ 65: 2,
+ 66: 6,
+ 67: 4,
+ 68: 12,
+ 69: 12,
+ 70: 2,
+ 71: 2,
+ 72: 2,
+ 73: 6,
+ 74: 12,
+ 75: 12,
+ 76: 10,
+ 77: 10,
+ 78: 10,
+ 79: 10,
+ 80: 14,
+ 81: 12,
+ 82: 10,
+ 83: 10,
+ 84: 10,
+ 85: 10,
+ 86: 10,
+ 87: 14,
+ 88: 1,
+ 89: 1,
+ 90: 5,
+ 91: 4,
+ 92: 12,
+ 93: 12,
+ 94: 1,
+ 95: 1,
+ 96: 5,
+ 97: 4,
+ 98: 12,
+ 99: 12,
+ 100: 3,
+ 101: 3,
+ 102: 8,
+ 103: 4,
+ 104: 12,
+ 105: 12,
+ 106: 2,
+ 107: 2,
+ 108: 2,
+ 109: 6,
+ 110: 12,
+ 111: 12,
+ 112: 10,
+ 113: 10,
+ 114: 10,
+ 115: 10,
+ 116: 14,
+ 117: 12,
+ 118: 10,
+ 119: 10,
+ 120: 10,
+ 121: 10,
+ 122: 10,
+ 123: 14,
+ 124: 1,
+ 125: 1,
+ 126: 1,
+ 127: 5,
+ 128: 12,
+ 129: 12,
+ 130: 1,
+ 131: 1,
+ 132: 1,
+ 133: 5,
+ 134: 12,
+ 135: 12,
+ 136: 1,
+ 137: 1,
+ 138: 1,
+ 139: 5,
+ 140: 12,
+ 141: 12,
+ 142: 3,
+ 143: 3,
+ 144: 3,
+ 145: 7,
+ 146: 12,
+ 147: 12,
+ 148: 10,
+ 149: 10,
+ 150: 10,
+ 151: 10,
+ 152: 14,
+ 153: 12,
+ 154: 10,
+ 155: 10,
+ 156: 10,
+ 157: 10,
+ 158: 10,
+ 159: 14,
+ 160: 9,
+ 161: 9,
+ 162: 9,
+ 163: 9,
+ 164: 13,
+ 165: 12,
+ 166: 9,
+ 167: 9,
+ 168: 9,
+ 169: 9,
+ 170: 13,
+ 171: 12,
+ 172: 9,
+ 173: 9,
+ 174: 9,
+ 175: 9,
+ 176: 13,
+ 177: 12,
+ 178: 9,
+ 179: 9,
+ 180: 9,
+ 181: 9,
+ 182: 13,
+ 183: 12,
+ 184: 11,
+ 185: 11,
+ 186: 11,
+ 187: 11,
+ 188: 7,
+ 189: 12,
+ 190: 10,
+ 191: 10,
+ 192: 10,
+ 193: 10,
+ 194: 10,
+ 195: 14,
+ 196: 9,
+ 197: 9,
+ 198: 9,
+ 199: 9,
+ 200: 9,
+ 201: 13,
+ 202: 9,
+ 203: 9,
+ 204: 9,
+ 205: 9,
+ 206: 9,
+ 207: 13,
+ 208: 9,
+ 209: 9,
+ 210: 9,
+ 211: 9,
+ 212: 9,
+ 213: 13,
+ 214: 9,
+ 215: 9,
+ 216: 9,
+ 217: 9,
+ 218: 9,
+ 219: 13,
+ 220: 9,
+ 221: 9,
+ 222: 9,
+ 223: 9,
+ 224: 9,
+ 225: 13,
+ 226: 11,
+ 227: 11,
+ 228: 11,
+ 229: 11,
+ 230: 11,
+ 231: 15,
+ 232: 0,
+ 233: 0,
+ 234: 0,
+ 235: 0,
+ 236: 0,
+ 237: 0,
+ 238: 8,
+ 239: 8,
+ 240: 8,
+ 241: 8,
+ 242: 8,
+ 243: 8,
+ 244: 7,
+ 245: 7,
+ 246: 7,
+ 247: 7,
+ 248: 7,
+ 249: 7,
+ 250: 15,
+ 251: 15,
+ 252: 15,
+ 253: 15,
+ 254: 15,
+ 255: 15,
+}
diff --git a/vendor/github.com/charmbracelet/x/ansi/cursor.go b/vendor/github.com/charmbracelet/x/ansi/cursor.go
index 0c364d608a..2a74c483cb 100644
--- a/vendor/github.com/charmbracelet/x/ansi/cursor.go
+++ b/vendor/github.com/charmbracelet/x/ansi/cursor.go
@@ -1,6 +1,8 @@
package ansi
-import "strconv"
+import (
+ "strconv"
+)
// SaveCursor (DECSC) is an escape sequence that saves the current cursor
// position.
@@ -260,7 +262,7 @@ func CHA(col int) string {
// See: https://vt100.net/docs/vt510-rm/CUP.html
func CursorPosition(col, row int) string {
if row <= 0 && col <= 0 {
- return HomeCursorPosition
+ return CursorHomePosition
}
var r, c string
diff --git a/vendor/github.com/charmbracelet/x/ansi/finalterm.go b/vendor/github.com/charmbracelet/x/ansi/finalterm.go
new file mode 100644
index 0000000000..2c28347284
--- /dev/null
+++ b/vendor/github.com/charmbracelet/x/ansi/finalterm.go
@@ -0,0 +1,67 @@
+package ansi
+
+import "strings"
+
+// FinalTerm returns an escape sequence that is used for shell integrations.
+// Originally, FinalTerm designed the protocol hence the name.
+//
+// OSC 133 ; Ps ; Pm ST
+// OSC 133 ; Ps ; Pm BEL
+//
+// See: https://iterm2.com/documentation-shell-integration.html
+func FinalTerm(pm ...string) string {
+ return "\x1b]133;" + strings.Join(pm, ";") + "\x07"
+}
+
+// FinalTermPrompt returns an escape sequence that is used for shell
+// integrations prompt marks. This is sent just before the start of the shell
+// prompt.
+//
+// This is an alias for FinalTerm("A").
+func FinalTermPrompt(pm ...string) string {
+ if len(pm) == 0 {
+ return FinalTerm("A")
+ }
+ return FinalTerm(append([]string{"A"}, pm...)...)
+}
+
+// FinalTermCmdStart returns an escape sequence that is used for shell
+// integrations command start marks. This is sent just after the end of the
+// shell prompt, before the user enters a command.
+//
+// This is an alias for FinalTerm("B").
+func FinalTermCmdStart(pm ...string) string {
+ if len(pm) == 0 {
+ return FinalTerm("B")
+ }
+ return FinalTerm(append([]string{"B"}, pm...)...)
+}
+
+// FinalTermCmdExecuted returns an escape sequence that is used for shell
+// integrations command executed marks. This is sent just before the start of
+// the command output.
+//
+// This is an alias for FinalTerm("C").
+func FinalTermCmdExecuted(pm ...string) string {
+ if len(pm) == 0 {
+ return FinalTerm("C")
+ }
+ return FinalTerm(append([]string{"C"}, pm...)...)
+}
+
+// FinalTermCmdFinished returns an escape sequence that is used for shell
+// integrations command finished marks.
+//
+// If the command was sent after
+// [FinalTermCmdStart], it indicates that the command was aborted. If the
+// command was sent after [FinalTermCmdExecuted], it indicates the end of the
+// command output. If neither was sent, [FinalTermCmdFinished] should be
+// ignored.
+//
+// This is an alias for FinalTerm("D").
+func FinalTermCmdFinished(pm ...string) string {
+ if len(pm) == 0 {
+ return FinalTerm("D")
+ }
+ return FinalTerm(append([]string{"D"}, pm...)...)
+}
diff --git a/vendor/github.com/charmbracelet/x/ansi/graphics.go b/vendor/github.com/charmbracelet/x/ansi/graphics.go
index 604fef47cf..b5b1dc82f7 100644
--- a/vendor/github.com/charmbracelet/x/ansi/graphics.go
+++ b/vendor/github.com/charmbracelet/x/ansi/graphics.go
@@ -8,11 +8,49 @@ import (
"image"
"io"
"os"
+ "strconv"
"strings"
"github.com/charmbracelet/x/ansi/kitty"
)
+// SixelGraphics returns a sequence that encodes the given sixel image payload to
+// a DCS sixel sequence.
+//
+// DCS p1; p2; p3; q [sixel payload] ST
+//
+// p1 = pixel aspect ratio, deprecated and replaced by pixel metrics in the payload
+//
+// p2 = This is supposed to be 0 for transparency, but terminals don't seem to
+// to use it properly. Value 0 leaves an unsightly black bar on all terminals
+// I've tried and looks correct with value 1.
+//
+// p3 = Horizontal grid size parameter. Everyone ignores this and uses a fixed grid
+// size, as far as I can tell.
+//
+// See https://shuford.invisible-island.net/all_about_sixels.txt
+func SixelGraphics(p1, p2, p3 int, payload []byte) string {
+ var buf bytes.Buffer
+
+ buf.WriteString("\x1bP")
+ if p1 >= 0 {
+ buf.WriteString(strconv.Itoa(p1))
+ }
+ buf.WriteByte(';')
+ if p2 >= 0 {
+ buf.WriteString(strconv.Itoa(p2))
+ }
+ if p3 > 0 {
+ buf.WriteByte(';')
+ buf.WriteString(strconv.Itoa(p3))
+ }
+ buf.WriteByte('q')
+ buf.Write(payload)
+ buf.WriteString("\x1b\\")
+
+ return buf.String()
+}
+
// KittyGraphics returns a sequence that encodes the given image in the Kitty
// graphics protocol.
//
@@ -43,7 +81,7 @@ var (
KittyGraphicsTempPattern = "tty-graphics-protocol-*"
)
-// WriteKittyGraphics writes an image using the Kitty Graphics protocol with
+// EncodeKittyGraphics writes an image using the Kitty Graphics protocol with
// the given options to w. It chunks the written data if o.Chunk is true.
//
// You can omit m and use nil when rendering an image from a file. In this
@@ -54,7 +92,7 @@ var (
// the terminal.
//
// See https://sw.kovidgoyal.net/kitty/graphics-protocol/
-func WriteKittyGraphics(w io.Writer, m image.Image, o *kitty.Options) error {
+func EncodeKittyGraphics(w io.Writer, m image.Image, o *kitty.Options) error {
if o == nil {
o = &kitty.Options{}
}
diff --git a/vendor/github.com/charmbracelet/x/ansi/mode.go b/vendor/github.com/charmbracelet/x/ansi/mode.go
index 57f3f0a8e3..b57b09cc73 100644
--- a/vendor/github.com/charmbracelet/x/ansi/mode.go
+++ b/vendor/github.com/charmbracelet/x/ansi/mode.go
@@ -243,6 +243,21 @@ const (
RequestInsertReplaceMode = "\x1b[4$p"
)
+// BiDirectional Support Mode (BDSM) is a mode that determines whether the
+// terminal supports bidirectional text. When enabled, the terminal supports
+// bidirectional text and is set to implicit bidirectional mode. When disabled,
+// the terminal does not support bidirectional text.
+//
+// See ECMA-48 7.2.1.
+const (
+ BiDirectionalSupportMode = ANSIMode(8)
+ BDSM = BiDirectionalSupportMode
+
+ SetBiDirectionalSupportMode = "\x1b[8h"
+ ResetBiDirectionalSupportMode = "\x1b[8l"
+ RequestBiDirectionalSupportMode = "\x1b[8$p"
+)
+
// Send Receive Mode (SRM) or Local Echo Mode is a mode that determines whether
// the terminal echoes characters back to the host. When enabled, the terminal
// sends characters to the host as they are typed.
diff --git a/vendor/github.com/charmbracelet/x/ansi/modes.go b/vendor/github.com/charmbracelet/x/ansi/modes.go
index 1bec5bc807..6856d35e48 100644
--- a/vendor/github.com/charmbracelet/x/ansi/modes.go
+++ b/vendor/github.com/charmbracelet/x/ansi/modes.go
@@ -4,12 +4,6 @@ package ansi
// 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 {
diff --git a/vendor/github.com/charmbracelet/x/ansi/sgr.go b/vendor/github.com/charmbracelet/x/ansi/sgr.go
index 1a18c98ef4..c4bd2afad3 100644
--- a/vendor/github.com/charmbracelet/x/ansi/sgr.go
+++ b/vendor/github.com/charmbracelet/x/ansi/sgr.go
@@ -1,7 +1,5 @@
package ansi
-import "strconv"
-
// Select Graphic Rendition (SGR) is a command that sets display attributes.
//
// Default is 0.
@@ -14,20 +12,7 @@ func SelectGraphicRendition(ps ...Attr) string {
return ResetStyle
}
- var s Style
- for _, p := range ps {
- attr, ok := attrStrings[p]
- if ok {
- s = append(s, attr)
- } else {
- if p < 0 {
- p = 0
- }
- s = append(s, strconv.Itoa(p))
- }
- }
-
- return s.String()
+ return NewStyle(ps...).String()
}
// SGR is an alias for [SelectGraphicRendition].
@@ -36,60 +21,59 @@ func SGR(ps ...Attr) string {
}
var attrStrings = map[int]string{
- ResetAttr: "0",
- BoldAttr: "1",
- FaintAttr: "2",
- ItalicAttr: "3",
- UnderlineAttr: "4",
- SlowBlinkAttr: "5",
- RapidBlinkAttr: "6",
- ReverseAttr: "7",
- ConcealAttr: "8",
- StrikethroughAttr: "9",
- NoBoldAttr: "21",
- NormalIntensityAttr: "22",
- NoItalicAttr: "23",
- NoUnderlineAttr: "24",
- NoBlinkAttr: "25",
- NoReverseAttr: "27",
- NoConcealAttr: "28",
- NoStrikethroughAttr: "29",
- BlackForegroundColorAttr: "30",
- RedForegroundColorAttr: "31",
- GreenForegroundColorAttr: "32",
- YellowForegroundColorAttr: "33",
- BlueForegroundColorAttr: "34",
- MagentaForegroundColorAttr: "35",
- CyanForegroundColorAttr: "36",
- WhiteForegroundColorAttr: "37",
- ExtendedForegroundColorAttr: "38",
- DefaultForegroundColorAttr: "39",
- BlackBackgroundColorAttr: "40",
- RedBackgroundColorAttr: "41",
- GreenBackgroundColorAttr: "42",
- YellowBackgroundColorAttr: "43",
- BlueBackgroundColorAttr: "44",
- MagentaBackgroundColorAttr: "45",
- CyanBackgroundColorAttr: "46",
- WhiteBackgroundColorAttr: "47",
- ExtendedBackgroundColorAttr: "48",
- DefaultBackgroundColorAttr: "49",
- ExtendedUnderlineColorAttr: "58",
- DefaultUnderlineColorAttr: "59",
- BrightBlackForegroundColorAttr: "90",
- BrightRedForegroundColorAttr: "91",
- BrightGreenForegroundColorAttr: "92",
- BrightYellowForegroundColorAttr: "93",
- BrightBlueForegroundColorAttr: "94",
- BrightMagentaForegroundColorAttr: "95",
- BrightCyanForegroundColorAttr: "96",
- BrightWhiteForegroundColorAttr: "97",
- BrightBlackBackgroundColorAttr: "100",
- BrightRedBackgroundColorAttr: "101",
- BrightGreenBackgroundColorAttr: "102",
- BrightYellowBackgroundColorAttr: "103",
- BrightBlueBackgroundColorAttr: "104",
- BrightMagentaBackgroundColorAttr: "105",
- BrightCyanBackgroundColorAttr: "106",
- BrightWhiteBackgroundColorAttr: "107",
+ ResetAttr: resetAttr,
+ BoldAttr: boldAttr,
+ FaintAttr: faintAttr,
+ ItalicAttr: italicAttr,
+ UnderlineAttr: underlineAttr,
+ SlowBlinkAttr: slowBlinkAttr,
+ RapidBlinkAttr: rapidBlinkAttr,
+ ReverseAttr: reverseAttr,
+ ConcealAttr: concealAttr,
+ StrikethroughAttr: strikethroughAttr,
+ NormalIntensityAttr: normalIntensityAttr,
+ NoItalicAttr: noItalicAttr,
+ NoUnderlineAttr: noUnderlineAttr,
+ NoBlinkAttr: noBlinkAttr,
+ NoReverseAttr: noReverseAttr,
+ NoConcealAttr: noConcealAttr,
+ NoStrikethroughAttr: noStrikethroughAttr,
+ BlackForegroundColorAttr: blackForegroundColorAttr,
+ RedForegroundColorAttr: redForegroundColorAttr,
+ GreenForegroundColorAttr: greenForegroundColorAttr,
+ YellowForegroundColorAttr: yellowForegroundColorAttr,
+ BlueForegroundColorAttr: blueForegroundColorAttr,
+ MagentaForegroundColorAttr: magentaForegroundColorAttr,
+ CyanForegroundColorAttr: cyanForegroundColorAttr,
+ WhiteForegroundColorAttr: whiteForegroundColorAttr,
+ ExtendedForegroundColorAttr: extendedForegroundColorAttr,
+ DefaultForegroundColorAttr: defaultForegroundColorAttr,
+ BlackBackgroundColorAttr: blackBackgroundColorAttr,
+ RedBackgroundColorAttr: redBackgroundColorAttr,
+ GreenBackgroundColorAttr: greenBackgroundColorAttr,
+ YellowBackgroundColorAttr: yellowBackgroundColorAttr,
+ BlueBackgroundColorAttr: blueBackgroundColorAttr,
+ MagentaBackgroundColorAttr: magentaBackgroundColorAttr,
+ CyanBackgroundColorAttr: cyanBackgroundColorAttr,
+ WhiteBackgroundColorAttr: whiteBackgroundColorAttr,
+ ExtendedBackgroundColorAttr: extendedBackgroundColorAttr,
+ DefaultBackgroundColorAttr: defaultBackgroundColorAttr,
+ ExtendedUnderlineColorAttr: extendedUnderlineColorAttr,
+ DefaultUnderlineColorAttr: defaultUnderlineColorAttr,
+ BrightBlackForegroundColorAttr: brightBlackForegroundColorAttr,
+ BrightRedForegroundColorAttr: brightRedForegroundColorAttr,
+ BrightGreenForegroundColorAttr: brightGreenForegroundColorAttr,
+ BrightYellowForegroundColorAttr: brightYellowForegroundColorAttr,
+ BrightBlueForegroundColorAttr: brightBlueForegroundColorAttr,
+ BrightMagentaForegroundColorAttr: brightMagentaForegroundColorAttr,
+ BrightCyanForegroundColorAttr: brightCyanForegroundColorAttr,
+ BrightWhiteForegroundColorAttr: brightWhiteForegroundColorAttr,
+ BrightBlackBackgroundColorAttr: brightBlackBackgroundColorAttr,
+ BrightRedBackgroundColorAttr: brightRedBackgroundColorAttr,
+ BrightGreenBackgroundColorAttr: brightGreenBackgroundColorAttr,
+ BrightYellowBackgroundColorAttr: brightYellowBackgroundColorAttr,
+ BrightBlueBackgroundColorAttr: brightBlueBackgroundColorAttr,
+ BrightMagentaBackgroundColorAttr: brightMagentaBackgroundColorAttr,
+ BrightCyanBackgroundColorAttr: brightCyanBackgroundColorAttr,
+ BrightWhiteBackgroundColorAttr: brightWhiteBackgroundColorAttr,
}
diff --git a/vendor/github.com/charmbracelet/x/ansi/style.go b/vendor/github.com/charmbracelet/x/ansi/style.go
index 46ddcaa99b..c8663f32b9 100644
--- a/vendor/github.com/charmbracelet/x/ansi/style.go
+++ b/vendor/github.com/charmbracelet/x/ansi/style.go
@@ -17,6 +17,26 @@ type Attr = int
// Style represents an ANSI SGR (Select Graphic Rendition) style.
type Style []string
+// NewStyle returns a new style with the given attributes.
+func NewStyle(attrs ...Attr) Style {
+ if len(attrs) == 0 {
+ return Style{}
+ }
+ s := make(Style, 0, len(attrs))
+ for _, a := range attrs {
+ attr, ok := attrStrings[a]
+ if ok {
+ s = append(s, attr)
+ } else {
+ if a < 0 {
+ a = 0
+ }
+ s = append(s, strconv.Itoa(a))
+ }
+ }
+ return s
+}
+
// String returns the ANSI SGR (Select Graphic Rendition) style sequence for
// the given style.
func (s Style) String() string {
@@ -127,11 +147,6 @@ func (s Style) Strikethrough() Style {
return append(s, strikethroughAttr)
}
-// NoBold appends the no bold style attribute to the style.
-func (s Style) NoBold() Style {
- return append(s, noBoldAttr)
-}
-
// NormalIntensity appends the normal intensity style attribute to the style.
func (s Style) NormalIntensity() Style {
return append(s, normalIntensityAttr)
@@ -236,7 +251,6 @@ const (
ReverseAttr Attr = 7
ConcealAttr Attr = 8
StrikethroughAttr Attr = 9
- NoBoldAttr Attr = 21 // Some terminals treat this as double underline.
NormalIntensityAttr Attr = 22
NoItalicAttr Attr = 23
NoUnderlineAttr Attr = 24
@@ -298,7 +312,6 @@ const (
reverseAttr = "7"
concealAttr = "8"
strikethroughAttr = "9"
- noBoldAttr = "21"
normalIntensityAttr = "22"
noItalicAttr = "23"
noUnderlineAttr = "24"
diff --git a/vendor/github.com/charmbracelet/x/ansi/title.go b/vendor/github.com/charmbracelet/x/ansi/title.go
index 8fd8bf98da..54ef942355 100644
--- a/vendor/github.com/charmbracelet/x/ansi/title.go
+++ b/vendor/github.com/charmbracelet/x/ansi/title.go
@@ -30,3 +30,19 @@ func SetIconName(s string) string {
func SetWindowTitle(s string) string {
return "\x1b]2;" + s + "\x07"
}
+
+// DECSWT is a sequence for setting the window title.
+//
+// This is an alias for [SetWindowTitle]("1;