Coder Social home page Coder Social logo

Comments (4)

barmalei avatar barmalei commented on September 28, 2024

Your HTTP reading strategy is quite aggressive :) Think it can make browser busy. From the zebra point of view there are number of things that you don't have to do:

  • don't call event listener methods directly (textUpdated). This is only text model who knows how to fire events.
  • Don't touch setExtraChar. That is one of weird thing I want to remove. Now it is supposed to be used for internal cache that keeps measured line width. The result of the method calling with label is unpredictable.
  • You also should not call parse method, since it is just parse and update text without triggering any text model events. There are three methods in text model that are supposed to be used for text updaing: setValue, write, remove

One more thing I suggest is replace label with text field (in read only mode). It allows user to copy paste desired parts. So, try the code snippet below (it is simplified comparatively to your code, but think you can easily modify for your needs):

zebra.ready(function() {
    eval(zebra.Import("ui", "layout"));

    var canvas = new zCanvas(400, 400);
    canvas.fullScreen();
    var root = canvas.root;
    var log = new zebra.ui.TextField(new zebra.data.Text("Internal Log"));
    log.setEditable(false);
    log.setFont(new zebra.ui.Font("Courier New", 14));

    root.properties({
        layout : new BorderLayout(8,8),
        border : new Border(),
        padding: 8,
        kids: {
           CENTER: new zebra.ui.ScrollPan(log),
        }
    });

    // read log every 1.5 second
    zebra.util.task(function(ctx) {
        zebra.io.GET("http://localhost:8090/tests/server.log", function(r) {
            var model = log.view.target;
            // add text to the end of text field
            model.write(r.responseText, model.textLength);
            log.repaint();
        });
    }).run(1000, 1500);
});

from zebkit.

williame avatar williame commented on September 28, 2024

Your HTTP reading strategy is quite aggressive :) Think it can make browser busy.

Its a 'long poll' so it stalls if there's no update.

replace label with text field (in read only mode)

Thanks, this is much nicer! I can get it to tail by putting the cursor at the end, and I don't have the mess with scroll bars any more.

model.write(r.responseText, model.textLength);

This works nicely. The reason I had avoided it before and done my own calls to parse() is that I want to syntax-highlight and the write() destroys the last Line each time, overwriting whatever I set with setExtraChar.

As an alternative to using setExtraChar to track my own attributes-per-line, I've changed my code to have its own shadow array of attributes. This is fine for read-only scenarios but might need rethinking if I enable edit.

from zebkit.

barmalei avatar barmalei commented on September 28, 2024

As an alternative of "setExtraChar" method to keep meta information about a line you can consider of usage internal line structure." zebra.data.Text" keeps lines as the following structure:

function Line(s) {
    this.s = s;
    this.l = 0;
}

You can iterate through the structures by accessing "lines" field (array) of the text model class and add desired attribute to it.

from zebkit.

williame avatar williame commented on September 28, 2024

Yes, I tried that before settling on a separate array showing the model's lines.

The problem seems to be that when write is called, it recreates the last line's Line() so any attributes I put in there get lost.

from zebkit.

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.