Exiting the interactive editor, Ctrl-C

Posted on
  • Hey,

    I was using ctrl-c when I wanted to break out of the interactive editor when connected via terminal. That worked great, so far. (BTW, that simple interactive mode is the coolest thing since years. Could ignore/convert special chars, as it doesn't handle them very well, but other than that, so damn perfect.)

    Now I have that cc3000 on my Espruino board (1v63), ctrl-c does a power cycle for the cc3000 and won't let me out of the editor anymore.

    Any other way to exit the editor (without equalizing the bracket levels or deleting all lines).
    And that power cycling, bug or feature?

  • Yeah, it's a bit tricky - Ctrl-C should really break out of what's currently executing (which is what's happening with the CC3000). I guess I could make it only break out of execution if you press it twice though...

    At the moment the only solution is to just hold down delete when the CC3000 is active. If there's another common control code I could implement for clearing the line I'm happy to do that though? Ctrl+L seems possible.

    With the power cycling, it's a feature (sadly). It's taken quite a lot of work to modify the CC3000 drivers such that they don't just totally hang the device when the CC3000 fails to respond. I don't know if it crashes because of something Espruino is doing, but I don't believe so. There's no error correction or checking so even the slightest glitch would cause a problem - I think it's something that other microcontrollers using CC3000 will have to work around as well if they want something reliable :(

  • Hey Gordon,

    Thanks. At least I don't feel that stupid when blindly deleting lines :)

    I guess, I would keep ctrl-C for the interactive part and add a "system" key shortcut to kill the rest. Ctrl-S/R/Q or something (therby totally ignoring what traditional bindings might exist in another geek's world).

  • I'm with Stev, keep ctrl+c for breaking out of editor, so it behaves in a manner similar to how other CLIs work.

    If a magic keystroke is needed for resetting certain attached device, it should be something different.

  • Hmm - I wonder how you'd break out of while (1); in node? Ctrl-C doesn't work (i'd assumed it did!).

    Imagine you typed while(1); in Espruino and you then wanted to stop execution, what would you actually press that you'd expect would break out? For me it'd be Ctrl+C.

    If you're looking at how other CLIs work: if you're using Bash/sh/etc and you run a program, maybe cat, and you want to exit it you press Ctrl+C, which sends SIGINT. If you do a loop and want to break out in Python, you press Ctrl+C. It's the obvious way to break out of what's running.

    Perhaps what's needed is actually to make Ctrl-C clear the line, but if Espruino hasn't returned to the console and handled it within ~200ms, it properly breaks out of what it's doing?

  • So is the reason that ctrl+c resets the CC3000 instead of clearing the line because there's always something executing related to the CC3000, and ctrl+c is hitting that instead of clearing the line? If so, I missed that bit - that would make more sense.

    As for behavior of ctrl+c, what about having it clear the line if there's anything in the line editor - or if there isn't, break out of whatever it's doing.

  • Yes, that's the issue. Espruino checks the CC3000 on idle - and realistically that means that it's spending 99% of it's time waiting for the CC3000, so chances are that when you hit Ctrl+C it'll be in that code.

    While I guess it could ignore Ctrl+C while in CC3000 code, it's probably a good thing that you can break out of it if you need to.

    I guess the clear line thing is a possibility, but I guess you still risk accidentally resetting the CC3000 - quite often I Ctrl-C on a blank line just out of habit :)

  • Right, just fixed. When compiled it'll be at: http://www.espruino.com/binaries/git/com­mits/e2f0e2357c1465811388e2d32654174e460­0b0a6

    So what it does is if you press Ctrl-C and no task is taking more than ~0.5 sec it'll clear the line, but if a task carries on for longer than 0.5 sec after you press Ctrl-C then it'll break out of that task.

    It seems to work really well - it basically does exactly what you'd expect :)

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

Exiting the interactive editor, Ctrl-C

Posted by Avatar for Stev @Stev