Skip to content

Commit

Permalink
feat: add wrapping to lines
Browse files Browse the repository at this point in the history
  • Loading branch information
NSEcho committed Feb 20, 2024
1 parent 103f167 commit 16231ec
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
11 changes: 5 additions & 6 deletions cmd/fuzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ var fuzzCmd = &cobra.Command{
sess.On("detached", func(reason frida.SessionDetachReason, crash *frida.Crash) {
// Add sleep here so that we can wait for the context to get cancelled
time.Sleep(3 * time.Second)
defer p.Send(tui.SessionDetached{})
if hasCrashed {
sendStats(p, fmt.Sprintf("Session detached; reason=%s", reason.String()))
out := fmt.Sprintf("fcrash_%s_%s", app, crashSHA256(lastInput))
Expand All @@ -151,8 +152,8 @@ var fuzzCmd = &cobra.Command{
if err != nil {
return err
}
f.WriteString(lastInput)
return nil
_, err = f.WriteString(lastInput)
return err
}()
if err != nil {
sendErr(p, fmt.Sprintf("Could not write crash file: %s", err.Error()))
Expand All @@ -174,7 +175,6 @@ var fuzzCmd = &cobra.Command{
sendStats(p, "Written session file")
}
}
p.Send(tui.SessionDetached{})
})

script, err = sess.CreateScript(scriptContent)
Expand Down Expand Up @@ -214,9 +214,8 @@ var fuzzCmd = &cobra.Command{
}
}()

p.Run()

return nil
_, err = p.Run()
return err
},
}

Expand Down
32 changes: 28 additions & 4 deletions internal/tui/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}

func (m Model) View() string {
b := ""
for i := 0; i < len(m.Base); i++ {
if i != 0 && i%28 == 0 {
b += "\n"
}
b += string(m.Base[i])
}

s := ""
box1 := leftBoxContainer.Render(renderBox(leftBox,
stripOrNA(m.App, 37),
Expand All @@ -104,7 +112,7 @@ func (m Model) View() string {
stripOrNA(m.Method, 37),
stripOrNA(m.UIApp, 37),
stripOrNA(m.Scene, 37),
stripOrNA(m.Base, 37)))
b))

totalRuns := ""
if m.Runs == 0 {
Expand All @@ -113,7 +121,15 @@ func (m Model) View() string {
totalRuns = strconv.Itoa(int(m.Runs))
}

box2 := rightBoxContainer.Render(renderBox(middleBox, m.ctr, totalRuns, m.Timeout, stripOrNA(m.op, 47), stripOrNA(m.ur, 47)))
inp := ""
for i := 0; i < len(m.ur); i++ {
if i != 0 && i%40 == 0 {
inp += "\n"
}
inp += string(m.ur[i])
}

box2 := rightBoxContainer.Render(renderBox(middleBox, m.ctr, totalRuns, m.Timeout, stripOrNA(m.op, 47), inp))

s += lipgloss.JoinHorizontal(lipgloss.Top, box1, box2)

Expand All @@ -134,8 +150,16 @@ func (m Model) View() string {
// Add previous messages in reversed order
reversed := make([]string, len(m.messages))
for i := len(m.messages) - 1; i >= 0; i-- {
if len(m.messages[i]) > 60 {
reversed[len(m.messages)-1-i] = m.messages[i][:57] + "..."
if len(m.messages[i]) > 88 {
// Add code here to wrap it
msg := ""
for j := 0; j < len(m.messages[i]); j++ {
if j != 0 && j%89 == 0 {
msg += "\n"
}
msg += string(m.messages[i][j])
}
reversed[len(m.messages)-1-i] = msg
} else {
reversed[len(m.messages)-1-i] = m.messages[i]
}
Expand Down

0 comments on commit 16231ec

Please sign in to comment.