Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_char/1 panic #2794

Closed
flexoron opened this issue Jan 26, 2025 · 9 comments
Closed

get_char/1 panic #2794

flexoron opened this issue Jan 26, 2025 · 9 comments

Comments

@flexoron
Copy link

v0.9.4-286-g00e6e323

$ scryer-prolog -f
?- get_char(A).
a
   A = a.
?- get_char(a).
a
   true.
?- get_char(End_of_file).
^D
   End_of_file = end_of_file.
?- get_char(end_of_file).
^D
thread 'main' panicked at src/machine/system_calls.rs:3469:50:
called `Option::unwrap()` on a `None` value
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
$
@UWN
Copy link

UWN commented Jan 26, 2025

even

?- get_char(end_of_file).
a
thread 'main' panicked at src/machine/system_calls.rs:3485:50:
called `Option::unwrap()` on a `None` value

in other words:

?- get_char(end_of_file).
   inputs("a"),
   false. % expected, but not found

However,

?- open('/dev/null',read,S),get_char(S,end_of_file).
   S = '$stream'(0x638d31165ea0).
?- open('/dev/null',read,S),get_char(S,end_of_file),close(S).
   S = '$dropped_value'.

@flexoron
Copy link
Author

flexoron commented Jan 26, 2025

On the side, get_single_char/1 behaves different. Are these results below expected?

?- use_module(library(charsio)). 
   true.

?- get_single_char(C). % Ctrl-D pressed 
   C = d. % unexpected

?- get_single_char(Char). % Ctrl-Shift-D pressed
   Char = d. % why not 'D' ?

?- get_single_char(Char). % Shift-D
   Char = 'D'. % expected

Question: Ctrl key is generally ineffective? Except Ctrl-C, Ctrl-M and (Toplevel) Ctrl-J.

?- get_single_char(Char). % Instead of <Return>, press Ctr-M Ctrl-M 
   Char = '\n'.
?- get_single_char(Char). % Ctrl-J Ctrl-M
   Char = '\n'.
?- get_single_char(Char). % Ctrl-J Ctrl-J
   Char = j. % Ctrl-J is ignored but behaves like <Return> or Ctrl-M (at the toplevel). 

?- get_char(Char). % Ctrl-J Ctrl-J

   Char = '\n'.
?- 

@bakaq
Copy link
Contributor

bakaq commented Jan 26, 2025

The Ctrl key is used in the terminal to send special terminal codes, which can be detected and identified but which do not interact with the Shift key, so the combination Ctrl+Shift is kind of useless in the terminal because it will send the same code as with just Ctrl. That's why you won't see Ctrl+Shift being used in Vim, and probably part of the reason Emacs users (which use A LOT of modifiers) prefer the GUI.

I don't think it's the role of get_char/1 or get_single_char/1 to get modifiers (Ctrl, Alt), but we probably should present some way to do that eventually.

@flexoron
Copy link
Author

Useless?
Ctrl-C = SIGINT
Ctrl-Shift-C = Copy text

@bakaq
Copy link
Contributor

bakaq commented Jan 26, 2025

Ctrl-Shift-C doesn't get passed to applications, is just what most terminals use to copy text. Notice that it's the terminal that does the work in this case, and the application doesn't get anything.

@flexoron
Copy link
Author

flexoron commented Jan 27, 2025

A keyboard is attached to the kernel who provides scancodes.
So, I guess, a detached application can open /dev/input/event5 (perhaps the keyboard)?.

Another example how scryer reacts on a Ctrl key:

$ scryer-prolog -f
?- use_module(library(charsio)).
   true.
?- get_single_char(C). % Ctrl-Z
   C = z.
?- halt.
but
$ scryer-prolog -f
?- get_char(C). % Ctrl-Z

[1]+  Stopped                 scryer-prolog -f
$

I know what you talking about, so don't let us discuss it.
The point is that I get different results( get_char, get_single_char)
and the question is why do we need it and for what?
And let me say in case of ^M (get_single_char/1)
I expect 'm' and not '\n' or the other way around for ^J expecting '\n' and not 'j'.

@flexoron
Copy link
Author

flexoron commented Jan 27, 2025

Here is another issue:
?- get_char(C).%comment
C = '%'.
?-
#2795

@UWN
Copy link

UWN commented Jan 28, 2025

Please do not mix so many different aspects into one single issue. The only effect is that this issue will then never be closed, because of some entirely unrelated thing.

@flexoron
Copy link
Author

Replaced! #2797

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants