Project

General

Profile

Feature #2131

implement the Windows equivalent to the NCURSES/terminal support

Added by Greg Shah about 11 years ago. Updated over 7 years ago.

Status:
Closed
Priority:
Normal
Start date:
06/05/2013
Due date:
07/03/2013
% Done:

100%

Estimated time:
160.00 h
billable:
No
vendor_id:
GCD

evl_upd20130731a.zip - The first proposal (14 KB) Eugenie Lyzenko, 07/31/2013 09:15 AM

evl_upd20130814a.zip - Workable drop in progress (14.6 KB) Eugenie Lyzenko, 08/14/2013 08:05 PM

testcases_console_20130814a.zip - Console testcases (647 Bytes) Eugenie Lyzenko, 08/14/2013 08:05 PM

testcases_console_20130816a.zip - Testcases as of 20130816 (1.49 KB) Eugenie Lyzenko, 08/16/2013 11:36 AM

evl_upd20130816a.zip - Attributes support for NORMAL, REVERSE and UNDERLINE, key reading code refresh (20.6 KB) Eugenie Lyzenko, 08/16/2013 11:36 AM

evl_upd20130816b.zip - NORMAL text attribute fix (20.9 KB) Eugenie Lyzenko, 08/16/2013 06:21 PM

color-4gl-linux.jpg - color skip in 4GL Linux (184 KB) Eugenie Lyzenko, 08/19/2013 11:03 AM

color-4gl-windows.jpg - color skip in 4GL Windows (77.8 KB) Eugenie Lyzenko, 08/19/2013 11:03 AM

color-p2j-linux.jpg - color skip in P2J Linux (196 KB) Eugenie Lyzenko, 08/19/2013 11:03 AM

color-p2j-windows.jpg - color skip in P2J Windows (123 KB) Eugenie Lyzenko, 08/19/2013 11:03 AM

normal-4gl-linux.jpg - first skip in 4GL Linux (195 KB) Eugenie Lyzenko, 08/19/2013 11:03 AM

normal-4gl-windows.jpg - first skip in 4GL Windows (118 KB) Eugenie Lyzenko, 08/19/2013 11:03 AM

normal-p2j-linux.jpg - first skip in P2J Linux (194 KB) Eugenie Lyzenko, 08/19/2013 11:03 AM

normal-p2j-windows.jpg - first skip in P2J Windows (126 KB) Eugenie Lyzenko, 08/19/2013 11:03 AM

testcases_console_20130820a.zip - The testcases refresh as of 20130820 (4.05 KB) Eugenie Lyzenko, 08/20/2013 07:14 PM

console_test4-4gl-winodows.jpg - console test 4 layout in 4GL under Windows (105 KB) Eugenie Lyzenko, 08/20/2013 07:14 PM

evl_upd20130822a.zip - The new characters added and key processing rework (28.9 KB) Eugenie Lyzenko, 08/22/2013 07:47 PM

testcases_console_20130822a.zip - Testcases as of 20130822 (5.34 KB) Eugenie Lyzenko, 08/22/2013 07:47 PM

console_test7-4gl-windows.jpg - Console test #7 4GL CHUI windows (109 KB) Eugenie Lyzenko, 08/22/2013 07:47 PM

console_test7-4gl-WinUI-windows.jpg - Console test #7 4GL WinUI windows (70 KB) Eugenie Lyzenko, 08/22/2013 07:47 PM

console_test7-p2j-windows.jpg - Console test #7 P2J implementation CHUI windows (110 KB) Eugenie Lyzenko, 08/22/2013 07:47 PM

evl_upd20130823a.zip - Error processing code added (29.4 KB) Eugenie Lyzenko, 08/23/2013 06:47 PM

testcases_console_20130823a.zip - Console testcases as of 20130823 (5.96 KB) Eugenie Lyzenko, 08/23/2013 06:47 PM

console_test7-update-p2j-windows.jpg - Different widgets with scrollbars demo, suggested correct look in P2J on Windows (108 KB) Eugenie Lyzenko, 08/23/2013 06:47 PM

evl_upd20130826a.zip - Terminal type code (29.5 KB) Eugenie Lyzenko, 08/26/2013 04:35 PM

testcases_console_20130826a.zip - Testcases as of 20130826 (7.1 KB) Eugenie Lyzenko, 08/26/2013 04:35 PM

console_test10-4gl-windows-step1.jpg - The initial console screen(terminal is CO80) (53.8 KB) Eugenie Lyzenko, 08/26/2013 04:35 PM

console_test10-4gl-windows-step2.jpg - After trying to set "BW80" (42.8 KB) Eugenie Lyzenko, 08/26/2013 04:35 PM

console_test10-4gl-windows-step3.jpg - After trying to set "MONO" (51.2 KB) Eugenie Lyzenko, 08/26/2013 04:35 PM

evl_upd20130829a.zip - Suspend/resume code implementation (36.9 KB) Eugenie Lyzenko, 08/29/2013 04:04 PM

