• Reset Initial State

    From shinobi@21:1/153 to All on Thu Mar 1 18:38:39 2018
    Hello All,

    I'm having trouble after return from NCurses program in c to BBS.
    After that the newlines in some cases are not correct. It just simply
    doesn't scroll by a page when there is multi-page document but writes
    all the lines to the last line and overwrite what was there.

    I tried to put some ANSI codes into the C to the end of it like RSI
    Reset Initial State or Set New Line. But nothing helps. Could anyone
    please guide me what to use? (ESC Sequence)

    I also terminate the program with endwin at the end of it.

    Thanks in advance

    Shinobi

    P.S. Resources

    http://www.climagic.org/mirrors/VT100_Escape_Codes.html http://wiki.bash-hackers.org/scripting/terminalcodes

    --- Mystic BBS v1.12 A38 2018/01/01 (Linux/64)
    * Origin: INFOLINKA BBS (21:1/153)
  • From Gryphon@21:1/120 to shinobi on Fri Mar 2 10:18:50 2018
    On 03/01/18, shinobi said the following...

    Hello All,

    I'm having trouble after return from NCurses program in c to BBS.
    After that the newlines in some cases are not correct. It just simply doesn't scroll by a page when there is multi-page document but writes
    all the lines to the last line and overwrite what was there.

    I tried to put some ANSI codes into the C to the end of it like RSI
    Reset Initial State or Set New Line. But nothing helps. Could anyone please guide me what to use? (ESC Sequence)

    I also terminate the program with endwin at the end of it.

    I have expereienced the same thing when calling curses-based apps as doors
    from Mystic. I believe it is a terminal issue. I'm not sure there's a fix
    for it.

    --- Mystic BBS v1.12 A38 2018/01/01 (Linux/64)
    * Origin: Cyberia BBS | cyberia.darktech.org | San Jose, CA (21:1/120)
  • From shinobi@21:1/153 to shinobi on Thu Mar 1 19:27:12 2018
    I'm having trouble after return from NCurses program in c to BBS.

    Just as usual right after I sent this echomail I found the answer.
    The solution has been found here:

    http://www.tldp.org/HOWTO/Keyboard-and-Console-HOWTO-4.html

    I added this line to my program:

    int c=27;
    printf ("%c[1;25r",esc); /* reset and refresh the screen */

    And finally the terminal works as expected.

    Best regards

    Shinobi

    --- Mystic BBS v1.12 A38 2018/01/01 (Linux/64)
    * Origin: INFOLINKA BBS (21:1/153)
  • From shinobi@21:1/153 to Gryphon on Fri Mar 2 20:26:41 2018
    I have expereienced the same thing when calling curses-based apps as
    doors from Mystic. I believe it is a terminal issue. I'm not sure there's a fix for it.

    Yes it is. What I found resetting the terminal solved the problem.

    int c=27;
    printf ("%c[1;25r",esc); /* reset and refresh the screen */

    Now I'm able to use ncurses door without having to relogon.

    It could be possible to compile it on any platform and then just
    add it as a step on return to BBS.

    Regards

    Shinobi

    --- Mystic BBS v1.12 A38 2018/01/01 (Linux/64)
    * Origin: INFOLINKA BBS (21:1/153)
  • From Erazmus@21:1/133 to shinobi on Tue Mar 6 13:45:14 2018
    On 03/01/18, shinobi said the following...
    I added this line to my program:

    int c=27;
    printf ("%c[1;25r",esc); /* reset and refresh the screen
    */

    Not to critique your code, but you've got a mismatch of your variables - 'c' and 'esc' - you'll need to use one or the other.

    Also, you're using '%c' as your format string - this is a character. You
    should define 'c' as an unsigned char instead of an int.

    But really, to help your compiler from writing inefficient code, you should just embed the escape character in your string, like this:

    printf("\x1b[1;25r");

    The '\x1b' is the escape character (1B hex is 27 decimal).

    Ian

    --- Mystic BBS v1.12 A38 2018/01/01 (Linux/32)
    * Origin: The Parity Error BBS - Kelowna, BC, Canada (21:1/133)
  • From tenser@21:1/112 to Erazmus on Wed Mar 7 10:38:45 2018
    'c' and 'esc' - you'll need to use one or the other.

    Also, you're using '%c' as your format string - this is a character. You should define 'c' as an unsigned char instead of an int.

    Well yes; he's using '%c' because he wants to print 'c' as a character,
    not as an integer.

    Given that printf() is variadic, the argument corresponding to the '%c'
    verb in the format string will be promoted to an int, in accordance with
    the type promotion rules, so passing an `int` here is fine.

    But really, to help your compiler from writing inefficient code, you should just embed the escape character in your string, like this:

    printf("\x1b[1;25r");

    The '\x1b' is the escape character (1B hex is 27 decimal).

    This is good advice.

    --- Mystic BBS v1.12 A38 2018/01/01 (Windows/32)
    * Origin: Black Flag : ACiD Telnet HQ > blackflag.acid.org (21:1/112)
  • From shinobi@21:1/153 to Erazmus on Wed Mar 7 13:50:08 2018
    int c=27;
    printf ("%c[1;25r",esc); /* reset and refresh the scre

    Not to critique your code, but you've got a mismatch of your variables - 'c' and 'esc' - you'll need to use one or the other.

    I agree with You. That wouldn't compile. And Your version is much better.

    printf("\x1b[1;25r");

    You got the idea, right?

    Thanks & best regards

    Shinobi

    --- Mystic BBS v1.12 A38 2018/01/01 (Linux/64)
    * Origin: INFOLINKA BBS (21:1/153)
  • From shinobi@21:1/153 to tenser on Wed Mar 7 16:12:08 2018
    Well yes; he's using '%c' because he wants to print 'c' as a character, not as an integer.

    Just right. According to ASCII table the number 27 is Escape character.

    The retype is there on purpose. Therefore c=27;printf("%c",c); prints ESC character. I know it's possibly not very well readable. But I use it to
    ensure I got the sequence right. I can write it easier.

    The '\x1b' is the escape character (1B hex is 27 decimal).
    This is good advice.

    Is there really any difference between writing the printf and variable and using the \x1b notation. Except of course in prior You define one variable more. When I tried that I failed to comprehend the code when I read it again. But that's more or less just my inability to use proper code. I went with
    like 10 tries and I got lost in the Hexadecimal world.

    Best regards

    Shinobi

    --- Mystic BBS v1.12 A38 2018/01/01 (Linux/64)
    * Origin: INFOLINKA BBS (21:1/153)
  • From Erazmus@21:1/133 to shinobi on Wed Mar 7 14:45:09 2018
    On 03/07/18, shinobi said the following...

    Is there really any difference between writing the printf and variable
    and using the \x1b notation. Except of course in prior You define one variable more. When I tried that I failed to comprehend the code when I read it again. But that's more or less just my inability to use proper code. I went with like 10 tries and I got lost in the Hexadecimal world.

    I guess my problem is I come from an embedded programmer background - I tend
    to work towards the most efficient code, not necessarily the easiest to read. That's why I suggested a char instead of an int - saves at least one byte of data. Also, creating a variable and asking printf to parse your string and replace the %c with your variable will take time to process at runtime, and will produce more bytes of code in your compiled binary. But there's nothing wrong with writing the code as I suggested, then putting in a comment explaining what it's doing :)

    Ian

    --- Mystic BBS v1.12 A38 2018/01/01 (Linux/32)
    * Origin: The Parity Error BBS - Kelowna, BC, Canada (21:1/133)
  • From shinobi@21:1/153 to Erazmus on Thu Mar 8 07:07:45 2018
    I guess my problem is I come from an embedded programmer background - I tend to work towards the most efficient code, not necessarily the
    easiest to read. That's why I suggested a char instead of an int - saves at least one byte of data. Also, creating a variable and asking printf
    to parse your string and replace the %c with your variable will take
    time to process at runtime, and will produce more bytes of code in your compiled binary. But there's nothing wrong with writing the code as I suggested, then putting in a comment explaining what it's doing :)

    That's totally understandable. On the other hand I'm coming from the "Big
    Data" background. That means while it runs withing 24-hours it works. :-) Well... of course it's disastrous in case I'd have to code anything for ZX Spectrum or rather Smart Watch.

    Best regards

    Shinobi

    --- Mystic BBS v1.12 A38 2018/01/01 (Linux/64)
    * Origin: INFOLINKA BBS (21:1/153)
  • From tenser@21:1/112 to shinobi on Mon Mar 12 23:03:24 2018
    Is there really any difference between writing the printf and variable
    and using the \x1b notation. Except of course in prior You define one variable more. When I tried that I failed to comprehend the code when I read it again. But that's more or less just my inability to use proper code. I went with like 10 tries and I got lost in the Hexadecimal world.

    I suppose the answer is, "it depends on what you mean by 'difference'."

    The effect on the external world, namely that some string of characters
    was printed to some stream somewhere, is the same.

    But HOW that string was printed is different.

    In general, I'd embed the character in the format string and eschew the verb/variable combination. You don't need it and in time it's just as easy
    to read the hex sequence (or the perhaps more common but admittedly
    antiquated octal syntax: "\033[...").

    --- Mystic BBS v1.12 A38 2018/01/01 (Windows/32)
    * Origin: Black Flag : ACiD Telnet HQ > blackflag.acid.org (21:1/112)
  • From tenser@21:1/112 to Erazmus on Mon Mar 12 23:36:54 2018
    I guess my problem is I come from an embedded programmer background - I tend to work towards the most efficient code, not necessarily the
    easiest to read. That's why I suggested a char instead of an int - saves at least one byte of data. Also, creating a variable and asking printf

    Except it kind of doesn't, since the argument will be promoted to an
    int in accordance with the integer promotion rules anyway.

    to parse your string and replace the %c with your variable will take
    time to process at runtime, and will produce more bytes of code in your compiled binary. But there's nothing wrong with writing the code as I suggested, then putting in a comment explaining what it's doing :)

    I don't will include a longer calling sequence and some space somewhere
    for the literal, but given that you're calling printf() anyway, it won't
    be appreciably longer unless you've got some form of very effective LTO
    that can tell that the '%c' verb is never used and avoids whatever function printf() calls internally to handle '%c'. That's unlikely.

    In my own experiment with a trivial test program, the version that uses
    the variable is actually slightly smaller on x86_64, and a tiny bit larger
    on i386 (16 bytes).

    : grex; cat a.c
    #include <stdio.h>
    int
    main()
    {
    int c = 27;

    printf("%c[H\n", c);

    return 0;
    }
    : grex; cat b.c
    #include <stdio.h>
    int
    main()
    {
    printf("\033[H\n");

    return 0;
    }
    : grex; egcc -Ofast -s -static -flto -o a a.c
    : grex; egcc -Ofast -s -static -flto -o b b.c
    : grex; ls -l a b
    -rwxr-xr-x 1 cross staff 95048 Mar 12 23:16 a
    -rwxr-xr-x 1 cross staff 95032 Mar 12 23:16 b
    : grex; size a b
    text data bss dec hex
    82357 4808 20500 107665 1a491 a
    82490 4784 19544 106818 1a142 b
    : grex;

    Note that the text segment for `a` is actually somewhat smaller
    than for `b`, though the former has a larger data segment and BSS.
    Looking at the unstripped binaries, one can see that the constant
    value for the escape character is folded directly into a push-immediate instruction, whereas it's just the lea and push for the format
    string in the version without the variable (this is for i386).

    Results are similar for amd64:

    : gaja; ls -l a b
    -rwxr-xr-x 1 cross staff 104048 Mar 13 03:13 a
    -rwxr-xr-x 1 cross staff 104040 Mar 13 03:13 b
    : gaja; size a b
    text data bss dec hex
    94533 5984 20528 121045 1d8d5 a
    94564 5976 19616 120156 1d55c b
    : gaja;

    I'm not set up at the moment to call `printf` from an embedded ARM
    program, but results compiling for aarch32 are a bit more expected:

    : gaja; arm-none-eabi-gcc -Wno-implicit-function-declaration -Ofast -c a.c
    : gaja; arm-none-eabi-gcc -Wno-implicit-function-declaration -Ofast -c b.c
    : gaja; ls -l a.o b.o
    -rw-r--r-- 1 cross staff 1036 Mar 13 03:34 a.o
    -rw-r--r-- 1 cross staff 1032 Mar 13 03:34 b.o
    : gaja; arm-none-eabi-size a.o b.o
    text data bss dec hex filename
    38 0 0 38 26 a.o
    32 0 0 32 20 b.o
    : gaja; arm-none-eabi-strip a.o b.o
    : gaja; ls -l a.o b.o
    -rw-r--r-- 1 cross staff 624 Mar 13 03:34 a.o
    -rw-r--r-- 1 cross staff 616 Mar 13 03:34 b.o
    : gaja;

    And indeed, comparing the assembler for these shows the
    single additional instruction in a.o to load 27 into r1.

    --- Mystic BBS v1.12 A38 2018/01/01 (Windows/32)
    * Origin: Black Flag : ACiD Telnet HQ > blackflag.acid.org (21:1/112)
  • From shinobi@21:1/153 to tenser on Wed Mar 14 05:43:22 2018
    and using the \x1b notation. Except of course in prior You define one
    I suppose the answer is, "it depends on what you mean by 'difference'." antiquated octal syntax: "\033[...").

    .. Correct me if I'm wrong but the \x1b syntax doesn't work on Windows. Is
    that right? Well... I mean in the Windows console none of the above works. Is it like so?

    --- Mystic BBS v1.12 A38 2018/01/01 (Linux/64)
    * Origin: INFOLINKA BBS (21:1/153)
  • From tenser@21:1/112 to shinobi on Wed Mar 14 14:26:23 2018
    .. Correct me if I'm wrong but the \x1b syntax doesn't work on Windows.
    Is that right? Well... I mean in the Windows console none of the above works. Is it like so?

    It depends on the program that's displaying the text.

    In the bad old days, we had hardwired serial terminals that just displayed whatever was sent to them in an endless scroll of text. Text was produced
    by the computer slowly enough that the user could read it as it scrolled by. Before that, terminals printed onto actual physical paper.

    Eventually, computers and terminals (and the UARTs connecting them) got
    fast enough that this sort of sucked, so you saw primitive "hit a key to continue" after a screenful of text sorts of interfaces. Multics, for
    instance, does this when printing a file to its output.

    Then someone came up with the bright idea of putting a little microcontroller into the terminal and embedding special little command sequences that the terminal could recognize and respond to *in the data sent to the terminal*. These little in-band control messages gave rise to cursor-addressing and setting little control fields for things like colors and other text
    attributes. However, each terminal vendor did this slightly differently. Eventually an ANSI committee was formed to standardize the madness and come
    up with a common subset of these so-called "terminal escape sequences." Microsoft implemented understanding these in MS-DOS in the form of 'ANSI.SYS'. Paired with the pseudo-graphical characters that IBM put in the 437 code
    page used by the IBM-PC, you had a primitive graphics facility for the PC.
    This was, of course, heavily used by BBSes.

    These days, we aren't using hardwired serial terminals all that much anymore, very few people are running MS-DOS for real work, and code pages have been replaced by Unicode and UTF-8. However, the legacy lives on in programs that are written to emulate these antiquated terminals (so called "terminal emulators" <-- a rather unsurprising name).

    It could be that the default Windows command terminal doesn't understand
    ANSI terminal escape sequences, but I'm afraid I just don't know: I don't
    use Windows. But something like SyncTERM should do ok for you.

    --- Mystic BBS v1.12 A38 2018/01/01 (Windows/32)
    * Origin: Black Flag : ACiD Telnet HQ > blackflag.acid.org (21:1/112)
  • From shinobi@21:1/153 to tenser on Thu Mar 15 06:52:46 2018
    Hello Tenser,

    It could be that the default Windows command terminal doesn't understand ANSI terminal escape sequences, but I'm afraid I just don't know: I don't use Windows. But something like SyncTERM should do ok for you.

    Thanks so much for in-depth explanation on history of terminals. So far the situation gets a bit worse when You don't use utf-8 and want to use national characters.
    In my case I tried some "door" to read book in Czech. However e.g. SyncTerm doesn't have the desired fonts. And some terminal does. It's kind of trouble
    on top of ANSI characters.
    At least I forced the Linux to get along with ANSI. It's sufficient to use
    the VT100 emulation in console and ANSI characters are there.
    Well... I guess I'll just give up the tries to support Windows. The situation is quite weird there. And I guess there are not many voices to support ANSI
    in terminal anymore.

    Thanks again & best regards

    Shinobi

    --- Mystic BBS v1.12 A38 2018/01/01 (Linux/64)
    * Origin: INFOLINKA BBS (21:1/153)