Skip to content

Add scientific and programmer calculator - #2090

Open
Sushant215-cpu wants to merge 4 commits into
1jehuang:masterfrom
Sushant215-cpu:sushant215-cpu-scientific-calculator
Open

Sushant215-cpu wants to merge 4 commits into
1jehuang:masterfrom
Sushant215-cpu:sushant215-cpu-scientific-calculator

Conversation

@Sushant215-cpu

Copy link
Copy Markdown

No description provided.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@greptile-apps

greptile-apps Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 2/5

[Medium impact] The PR adds a calculator workflow within the terminal app.

The PR needs fixes before merging because shifts, continued calculations, and history recall can return wrong answers.

Findings

  1. P1 History recall changes saved answers ▶
  2. P1 Large shifts return wrong answers ▶
  3. P1 Continued calculations reuse old expressions ▶
  4. P2 Pasted expressions enter chat ▶
  5. P2 Answers cannot be copied ▶
  6. P2 Angle mode disappears ▶
  7. P2 Small panes go blank ▶
Fix with agent prompt
### Issue 1
crates/jcode-tui/src/tui/app/calculator.rs:196-200
Evaluate `sin(30)` in degrees, switch to radians, then select that calculation with F9 and Enter. History shows `0.5`, but recall copies only the expression and recalculates it in radians, showing about `-0.988`. Save the angle mode with each entry and restore it before recalculating.

### Issue 2
crates/jcode-tui/src/tui/app/calculator.rs:512-513
`parse_shift` checks the size only after `wrapping_shl` has discarded overflowing bits. For example, `/calc 4 << 62` returns `0` instead of rejecting a result outside the supported 53-bit range. Shift in `i128` and check the range before narrowing the result.

### Issue 3
crates/jcode-tui/src/tui/app/calculator.rs:337-339
After evaluation, an operator appends to the original expression rather than the displayed answer. Pressing `2`, `+`, `3`, Enter, `*`, `4`, Enter evaluates `2+3*4` and shows `14`; continuing from the displayed answer `5` should give `20`. When an operator follows a successful evaluation, start the next expression from the saved result.

### Issue 4
crates/jcode-tui/src/tui/app/input.rs:2728-2729
The calculator captures keys but not terminal paste events. With `/calc` open, pasting `1+2` still calls `handle_paste`, which inserts it into the hidden chat draft instead of `CalculatorOverlay.expression`. Route pasted text to the calculator while it is open, without changing the draft.

### Issue 5
crates/jcode-tui/src/tui/ui_overlays.rs:undefined-337
Each frame clears the text-selection snapshot, and the calculator returns before recording a replacement. Its key handler also has no copy action. Add a copy-result shortcut or make the displayed text selectable so users do not have to retype long answers.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

### Issue 6
crates/jcode-tui/src/tui/ui_overlays.rs:520-523
At terminal widths of 49 columns or less, the fixed spacer pushes the entire `DEG`/`RAD` label out of view. Users can still press `d` and run trigonometric calculations, but cannot see which angle mode produced the answer. Reserve space for the angle label before adding padding or truncating the header.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

### Issue 7
crates/jcode-tui/src/tui/ui_overlays.rs:414-415
When the terminal is shorter than eight rows or narrower than 20 columns, this new guard draws nothing. The caller has already cleared the frame and still returns without drawing the chat, so opening or resizing the calculator leaves a blank screen while it continues capturing keys. Show a compact result or a size warning with the close shortcut instead of returning silently.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

Adds a scientific and programmer calculator through /calc.

  • The terminal opens a scientific and programmer calculator from /calc.

Reviews (4) · Last reviewed commit: "Add calculator history and white theme" · Reviewed by Greptile

Comment on lines +386 to +387
let shifted = as_integer(value)?.wrapping_shl(shift as u32);
if shifted.unsigned_abs() > (1u64 << 53) - 1 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Large shifts return wrong answers

parse_shift checks the size only after wrapping_shl has discarded overflowing bits. For example, /calc 4 << 62 returns 0 instead of rejecting a result outside the supported 53-bit range. Shift in i128 and check the range before narrowing the result.

Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/jcode-tui/src/tui/app/calculator.rs
Line: 386-387

Comment:
**Large shifts return wrong answers**

`parse_shift` checks the size only after `wrapping_shl` has discarded overflowing bits. For example, `/calc 4 << 62` returns `0` instead of rejecting a result outside the supported 53-bit range. Shift in `i128` and check the range before narrowing the result.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Comment on lines +233 to +235
overlay.expression.clear();
}
overlay.expression.push_str(text);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Continued calculations reuse old expressions

After evaluation, an operator appends to the original expression rather than the displayed answer. Pressing 2, +, 3, Enter, *, 4, Enter evaluates 2+3*4 and shows 14; continuing from the displayed answer 5 should give 20. When an operator follows a successful evaluation, start the next expression from the saved result.

Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/jcode-tui/src/tui/app/calculator.rs
Line: 233-235

Comment:
**Continued calculations reuse old expressions**