evl_upd20130830a.zip - The first release candidate (38.6 KB) Eugenie Lyzenko, 08/30/2013 08:13 PM

evl_upd20130902a.zip - Cursor status restore added (38.6 KB) Eugenie Lyzenko, 09/02/2013 07:30 PM

evl_upd20130904a.zip - Code refactoring (156 KB) Eugenie Lyzenko, 09/04/2013 08:50 PM

evl_upd20130905a.zip - Refactoring (148 KB) Eugenie Lyzenko, 09/05/2013 06:42 PM


Related issues

Blocked by User Interface - Feature #1898: write a replacement for the CHARVA libTerminal.so as an NCURSES-based Linux shared library Closed 05/21/2013 06/04/2013

History

#1 Updated by Greg Shah about 11 years ago

I suspect you would use the WIN32 console API to do this. The bottom line is that character mode applications should run on Windows just like they run on Linux. The #1898 task created backing functions for Linux that use NCURSES. This task implements the same features in libp2j.so/p2j.dll but for Windows. It can't use NCURSES on Windows, as that would require Cygwin. We must use the WIN32 API to do this.

#2 Updated by Eugenie Lyzenko over 10 years ago

The first proposal of the Windows console native implementation for you to review. A lot of comments still left - be cleaned up later. But the general way is here.

Also I did separation for common code in terminal.c file to have only platform specific code in terminal_linux(win).c files. The Linux part works OK in my small local testing. Not ready to test in devsrv01 for runtime because the changes in Linux code are still possible.

Continue working.

#3 Updated by Greg Shah over 10 years ago

It is a good start. Keep going.

#4 Updated by Eugenie Lyzenko over 10 years ago

The next drop for review. This is the first workable version. The main issue I struggled with is character coding to display. The testing shows the Windows doe not have good support for Unicode in console so looks like we have to be limited to use OEM coding in this case. This makes the code dependent on the codepage used on client machine(or temporary installs the 850 cp for console session because not all codepages can properly display box-drawing characters and other pseudo-graphics).

Another point here is the color/attributes usage in console. If we need the color or intensity change - we need to pack character key to display and color/attribute in a single int value. I guess it is better to store attribute/color in a upped word if the int, while character value - in the lower half of int.

The code can be tested in any frame oriented testcase(one example has been uploaded here too) with one note - the current key reader does not properly handle F4 - it uses getch() temporary because ReadConsole() usage is under investigation.

Continue working...

#5 Updated by Greg Shah over 10 years ago

At this time our character driver for NCURSES doesn't support real colors either. But it is very important to support attributes (e.g. underline, reverse...). These are heavily used in ChUI code and are required in the first version. Don't implement color support (e.g. red, blue...) at this time.

I will review the code shortly.

#6 Updated by Eugenie Lyzenko over 10 years ago

... But it is very important to support attributes (e.g. underline, reverse...). These are heavily used in ChUI code and are required in the first version. Don't implement color support (e.g. red, blue...) at this time.

OK.

The readKey() implementation is done. There are two possible approaches:
1. Using console function ReadConsoleInput():

...
   INPUT_RECORD inRec;
   DWORD numberOfRecRead = 0;

   if (ReadConsoleInput(hConsoleIn, &inRec, 1, &numberOfRecRead))
   {
      if (numberOfRecRead > 0 && inRec.EventType == KEY_EVENT && inRec.Event.KeyEvent.bKeyDown)
      {
         // We need this call to disable event passing to parent console
         if (FlushConsoleInputBuffer(hConsoleIn))
         {
            // If there is a char, get it otherwise get virtual key
            if (inRec.Event.KeyEvent.uChar.AsciiChar != 0)
            {
               return (jint) inRec.Event.KeyEvent.uChar.AsciiChar;
            }
            else
            {
               return (jint) inRec.Event.KeyEvent.wVirtualKeyCode;
            }
         }
      }
   }

   return (jint) -1;
...

2. Using libc call _getch():

...
   jint chResult = _getch();

   if (FlushConsoleInputBuffer(hConsoleIn))
   {
      return chResult;
   }
   else
   {
      return (jint) -1;
   }
...

The both of them are identical in behavior. We need to flush console buffer after read input in both cases because for some keys like F4 the key event is passing to "parent" console and causing some artifacts. Both approaches properly handle CTRL-C and F4 events. In addition for this to work we need to modify KeyProcessor.java to include Windows version of the VK_* codes for some keys:
OLD_VK_DOWN ... OLD_VK_END. Something like:

...
   public static final int  WIN_VK_F4         = 0x73; // ReadConsoleInput()
or
   public static final int  WIN_VK_F4         = 0x3E; // _getch()
...
   private int translate(int key)
   {
      switch (key)
      {
...
         case OLD_VK_F4:
         case WIN_VK_F4: // Add Windows mapping
            key = Key.VK_F4;
            break;
...
      }
      return key;
   }
}
...

