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

Fixed issue where lineclear sometimes would leave a line of raw text #31

Merged
merged 1 commit into from
Feb 8, 2025
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
23 changes: 23 additions & 0 deletions internal/text/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,29 @@ func (q *Querier[C]) postProcessOutput(newSysMsg models.Message) {

if q.termWidth > 0 {
utils.UpdateMessageTerminalMetadata(q.fullMsg, &q.line, &q.lineCount, q.termWidth)
// Write the details of q to the file determined by the environment variable DEBUG_OUTPUT_FILE
if debugOutputFile := os.Getenv("DEBUG_OUTPUT_FILE"); debugOutputFile != "" {
file, err := os.Create(debugOutputFile)
if err != nil {
ancli.PrintErr(fmt.Sprintf("failed to create debug output file: %v\n", err))
} else {
defer file.Close()
_, err = file.WriteString(debug.IndentedJsonFmt(struct {
FullMessage string
Line string
LineCount int
TermWidth int
}{
FullMessage: q.fullMsg,
Line: q.line,
LineCount: q.lineCount,
TermWidth: q.termWidth,
}))
if err != nil {
ancli.PrintErr(fmt.Sprintf("failed to write to debug output file: %v\n", err))
}
}
}
utils.ClearTermTo(q.termWidth, q.lineCount-1)
} else {
fmt.Println()
Expand Down
3 changes: 3 additions & 0 deletions internal/utils/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ func UpdateMessageTerminalMetadata(msg string, line *string, lineCount *int, ter
for _, line := range newlineSplit {
amNewlines += countNewLines(line, termWidth)
}
if amNewlines == 1 {
amNewlines = 2
}

amNewlineChars := len(newlineSplit)
if amNewlineChars == 1 {
Expand Down
9 changes: 9 additions & 0 deletions internal/utils/print_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ func TestUpdateMessageTerminalMetadata(t *testing.T) {
expectedLine: "66",
expectedLineCount: 5,
},
{
name: "it should not fail on this edge case that I found",
msg: "Debugging involves systematically finding and resolving issues within your code or software. Start by identifying the problem, replicate the error, and use tools like breakpoints or logging to trace the source. Testing changes iteratively helps ensure the fix is successful and doesn't cause new issues.",
// This is not correct, but that's fine, the last line functionality isn't used anywhere anyways
expectedLine: "issues.",
lineCount: 0,
termWidth: 223,
expectedLineCount: 2,
},
}

for _, tc := range testCases {
Expand Down