Comments (4)
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.
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.
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.
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)
- Rotation sample HOT 7
- Keyboard Event error when run in CEF framework HOT 2
- How to trigger the tree and Combo box selected event HOT 5
- How to refresh page after I have updated the UI component? HOT 7
- The zebkit canvas will block the html event.
- Calendar can't choose time, minute and second HOT 2
- ui.Lable and grid cells and captions alignment is changed in latest chrome HOT 9
- Is there a possibility to export hierarchy of UI components to ZSON? HOT 2
- INPUT fields: Unable to enter special / national characters HOT 2
- How to stop event in zebra?
- Does zebkit works with webpack?
- Error on display text, this is empty in Edge and Internet Explorer version 11-10
- Resizing the left caption of Grid
- When We create Object of new ui.zCanvas(element,width,height) except chrome other browser throw type undefine or null error. HOT 2
- Issue regarding margin left or padding left to label.
- HtmlTextField can't works in modal window HOT 1
- Future of Zebkit HOT 2
- HtmlElement Placed In ShaperPan Is Not Visible
- how can I change the text label of a button? HOT 4
- setFullSize causing an issue HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zebkit.