I prefer to use ReadConsoleInput() console API if there is no objections. It is low-level console input function and we have more control for what is going on. And as you can see this function returns real documented Windows VK_* codes while _getch() returns not a Windows virtual key.

The high level console function ReadConsole() is not acceptable because it waits for ENTER key to be pressed before returning value meaning troubles in handling non-character keys.

#7 Updated by Greg Shah over 10 years ago

I prefer to use ReadConsoleInput() console API if there is no objections. It is low-level console input function and we have more control for what is going on. And as you can see this function returns real documented Windows VK_* codes while _getch() returns not a Windows virtual key.

One question: are the _getch() returned key values compatible with the same keys returned under Linux?

#8 Updated by Eugenie Lyzenko over 10 years ago

On Linux it returns 304 or 414 for F4 for example. On Windows _getch() returns 0x3E or 62 in decimal, so looks like not the same value. If you mean standalone getch() Linux call return.

#9 Updated by Greg Shah over 10 years ago

Go ahead with the ReadConsoleInput() version.

#10 Updated by Eugenie Lyzenko over 10 years ago

The next drop for review. The changes:
1. Implemented key reader code. The java KeyProcessor.java class has also been modified respectively.

2. Attribute handling base implementation. Now support includes NORMAL, REVERSE and UNDERLINE attributes. One important note here. The native 4GL code in Windows console does not support underlined characters due to console implementation restrictions. So in Windows the underlined chars are the same as reversed.

Another note - the attribute constants array has been changed to be able to store individual attributes as binary flags in upper 16 bits of the integer char. The lower 16 bits are used to store the char itself(for the case if we decide to work with Unicode sometimes in the future).

The documented Windows flags
COMMON_LVB_UNDERSCORE and COMMON_LVB_REVERSE_VIDEO
does not work with SBCS. From official MSDN forum: these attributes are working with DBCS for Japanese, Korean and China codepages which is certainly not our case. So the reverse attribute is implemented as the simulation by combining other color attributes.

These currently supported 3 attributes works the same way as in native 4GL under Windows.

3. The new testcases have been added.

Continue working on more attribute investigations, testcases and others.

#11 Updated by Eugenie Lyzenko over 10 years ago

Additional note for the previous update. The NORMAL text attribute usage there is correct for the monochrome monitors. For color monitors the NORMAL text is white text on blue background. Will be fixed shortly.

#12 Updated by Eugenie Lyzenko over 10 years ago

The second drop for today. The NORMAL text attribute has been changed for color displays according to the Progress documentation. Also the new exit function has been added to restore Windows console to the state before starting the P2J application.

Looks like we need the testcases for every widget like combo-box, selection-list, radio-set ... to verify the CHUI driver correct work.

Another point I'm worry about is error handling in our windows console module. What if something become wrong and Win32 console API calls will return FALSE. What is our strategy here? Ignoring? For example if cursor positioning fails - the screen will possibly become corrupted and further input/output action will produce wrong lay out even if they will work without errors. Or in the case of any error we have to terminate application? Or we need to have error handler to try to fix the issue and continue?

#13 Updated by Eugenie Lyzenko over 10 years ago

Looks like writing the console testcases I've found two P2J AlertBox issues. Consider the following code:

...
message color skip
   "This is the color attribute text. Depending on the " skip(0)
   "current console OS color settings it can be colored" skip(0)
   "or not. The buttons below should have one letter   " skip(0)
   "underligned and button <No> should have reverse    " skip(0)
   "color attribute meaning the current selection. Hit " skip(0)
   "arrow keys to change the current selection, ENTER  " skip(0)
   "to select curent button.                           " skip(0)
    view-as alert-box warning buttons yes-no-cancel update res as log.
...

and
...
message skip
   "This is the normal attribute text. Depending on the" skip(0)
   "current console OS color settings it can be colored" skip(0)
   "or not. The buttons below should have one letter   " skip(0)
   "underligned and button <No> should have reverse    " skip(0)
   "color attribute meaning the current selection. Hit " skip(0)
   "arrow keys to change the current selection, ENTER  " skip(0)
   "to select curent button.                           " skip(0)
    view-as alert-box warning buttons yes-no-cancel update res as log.
...

The first one has potentially wrong 4GL clause (standalone color phrase) but it is considered as correct in 4GL and produces the alert box below(like following skip has been ignored). To see: color-4gl-linux.jpg and color-4gl-windows.jpg
The P2J converts this as:

...
            messageBox(new Object[]
            {
               "This is the color attribute text. Depending on the ",
               new SkipEntity(0),
               "current console OS color settings it can be colored",
               new SkipEntity(0),
               "or not. The buttons below should have one letter   ",
               new SkipEntity(0),
               "underligned and button <No> should have reverse    ",
               new SkipEntity(0),
               "color attribute meaning the current selection. Hit ",
               new SkipEntity(0),
               "arrow keys to change the current selection, ENTER  ",
               new SkipEntity(0),
               "to select curent button.                           ",
               new SkipEntity(0)
            }, false, new AccessorWrapper(res), ALERT_WARNING, BTN_YES_NO_CANCEL, null, new ColorSpec("skip"));
