Thread overview
ImportC and color syntax highlighting
Sep 11, 2021
Walter Bright
Sep 11, 2021
jfondren
Sep 12, 2021
Walter Bright
Sep 12, 2021
Walter Bright
Sep 12, 2021
Walter Bright
Sep 12, 2021
Brian
Sep 13, 2021
Walter Bright
Sep 12, 2021
jfondren
Sep 13, 2021
Walter Bright
Sep 13, 2021
Walter Bright
September 11, 2021
Now that I'm writing C test cases again (for #ImportC), the lack of color syntax highlighting was annoying. Fixed it:

https://github.com/DigitalMars/med/commit/adcc084e21427236957a7f94f3547b22a89c7c1c

and did C++ while I was at it.
September 11, 2021

On Saturday, 11 September 2021 at 22:25:31 UTC, Walter Bright wrote:

>

Now that I'm writing C test cases again (for #ImportC), the lack of color syntax highlighting was annoying. Fixed it:

https://github.com/DigitalMars/med/commit/adcc084e21427236957a7f94f3547b22a89c7c1c

and did C++ while I was at it.

Neat, I wasn't aware of this.

It's a little bit annoying to compile from source as my distro's dmd/ldc2 packages don't include 32-bit libraries but this doesn't build under -m32, and gdc doesn't come with gdmd. But with gdmd, it builds out of master with

make DMD=gdmd -f linux.mak

It only has one v1.0.0 tag from 2014, so dub run med fails with a bunch of ancient errors:

.dub/packages/med-1.0.0/med/src/med/buffer.d(254,16): Error: instead of C-style syntax, use D-style `dchar[6 + 1] b

meanwhile dub run med@~master --compiler=gdc --arch=x86 pulls the latest code but can't build due to -Werror and some "statement is not reachable" warnings.

When running it, it pegs a CPU at 100% because it's constantly running ttkeysininput(). That's enough to cause a fan to run at high speed on this laptop. But, that's easily fixed with select() or similar against stdin.

September 12, 2021
On 9/11/2021 4:04 PM, jfondren wrote:
> On Saturday, 11 September 2021 at 22:25:31 UTC, Walter Bright wrote:
>> Now that I'm writing C test cases again (for #ImportC), the lack of color syntax highlighting was annoying. Fixed it:
>>
>> https://github.com/DigitalMars/med/commit/adcc084e21427236957a7f94f3547b22a89c7c1c 
>>
>>
>> and did C++ while I was at it.
> 
> Neat, I wasn't aware of this.
> 
> It's a little bit annoying to compile from source as my distro's dmd/ldc2 packages don't include 32-bit libraries but this doesn't build under -m32, and gdc doesn't come with gdmd. But with gdmd, it builds out of master with
> 
> ```
> make DMD=gdmd -f linux.mak
> ```
> 
> It only has one v1.0.0 tag from 2014, so `dub run med` fails with a bunch of ancient errors:
> ```
> .dub/packages/med-1.0.0/med/src/med/buffer.d(254,16): Error: instead of C-style syntax, use D-style `dchar[6 + 1] b
> ```
> 
> meanwhile `dub run med@~master --compiler=gdc --arch=x86` pulls the latest code but can't build due to -Werror and some "statement is not reachable" warnings.
> 
> When running it, it pegs a CPU at 100% because it's constantly running ttkeysininput(). That's enough to cause a fan to run at high speed on this laptop. But, that's easily fixed with select() or similar against stdin.

Thanks. I'll see what I can do. I've never heard of select().
September 12, 2021
On 9/11/2021 4:04 PM, jfondren wrote:
> When running it, it pegs a CPU at 100% because it's constantly running ttkeysininput(). That's enough to cause a fan to run at high speed on this laptop. But, that's easily fixed with select() or similar against stdin.

