Skip to content

Commit

Permalink
go fmt/pg up/down
Browse files Browse the repository at this point in the history
  • Loading branch information
JFryy committed Jul 30, 2024
1 parent fa44318 commit 3f5732e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
10 changes: 5 additions & 5 deletions cli/qq.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ func CreateRootCmd() *cobra.Command {
var interactive bool
var version bool
var help bool
var encodings string
for _, t := range codec.SupportedFileTypes {
encodings += t.Ext.String() + ", "
}
encodings = strings.TrimSuffix(encodings, ", ")
var encodings string
for _, t := range codec.SupportedFileTypes {
encodings += t.Ext.String() + ", "
}
encodings = strings.TrimSuffix(encodings, ", ")
v := "v0.2.1"
desc := fmt.Sprintf("qq is a interoperable configuration format transcoder with jq querying ability powered by gojq. qq is multi modal, and can be used as a replacement for jq or be interacted with via a repl with autocomplete and realtime rendering preview for building queries. Supported formats include %s", encodings)
cmd := &cobra.Command{
Expand Down
3 changes: 1 addition & 2 deletions codec/gron.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func setValueJSON(data map[string]interface{}, key string, value interface{}) {
m[part] = value
}
} else {
// fix index assignment nested map: this is needs optimization
// fix index assignment nested map: this is needs optimization
if strings.Contains(part, "[") && strings.Contains(part, "]") {
k := strings.Split(part, "[")[0]
index := parseArrayIndex(part)
Expand Down Expand Up @@ -162,4 +162,3 @@ func parseArrayIndex(part string) int {
index, _ := strconv.Atoi(indexStr)
return index
}

26 changes: 14 additions & 12 deletions internal/tui/interactive.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import (
)

var (
focusedStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("205"))
cursorStyle = focusedStyle
previewStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("178")).Italic(true)
outputStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("36"))
focusedStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("205"))
cursorStyle = focusedStyle
previewStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("178")).Italic(true)
outputStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("36"))
)

type model struct {
Expand All @@ -36,8 +36,8 @@ type model struct {

func newModel(data string) model {
m := model{
inputs: make([]textinput.Model, 1),
viewport: viewport.New(0, 0), // Initial size will be set in Init()
inputs: make([]textinput.Model, 1),
viewport: viewport.New(0, 0),
}

t := textinput.New()
Expand All @@ -49,8 +49,6 @@ func newModel(data string) model {
t.TextStyle = focusedStyle
m.inputs[0] = t
m.jsonInput = string(data)

// Generate jq options based on JSON input
m.jqOptions = generateJqOptions(m.jsonInput)

m.runJqFilter()
Expand Down Expand Up @@ -114,8 +112,8 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case "ctrl+c", "esc":
return m, tea.Quit

case "tab":
// Suggest next jq option
case "tab":
if !m.showingPreview {
m.showingPreview = true
m.currentIndex = 0
Expand All @@ -133,7 +131,6 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.runJqFilter()
return m, nil
}
// put result and quit
m.jsonObj, _ = jsonStrToInterface(m.jsonInput)
return m, tea.Quit

Expand All @@ -145,6 +142,13 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.viewport.LineDown(1)
return m, nil

case "pageup":
m.viewport.ViewUp()
return m, nil
case "pagedown":
m.viewport.ViewDown()
return m, nil

default:
if m.showingPreview {
m.showingPreview = false
Expand Down Expand Up @@ -234,7 +238,6 @@ func (m *model) runJqFilter() {
}

func (m *model) updateViewportContent() {
// Ensure jqOutput is pretty formatted
prettyOutput, err := codec.PrettyFormat(m.jqOutput, codec.JSON, false)
if err != nil {
m.viewport.SetContent(fmt.Sprintf("Error formatting output: %s", err))
Expand Down Expand Up @@ -283,4 +286,3 @@ func Interact(s string) {
}
printOutput(m.(model))
}

0 comments on commit 3f5732e

Please sign in to comment.