Hark Dand
Hark Dand
CC#
Created by Hark Dand on 5/31/2024 in #help
[SOLVED] .NET runtime control over tty input and output
Summary: .NET seems to behave correctly when using termios. .NET does not seem to add any preprocessing to the I/O of a console application if configured correctly.
11 replies
CC#
Created by Hark Dand on 5/31/2024 in #help
[SOLVED] .NET runtime control over tty input and output
Turns out: The code does work. I just had a major flaw my approach of testing this... Changing the Console.Readkey(true); to a while(true) { Console.Readkey(true); } works a lot better. CTRL+C, of course, is a keystroke, and will end the running program... not because the interrupt gets processed, but because the program ends after a single key press...
11 replies
CC#
Created by Hark Dand on 5/31/2024 in #help
[SOLVED] .NET runtime control over tty input and output
Printing the c_lflag also correctly shows me 101000110000
11 replies
CC#
Created by Hark Dand on 5/31/2024 in #help
[SOLVED] .NET runtime control over tty input and output
I have this minimal example:
public class NonCanonicalTerminalExample
{
private const int STDIN_FILENO = 0;
private const int TCSAFLUSH = 2;

[DllImport("libc")]
public static extern int tcgetattr(int fd, out Termios termios);

[DllImport("libc")]
public static extern void cfmakeraw(ref Termios termios);

[DllImport("libc")]
public static extern int tcsetattr(int fd, int optional_actions, ref Termios termios);

public static void Main(string[] args)
{
var termios = new Termios();
tcgetattr(STDIN_FILENO, out termios);
cfmakeraw(ref termios);
tcsetattr(STDIN_FILENO, TCSAFLUSH, ref termios);

Console.ReadKey(true);
}
}
public class NonCanonicalTerminalExample
{
private const int STDIN_FILENO = 0;
private const int TCSAFLUSH = 2;

[DllImport("libc")]
public static extern int tcgetattr(int fd, out Termios termios);

[DllImport("libc")]
public static extern void cfmakeraw(ref Termios termios);

[DllImport("libc")]
public static extern int tcsetattr(int fd, int optional_actions, ref Termios termios);

public static void Main(string[] args)
{
var termios = new Termios();
tcgetattr(STDIN_FILENO, out termios);
cfmakeraw(ref termios);
tcsetattr(STDIN_FILENO, TCSAFLUSH, ref termios);

Console.ReadKey(true);
}
}
I use cfmakeraw here for ease of use; It disables the ISIG flag which is responsible for processing the CTRL+C keybind. However, this still cancels on CTRL+C, which it should not.
11 replies
CC#
Created by Hark Dand on 5/31/2024 in #help
[SOLVED] .NET runtime control over tty input and output
I would agree with this if it weren't for the fact that the same approach (calling the same functions from termios) works as expected when using C. Additionally, setting Console.TreatControlCAsInput to true does disable CTRL+C. That leads me to the assumption that this would not be something the OS is responsible for but rather the .NET runtime
11 replies
CC#
Created by Hark Dand on 2/13/2023 in #help
✅ Indexer return collection or single object depending on parameter
I think that seems to be the answer to my question, so thank you.
44 replies
CC#
Created by Hark Dand on 2/13/2023 in #help
✅ Indexer return collection or single object depending on parameter
Would you have an idea on how that has been implemented?
44 replies
CC#
Created by Hark Dand on 2/13/2023 in #help
✅ Indexer return collection or single object depending on parameter
Yeah, I know that
44 replies
CC#
Created by Hark Dand on 2/13/2023 in #help
✅ Indexer return collection or single object depending on parameter
I found an example of what I am trying to do: https://ironsoftware.com/csharp/excel/examples/read-excel/
44 replies
CC#
Created by Hark Dand on 2/13/2023 in #help
✅ Indexer return collection or single object depending on parameter
And the latter is what I am trying to achieve
44 replies
CC#
Created by Hark Dand on 2/13/2023 in #help
✅ Indexer return collection or single object depending on parameter
Yes, that would solve the problem. @Sterbehilfe already proposed that. But using the indexer for ranges would then look look like this someClass[“A1“, “A11“] Instead of someClass[“A1:A11“]
44 replies
CC#
Created by Hark Dand on 2/13/2023 in #help
✅ Indexer return collection or single object depending on parameter
Not really, since I am still looking for what I wrote in the original post
44 replies
CC#
Created by Hark Dand on 2/13/2023 in #help
✅ Indexer return collection or single object depending on parameter
Whether or not it would be sensible to implement it with indexers, I would still like to know if it is possible
44 replies
CC#
Created by Hark Dand on 2/13/2023 in #help
✅ Indexer return collection or single object depending on parameter
I don’t know if I can agree with that
44 replies
CC#
Created by Hark Dand on 2/13/2023 in #help
✅ Indexer return collection or single object depending on parameter
Yeah, my bad, it does
44 replies
CC#
Created by Hark Dand on 2/13/2023 in #help
✅ Indexer return collection or single object depending on parameter
Something interesting I found: The range operator is exclusive of the latter part, So [1..4] will give back the first 3 elements, which I find to be quite unintuitive.
44 replies
CC#
Created by Hark Dand on 2/13/2023 in #help
✅ Indexer return collection or single object depending on parameter
Okay, had a quick look at Range. It seems like Ranges won't be the solution either. Their constructor is Range(Index, Index), and the Index constructor is Index(int value, bool fromEnd = false), which I wouldn't be able to properly use as my data structure is more like a Dictionary. I could, of course, introduce some sort of ordering on the Dictionary, but the Range "operator" (e.g. [1..3]) still isn't what I'm searching for.
44 replies
CC#
Created by Hark Dand on 2/13/2023 in #help
✅ Indexer return collection or single object depending on parameter
Yes, that would be the solution @Sterbehilfe proposed, that would surely work. I'll have a look into ranges. Never used them before, so I can't for sure say whether or not they work for my use case. Thanks for the suggestions, though!
44 replies
CC#
Created by Hark Dand on 2/13/2023 in #help
✅ Indexer return collection or single object depending on parameter
Yeah, I thought about doing that. That would probably work (and I considered that option, maybe should've included that), but partially just out of interest I would really like to know if it would be possible with my proposition.
44 replies
CC#
Created by Hark Dand on 2/5/2023 in #help
✅ Set up SpecFlow Logging with 2 different projects
The following did the trick: 1. Add the SpecFlow NuGet package with the same version I had in Project.Specs to Project. 2. From there, put a reference into the class which needs to use the logger 3. Assign the logger in test methods Need to find out how to automatically set the logger via the SpecFlow hooks in Project.Specs, but that's a question for another day. Thank you for your help!
9 replies