iNamik / java_text_tables

Text Table Library in Java
MIT License
57 stars 14 forks source link

error format under windows java 1.8 #5

Open lc82111 opened 7 years ago

lc82111 commented 7 years ago
╔════════════════════╦══════════════════
═══════════════╗
║Hearder ID: 00000001║RTU ID: 01    Valves status: 0000║
║                    ║RTU ID: 02    Valves status: 0000║
╚════════════════════╩══════════════════
═══════════════╝

╔════════════════════╦══════════════════
═══════════════╗
║Hearder ID: 00000001║RTU ID: 01    Valves status: 0000║
║                    ║RTU ID: 02    Valves status: 0000║
╚════════════════════╩══════════════════
═══════════════╝

[edit] Wrapped sample table with ``` to show it in code format

iNamik commented 7 years ago

Hi!

Sorry you are having problems with my library.

I would like to help you, but the information you posted isn't enough to fully understand the problem.

I'm going to need to see a code sample that reproduces the problem, so we can:

1) Confirm its not a coding issue 2) reproduce the error so we we can test a fix for it

Can you produce a small code sample that shows the error on Java8/Windows? It does not need to be your exact production code, just a small program that consistently generates the error.

Thanks!

-David

iNamik commented 7 years ago

@lc82111 I haven't heard back from you on this - Are you still having issues? If so, please read my previous comment.

-D

lc82111 commented 7 years ago

Sorry for late. I think the issue was not caused by my code. Currently, I bypass the issue by following code which just avoids too long row.

/*
 * Smart Agriculture Servers
 */

public class ServerSA{
    public static Server serverHeader;
    public static Server serverAPP;
    // main
    public static void main(String[] args) throws IOException, InterruptedException {
        if (args.length != 2) {
            System.err.println("Usage: java socket server at: <Header port number> <APP port number>");
            System.exit(1);
        } else{
            int portNumberHeader  = Integer.parseInt(args[0]);
            int portNumberAPP     = Integer.parseInt(args[1]);

            ServerSA.serverHeader = new Server(portNumberHeader, "Header");
            ServerSA.serverAPP    = new Server(portNumberAPP, "APP");

            while(true){
                Thread.sleep(1000*5);
                Tabel.makeTable(serverHeader, serverAPP);
            }
        }
    }
}

class Tabel{
    public static void makeTable(Server serverHeader, Server serverAPP){
        if(serverHeader.connList.size()>0 || serverAPP.connList.size()>0){
            System.out.println();

            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
            Date date = new Date();
            String time = dateFormat.format(date);

            SimpleTable s = SimpleTable.of();
            //(0, 0)
            s.nextRow().nextCell().addLine("Time: " + time);

            // each Header
            if (serverHeader.connList.size()>0){
                for (Connection connHeader : serverHeader.connList){
                    Header header = (Header)connHeader.client;
                    s.nextRow().nextCell().addLine("Header ID: " + header.ID);
                    s.addLine("Last See: " + header.heartBeatLastSee);
                    s.addLine("Last time: " + header.heartLastTime);
                    if (header.RTUs.size()>0){
                        // each RTU
                        s.nextRow().nextCell();
                        for (RTU rtu : header.RTUs)
                            s.addLine("RTU: " + rtu.ID + ";  Valves: " + rtu.valves +";");
                    }
                }
            }

            // each APP
            if (serverAPP.connList.size()>0){
                s.nextRow().nextCell();
                for(Connection connAPP: serverAPP.connList){
                    APP app = (APP) connAPP.client;
                    s.addLine("APP: " + app.toString());
                }
            }

            GridTable g = s.toGrid();
            g = Border.SINGLE_LINE.apply(g);
            Util.print(g);
        }
    }
iNamik commented 7 years ago

@lc82111 - Thank you for taking time to reply, but your sample code has some issues:

This is not a complete test case. This looks like production code, but it doesn't run because you did not share what Server,Connection,Header,RTU,and APP classes look like.

I managed to make some guesses as to what the classes look like, was able to generate the following table in my local:

┌─────────────────────────┐
│Time: 2017/09/13 11:12:03│
├─────────────────────────┤
│Header ID: 00000001      │
│Last See: hbls1          │
│Last time: hlt1          │
├─────────────────────────┤
│RTU: 11;  Valves: 1001;  │
│RTU: 12;  Valves: 1002;  │
├─────────────────────────┤
│Header ID: 00000002      │
│Last See: hbls2          │
│Last time: hlt2          │
├─────────────────────────┤
│RTU: 21;  Valves: 2001;  │
│RTU: 22;  Valves: 2002;  │
├─────────────────────────┤
│APP: APP1                │
│APP: APP2                │
└─────────────────────────┘

This table format does not look anything like the original table format you submitted with the issue.

What does your sample code print in your local environment?

iNamik commented 7 years ago

@lc82111

I have modified your original description to show the table format as code. It looks like this:

╔════════════════════╦══════════════════
═══════════════╗
║Hearder ID: 00000001║RTU ID: 01    Valves status: 0000║
║                    ║RTU ID: 02    Valves status: 0000║
╚════════════════════╩══════════════════
═══════════════╝

╔════════════════════╦══════════════════
═══════════════╗
║Hearder ID: 00000001║RTU ID: 01    Valves status: 0000║
║                    ║RTU ID: 02    Valves status: 0000║
╚════════════════════╩══════════════════
═══════════════╝

Is this what your original error looked like? i.e. It appears that the table border gets line-wrapped at 40 characters, but the table row doesn't get wrapped?

Or was the was the line-wrapping caused because you copy/pasted from a 40-character console window?

Without those 2 lines being wrapped, the table looks pretty good:

╔════════════════════╦═════════════════════════════════╗
║Hearder ID: 00000001║RTU ID: 01    Valves status: 0000║
║                    ║RTU ID: 02    Valves status: 0000║
╚════════════════════╩═════════════════════════════════╝

╔════════════════════╦═════════════════════════════════╗
║Hearder ID: 00000001║RTU ID: 01    Valves status: 0000║
║                    ║RTU ID: 02    Valves status: 0000║
╚════════════════════╩═════════════════════════════════╝

But as mentioned previously, your sample code table doesn't look anything like this table.

So I'm really not sure what your original bug was ?

If you are still having the issue, please try to design a simple example i.e. no extra classes, no method calls, no loops ... just very simple code to build a table with static values and print it to show the error.

Thanks!