Pebble SDK / SimplyJS doesn't honor the \ t character

I have an interesting time trying to get my Pebble watch to follow the escape character \t

when pushing data to my watch (using SimplyJS).

The following snippet is the code I used:

simply.scrollable(true);
simply.style('small');
simply.fullscreen(true);

var aflLadderUrl = 'http://www.sportal.com.au/feeds/sss/afl_ladder.json';

var ladderContent = '';

ajax({ url: aflLadderUrl, type: 'json'}, 
  function(data) {
   var i = 0;
   while (i < 18){
     ladderContent = ladderContent + data.ladder[i].friendly_name + '\t\t\t' + data.ladder[i].percentage + '\n';
        i++;  
   } 
   simply.text({
     title: 'AFL Ladder',
     body: ladderContent
   });
  }, 
  function() {
   simply.text({
    title: 'AFL Ladder',
    body: 'No internet connection'
   });
  }
);

      

I am currently observing what \n

is running and I can see that on my watch each row of data is displayed on a separate line. However, it looks like mine is being \t

ignored, and instead of tabs inserted into my string, zero white space is 'my name is' + '\t\t\t' + 'dave'

displayed (i.e. displayed as my name isdave

).

I also tried to compile the Hello World program using only the Pebble SDK (taking the code from https://github.com/kristofvc/pebble-hello-world/blob/master/src/pebble_hello_world.c and adding a couple \t\t

in the line to be printed in line 11) and also noticed that the SDK distinguishes \n

characters, but not \t

characters (as my SimplyJS app did).

My question is, is it possible for Pebble's display tabs (or via SDK or SimplyJS) to be the same as you'd expect them to work when printed to the console? I understand that the \ t character may not be supported, and instead of using it, \t

I could just use spaces, but I'm curious about that.

Please let me know if you need more information.

Thanks in advance!

+3


source to share


1 answer


Since it \t

is a control (non-printable) character, it does not match any glyph and will not be "displayed" sequentially, if at all. Terminal emulators will interpret it differently than spreadsheet software reading TSV file, for example. It looks like the part of Pebble's firmware that converts the bytestring to display pixels is simply ignoring \t

, although I can't find it in the SDK documentation.

If you are using a fixed width font, you can implement your own tabs using spaces, for example:



var data = {ladder: [
  {friendly_name: "Cool Team", percentage: 80.0},
  {friendly_name: "Really Cool Team", percentage: 80.0},
  {friendly_name: "The Coolest Team of All", percentage: 80.0}
]}

var len = function(obj) {return obj.friendly_name.length}
var longer = function(a, b) {return len(a) > len(b) ? a : b}
var longestName = len(data.ladder.reduce(longer))

var tab = function(obj) { return new Array(longestName - len(obj) + 2).join(" ") }
var print = function(obj) { return obj.friendly_name + tab(obj) + obj.percentage }

var ladderContent = data.ladder.map(print).join("\n")
// Cool Team               80
// Really Cool Team        80
// The Coolest Team of All 80

      

+2


source







All Articles