Giter Club home page Giter Club logo

Comments (2)

Chainfire avatar Chainfire commented on July 20, 2024

Related to #38 . This is a real issue, your suggested fix may work as a temporary work-around. Looking at a better way to fix it.

from libsuperuser.

d4rken avatar d4rken commented on July 20, 2024

My code is a bit different, but it's based on libsuperuser and I've got the same bug, funnily enough I never ran into this until yesterday (when doing cat on an xml file). The mentioned workaround above doesn't work like that for me.
This works:

echo $'\n" + command.getMarker() + "' $?\n
echo $'\n" + command.getMarker() + "' >&2\n

The issue with the workaround is that in all non edge cases like this we get an extra empty line in our ouput.

Currently my solution is to check the index and if necessary split the output.
This is cleaner because it doesn't alter the output, but slightly worse in performance, because instead of just checking every line with String.startsWith(marker) we do a String.contains(marker) but I doubt that is noticeable. So inside the stream gobblers onNewLine method we have:

public void onNewLine(@NonNull String line) {
     synchronized (InteractiveShell.this) {
         if (mCommand == null)
             return;
         int markerIndex = line.indexOf(mCommand.getMarker());
         if (markerIndex != -1) { // Line contains a marker
             if (markerIndex > 0) { // We have hit the edge case, split off output.
                 String clingyOutput = line.substring(0, markerIndex);
                 addBufferOutput(clingyOutput);
                 processLine(clingyOutput, mGlobalOutputListener); 
             }
             try {
                 int exitCodeIndex = markerIndex + mCommand.getMarker().length() + 1; // Adjust exitcode position for edge case if necessary
                 mLastExitCode = Integer.valueOf(line.substring(exitCodeIndex, exitCodeIndex + 1));
             } catch (Exception e) {
                 Timber.tag(TAG).e(e, null);
                 Bugsnag.notify(e);
             }
             mLastMarkerOutput = mCommand.getMarker();
             processMarker();
         } else {
             addBufferOutput(line);
             processLine(line, mGlobalOutputListener);
         }
     }
 }

@Chainfire If you want I can submit a PR with this change.

from libsuperuser.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.