- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm looking for a way to limit user keyboard input in a console application that runs in Linux and is compiled with Intel Fortran 2017.
At some juncture, input is collected from the user to provide a comment that is then saved to a database.
The relevant lines of code are:
PRINT *, 'Provide a brief description of your change: '
ACCEPT '(A50)', REVCOM
The REVCOM (revision comment) variable is defined as CHARACTER*50 and it gets inserted into a database field that is defined as VARCHAR(50).
If the user types more than 50 characters, the extra characters are simply discarded (without any "warning" given to the user). I suppose I could make REVCOM allow more than 50 characters, then if LEN(REVCOM) > 50 tell the user it's too long and make them reenter the comment. However, I'd rather not make them have to retype anything or count characters. I'd like to know if there is a way to make the keyboard buffer simply stop accepting more input once 50 characters is reached, so that the user can easily tell when they've reached the maximum length.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In @stevelong_rrx 's defense, it was mentioned in the first line of the original post the console app is question runs on Linux.
@stevelong_rrx , I am unaware of an immediate solution you can start using but can make a few long-winded suggestions:
- Take a look at the Fortran-lang site (https://fortran-lang.org/) and the resources there under terminal (and color) options, perhaps you might find something useful,
- Also, make an inquiry at the related Fortran Discourse site (https://fortran-lang.discourse.group/), perhaps at this thread: https://fortran-lang.discourse.group/t/toml-fortran-0-3-0/4108/2. Chances are a couple of readers there going by the handles of @awvwgk and @urbanjost may have some options for you.
- And/or post an inquiry at the Fortran stdlib site (https://github.com/fortran-lang/stdlib) , especially on the Issues thread at https://github.com/fortran-lang/stdlib/pull/580. You might receive some useful guidance there.
By the way, you may know `ACCEPT` is a non-standard extension to Fortran - you may consider simply replacing it with the standard READ statement which will be supported reliably by all the Fortran compilers.
Good luck,
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Fortran has no such feature. If you are on Windows, you could design a form with a text field and that can be limited to 50 characters and do what you want. It's some more coding on your part to design the form, display it and get the values using the IFLOGM (Dialog) library. For more information, see Using Intel® Visual Fortran to Create and Build Windows*-Based Applications
There are also dialog examples in the Samples Bundle.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You should be able to, either directly or via a C interop function, call the C Runtime Library function getch and selectively use the CRTL function putch. This should work in both Windows and Linux.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks, Jim! As a Fortran novice and with even less experience with C, I might find pulling this off a little more complicated than the task warrants, but I think I understand the concept (while len(revcom)<50, print the typed character to the screen, append the character to the revcom variable, and accept another character).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
SetConsoleScreenBufferSize sets the number of lines and the line length of the console buffer.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Is SetConsoleScreenBufferSize part of the Windows API? I'm not find any documentation that shows how it would be used in a Linux application that runs in a terminal console.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, that's a Windows API routine. You did not say you were using Linux before.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In @stevelong_rrx 's defense, it was mentioned in the first line of the original post the console app is question runs on Linux.
@stevelong_rrx , I am unaware of an immediate solution you can start using but can make a few long-winded suggestions:
- Take a look at the Fortran-lang site (https://fortran-lang.org/) and the resources there under terminal (and color) options, perhaps you might find something useful,
- Also, make an inquiry at the related Fortran Discourse site (https://fortran-lang.discourse.group/), perhaps at this thread: https://fortran-lang.discourse.group/t/toml-fortran-0-3-0/4108/2. Chances are a couple of readers there going by the handles of @awvwgk and @urbanjost may have some options for you.
- And/or post an inquiry at the Fortran stdlib site (https://github.com/fortran-lang/stdlib) , especially on the Issues thread at https://github.com/fortran-lang/stdlib/pull/580. You might receive some useful guidance there.
By the way, you may know `ACCEPT` is a non-standard extension to Fortran - you may consider simply replacing it with the standard READ statement which will be supported reliably by all the Fortran compilers.
Good luck,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I suggest that your input routine be constructed to emulate what users are familiar with.
Accept input up to Enter
Handle backspace (rubout)
Echo and insert characters .le. buffer length
Ignore characters in excess of input buffer (permissible to make sound)
If you want to be fancy, permit left and right arrows and character insertion.
Note, you should be able to locate (google) a ready made console input routine that does all this.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the various suggestions!
For now, I've gone with a very low-tech method that isn't foolproof, but was very easy to implement and is better than nothing!
PRINT *, 'Provide brief description of your change: '
PRINT *, '(Maximum comment length: 50 characters----------->|'
ACCEPT '(A50)', REVCOM
This feature won't be used frequently, and if users ignore the on-screen indication of maximum length, and complain about lost characters, then I'll revisit adding a console input routine to the code.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page