After evaluation, an operator appends to the original expression rather than the displayed answer. Pressing `2`, `+`, `3`, Enter, `*`, `4`, Enter evaluates `2+3*4` and shows `14`; continuing from the displayed answer `5` should give `20`. When an operator follows a successful evaluation, start the next expression from the saved result.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Comment on lines +2728 to +2729
} else if app.calculator_overlay.is_some() {
app.handle_calculator_key(code)?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Pasted expressions enter chat

The calculator captures keys but not terminal paste events. With /calc open, pasting 1+2 still calls handle_paste, which inserts it into the hidden chat draft instead of CalculatorOverlay.expression. Route pasted text to the calculator while it is open, without changing the draft.

Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/jcode-tui/src/tui/app/input.rs
Line: 2728-2729

Comment:
**Pasted expressions enter chat**

The calculator captures keys but not terminal paste events. With `/calc` open, pasting `1+2` still calls `handle_paste`, which inserts it into the hidden chat draft instead of `CalculatorOverlay.expression`. Route pasted text to the calculator while it is open, without changing the draft.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Comment thread crates/jcode-tui/src/tui/ui_overlays.rs Outdated
.iter()
.map(|line| jcode_tui_render::truncate_line_with_ellipsis_to_width(line, inner_width))
.collect::<Vec<_>>();
frame.render_widget(Paragraph::new(lines).block(block), popup);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Answers cannot be copied

Each frame clears the text-selection snapshot, and the calculator returns before recording a replacement. Its key handler also has no copy action. Add a copy-result shortcut or make the displayed text selectable so users do not have to retype long answers.

Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/jcode-tui/src/tui/ui_overlays.rs
Line: 337

Comment:
**Answers cannot be copied**

Each frame clears the text-selection snapshot, and the calculator returns before recording a replacement. Its key handler also has no copy action. Add a copy-result shortcut or make the displayed text selectable so users do not have to retype long answers.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Comment on lines +370 to +373
let header = Line::from(vec![
Span::styled("READY WHEN YOU ARE", Style::default().fg(palette.muted)),
Span::styled(" ", Style::default()),
Span::styled(angle, Style::default().fg(palette.muted)),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Angle mode disappears

At terminal widths of 49 columns or less, the fixed spacer pushes the entire DEG/RAD label out of view. Users can still press d and run trigonometric calculations, but cannot see which angle mode produced the answer. Reserve space for the angle label before adding padding or truncating the header.

Knowledge Base Used: Terminal user interface

Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/jcode-tui/src/tui/ui_overlays.rs
Line: 370-373

Comment:
**Angle mode disappears**

At terminal widths of 49 columns or less, the fixed spacer pushes the entire `DEG`/`RAD` label out of view. Users can still press `d` and run trigonometric calculations, but cannot see which angle mode produced the answer. Reserve space for the angle label before adding padding or truncating the header.

**Knowledge Base Used:** [Terminal user interface](https://app.greptile.com/-/switch-tenant?tenant=solo-systems&next=%2Fcustom-context%2Fknowledge-base%2F1jehuang%2Fjcode%2F-%2Fdocs%2Fterminal-user-interface.md)

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Comment on lines +320 to +321
if width < 20 || height < 8 {
return;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Small panes go blank

When the terminal is shorter than eight rows or narrower than 20 columns, this new guard draws nothing. The caller has already cleared the frame and still returns without drawing the chat, so opening or resizing the calculator leaves a blank screen while it continues capturing keys. Show a compact result or a size warning with the close shortcut instead of returning silently.

Knowledge Base Used: Terminal user interface

Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/jcode-tui/src/tui/ui_overlays.rs
Line: 320-321

Comment:
**Small panes go blank**

When the terminal is shorter than eight rows or narrower than 20 columns, this new guard draws nothing. The caller has already cleared the frame and still returns without drawing the chat, so opening or resizing the calculator leaves a blank screen while it continues capturing keys. Show a compact result or a size warning with the close shortcut instead of returning silently.

**Knowledge Base Used:** [Terminal user interface](https://app.greptile.com/-/switch-tenant?tenant=solo-systems&next=%2Fcustom-context%2Fknowledge-base%2F1jehuang%2Fjcode%2F-%2Fdocs%2Fterminal-user-interface.md)

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Sushant215-cpu and others added 2 commits November 7, 2026 14:52
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Comment on lines +196 to +200
overlay.expression = overlay.history[*index].expression.clone();
overlay.history_visible = false;
overlay.history_query.clear();
overlay.history_cursor = 0;
update_calculator_preview(&mut overlay);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 History recall changes saved answers

Evaluate sin(30) in degrees, switch to radians, then select that calculation with F9 and Enter. History shows 0.5, but recall copies only the expression and recalculates it in radians, showing about -0.988. Save the angle mode with each entry and restore it before recalculating.

Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/jcode-tui/src/tui/app/calculator.rs
Line: 196-200

Comment:
**History recall changes saved answers**

Evaluate `sin(30)` in degrees, switch to radians, then select that calculation with F9 and Enter. History shows `0.5`, but recall copies only the expression and recalculates it in radians, showing about `-0.988`. Save the angle mode with each entry and restore it before recalculating.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant