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 definitions for Wincon.GetConsoleScreenBufferInfo() #1190
Conversation
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.
Added a few comments inline. Can you add a test case to Kernel32ConsoleTest
exercising this method?
|
||
@Override | ||
public String toString() { | ||
return String.format("COORD[%s,%s]", X, Y); |
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.
X and Y are primitives, so should the %s
be %d
here?
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.
When I wrote this, I thought surely Java was more efficient knowing it had an integer value here. In fact, the way you have it simply invokes Short.toString(X)
while the %d
version goes through a bunch of conversions to BigInteger
, extracting a long
from that, and finally calling Long.toString()
, although I don't know if any of those steps are eventually optimized out...
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.
My personal rule is to avoid %d
because you will unexpectedly get different results depending on Locale.getDefault()
.
e.g.
Locale.setDefault(new Locale("ar"))
def s = String.format("%d,%d,%d", 1, 2, 3)
System.out.println(s)
// prints "١,٢,٣" (and not "1,2,3" as one would expect)
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.
Don't ask me how I know this. Those are many ours of my life I won't get back. ٣
doesn't match \d
and can't be parsed as number, and Windows CMD won't print it because it's not ASCII either, and the issue will only affect users in certain with uncommon rare locales so you won't ever be able to reproduce the issue with a debugger on a typical developer machine that's set on en_US
.
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.
Sounds reasonable!
|
||
@Override | ||
public String toString() { | ||
return String.format("SMALL_RECT[%s,%s,%s,%s]", Left, Top, Right, Bottom); |
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.
Same comment here on %d
vs %s
. Also just my opinion, but while (X,Y) is standard for coordinates, I'm not sure there's a generally accepted standard order of values for a "rectangle". I've seen (left,top,width,height) for example, so this would be more clear with L=%d,T=%d,R=%d,B=%d
or possibly combining left/top and right/bottom as a coordinate pair (%d,%d)(%d,%d)
.
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.
I just added toString()
for the sake of completeness. I don't actually use them in my code. I'm happy to make any changes you see fit.
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.
I'm just offering suggestions!
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.
Sure thing. I switched to ()
because the other classes use that as well.
Is it ok to just have a dummy test in Because we'll need a |
I've added a |
…teractive console context
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.
Thank you looks sane to me. I left one inline comment about a potential optimisation.
Before merging, please add an entry to the features section of the CHANGES.md
file. Please follow the examples set in the existing entries. Thank you.
|
||
public COORD dwSize; | ||
public COORD dwCursorPosition; | ||
public WORD wAttributes; |
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.
COORD
and SMALL_RECT
both map to java shorts. It would be an option to also map wAttributes to java short. If I read the documentation correctly it is a set of shorts ORed together, so the sign is not relevant.
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.
I thought similar when I looked at it, but decided the plain structure interpretation (dwSize.X
and dwSize.Y
) would be preferred over an int
with bitshifting/bitmasking getters to access the underlying values. About the only thing I might change in this mapping is that wAttributes
as a short
would more directly map to the WINAPI enum
values it represents.
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.
Er... that's what you said. I misread it the first time.
I'm adding bindings for a few additional Windows Console API functions. Please don't merge anything else, so we can all do it in one pull later on. |
* ReadConsoleInput * GetNumberOfConsoleInputEvents * WriteConsole
Done. All that just so we can capture |
…b/platform/src/com/sun/jna/platform/win32/WinDef.java:1852: 'case' child has incorrect indentation level 12, expected level should be 16. [Indentation]
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.
I only had a quick glance, but I noticed, that WORD
could be mapped to a java short, DWORD
can be mapped to a int and BOOL
could be mapped to boolean. DWORD
and WORD
are only interesting IMHO when the unsigned nature is important and trumps the easier handling of integer in java. The corresponding ByReference
types exist and I would use these.
I saw lots of code in the |
Yes, but it also makes it create more garbadge (more wrapper classes) and harder to use as you need to wrap each number. This is also not consistent, the COORD and SMALL_RECT structs are both mapped to java shorts. As said, there are reasons to prefer the wrappers, but I don't see many. For an enum like value like EventType for example, that is created from constants or ORed from constants you don't gain anything. |
Reasonable enough. I'll switch to native types and run a few tests. |
|
Please rebase this PR onto current master, @dbwiddis fixed a stability issue, that was caused by wrong assumptions about the apache mirror system. |
Fix statvfs filesystem - it is unstable in docker environments
Remove invalid GetTcpStatistics test
As of 2020-05-13, there are two versions of Apache Ant 1.9.x binaries available for download. The regexp parsing incorrectly resolves to a string containing both versions, separated by a newline character, and the download fails. This change limits the grep to only the last line, so the latest 1.9.x version will be downloaded.
Only fetch the latest ant version in Travis script
…to primarygroup
Add getTokenPrimaryGroup to Advapi32Util
Closes: #1182
Mmhhh. Now these changes appear in my pull request as well... |
That's an annoying "feature" of github. The steps here should fix it (basically: add a dummy file, commit, push, rebase to previous commit before you added the file, force push). |
Didn't work. Nevermind. I'll just fork again and apply a patch and create a new clean pull request. |
👉 #1194 |
Add the missing definitions for the
GetConsoleScreenBufferInfo
function of the Windows Console API:https://docs.microsoft.com/en-us/windows/console/getconsolescreenbufferinfo