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

fix: force tabs to fixed size #37

Merged
merged 4 commits into from
Jun 29, 2024
Merged

Conversation

firestack
Copy link
Collaborator

@firestack firestack commented Apr 22, 2024

This is a simple fix for #2 Rendering Tab Characters. I think this could be made smarter in the future (i.e., making the tab replacement characters configurable. Potentially getting the tab size from the terminal) but this fixes the immediate issue.

I added a stub of tests, but I'm not confident that I've done this correctly, so I figure we can chat about it.

I also noticed I could try doing this logic in Viewport::draw_text instead, but I wasn't sure if that'd be desired.


Partially Addresses: #2

@firestack firestack force-pushed the kf/jj/ukzomnvtpnvu branch from 90ecc5d to 2007768 Compare April 24, 2024 11:17
@firestack
Copy link
Collaborator Author

I ran CI in my repo and I believe I fixed the previous failure

@arxanas
Copy link
Owner

arxanas commented Apr 27, 2024

Thanks!

  • It looks like this doesn't render the tab character in gray, like we do with the newline character. We definitely want to portray a semantic difference between literal characters and control characters that we added custom renderings for. (Color is suboptimal as the sole indicator, but the terminal doesn't give us a lot of accessibility options here.)
  • Can we actually combine the rendering of newlines and tabs into the same function, and render them both in gray as their specified replacement string?
    • We would change the behavior for newlines to render them anywhere on the line, not just at the very end. This would handle callers passing multiple newline characters at the end of the line for whatever reason, or cases where newlines are not the selection boundary (I experimented with word diff once, which might have run into this), or maybe cases with string literals with embedded control characters. Currently I expect that it would affect no consumers, though.
    • Rather than print each Span in a loop yourself, it's probably best to collect them into a container (Line?) and use the normal printing functions to print that container.

Copy link
Owner

@arxanas arxanas left a comment

Choose a reason for hiding this comment

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

Putting back in your queue for now.

@firestack
Copy link
Collaborator Author

  • We would change the behavior for newlines to render them anywhere on the line, not just at the very end. This would handle callers passing multiple newline characters at the end of the line for whatever reason, or cases where newlines are not the selection boundary

One question, when would multiple newlines appear in a single line?.. A line, by definition, shouldn't contain multiple newlines, correct?

@firestack
Copy link
Collaborator Author

  • We would change the behavior for newlines to render them anywhere on the line, not just at the very end. This would handle callers passing multiple newline characters at the end of the line for whatever reason, or cases where newlines are not the selection boundary

One question, when would multiple newlines appear in a single line?.. A line, by definition, shouldn't contain multiple newlines, correct?

The way I've tried implementing this doesn't actually care, so this will work out anyway if it does happen 👍🏻

@firestack
Copy link
Collaborator Author

I think I've got something that addresses feedback! Cleaning things up and then will push 👍🏻

@firestack firestack marked this pull request as draft May 24, 2024 03:57
@firestack firestack force-pushed the kf/jj/ukzomnvtpnvu branch 4 times, most recently from db2e9bd to cb0232e Compare May 25, 2024 21:19
src/ui.rs Show resolved Hide resolved
src/ui.rs Outdated Show resolved Hide resolved
src/ui.rs Outdated Show resolved Hide resolved
src/ui.rs Outdated Show resolved Hide resolved
tests/test_scm_record.rs Outdated Show resolved Hide resolved
src/render.rs Outdated Show resolved Hide resolved
src/ui.rs Outdated Show resolved Hide resolved
src/ui.rs Outdated Show resolved Hide resolved
src/ui.rs Outdated Show resolved Hide resolved
@firestack firestack marked this pull request as ready for review May 25, 2024 21:30
@firestack firestack requested a review from arxanas May 25, 2024 21:30
@firestack firestack force-pushed the kf/jj/ukzomnvtpnvu branch from cb0232e to 3a453f0 Compare May 27, 2024 17:58
Copy link
Owner

@arxanas arxanas left a comment

Choose a reason for hiding this comment

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

Thanks for fixing this! I think there's just a few minor points.

src/ui.rs Outdated Show resolved Hide resolved
src/ui.rs Outdated Show resolved Hide resolved
src/ui.rs Outdated Show resolved Hide resolved
src/ui.rs Outdated Show resolved Hide resolved
tests/test_scm_record.rs Outdated Show resolved Hide resolved
src/render.rs Outdated Show resolved Hide resolved
@arxanas
Copy link
Owner

arxanas commented Jun 15, 2024

I queued #46 for merge; you might have to rebase/update tests.