...

Note the "color skip" also ignore the "skip" word considering the "skip" as color name. This is wrong and the resulting alert box becomes in wrong color. This is the first issue. We can not detect this in regression testing because the text attributes are not comparing. The both Linux and Windows P2J implementations show the same results: color-p2j-linux.jpg and color-p2j-windows.jpg. The correct color to be used in this case is ColorSpec("MESSAGES").

The second 4GL code above converts OK and has the correct color attribute in result. Compare normal-4gl-linux.jpg and normal-4gl-windows.jpg with normal-p2j-linux.jpg and normal-p2j-windows.jpg. However here we see the second issue: in P2J text start coordinate for all lines except last on is different(one more extra " " char inserted before line start). And the alert--box width become different. The converted code is:

...
            messageBox(new Object[]
            {
               new SkipEntity(),
               "This is the normal attribute text. Depending on the",
               new SkipEntity(0),
               "current console OS color settings it can be colored",
               new SkipEntity(0),
               "or not. The buttons below should have one letter   ",
               new SkipEntity(0),
               "underligned and button <No> should have reverse    ",
               new SkipEntity(0),
               "color attribute meaning the current selection. Hit ",
               new SkipEntity(0),
               "arrow keys to change the current selection, ENTER  ",
               new SkipEntity(0),
               "to select curent button.                           ",
               new SkipEntity(0)
            }, false, new AccessorWrapper(res), ALERT_WARNING, BTN_YES_NO_CANCEL, null);
...

It is happening in some rare conditions so in our tests we just can not screens to verify this mismatch.

Note this behavior is not depending on conversion OS, so the problem is somewhere in common code, probably AlertBox class and conversion rule that handles the "color skip" phrase.

4GL Original for Linux and Windows:

           ┌─────────────────────── Warning ───────────────────────┐
           │ This is the color attribute text. Depending on the    │
           │ current console OS color settings it can be colored   │
           │ or not. The buttons below should have one letter      │
           │ underligned and button <No> should have reverse       │
           │ color attribute meaning the current selection. Hit    │
           │ arrow keys to change the current selection, ENTER     │
           │ to select curent button.                              │
           │ ───────────────────────────────────────────────────── │
           │                  <Yes> <No> <Cancel>                  │
           └───────────────────────────────────────────────────────┘
           ┌─────────────────────── Warning ───────────────────────┐
           │                                                       │
           │ This is the normal attribute text. Depending on the   │
           │ current console OS color settings it can be colored   │
           │ or not. The buttons below should have one letter      │
           │ underligned and button <No> should have reverse       │
           │ color attribute meaning the current selection. Hit    │
           │ arrow keys to change the current selection, ENTER     │
           │ to select curent button.                              │
           │ ───────────────────────────────────────────────────── │
           │                  <Yes> <No> <Cancel>                  │
           └───────────────────────────────────────────────────────┘

P2J Linux and Windows:
           ┌─────────────────────── Warning ───────────────────────┐
           │ This is the color attribute text. Depending on the    │
           │ current console OS color settings it can be colored   │
           │ or not. The buttons below should have one letter      │
           │ underligned and button <No> should have reverse       │
           │ color attribute meaning the current selection. Hit    │
           │ arrow keys to change the current selection, ENTER     │
           │ to select curent button.                              │
           │ ───────────────────────────────────────────────────── │
           │                  <Yes> <No> <Cancel>                  │
           └───────────────────────────────────────────────────────┘
          ┌─────────────────────── Warning ────────────────────────┐
          │                                                        │
          │  This is the normal attribute text. Depending on the   │
          │  current console OS color settings it can be colored   │
          │  or not. The buttons below should have one letter      │
          │  underligned and button <No> should have reverse       │
          │  color attribute meaning the current selection. Hit    │
          │  arrow keys to change the current selection, ENTER     │
          │ to select curent button.                               │
          │ ────────────────────────────────────────────────────── │
          │                  <Yes> <No> <Cancel>                   │
          └────────────────────────────────────────────────────────┘

I've just to note this, probably fixing the issues are the separate task we need to create.

#14 Updated by Greg Shah over 10 years ago

In regard to note 13, please open 2 new tasks: one for the alert-box "color skip" issue and a different task for the alert-box layout issue.

I think that both of these issues are runtime problems. Even the color skip issue is something that the runtime should handle the same way as the 4GL. The 4GL code in this case is picking a different default match for a "non-sense" color name. We need to do the same. If I recall correctly, we have seen this before and for some reason, matching this behavior caused issues elsewhere. If that is correct, then there are something deeper that is wrong with our implementation which we didn't figure out the first time. Please add this comment into the color skip task so that we "remember" it for the future.

#15 Updated by Eugenie Lyzenko over 10 years ago

More investigation results from testcases written:

