Skip to content

Commit

Permalink
Add HTTP headers parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkunin committed Mar 23, 2024
1 parent 8f35139 commit eabbebb
Show file tree
Hide file tree
Showing 7 changed files with 420 additions and 171 deletions.
11 changes: 11 additions & 0 deletions internal/jsonx/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ import (
jsonpath "github.com/antonmedv/fx/path"
)

type NodeKind uint8

const (
Unspecified NodeKind = iota
HttpStatus
HttpHeader
HttpHeaderContinuation
HttpBlank
)

type Node struct {
Prev, Next, End *Node
directParent *Node
Expand All @@ -19,6 +29,7 @@ type Node struct {
ChunkEnd *Node
Comma bool
Index int
Kind NodeKind
}

// append ands a node as a child to the current node (body of {...} or [...]).
Expand Down
4 changes: 2 additions & 2 deletions internal/jsonx/wrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

func DropWrapAll(n *Node) {
for n != nil {
if n.Value != nil && n.Value[0] == '"' {
if n.Value != nil && (n.Value[0] == '"' || n.Kind == HttpHeader) {
n.dropChunks()
}
if n.IsCollapsed() {
Expand All @@ -24,7 +24,7 @@ func WrapAll(n *Node, termWidth int) {
return
}
for n != nil {
if n.Value != nil && n.Value[0] == '"' {
if n.Value != nil && (n.Value[0] == '"' || n.Kind == HttpHeader) {
n.dropChunks()
lines, count := doWrap(n, termWidth)
if count > 1 {
Expand Down
298 changes: 167 additions & 131 deletions internal/theme/theme.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,20 @@ import (
)

type Theme struct {
Cursor Color
Syntax Color
Preview Color
StatusBar Color
Search Color
Key Color
String Color
Null Color
Boolean Color
Number Color
Size Color
Cursor Color
Syntax Color
Preview Color
StatusBar Color
Search Color
Key Color
String Color
Null Color
Boolean Color
Number Color
Size Color
HttpStatus Color
HttpHeaderName Color
HttpHeaderValue Color
}

type Color func(s []byte) []byte
Expand Down Expand Up @@ -119,150 +122,183 @@ var (

var themes = map[string]Theme{
"0": {
Cursor: defaultCursor,
Syntax: noColor,
Preview: noColor,
StatusBar: noColor,
Search: defaultSearch,
Key: noColor,
String: noColor,
Null: noColor,
Boolean: noColor,
Number: noColor,
Size: noColor,
Cursor: defaultCursor,
Syntax: noColor,
Preview: noColor,
StatusBar: noColor,
Search: defaultSearch,
Key: noColor,
String: noColor,
Null: noColor,
Boolean: noColor,
Number: noColor,
Size: noColor,
HttpStatus: noColor,
HttpHeaderName: noColor,
HttpHeaderValue: noColor,
},
"1": {
Cursor: defaultCursor,
Syntax: noColor,
Preview: defaultPreview,
StatusBar: defaultStatusBar,
Search: defaultSearch,
Key: boldFg("4"),
String: fg("2"),
Null: defaultNull,
Boolean: fg("5"),
Number: fg("6"),
Size: defaultSize,
Cursor: defaultCursor,
Syntax: noColor,
Preview: defaultPreview,
StatusBar: defaultStatusBar,
Search: defaultSearch,
Key: boldFg("4"),
String: fg("2"),
Null: defaultNull,
Boolean: fg("5"),
Number: fg("6"),
Size: defaultSize,
HttpStatus: fg("2"),
HttpHeaderName: boldFg("4"),
HttpHeaderValue: fg("2"),
},
"2": {
Cursor: defaultCursor,
Syntax: noColor,
Preview: defaultPreview,
StatusBar: defaultStatusBar,
Search: defaultSearch,
Key: fg("2"),
String: fg("4"),
Null: defaultNull,
Boolean: fg("5"),
Number: fg("6"),
Size: defaultSize,
Cursor: defaultCursor,
Syntax: noColor,
Preview: defaultPreview,
StatusBar: defaultStatusBar,
Search: defaultSearch,
Key: fg("2"),
String: fg("4"),
Null: defaultNull,
Boolean: fg("5"),
Number: fg("6"),
Size: defaultSize,
HttpStatus: fg("4"),
HttpHeaderName: fg("2"),
HttpHeaderValue: fg("4"),
},
"3": {
Cursor: defaultCursor,
Syntax: noColor,
Preview: defaultPreview,
StatusBar: defaultStatusBar,
Search: defaultSearch,
Key: fg("13"),
String: fg("11"),
Null: defaultNull,
Boolean: fg("1"),
Number: fg("14"),
Size: defaultSize,
Cursor: defaultCursor,
Syntax: noColor,
Preview: defaultPreview,
StatusBar: defaultStatusBar,
Search: defaultSearch,
Key: fg("13"),
String: fg("11"),
Null: defaultNull,
Boolean: fg("1"),
Number: fg("14"),
Size: defaultSize,
HttpStatus: fg("11"),
HttpHeaderName: fg("13"),
HttpHeaderValue: fg("11"),
},
"4": {
Cursor: defaultCursor,
Syntax: noColor,
Preview: defaultPreview,
StatusBar: defaultStatusBar,
Search: defaultSearch,
Key: fg("#00F5D4"),
String: fg("#00BBF9"),
Null: defaultNull,
Boolean: fg("#F15BB5"),
Number: fg("#9B5DE5"),
Size: defaultSize,
Cursor: defaultCursor,
Syntax: noColor,
Preview: defaultPreview,
StatusBar: defaultStatusBar,
Search: defaultSearch,
Key: fg("#00F5D4"),
String: fg("#00BBF9"),
Null: defaultNull,
Boolean: fg("#F15BB5"),
Number: fg("#9B5DE5"),
Size: defaultSize,
HttpStatus: fg("#00BBF9"),
HttpHeaderName: fg("#00F5D4"),
HttpHeaderValue: fg("#00BBF9"),
},
"5": {
Cursor: defaultCursor,
Syntax: noColor,
Preview: defaultPreview,
StatusBar: defaultStatusBar,
Search: defaultSearch,
Key: fg("#faf0ca"),
String: fg("#f4d35e"),
Null: defaultNull,
Boolean: fg("#ee964b"),
Number: fg("#ee964b"),
Size: defaultSize,
Cursor: defaultCursor,
Syntax: noColor,
Preview: defaultPreview,
StatusBar: defaultStatusBar,
Search: defaultSearch,
Key: fg("#faf0ca"),
String: fg("#f4d35e"),
Null: defaultNull,
Boolean: fg("#ee964b"),
Number: fg("#ee964b"),
Size: defaultSize,
HttpStatus: fg("#f4d35e"),
HttpHeaderName: fg("#faf0ca"),
HttpHeaderValue: fg("#f4d35e"),
},
"6": {
Cursor: defaultCursor,
Syntax: noColor,
Preview: defaultPreview,
StatusBar: defaultStatusBar,
Search: defaultSearch,
Key: fg("#4D96FF"),
String: fg("#6BCB77"),
Null: defaultNull,
Boolean: fg("#FF6B6B"),
Number: fg("#FFD93D"),
Size: defaultSize,
Cursor: defaultCursor,
Syntax: noColor,
Preview: defaultPreview,
StatusBar: defaultStatusBar,
Search: defaultSearch,
Key: fg("#4D96FF"),
String: fg("#6BCB77"),
Null: defaultNull,
Boolean: fg("#FF6B6B"),
Number: fg("#FFD93D"),
Size: defaultSize,
HttpStatus: fg("#6BCB77"),
HttpHeaderName: fg("#4D96FF"),
HttpHeaderValue: fg("#6BCB77"),
},
"7": {
Cursor: defaultCursor,
Syntax: noColor,
Preview: defaultPreview,
StatusBar: defaultStatusBar,
Search: defaultSearch,
Key: boldFg("42"),
String: boldFg("213"),
Null: defaultNull,
Boolean: boldFg("201"),
Number: boldFg("201"),
Size: defaultSize,
Cursor: defaultCursor,
Syntax: noColor,
Preview: defaultPreview,
StatusBar: defaultStatusBar,
Search: defaultSearch,
Key: boldFg("42"),
String: boldFg("213"),
Null: defaultNull,
Boolean: boldFg("201"),
Number: boldFg("201"),
Size: defaultSize,
HttpStatus: boldFg("213"),
HttpHeaderName: boldFg("42"),
HttpHeaderValue: boldFg("213"),
},
"8": {
Cursor: defaultCursor,
Syntax: noColor,
Preview: defaultPreview,
StatusBar: defaultStatusBar,
Search: defaultSearch,
Key: boldFg("51"),
String: fg("195"),
Null: defaultNull,
Boolean: fg("50"),
Number: fg("123"),
Size: defaultSize,
Cursor: defaultCursor,
Syntax: noColor,
Preview: defaultPreview,
StatusBar: defaultStatusBar,
Search: defaultSearch,
Key: boldFg("51"),
String: fg("195"),
Null: defaultNull,
Boolean: fg("50"),
Number: fg("123"),
Size: defaultSize,
HttpStatus: fg("195"),
HttpHeaderName: boldFg("51"),
HttpHeaderValue: fg("195"),
},
"🔵": {
Cursor: toColor(lipgloss.NewStyle().
Foreground(lipgloss.Color("15")).
Background(lipgloss.Color("33")).
Render),
Syntax: boldFg("33"),
Preview: defaultPreview,
StatusBar: defaultStatusBar,
Search: defaultSearch,
Key: fg("33"),
String: noColor,
Null: noColor,
Boolean: noColor,
Number: noColor,
Size: defaultSize,
Syntax: boldFg("33"),
Preview: defaultPreview,
StatusBar: defaultStatusBar,
Search: defaultSearch,
Key: fg("33"),
String: noColor,
Null: noColor,
Boolean: noColor,
Number: noColor,
Size: defaultSize,
HttpStatus: noColor,
HttpHeaderName: fg("33"),
HttpHeaderValue: noColor,
},
"🥝": {
Cursor: defaultCursor,
Syntax: fg("179"),
Preview: defaultPreview,
StatusBar: defaultStatusBar,
Search: defaultSearch,
Key: boldFg("154"),
String: fg("82"),
Null: fg("230"),
Boolean: fg("226"),
Number: fg("226"),
Size: defaultSize,
Cursor: defaultCursor,
Syntax: fg("179"),
Preview: defaultPreview,
StatusBar: defaultStatusBar,
Search: defaultSearch,
Key: boldFg("154"),
String: fg("82"),
Null: fg("230"),
Boolean: fg("226"),
Number: fg("226"),
Size: defaultSize,
HttpStatus: fg("82"),
HttpHeaderName: boldFg("154"),
HttpHeaderValue: fg("82"),
},
}

Expand Down
Loading

0 comments on commit eabbebb

Please sign in to comment.