I'm not too familiar with I/O on Linux. If you could modify ttkeysininput() to use select(), I'm interested to learn how it's done. Thanks!
September 12, 2021
On 9/12/2021 2:23 AM, Walter Bright wrote:
> On 9/11/2021 4:04 PM, jfondren wrote:
>> When running it, it pegs a CPU at 100% because it's constantly running ttkeysininput(). That's enough to cause a fan to run at high speed on this laptop. But, that's easily fixed with select() or similar against stdin.
> 
> I'm not too familiar with I/O on Linux. If you could modify ttkeysininput() to use select(), I'm interested to learn how it's done. Thanks!

I'm looking at:

 #include <stdio.h>
 #include <sys/select.h>

 int main(void) {
    fd_set s_rd, s_wr, s_ex;
    FD_ZERO(&s_rd);
    FD_ZERO(&s_wr);
    FD_ZERO(&s_ex);
    FD_SET(fileno(stdin), &s_rd);
    select(fileno(stdin)+1, &s_rd, &s_wr, &s_ex, NULL);
    return 0;
 }

from


https://stackoverflow.com/questions/6418232/how-to-use-select-to-read-input-from-keyboard-in-c

Comparing it with the man page makes sense.

  https://man7.org/linux/man-pages/man2/select.2.html

I'll give it a try.
September 12, 2021
On Sunday, 12 September 2021 at 09:32:38 UTC, Walter Bright wrote:
> On 9/12/2021 2:23 AM, Walter Bright wrote:
>> On 9/11/2021 4:04 PM, jfondren wrote:
>>> When running it, it pegs a CPU at 100% because it's constantly running ttkeysininput(). That's enough to cause a fan to run at high speed on this laptop. But, that's easily fixed with select() or similar against stdin.
>> 
>> I'm not too familiar with I/O on Linux. If you could modify ttkeysininput() to use select(), I'm interested to learn how it's done. Thanks!

Speaking of I/O: did you know that med will work just fine on OpenBSD (and every other Posix system, and probably macOS too) if all the version(linux) are replaced with version(Posix)? This is because med is using generic Unix I/O.

A PR doing the mechanical change: https://github.com/DigitalMars/med/pull/9
September 12, 2021

On Sunday, 12 September 2021 at 09:23:06 UTC, Walter Bright wrote:

>

On 9/11/2021 4:04 PM, jfondren wrote:

>

When running it, it pegs a CPU at 100% because it's constantly running ttkeysininput(). That's enough to cause a fan to run at high speed on this laptop. But, that's easily fixed with select() or similar against stdin.

I'm not too familiar with I/O on Linux. If you could modify ttkeysininput() to use select(), I'm interested to learn how it's done. Thanks!

I went with adding a tt* function:

/**************************
 * Return when there are unread chars ready in the input.
 */

void ttwaitkeys()
{
    import core.sys.posix.sys.select;
    fd_set readfds;
    FD_ZERO(&readfds);
    FD_SET(0, &readfds);
    select(1, &readfds, null, null, null);
}

and running that in the while loop at the outset of getkey():

    ttyield();
    while (hasmouse && !ttkeysininput())
    {   c = mouse_command();
        if (c)
            return c;
        ttyield();
        ttwaitkeys();
    }
    c = term.t_getchar();

This fixes the CPU use and results in normal key input. But, it can just be replaced with a 'break;' in the same place of that loop. And it should break mouse handling.

September 13, 2021
On 9/12/2021 12:38 PM, jfondren wrote:
> This fixes the CPU use and results in normal key input. But, it can just be replaced with a 'break;' in the same place of that loop. And it should break mouse handling.

I added this. It turns med from burning all the CPU to using negligible amounts. The mouse still works, too! Thanks!
September 13, 2021
On 9/12/2021 5:14 AM, Brian wrote:
> A PR doing the mechanical change: https://github.com/DigitalMars/med/pull/9

Pulled. Thanks!
September 13, 2021
On 9/11/2021 4:04 PM, jfondren wrote:
> [...]

Should be good to go now, including adding a v1.1.0 tag.