1. Toggle-Box widget is not implemented in our runtime.
2. Slider widget is not implemented(need more investigation if we have even conversion support).
3. Radio-button has a bit different look as in 4GL form the attributes point of view. The focused button character between braces ( ), X or " " should have blinked attribute in Linux and reverse one in Windows.
4. As you can see from opened combo-box screenshots and one new console_test4-4gl-windows.jpg we need to introduce usage of the 4 new characters into OutputManager and related logic:
- the known '>' current selection character in selection-list should be replaced with dynamically calculated char depending on underlying platform because in Windows we have the small 1(Superscript One may be) digit instead.
- the small up and down arrows character should be used in combo-box in Windows (0x18,0x19,0x1A,Ox1B in IBM850 charset).
- the checkerboard character should be used in Windows to draw the scrollbars in vertical selection list. May be we need another two for horizontal srcollbars(0x1A,Ox1B for left and right).
5. Also I have noted the scrollbar in selection list does not reflect the current position of the scrollable window. I mean the thumb char is not moving when scrolling. In linux it is not detected in regression tests because the scrollbar is completely consist of ' ' chars with different attributes. This is the issue we certainly need to fix for windows code because there the scrollbar has the character other that ' '.

Continue working.

#16 Updated by Eugenie Lyzenko over 10 years ago

The testing highlights one point to discuss. Previously findings show us the key codes returned from Windows key reader are different than ones we have from Linux NCURSES code for functional keys and "blind" keys. So I introduced the WIN_VK_* constant into KeyProcessor class to transform these codes to what we need. But I've found this approach has the issues in Linux because the codes returned in Windows match some alphabetical characters returned from NCURSES. As result pressing "s" key in Linux inside editor widget finishes the client instead of typing "s" char. So we need to isolate this transformation from code running in Linux.

There are two possible ways I can see. The one is to simulate NCURSES keys inside terminal_win.c native code. The other way is to make separation for Linux and Windows inside Java code for such separation. What do you think about this? Should Java part contain only platform-independent code? I think it is not good to check what is the Operating System behind every time the next key is pressed. It looks not optimal.

#17 Updated by Eugenie Lyzenko over 10 years ago

This drop is a result of checking different widgets layout on Windows 4GL system. I have modified in addition OutputManager class to add 6 new special characters, 4 for scrollbars edge "buttons", in CHUI we need 2 of them for vertical and 2 - for horizontal. All these chars are just ' ' in Linux. Two other chars are selection char('>' for Linux and 0xFB for Windows) to be used in selection-list widget and checkerboard character(' ' for Linux and 0xB0 for Windows) to draw the scrollbar body.

One additional finding: The 4GL CHUI for Windows does not show the horizontal scroll bars in selection-list even it is required and explicitly declared. You can see this on console_test7.p screenshots attached. The Window 4GL interface has the horizontal scrollbar for selection-list.

The other change - the class KeyProcessor.java was removed from update because the Windows -> NCURSES key transformations are now performed inside terminal_win.c module according to previously found issue.

To demonstrate the changes is working I've made some fast fixes to different widgets layout artifacts(which has not many time to debug). The layout fixes are NOT included in this drop. For the test console_test7.p you can see the screenshots taken from original Windows 4GL system and one from P2J implementation.

#18 Updated by Eugenie Lyzenko over 10 years ago

The today drop includes error processing code approach for terminal_win.c module for you to review. The gathering info will have module info, function name where error happen and the Windows integer error code. May be this is too much for user to know such details, what do you think?

Also I have included the screenshot for P2J selection list with vertical scrollbar. We need to fix Java code for scroll pane implementation class.

Next I'm going to document all remaining widget layout issues found while testing console module if you do not mind before resuming work on CHUI client implementation for Windows. The rest points there are suspending,resuming,restarting and refreshing code.

#19 Updated by Eugenie Lyzenko over 10 years ago

The drop includes the get/set terminal type implementation. The real 4gL Windows shows the terminal type is constant for given console and returns "CO80". Moreover it is not possible to change it to either "BW80" or "MONO"(testcase console_test10.p). According to Progress doc the TERMINAL function results depends on current display capability.

The implemented approach uses GetDeviceCaps() to get info about color resolution for parameters BITSPIXEL and NUMCOLORS. If bit per pixel > 8 - we certainly have "CO80" display. If NUMCOLORS < 16 - this probably means we have monochrome display. In case of palette based color table 16 or 256 it is "BW80"(or may be "CO80" in certain cases). So probably we need the better way to detect. Moreover the current implementation requires the module to link with gdi32 library which probably we need to avoid. The simplest way is to consider the console is always "CO80".

The testcases update is also uploaded.

Continue to work on suspend/resume implementation...

#20 Updated by Eugenie Lyzenko over 10 years ago

The drop includes code checked for suspend/resume compatibility. The only usage foe these functions I have found is the running external OS command in standalone session. The example is simple Progress code:
...
os-command "dir".
...
In addition to modification fro terminal*.c code we need to make some changes in other modules:

