Add 'src/jexer/' from commit 'cf01c92f5809a0732409e280fb0f32f27393618d'
[nikiroo-utils.git] / src / jexer / TPasswordField.java
index 1b78fc8b8db65256bf18b555004c078333da1b98..9c200d7dc7dcfea44a2fef0d3f59f8df9505ec81 100644 (file)
@@ -30,9 +30,11 @@ package jexer;
 
 import jexer.bits.CellAttributes;
 import jexer.bits.GraphicsChars;
+import jexer.bits.StringUtils;
 
 /**
- * TField implements an editable text field.
+ * TPasswordField implements an editable text field that displays
+ * stars/asterisks when it is not active.
  */
 public class TPasswordField extends TField {
 
@@ -111,15 +113,16 @@ public class TPasswordField extends TField {
         }
 
         int end = windowStart + getWidth();
-        if (end > text.length()) {
-            end = text.length();
+        if (end > StringUtils.width(text)) {
+            end = StringUtils.width(text);
         }
 
         hLineXY(0, 0, getWidth(), backgroundChar, fieldColor);
         if (showStars) {
             hLineXY(0, 0, getWidth() - 2, '*', fieldColor);
         } else {
-            putStringXY(0, 0, text.substring(windowStart, end), fieldColor);
+            putStringXY(0, 0, text.substring(screenToTextPosition(windowStart),
+                    screenToTextPosition(end)), fieldColor);
         }
 
         // Fix the cursor, it will be rendered by TApplication.drawAll().