digitalmars.D - ImportC and color syntax highlighting
- Walter Bright (4/4) Sep 11 2021 Now that I'm writing C test cases again (for #ImportC), the lack of colo...
- jfondren (23/27) Sep 11 2021 Neat, I wasn't aware of this.
- Walter Bright (2/34) Sep 12 2021 Thanks. I'll see what I can do. I've never heard of select().
- Walter Bright (3/6) Sep 12 2021 I'm not too familiar with I/O on Linux. If you could modify ttkeysininpu...
- Walter Bright (19/26) Sep 12 2021 I'm looking at:
- Brian (7/17) Sep 12 2021 Speaking of I/O: did you know that med will work just fine on
- Walter Bright (2/3) Sep 13 2021 Pulled. Thanks!
- jfondren (30/38) Sep 12 2021 I went with adding a tt* function:
- Walter Bright (3/6) Sep 13 2021 I added this. It turns med from burning all the CPU to using negligible ...
- Walter Bright (2/3) Sep 13 2021 Should be good to go now, including adding a v1.1.0 tag.
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.
Sep 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.
Sep 11 2021
On 9/11/2021 4:04 PM, jfondren wrote:On Saturday, 11 September 2021 at 22:25:31 UTC, Walter Bright wrote:Thanks. I'll see what I can do. I've never heard of select().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/adcc084e21427236957a f94f3547b22a89c7c1c 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.
Sep 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!
Sep 12 2021
On 9/12/2021 2:23 AM, Walter Bright wrote:On 9/11/2021 4:04 PM, jfondren wrote: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.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!
Sep 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: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/9On 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!
Sep 12 2021
On 9/12/2021 5:14 AM, Brian wrote:A PR doing the mechanical change: https://github.com/DigitalMars/med/pull/9Pulled. Thanks!
Sep 13 2021
On Sunday, 12 September 2021 at 09:23:06 UTC, Walter Bright wrote:On 9/11/2021 4:04 PM, jfondren wrote:I went with adding a tt* function: ```d /************************** * 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.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!
Sep 12 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!
Sep 13 2021
On 9/11/2021 4:04 PM, jfondren wrote:[...]Should be good to go now, including adding a v1.1.0 tag.
Sep 13 2021