Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add plain flag to diff #197

Merged
merged 5 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion app/cli/cmd/diffs.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package cmd

import (
"regexp"
"fmt"
"plandex/api"
"plandex/auth"
"plandex/lib"
Expand All @@ -9,6 +11,8 @@ import (
"github.com/spf13/cobra"
)

// var plainTextOutput bool

var diffsCmd = &cobra.Command{
Use: "diff",
Aliases: []string{"diffs"},
Expand All @@ -18,6 +22,9 @@ var diffsCmd = &cobra.Command{

func init() {
RootCmd.AddCommand(diffsCmd)

diffsCmd.Flags().BoolVarP(&plainTextOutput, "plain", "p", false, "Output diffs in plain text with no ANSI codes")

}

func diffs(cmd *cobra.Command, args []string) {
Expand All @@ -35,5 +42,15 @@ func diffs(cmd *cobra.Command, args []string) {
return
}

term.PageOutput(diffs)
if plainTextOutput {
fmt.Println(stripANSI(diffs))
} else {
term.PageOutput(diffs)
}
}

// stripANSI removes ANSI escape codes from the input string
func stripANSI(input string) string {
ansiEscape := regexp.MustCompile(`\x1b\[[0-9;]*[a-zA-Z]`)
return ansiEscape.ReplaceAllString(input, "")
}
3 changes: 2 additions & 1 deletion app/cli/term/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var CmdDesc = map[string][2]string{
"tell": {"t", "describe a task, ask a question, or chat"},
"changes": {"ch", "review pending changes in a TUI"},
"diff": {"", "review pending changes in 'git diff' format"},
"diff --plain": {"", "review pending changes in 'git diff' format with no color formatting"},
"summary": {"", "show the latest summary of the current plan"},
// "preview": {"pv", "preview the plan in a branch"},
"apply": {"ap", "apply pending changes to project files"},
Expand Down Expand Up @@ -143,7 +144,7 @@ func PrintCustomHelp(all bool) {
fmt.Fprintln(builder)

color.New(color.Bold, color.BgCyan, color.FgHiWhite).Fprintln(builder, " Changes ")
printCmds(builder, " ", []color.Attribute{color.Bold, ColorHiCyan}, "changes", "diff", "apply", "reject")
printCmds(builder, " ", []color.Attribute{color.Bold, ColorHiCyan}, "changes", "diff", "diff --plain", "apply", "reject")
fmt.Fprintln(builder)

color.New(color.Bold, color.BgCyan, color.FgHiWhite).Fprintln(builder, " Context ")
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ if ! [ -x "$(command -v reflex)" ]; then

# Check if the $GOPATH is empty
if [ -z "$GOPATH" ]; then
echo "Error: $GOPATH is not set. Please set it to continue..." >&2
echo "Error: GOPATH is not set. Please set it to continue..." >&2
exit 1
fi

Expand Down
2 changes: 2 additions & 0 deletions docs/docs/cli-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ Review pending changes in 'git diff' format.
plandex diff
```

`--plain/-p`: Output diffs in plain text with no ANSI codes.

### changes

Review pending changes in a TUI.
Expand Down
4 changes: 3 additions & 1 deletion docs/docs/core-concepts/reviewing-changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ When Plandex has finished with your task, you can review the proposed changes wi
plandex diff
```

Or you can view them in Plandex's changes TUI:
`--plain/-p`: Outputs the conversation in plain text with no ANSI codes.

You can also view them in Plandex's changes TUI:

```bash
plandex changes
Expand Down