Visible width of a printed string. ANSI color codes are removed.

    >>> _visible_width('\x1b[31mhello\x1b[0m'), _visible_width("world")
    (5, 5)
343733
def _visible_width(s):
    
    # optional wide-character support
    if wcwidth is not None and WIDE_CHARS_MODE:
        len_fn = wcwidth.wcswidth
    else:
        len_fn = len
    if isinstance(s, _text_type) or isinstance(s, _binary_type):
        return len_fn(_strip_invisible(s))
    else:
        return len_fn(_text_type(s))
1353602
def term_width():
    
    if fcntl and termios:
        try:
            winsize = fcntl.ioctl(0, termios.TIOCGWINSZ, '    ')
            _, width = struct.unpack('hh', winsize)
            return width
        except IOError:
            pass
    elif windll and create_string_buffer:  # pragma: no cover (windows)
        stderr_handle, struct_size = -12, 22
        handle = windll.kernel32.GetStdHandle(stderr_handle)
        csbi = create_string_buffer(struct_size)
        res = windll.kernel32.GetConsoleScreenBufferInfo(handle, csbi)
        if res:
            (_, _, _, _, _, left, _, right, _,
             _, _) = struct.unpack('hhhhHhhhhhh', csbi.raw)
            return right - left + 1
        else:
            return 0
548863
def ansi(color, text):
    """"""
    code = COLOR_CODES[color]
    return '\033[1;{0}m{1}{2}'.format(code, text, RESET_TERM)
1363032
def _visual_width(line):
    """"""

    return len(re.sub(colorama.ansitowin32.AnsiToWin32.ANSI_CSI_RE, "", line))
738580
function getCharWidth(png, x, delimiter) {
  var bottomY = png.height - 1;
  var width = 0;
  // Getting char width from bottom colored line (with delimiter color)
  for(var bottomColor = readPixel(png, x,bottomY); equalsColors(bottomColor,delimiter); bottomColor = readPixel(png,x,bottomY))
  {
    width++;
    x++;
  }

    return width;
}
288280
function getWidth(stringWidth, str) {
	if (!stringWidth || !stringWidth.toLowerCase)
		return str.length;
	switch (stringWidth.toLowerCase()) {
		case "wcwidth":
			return wcwidth(str);
		case "dbcs":
			return dbcswidth(str);
		case "length":
			return str.length;
		default:
			return str.length;
	}
}
443592
def get_width(self, cli, ui_content):
        "  "
        # Take the width from the first line.
        text = token_list_to_text(self.get_prompt_tokens(cli))
        return get_cwidth(text)
432093
def is_printable(c):
    ''''''
    global have_ascii
    if have_ascii:
        return ascii.isprint(c)
    if isinstance(c, int):
        ic = c
    else:
        ic = ord(c)
    return ic >= 32 and ic <= 126
428822
public String getSVGString(int width){
        StringBuffer out = new StringBuffer();

        int x = (int)(point.value(x_dim)*window_size);
        int y = (int)(point.value(y_dim)*window_size);
        int radius = panel_size/2;
        //radius = 1;

        Color c = getColor();

        String color = "rgb("+c.getRed()+","+c.getGreen()+","+c.getBlue()+")";
        double trans = c.getAlpha()/255.0;

        out.append("<circle ");
        out.append("cx='"+x+"' cy='"+y+"' r='"+radius+"'");
        out.append(" stroke='"+color+"' stroke-width='0' fill='"+color+"' fill-opacity='"+trans+"' stroke-opacity='"+trans+"'/>");
        out.append("\n");
        return out.toString();
    }
254327
def _padleft(width, s, has_invisible=True):
    

    def impl(val):
        iwidth = width + len(val) - len(_strip_invisible(val)) if has_invisible else width
        fmt = "{0:>%ds}" % iwidth
        return fmt.format(val)

    num_lines = s.splitlines()
    return len(num_lines) > 1 and '\n'.join(map(impl, num_lines)) or impl(s)
353678
def getWidth(self):
        
        width = 0
        if self.__width:
            width = sum( abs(x) for x in self.__width )
            width = width + len(self.__width) * len(self.__sep) + 1
        return width
375365
def wrap(self, string, width):
        
        if not string or width <= 0:
            logging.error("invalid string: %s or width: %s" % (string, width))
            return False

        tmp = ""
        for line in string.splitlines():
            if len(line) <= width:
                tmp += line + "\n"
                continue

            cur = 0
            length = len(line)
            while cur + width < length:
                cur = line[:cur+width].rfind(self.sep) + len(self.sep) - 1
                line = line[:cur] + "\n" + line[cur+1:]

            tmp += line + "\n\n"

        return tmp
1131526
def string_format(data, out, opts=None, **kwargs):
    '''
    
    '''
    raw_output = try_printout(data, out, opts, **kwargs)
    ansi_escape = re.compile(r'\x1b[^m]*m')
    return ansi_escape.sub('', raw_output)
789531
def example(self) -> str:
        
        if self.rgb_mode:
            colorcode = '\033[38;2;{};{};{}m'.format(*self.rgb)
        else:
            colorcode = '\033[38;5;{}m'.format(self.code)
        return '{code}{s}\033[0m'.format(code=colorcode, s=self)
1115168
def full_line_width(self):
        
        bar_str_len = sum([
            self._indent,
            ((len(self.title) + 1) if self._title_pos in ["left", "right"]
             else 0),  # Title if present
            len(self.start_char),
            self.max_width,  # Progress bar
            len(self.end_char),
            1,  # Space between end_char and amount_complete_str
            len(str(self.max_value)) * 2 + 1  # 100/100
        ])
        return bar_str_len
168896
def char_width(char):
    
    if ord(char) < 128:
        return 1
    elif unicodedata.east_asian_width(char) in ('F', 'W'):
        return 2
    elif unicodedata.category(char) in ('Mn',):
        return 0
    else:
        return 1
945541
public int getWidth(String text) {
        if (vertical)
            return text.length() * 1000;
        int total = 0;
        if (fontSpecific) {
            char cc[] = text.toCharArray();
            int len = cc.length;
            for (int k = 0; k < len; ++k) {
                char c = cc[k];
                if ((c & 0xff00) == 0 || (c & 0xff00) == 0xf000)
                    total += getRawWidth(c & 0xff, null);
            }
        }
        else {
            int len = text.length();
            for (int k = 0; k < len; ++k) {
                if (Utilities.isSurrogatePair(text, k)) {
                    total += getRawWidth(Utilities.convertToUtf32(text, k), encoding);
                    ++k;
                }
                else
                    total += getRawWidth(text.charAt(k), encoding);
            }
        }
        return total;
    }