-
Notifications
You must be signed in to change notification settings - Fork 8
Add Tab option
#24
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 Tab option
#24
Conversation
Codecov Report
@@ Coverage Diff @@
## main #24 +/- ##
==========================================
+ Coverage 75.14% 76.42% +1.27%
==========================================
Files 4 4
Lines 338 369 +31
Branches 50 56 +6
==========================================
+ Hits 254 282 +28
Misses 70 70
- Partials 14 17 +3
Flags with carried forward coverage won't be shown. Click here to find out more.
|
|
Should I add test-case? |
|
I can't test this right now, so if I'm wrong please correct me. I think the way that My theory is based on: https://www.gnu.org/software/coreutils/manual/html_node/General-output-formatting.html |
|
the CI isn't super happy :) |
Will make the necessary corrections. I'm sure my implementation is on the right track. Here's my summary as references: [trimed] To achieve the same output behavior as the ls, I introduced the snippet below, to deal first with,
let separator = match &self.grid.options.filling {
Filling::Spaces(n) if self.grid.options.tab_size <= 0 => " ".to_string().repeat(*n),
Filling::Spaces(n) => {
let tab_count = n / self.grid.options.tab_size;
let remaining_spaces = n % self.grid.options.tab_size;
"\t".repeat(tab_count) + &" ".repeat(remaining_spaces)
}
Filling::Text(s) => s.clone(),
}; |
|
this is GPL code. please don't copy it... |
|
I simply make it as reference for guidance (no copy pasta, since C code need to be written everything by hands) to deal with tab behaviour/defining tab_size and print tab instead of empty space... Maybe you can double check to make sure no licensing issues. :) Edit: Do you mean remove the code in my pull request or remove my previous comment that has GPL code? |
|
The previous comment with gpl code. |
|
i did it for you :) |
tests/test.rs
Outdated
| let mut grid = Grid::new(GridOptions { | ||
| filling: Filling::Spaces(10), | ||
| direction: Direction::LeftToRight, | ||
| tab_size: 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you please add a test with -1 as tab_size ? :)
tests/test.rs
Outdated
| let grid = Grid::new(GridOptions { | ||
| direction: Direction::TopToBottom, | ||
| filling: Filling::Spaces(2), | ||
| ..Default::default() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems that you are changing the usage of the API by making default mandatory.
I would prefer we don't have to do that.
tests/test.rs
Outdated
| let grid = Grid::new(GridOptions { | ||
| direction: Direction::TopToBottom, | ||
| filling: Filling::Spaces(2), | ||
| tab_size: 8, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why does it has to be mandatory ? :)
thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because it is stated in the documentation under the category '--tabsize=cols'.
In contrast, the statement in the coreutils "comment" claims that
"Assuming cursor is at position FROM, indent up to position TO. Use a TAB character instead of two or more spaces whenever possible."
So, there are two times (probably more, for the sake of efficiency) where tabs will be used instead of normal spaces:
- One is that when using
ls, it will replace 8 spaces with 1 tab. - Another is that when using
ls -CF, it will replace 2 spaces with 1 tab
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, I meant in the API :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I think I misread your question earlier. Apologize :)
If I understand correctly, you're asking to keep the original API without modifying it.
I think it can be achieved by introducing a new builder pattern or some sort of struct wrapper. This way, the original API can be maintained while giving users the option to modify the tab size using a stuct wrapper or builder pattern, not directly modify the original API.
That's my thought on how to solve tab's problem. If you have any design in mind, please let me know so that I can write the code and learn. :)
Edit: I will update the new code as I am currently unable to do so.
|
TAB behavior summary:
When I first started working on this, I was confused because I got different results from terminal and texfile when using TAB. That is why I attempted to change the API to ensure everything was in order, but I was mistaken. TAB is interpreted differently on different platforms and text editors, but has the same length on the terminal (8 spaces). |
|
Looks like it's going in the right direction, but I don't think it's quite right. Here's what GNU is doing: Note that the separator is still spaces, but that it's instead the alignment that uses tabs. The tabs should also still be configurable and it should be possible to turn this behaviour off. Does that make sense? |
|
@allaboutevemirolive are you still working on it ? thanks :) |
I believe the issue already fixed by this #27, or am I misunderstand? :) Edit: Minimizing |
Click to expand/collapse
I think I get it. There is a difference in the visual representation for STDIN. |
|
Hye, @sylvestre , I tried to investigate this issue and saw your comment below. I wonder if it is reasonable to integrate |
|
I'll try to set some things straight from my perspective, though @sylvestre might disagree with the final point.
|
|
I see. Thank you for your explanation. So, if it works, I assume that this approach will not require any additional |
|
I think the best way to do this is still in uutils-term-grid, so we don't really have to replace but can write tabs directly instead of writing spaces. If you do it in ls there are weird edge cases such as filenames containing 8 spaces (which should always be printed with spaces). |
|
any update on this PR ? |
|
I will close this PR temporarily. I believe I should go over issue #5396 and this PR to better understand what needs to be addressed, as well as hardcode (for testing purposes) uutils-term-grid to coreutils because this crate is an external dependency. As @tertsdiepraam pointed out, the tab option should be done in uutils-term-grid. I will create a new PR or open this issue later. |

As mentioned in Issue #5396, I have added an option to use
Tabas a separator to fix the problem with thelscommand.