1. Native process_win.c module. The function pseudoTerminalLaunch():
- The code when we use SW_HIDE option for stating process should be executed when we have any redirected output/input. Otherwise the new console session will be not visible.
- We need to set up the window title for newly created console. Because we use CMD.EXE to start process or command - we can just pass "cmd.exe" string. Otherwise we will have the title inherited from process-starter.
- The most important and possibly need discussion implementation is change the key for our CMD.EXE launcher from /c to /k in the case when we have not silent mode and have no any redirected input/output. Without this modification the behaviour will differ from one we have on real 4GL Windows system. In real 4GL the started session should remain running until the user closes it explicitly.

2. Java class com/goldencode/p2j/util/ProcessDaemon.java:
- Running the external process in NOT silent mode different in Linux and Windows. In Windows there is no pause with key waiting for this case. So we need to check the OS behind before prompting for additional pause.

As to recent change for process_win.c code I agree the fix is looks like a hack and probably we need more general solution in common ProcessDaemon.java class when preparing the arguments for process to be started. For example we can change prepareCommandLine() method or even respective launch(String[]. boolean, boolean). What do you thing for this point?

Another point to discuss - currently we have the code for clear screen in process_win.c module. Is it reasonable to move this function to console related module(terminal_win.c)?

#21 Updated by Eugenie Lyzenko over 10 years ago

The today drop includes:
1. Minor changing to clean up from old comments in terminal_win.c module and adding clear screen code on exiting the console client.
2. process_win.c also has the addition to detect the full path to the cmd.exe starter to reflect the native 4GL console layout for started application.

So this is the candidate for first release of the console module implementation. Now I need to re-test for possible regressions in the process_win.c with previously tested input/output/input-output-through samples.

#22 Updated by Eugenie Lyzenko over 10 years ago

The today drop includes small addition for restoring the cursor status that was before executing the console application.

The other note is there are no regressions found in the input/output/input-output-through samples. So we do not brake the process execution Windows module.

However there is one more difference found between our P2J implementation for Windows and original. The 4GL in Windows unlike 4GL in Linux does not show the cursor while PAUSE statement. So P2J implementation in Windows is different. To fix this I can offer to modify ThinClient pause() method:

