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

add linenoise.readLineStatus to get status (eg: ctrl-D or ctrl-C) #16977

Merged
merged 2 commits into from
Feb 9, 2021

Conversation

timotheecour
Copy link
Member

@timotheecour timotheecour commented Feb 9, 2021

  • close Linenoise returned nil [IOError] #5795 by providing a suitable workaround; since we're now returning a status indicator, user can forward this to call into exitHandler if status was ctrl-C for example
  • allows fixing nim secret being un-quittable, as described in control+D should exit nim secret; quit sometimes doesn't work timotheecour/Nim#533: in a next PR, we can use the new API readLineStatus and exit the nim secret REPL if status was ctrl-D
  • allows user to implement a very common shell/REPL feature (found in bash, python, and pretty much all REPL I've used) which is to quit the REPL loop on ctrl-D, but just abort the prompt and go to next prompt on ctrl-C without exiting the loop

note

Please rewrite all the C code in Nim. We don't need more "static" variables, it's a desaster for multi-threading.

however this PR doesn't add more static variables, insted the state is propagated as a side variable allocated on the stack.

links

   40 typedef enum lino_error {
   41     lino_no_error,      /* No error has occurred. */
   42     lino_error,         /* Unspecified error */
   43     lino_eof,           /* Line input terminated by Ctrl-D or EOF. */
   44     lino_ioerr,         /* Line input terminated by I/O error. */
   45     lino_notty,         /* Input is not a terminal. */
   46     lino_intr           /* Line innput terminated by Ctrl-C or interrupt */
   47 } lino_error_t;

future work

allows fixing nim secret being un-quittable, as described in timotheecour#533: in a next PR, we can use the new API readLineStatus and exit the nim secret REPL if status was ctrl-D

@timotheecour timotheecour marked this pull request as ready for review February 9, 2021 03:27
@Araq
Copy link
Member

Araq commented Feb 9, 2021

New enum types should be non-pure, non-prefix but Uppercased, but this probably requires an RFC...

@Araq Araq merged commit 630f867 into nim-lang:devel Feb 9, 2021
@timotheecour timotheecour deleted the pr_close_5795_rdstdin branch February 9, 2021 17:50
@timotheecour
Copy link
Member Author

timotheecour commented Feb 9, 2021

New enum types should be non-pure, non-prefix but Uppercased, but this probably requires an RFC...

that seems controversial; non-pure and non-prefix, even if Uppercased, increases likelihood of name clashes (because of other enum's or types or const symbols).

New enum types should be non-prefix, {.pure.}, lowercase would make more sense IMO.

EDIT: as done in compilesettings which uses the quite intuitive/readable:

type
  SingleValueSetting* {.pure.} = enum ## \
                      ## settings resulting in a single string value
    arguments,        ## experimental: the arguments passed after '-r'
    outFile,          ## experimental: the output file
    ...

@Araq
Copy link
Member

Araq commented Feb 10, 2021

Pure enums have usability problems which is why every language ends up with a mechanism like "let's have a using statement inside switch" (C++). Name clashes should be resolved via EnumType.value if and when they come up, just like every other name clash.

@timotheecour timotheecour added the TODO: followup needed remove tag once fixed or tracked elsewhere label Mar 1, 2021
ardek66 pushed a commit to ardek66/Nim that referenced this pull request Mar 26, 2021
…m-lang#16977)

* add linenoise.readLineStatus to get status (eg: ctrl-D or ctrl-C)

* changelog
@timotheecour timotheecour removed the TODO: followup needed remove tag once fixed or tracked elsewhere label Jul 6, 2021
Araq pushed a commit that referenced this pull request Oct 6, 2024
follow up #16977

it was added in 1.6.0
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

Successfully merging this pull request may close these issues.

Linenoise returned nil [IOError]
2 participants