line(x + textWidth(val), y + 2, x + textWidth(val), y + textAscent() + 2);Having a quick look, my opinion is Processing's text facilties need a bit of love, as you can see here and here (and the commented code as well).
The F2XD renderer seems to handle this a bit better;
Looking at the images, there might be some special unicode characters not properly displayed and the font is variable with.
If you're willing to compromise with a basic proof of concept you could get something off the ground by sticking to a monospaced font such as Courier New: it produces more predictable results (and using FX2D helps):
float x = 5;
float y = 15;
String val = "Hello";
void setup(){
size(300, 60, FX2D);
fill(0, 192, 0);
strokeWeight(3);
textFont(createFont("Courier New", 16));
}
void draw(){
background(0);
text(val, x, y + textAscent());
stroke(0, sin(frameCount * 0.15) * 128, 0);
line(x + textWidth(val), y + 2, x + textWidth(val), y + textAscent() + 2);
}
void keyPressed(){
if(keyCode == DELETE || keyCode == BACKSPACE){
if(val.length() >= 1) val = val.substring(0, val.length() - 1);
}
if(key >= '0' && key <= 'z'){
val += key;
}
if(key == ' '){
val += ' ';
}
}
Another option might be using JavaFX mostly to manually handle text then rendering those text components into Processing's FX2D Canvas.
(This may be more verbose.)