...
   public int pause(int seconds, String text, boolean noMessage)
   {
      // EVL***<<
      boolean cursorRestore = PlatformHelper.isUnderWindowsFamily();
      boolean cursorOn = false;
      if (cursorRestore)
      {
         cursorOn = tk.setCursorStatus(false);
      }
      // EVL***>>
      // reset need pause condition
      setNeedPause(false);
...
      finally
      {
         // erase status message
         if (!noMessage)
         {
            status(null);

            // hide messages
            Window.getDefaultWindow().setMessageText(null, null);
         }

         pauseCleanup();
         // EVL***<<
         if (cursorRestore)
         {
            tk.setCursorStatus(cursorOn);
         }
         // EVL***>>
      }
...

This can fix the issue. What do you think about this approach(not yet included in this drop)?

#23 Updated by Greg Shah over 10 years ago

Code Review 0902a

1. About terminal_win.c errorProcessing() function:

  • Change the name to generateException().
  • The function always passes the "thisModule" pointer. Please just hard code the module name in the function.
  • The module name should be "terminal_win.c" instead of "P2J GHUI console".

2. In regard to the general error handling approach:

  • I only want to throw the IllegalStateException in cases where the failing function call really requires the client to abort. It seems to me that there are some cases in this file where we might be able to ignore the return code OR that we might be able to only throw the exception in a sub-set of the failures.
  • Please review the cases of throwing the exception and see if there are some non-fatal cases.
  • Generally, the code is much messier because of the error handling. This is somewhat unavoidable, but please use whitespace and formatting to make the code easier to read. Your code in general lacks whitespace and this makes it harder to read.

3. Please review the TODOs in terminal_win.c and report on the status of each one. If the TODO is no longer needed, fix the comment.

4. I am worried about hard coding terminal_win.c to the 850 codepage. I wonder if there is any option to query the characters dynamically from a Windows API. For example, in NCURSES, we read the ACS_ drawing characters at runtime. Please look for something similar on Windows. If that is not possible, then we may need to discuss alternatives, since we cannot be sure that all installations will use codepage 850.

5. Yes, you can move clearScreen() to the terminal module.

6. The console title should not be "P2J Character Client". What does this display in Progress? It must be the same.

7. Hiding the transformation of Windows virtual key codes into NCURSES in terminal_win.c is a good approach for now. In the future, we may find the need to make this more general (e.g. map all native code to our own custom codes that are exclusively used in our Java layer). But for now this is a reasonable solution.

8. I am OK with the current terminal type detection approach. Please add comments to describe the limitation of your approach.

9. Please refactor the code in terminal_win.c initConsole() to move sections of it to separate functions (where it makes sense). This should make that code more readable.

10. In regard to the CHUI bugs you found (#2166, #2168, #2169, #2170, #2171 and #2172), please remove the "Description" text and insert that same text as the 1st history item. We never use the "Description" field.

11. Please put an explanatory comment at the 'c' to 'k' conversion code in process_win.c.

12. Please put the cmd.exe full path calculation code into a separate function to make the code more readable.

13. You should only free(cmdFullPath) if it is not null. AND the free() can move into the function created in 12 above.

14. I am OK with the ProcessDaemon change.

15. In regard to the avoiding of drawing the horizontal scrollbar in selection list on Windows, please propose a solution.

16. In regard to the proposed change to pause() in ThinClient, go ahead with the change. But use this code at the end:

         if (cursorRestore && cursorOn)
         {
            tk.setCursorStatus(true);
         }

This will eliminate the unnecessary calls.

#24 Updated by Eugenie Lyzenko over 10 years ago

3. Please review the TODOs in terminal_win.c and report on the status of each one. If the TODO is no longer needed, fix the comment.

OK.

6. The console title should not be "P2J Character Client". What does this display in Progress? It must be the same.

The Progress in Windows displays "Character Client" title.

#25 Updated by Eugenie Lyzenko over 10 years ago

12. Please put the cmd.exe full path calculation code into a separate function to make the code more readable.

13. You should only free(cmdFullPath) if it is not null. AND the free() can move into the function created in 12 above.

Do you mean to have the single function to allocate and free memory? Something like createDestroyFullPath(char *, jboolean create);
If call with create == TRUE then allocate memory, otherwise - free memory if pointer is not NULL. Am I understand correctly?

#26 Updated by Greg Shah over 10 years ago

Do you mean to have the single function to allocate and free memory? Something like createDestroyFullPath(char *, jboolean create);

If call with create == TRUE then allocate memory, otherwise - free memory if pointer is not NULL. Am I understand correctly?

No.

Can't you just do this:


static char* CMD_EXE = "cmd.exe";

char* calcCmdFullPath()
{
   // Calculate the full path to cmd.exe
   int   sysDirNameLen = GetSystemDirectory(NULL, 0);
   int   cmdExeLen     = strlen(CMD_EXE);
   int   charsNeeded   = (sysDirNameLen > 0) ? (sysDirNameLen + cmdExeLen + 1) : cmdExeLen;
   char* cmdFullPath   = malloc(sizeof(char) * charsNeeded); 

   // This is the title to display in newly created console
   if (cmdFullPath != NULL)
   {
      if (sysDirNameLen > 0)
      {
         if (GetSystemDirectory(cmdFullPath, sysDirNameLength) != 0)
         {
            strcat(cmdFullPath, "\\");
         }
      }      

      strcat(cmdFullPath, CMD_EXE);
   }

   return cmdFullPath;
}

Then call it like this: sinfo.lpTitle = calcCmdFullPath();

And before returning:

if (sinfo.lpTitle != NULL)
   free(sinfo.lpTitle);

#27 Updated by Eugenie Lyzenko over 10 years ago

...but please use whitespace and formatting to make the code easier to read. Your code in general lacks whitespace and this makes it harder to read.

Do you mean the code like:

...
      base_rows = csbInfo.srWindow.Bottom-csbInfo.srWindow.Top+1;
      base_cols = csbInfo.srWindow.Right-csbInfo.srWindow.Left+1;
      initialTextAttribute = csbInfo.wAttributes;
...

Should be instead:
...
      base_rows            = csbInfo.srWindow.Bottom - csbInfo.srWindow.Top + 1;
      base_cols            = csbInfo.srWindow.Right - csbInfo.srWindow.Left + 1;
      initialTextAttribute = csbInfo.wAttributes;
...

Or additional blank lines between some related parts of code?

#28 Updated by Greg Shah over 10 years ago

I would probably choose this:

...
      base_rows = csbInfo.srWindow.Bottom - csbInfo.srWindow.Top + 1;
      base_cols = csbInfo.srWindow.Right - csbInfo.srWindow.Left + 1;

      initialTextAttribute = csbInfo.wAttributes;
...

I only use the vertical alignment of variable assignments when the var name lengths are not too mismatched. But the other spacing is required by our coding standards. You should never be writing this: num+5, it should be num + 5.

Or additional blank lines between some related parts of code?

Yes, this as well.

#29 Updated by Eugenie Lyzenko over 10 years ago

4. I am worried about hard coding terminal_win.c to the 850 codepage. I wonder if there is any option to query the characters dynamically from a Windows API. For example, in NCURSES, we read the ACS_ drawing characters at runtime. Please look for something similar on Windows. If that is not possible, then we may need to discuss alternatives, since we cannot be sure that all installations will use codepage 850.

Looks like there is a solution here. We can use Unicode UTF16LE in console. This is the internal Windows copepage beginning with Windows2000. To do this we have to use W postfixed functions to write the chars like WriteConsoleOutputW(). This way we can have the universal set of the box drawing characters(which is the same for different CP). Yes we will have the static table for all "special" characters, not function or macro like in NCURSES, but this table will be valid for every CP. No dependency from IBM850 code page or any other. All mapping between Unicode and real output will be done inside API calls. I did simple tests and it has good results.

Is this approach acceptable?

#30 Updated by Greg Shah over 10 years ago

Is this approach acceptable?

Yes, that is much better than using 850 directly. Go with it.

#31 Updated by Eugenie Lyzenko over 10 years ago

0. Merged with the recent P2J code base.
1. Reworked process_win.c to separate path calculation function.
2. Added ThinClient.java modification to hide the cursor unconditionally under Windows.
3. Reworked terminal_win.c to use Unicode range on console output.
4. generateException() has been changed.
5. clearScreen() is now in terminal_win module.
6. The console title is the same as in 4GL in Windows.

Continue refactoring according your feedback. There is only one TODO point left:
The selection symbol 0x00B9 displays differently in native 4GL(upper 1) and in my systems(? - means unknown I guess).

#32 Updated by Eugenie Lyzenko over 10 years ago

The today drop includes:
1. Improving readability of the terminal_win.c code.
2. Refactoring the initConsole() function.
3. The terminal type detection code has been moved into separate function.
4. The terminal selection approach has been explained in comments.

For the selection char('>' in Linux) I have performed investigation in Windows and found the Unicode symbol used is also 0x00B9. So we can use this code and leave the mapping and rendering up to current OS used to run P2J. The real representation can be different depending on the current locale settings.

#33 Updated by Greg Shah over 10 years ago

Code Review 0905a

I am OK with these changes.

Are you going to work on this:

15. In regard to the avoiding of drawing the horizontal scrollbar in selection list on Windows, please propose a solution.

As far as I can tell, everything else is done. Is that right?

#34 Updated by Eugenie Lyzenko over 10 years ago

Are you going to work on this:

15. In regard to the avoiding of drawing the horizontal scrollbar in selection list on Windows, please propose a solution.

As far as I can tell, everything else is done. Is that right?

Yes, I'm going to work on this issue. But to be clear the problem is in vertical scrollbar not horizontal. The horizontal scrollbar is not displaying in Windows 4GL system for character mode interface. So here we have no difference. But the vertical scrollbar is missing in P2J CHUI while it exists in Windows and Linux 4GL systems. Is this the problem we need solution(and thumb position wrong update)?

#35 Updated by Greg Shah over 10 years ago

But the vertical scrollbar is missing in P2J CHUI while it exists in Windows and Linux 4GL systems.

Is it missing in P2J on both Linux and Windows?

Is this the problem we need solution(and thumb position wrong update)?

The scrollbar sizing issue will be deferred until later. I believe you have fully documented it in a redmine issue, right?

The scrollbar missing issue is separate and you should work it only if it only manifests on Windows. If it also happens on Linux, then create a new redmine task and document the problem. We will leave that work for later.

#36 Updated by Eugenie Lyzenko over 10 years ago

But the vertical scrollbar is missing in P2J CHUI while it exists in Windows and Linux 4GL systems.

Is it missing in P2J on both Linux and Windows?

Yes, exactly. The problem is in com/goldencode/p2j/ui/chui/ScrollPaneImpl.java OS neutral class.

The scrollbar sizing issue will be deferred until later. I believe you have fully documented it in a redmine issue, right?

Yes, I created task #2169 to refer this issue

The scrollbar missing issue is separate and you should work it only if it only manifests on Windows. If it also happens on Linux, then create a new redmine task and document the problem. We will leave that work for later.

As I noted above this happens in both Linux and Windows P2J. And the task already created: #2170.

So we defer the solution for both for later time?

#37 Updated by Greg Shah over 10 years ago

Yes, defer it.

Please go ahead and get the 0905a update regression tested using devsrv01.

#38 Updated by Eugenie Lyzenko over 10 years ago

Please go ahead and get the 0905a update regression tested using devsrv01.

OK.

#39 Updated by Eugenie Lyzenko over 10 years ago

Please go ahead and get the 0905a update regression tested using devsrv01

The runtime regression tests all passed (except known TC-JOB-002 failure). The results can be found in 10379_9c2ae9a_20130907_evl.zip.

#40 Updated by Greg Shah over 10 years ago

Great! Please check in your update and distribute it.

#41 Updated by Eugenie Lyzenko over 10 years ago

Great! Please check in your update and distribute it.

OK. Committed in bzr as 10380.

#42 Updated by Eugenie Lyzenko over 10 years ago

I'm going to document one more issue related to the focus handling in combo-box. Part of it affects only Windows P2J and other - both Windows and Linux P2J. This can not be detected by regression testing.

#43 Updated by Greg Shah over 10 years ago

  • % Done changed from 0 to 100
  • Status changed from New to Closed

#44 Updated by Greg Shah over 7 years ago

  • Target version changed from Milestone 7 to Runtime Support for Server Features

Also available in: Atom PDF