Conversation
If a field of `struct cellsize` is not signed, it will always be false.
|
|
||
| // failed get pixel size. | ||
| if (cs.cs_xpixel == -1) | ||
| return; |
There was a problem hiding this comment.
Perhaps move this above the allocation of the list. So we do not try to allocate when it is not neccessary
src/testdir/Make_all.mak
Outdated
| test_functions \ | ||
| test_function_lists \ | ||
| test_ga \ | ||
| test_getcellpixels \ |
There was a problem hiding this comment.
I don't think this deserves it's own test. Let's just move the test into test_functions.vim
src/testdir/test_getcellpixels.vim
Outdated
| CheckNotMSWindows | ||
| let cellpixels = getcellpixels() | ||
| call assert_equal(2, len(cellpixels)) | ||
| endfunc |
There was a problem hiding this comment.
Can you add a second test like this:
func Test_getcellpixels_gui()
if has("gui_running")
call assert_equal([], getcellpixels())
endif
endfunc
Co-authored-by: Christian Brabandt <[email protected]>
Co-authored-by: Christian Brabandt <[email protected]>
|
Hmm, the test is failing now. Maybe it wasn't running before. https://github.com/vim/vim/actions/runs/11827146010/job/32954690492?pr=16047#step:18:3418 Failing with Consider how to identify the problem. |
|
I added " Test for getcellwidth()
" Pixel size of a cell is terminal-dependent, so in the test, only the list and size 2 are checked.
func Test_getcellpixels()
" Not yet Windows-compatible
CheckNotMSWindows
call ch_logfile('Test_getcellpixels.log', 'w')
let cellpixels = getcellpixels()
call assert_equal(2, len(cellpixels))
endfuncAs a result, it was found that $ head -n 2 testdir/Test_getcellpixels.log
==== start log session Wed Nov 13 23:47:25 2024 ====
0.000002764 : ioctl(TIOCGWINSZ) failedIn Vim's test, How do we test this? |
|
|
|
Oh, out of habit I was running it inside the Vim terminal. |
|
Sorry, What mean |
|
You can see |
|
Thank you. I maybe understand. |
src/testdir/test_functions.vim
Outdated
|
|
||
| " Test for getcellwidth() |
There was a problem hiding this comment.
| " Test for getcellwidth() | |
| " Test for getcellpixels() |
In particular, the code here is doing the work of passing that info in to the Vim embedded terminal (and is what would end up being tested): int
mch_report_winsize(int fd, int rows, int cols)
{
//...
// calcurate and set tty pixel size
struct cellsize cs;
mch_calc_cell_size(&cs);
ws.ws_xpixel = cols * cs.cs_xpixel;
ws.ws_ypixel = rows * cs.cs_ypixel;
retval = ioctl(tty_fd, TIOCSWINSZ, &ws);
//...
}It gets called to report the window size info to the embedded terminal in Vim's terminal.c ( However, in this situation when the ioctl call in the parent Vim fails, it is going to set You can see this behavior just running Vim within Vim and then calling |
|
@ychin Thank you for your comment.
Using a value of 5x10 when returning the value could lead the user to mistakenly believe that the result was correct, so we thought it would be better to change it to 0x0 (returning [0, 0]). I will fix it. diff --git a/src/os_unix.c b/src/os_unix.c
index 56bbc868d..80ca0ce26 100644
--- a/src/os_unix.c
+++ b/src/os_unix.c
@@ -4434,8 +4434,18 @@ mch_report_winsize(int fd, int rows, int cols)
// calcurate and set tty pixel size
struct cellsize cs;
mch_calc_cell_size(&cs);
- ws.ws_xpixel = cols * cs.cs_xpixel;
- ws.ws_ypixel = rows * cs.cs_ypixel;
+
+ if (cs.cs_xpixel == -1)
+ {
+ // failed get pixel size.
+ ws.ws_xpixel = 0;
+ ws.ws_ypixel = 0;
+ }
+ else
+ {
+ ws.ws_xpixel = cols * cs.cs_xpixel;
+ ws.ws_ypixel = rows * cs.cs_ypixel;
+ }
-
retval = ioctl(tty_fd, TIOCSWINSZ, &ws);
ch_log(NULL, "ioctl(TIOCSWINSZ) %s", retval == 0 ? "success" : "failed"); |
Fixed to return zero when failing to get pixel size.
followup PR of #16004.
list<any>