2

I working on my ANSI formatting code for jQuery Terminal. It almost working but I have one issue it's related to 0A ansi code that should move cursor (also other 0 cursor codes: B C D E F)

I've tested with ervy library and it make a difference If I remove \x1b\[0[A-D] from the string before outputting to terminal.

I'm not sure If I process the ANSI escapes correctly, I'm splitting the output into lines before each line I'm increasing the y position and set x to 0 and when there is cursor ANSI escape code I move the cursor. And I'm using array of arrays to hold the output of the screen. (Not sure but I think it will be faster if I don't join the lines into one strings till the end, but I created this that way because it was first idea not because of speed).

I'm not sure that I should do if there is 0.

Here is the output of two plots from ervy library

enter image description here

Correct plot

enter image description here

plot without zero codes.

I'm trying to debugg my code (I think that on one point the plot look on the second screen), but I don't know how to process 0 ANSI escape codes.

I'm using Wikipedia as reference.

4

The behavior seen in DEC VTs is easier to understand with ZDM (zero default mode) in mind. From ECMA-48:

A parameter value of 0 represents a default parameter value which may be different from 0.

For cursor movement sequences the spec defines the default as "1", therefore these are all equal in ZDM:

  • CSI A (omitted param defaults to 1)
  • CSI 0 A (0 has the special meaning of the default value)
  • CSI 1 A (param happens to be the default value)

As far as I am aware, all CSI sequences implemented in DEC devices follow the ZDM scheme.

Later on ZDM was removed from the specs, thus "0" now should read as number and not as special placeholder for a default value anymore. But the DEC devices did not switch that behavior. Thus it boils down to the question, whether a VT100+ compatible emulator can be spec conform at all.

|improve this answer|||||
6

These escape sequences take a repetition count as parameter, e.g. \e[5A moves the cursor up by 5 lines, \e[10C moves the cursor to the right by 10 columns, etc. The value, if omitted, defaults to 1.

But what should happen if the parameter is explicitly specified as 0?

Let's look at the standards. ECMA-48, as well as ctlseqs.html (documenting xterm's behavior) don't say anything about it, that is, implicitly imply that they should move by zero. On the other hand, DEC STD 070 says a value of 0 should move by 1.

Let's look at implementations. urxvt interprets 0 as 0 for some of these sequences, e.g. for vertical cursor movement, but not for horizontal (there it's 1). All other terminals I've checked interpret it as 1 (including xterm, thus its behavior and documentation don't match).

The standards are inconsistent. The implementations are inconsistent.

What could you do? Don't use these. If you encounter a library that emits these, file a bug and ask its developers to stop using these problematic escape sequences, since no matter what they expect, it's against some of the standards and sure breaks in some of the terminals.

|improve this answer|||||
  • I've tried multiple things, and it seems that the most correct output I've got when I use cursor.y -= value + 1; Maybe because on next line it increase cursor.y by 1. so In my code if I use 0 it's cursor.y-- so in next line cursor stay the same. If I change this code plot is completely broken. But the problem is that the code is at the beginning of the line. I'm not sure if I have but in other place that make this work that way. – jcubic Dec 29 '19 at 10:23
  • @jcubic I guess that that lib's broekn; try changing the curForward: ... in lib/utils.js to curForward: (step = 1) => { return step ? `\x1b[${step}C` : '' }, and all the curUp:, curDown:, curBack on the same pattern. – mosvy Dec 29 '19 at 15:47
  • I'm assuming that the rest of the code expects that if eg. move_by(1) moves the pointer by 1, then move_by(0) doesn't move it at all. That may not be a given ;-) – mosvy Dec 29 '19 at 15:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.