@firestack firestack force-pushed the kf/jj/ukzomnvtpnvu branch 2 times, most recently from 000a234 to 9a0bfe4 Compare June 16, 2024 00:02
@firestack firestack requested a review from arxanas June 16, 2024 00:07
Copy link
Owner

@arxanas arxanas left a comment

Choose a reason for hiding this comment

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

Looks good to me, just one nit!

src/render.rs Outdated Show resolved Hide resolved
@firestack firestack force-pushed the kf/jj/ukzomnvtpnvu branch 3 times, most recently from e68fd27 to 4f66b1e Compare June 16, 2024 18:05
@firestack firestack requested a review from arxanas June 27, 2024 11:50
Copy link
Owner

@arxanas arxanas left a comment

Choose a reason for hiding this comment

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

@firestack sorry for the delay, I meant to do this myself but haven't had time: can you check cargo clippy and cargo test and make sure they pass on each of the commits in the stack individually? IIRC two of them should be squashed

@firestack
Copy link
Collaborator Author

firestack commented Jun 28, 2024

can you check cargo clippy and cargo test and make sure they pass on each of the commits in the stack individually?

@arxanas Just ran both(at every commit in the stack, I wish JJ run worked lol), and didn't get any failures.

IIRC two of them should be squashed

I think it was handled in this? #37 (comment)

firestack and others added 2 commits June 29, 2024 11:44
…lines

Update src/ui.rs

Co-authored-by: Waleed Khan <me@waleedkhan.name>
@arxanas arxanas force-pushed the kf/jj/ukzomnvtpnvu branch from 4f66b1e to 1b75518 Compare June 29, 2024 18:45
@arxanas arxanas enabled auto-merge (rebase) June 29, 2024 18:45
@arxanas arxanas merged commit a68d8ea into arxanas:main Jun 29, 2024
2 checks passed
@arxanas
Copy link
Owner

arxanas commented Jun 29, 2024

This was the lint error I was talking about on the bottom of the stack:

    Checking scm-record v0.3.0 (/Users/waleed/Workspace/scm-record)
error: method `draw_line` is never used
   --> src/render.rs:527:12
    |
368 | impl<'a, ComponentId: Clone + Debug + Eq + Hash> Viewport<'a, ComponentId> {
    | -------------------------------------------------------------------------- method in this implementation
...
527 |     pub fn draw_line(&mut self, x: isize, y: isize, line: &Line) -> Rect {
    |            ^^^^^^^^^
    |
    = note: `-D dead-code` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(dead_code)]`

error: could not compile `scm-record` (lib) due to 1 previous error
warning: build failed, waiting for other jobs to finish...
error: could not compile `scm-record` (lib test) due to 1 previous error

I squashed together the bottom two commits to fix this. Thanks for implementing this!

@firestack
Copy link
Collaborator Author

This was the lint error I was talking about on the bottom of the stack:

    Checking scm-record v0.3.0 (/Users/waleed/Workspace/scm-record)
error: method `draw_line` is never used
   --> src/render.rs:527:12
    |
368 | impl<'a, ComponentId: Clone + Debug + Eq + Hash> Viewport<'a, ComponentId> {
    | -------------------------------------------------------------------------- method in this implementation
...
527 |     pub fn draw_line(&mut self, x: isize, y: isize, line: &Line) -> Rect {
    |            ^^^^^^^^^
    |
    = note: `-D dead-code` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(dead_code)]`

error: could not compile `scm-record` (lib) due to 1 previous error
warning: build failed, waiting for other jobs to finish...
error: could not compile `scm-record` (lib test) due to 1 previous error

I squashed together the bottom two commits to fix this. Thanks for implementing this!

oh sorry! I swear I tried to find them😅!
I have a bunch of my own clippy lints in my global config which makes it hard to see these sometimes but I had sworn that it had no failures.

@arxanas
Copy link
Owner

arxanas commented Jun 29, 2024

@firestack It's no trouble 😊. Can I interest you in git test? 😉

This is my config for this project:

$ git test run -c help  # HACK
The test command alias "help" was not defined.

To create it, run: git config branchless.test.alias.help <command>
Or use the -x/--exec flag instead to run a test command without first creating an alias.

These are the currently-configured command aliases:
• branchless.test.alias.lint = "cargo clippy --workspace --all-targets -- -D warnings"
• branchless.test.alias.fmt-fix = "cargo +nightly fmt --all"
• branchless.test.alias.test = "cargo nextest run --workspace --no-fail-fast"

$ git test run -c lint 'stack()'
...

which is how I checked for lint+test failures.

(Ideally, GitHub would just be better at doing stacked PRs, or make it easier to run actions on each commit in a PR, and we'd have CI per commit and it would be surfaced in a useful manner.)

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.

2 participants