onepub-dev / dcli

An extensive library and tooling for building console/cli applications and scripts using the Dart programming language.
236 stars 26 forks source link

ask doesnt accept backspace/delete keys being touched #160

Closed sboss closed 2 years ago

sboss commented 2 years ago

Describe the bug ask() doesnt accept backspace/delete keys being touched and adds invalid characters/fails.

To Reproduce use ask() and hit the backspace/delete keys

Expected behavior that the line honors the backspace/delete keys.

Run dcli doctor: From the cli run dcli doctor

DCli version      1.8.2
OS                macos
OS version        10.16
path separator    /
dart version      2.14.2
dcli path         /<HOME>/.pub-cache/bin/dcli
dart exe path     /usr/local/bin/dart
dart path         /usr/local/bin/dart                                     which: /usr/local/bin/dart
compiler          using 'dart compile exe'
pub               using 'dart pub'
pub cache         /<HOME>/.pub-cache
PUB_CACHE Env     false
package config    not passed
PATH
                  /usr/local/opt/openssl@1.1/bin
                  /<HOME>/perl5/bin
                  /usr/local/bin
                  /usr/bin
                  /bin
                  /usr/sbin
                  /sbin
                  /Applications/VMware Fusion.app/Contents/Public
                  /Applications/Little Snitch.app/Contents/Components
                  /Library/Apple/usr/bin
                  /<HOME>/bin
                  /<HOME>/flutter/bin
                  /usr/local/sbin
                  /<HOME>/.pub-cache/bin
Shell Settings
$SHELL            /bin/bash
detected          bash
Start script      not found
dart location(s)
                  /usr/local/bin/dart
permissions
HOME              rwxr-xr-x <user>: /<HOME>
.dcli             rwxr-xr-x <user>:root /<HOME>/.dcli
templates         rwxr-xr-x <user>:root /<HOME>/.dcli/templates
pub cache         rwxr-xr-x <user>:programmer /<HOME>/.pub-cache

Additional context Add any other context about the problem here.

sboss commented 2 years ago

I dont know if this is "as-designed" or if it truly is a bug.

bsutton commented 2 years ago

Don't know about delete but backspace should work. Can you post the exact 'ask' call that you are making.

There was a problem recently around this but I thought it had been fixed. Ultimately I want to add full line editing if we detect an ansi terminal.

Anything special about the terminal you are running in? e.g. is it an ansi terminal?

sboss commented 2 years ago

it is an ansi terminal. it is a bash shell prompt in MacOS. the shell is either Terminal.app or ShellCraft.app (form AppStore)

response = ask(' ', validator: Ask.required);

so nothing is going on odd that I can tell.

bsutton commented 2 years ago

Can you add:

print('terminal: ${Terminal().hasTerminal}'); print('Ansi: ${Terminal().isAnsi}');

before the ask statement and report the output.

On linux the backspace works as expected. Delete won't work as we don't support cursor navigation so you can't move the cursor in front of a char to use delete.

S. Brett Sutton Noojee Contact Solutions 03 8320 8100

On Wed, 22 Sept 2021 at 11:56, scott @.***> wrote:

it is an ansi terminal. it is a bash shell prompt in MacOS. the shell is either Terminal.app or ShellCraft.app (form AppStore)

response = ask(' ', validator: Ask.required);

so nothing is going on odd that I can tell.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/noojee/dcli/issues/160#issuecomment-924518630, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAG32OGKFBMW7WMSGXDMXTTUDEZULANCNFSM5EP7EKIQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

bsutton commented 2 years ago

So I'm using stdion.readLineSync which means I'm reading a whole line at at time. Have a play it looks like the delete char is being handled deep in the dart vm.

I've we changed to using non-line mode then I can actually see the del character in the input stream.

can you run the following code:


void main(List<String> args) {
  while (true) {
    stdin.lineMode = false;
    final byte = stdin.readByteSync();
    if (byte < 0) {}
    if (byte == 10 || byte == 14) break;
    print('byte: $byte');
  }
}

When its running type: a del

Then report the output.

Thanks.

Edit: added del key.

sboss commented 2 years ago

from your first response.

terminal: true
Ansi: true

from your second response

> dcli test.dart
abyte: 97
sboss commented 2 years ago

I switched to another terminal applicaton and backspace works. I believe that this was an issue was a user issue and not a real issue. sorry for the distraction.

--sb

bsutton commented 2 years ago

Which terminal where you using? I would prefer that dcli works with all popular terminals.

S. Brett Sutton Noojee Contact Solutions 03 8320 8100

On Thu, 23 Sept 2021 at 07:43, scott @.***> wrote:

I switched to another terminal applicaton and backspace works. I believe that this was an issue was a user issue and not a real issue. sorry for the distraction.

--sb

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/noojee/dcli/issues/160#issuecomment-925352337, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAG32OHAXYTOK42N2STOJI3UDJEYLANCNFSM5EP7EKIQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.