ImportC and color syntax highlighting
jfondren
julian.fondren at gmail.com
Sun Sep 12 19:38:40 UTC 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:
```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.
More information about the Digitalmars-d
mailing list